react-native-reanimated icon indicating copy to clipboard operation
react-native-reanimated copied to clipboard

[Reanimated] Duplicate shared tag "itemID" on the same screen

Open sezaiufuk opened this issue 3 years ago • 32 comments

Description

I have FlatList items listed on my screen on my React Native app, each item gets a sharedTransitionTag with their own IDs for uniqueness, but on re-render I get this warning on console:

[Reanimated] Duplicate shared tag "itemID" on the same screen

It does not throw an error just warning but later it causes app to crash both on IOS and Android, next transition attempt gets buggy, item gets stuck on middle of the screen above everything or directly disappears, few seconds later app gets crash, what should I do ?

  • I am switching between screens for the transition, chat title and avatar is getting placed on top of dialog screen with shared transition, if I do not re-render with ctrl+s via vs code I have no problem for a while.

Steps to reproduce

  1. FlatList Items Rendered with their own sharedTransitionTags
  2. Rerendered Component
  3. Got crash

Snack or a link to a repository

Reanimated version

3.4.2

React Native version

0.71.6

Platforms

Android, iOS

JavaScript runtime

Hermes

Workflow

None

Architecture

None

Build type

None

Device

None

Device model

No response

Acknowledgements

Yes

sezaiufuk avatar Aug 25 '23 05:08 sezaiufuk

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

github-actions[bot] avatar Aug 25 '23 05:08 github-actions[bot]

Hey! 👋

It looks like you've omitted a few important sections from the issue template.

Please complete Snack or a link to a repository section.

github-actions[bot] avatar Aug 25 '23 05:08 github-actions[bot]

Hi @ufukdev34, Shared Element Transitions are not working properly with hot-reloads (e.g. saving in VS Code as you mentioned) at the moment. Best way to develop your code is to leave the screen that contains Shared Element Tags do the hot-reload and then go to it again.

tjzel avatar Aug 25 '23 09:08 tjzel

Since this is probably a hot-reload issue I'm adding label "Close when stale"

Latropos avatar Aug 28 '23 14:08 Latropos

I'm experiencing the same issue while using the Shared Element transition example.

    "@react-navigation/native": "^6.1.7",
    "@react-navigation/native-stack": "^6.9.13",
    "react-native": "0.72.4",
    "react-native-reanimated": "^3.4.2",

Transition doesn't work, and Reanimated presents this warning:

 WARN  [Reanimated] Duplicate shared tag "sharedTag" on the same screen

It doesn't matter if it's a hot reload, a fresh metro instance, or even a rebuilt app.

lukebars avatar Sep 09 '23 08:09 lukebars

@lukebars I am facing the same issue!

OsaedYahyaCoretava avatar Sep 09 '23 16:09 OsaedYahyaCoretava

Hi @lukebars and @OsaedYahyaCoretava. I just tested it on Shared Element Transition example with the nightly version and didn't get any warnings.

tjzel avatar Sep 11 '23 06:09 tjzel

I'm experiencing this issue as well, when i tried to do conditional rendering for items in animated flatlist. Here is some of my code:

//*******
const DocketOrdersMainScreen = ({navigation}: Props) => {
  const {THEME_COLOR} = useDOXLETheme();
  const {
    ordersList,
    isFetchingOrderList,
    isSuccessFetchingOrderList,
    isErrorFetchingOrderList,
  } = useGetDocketOrderList({});
  const {selectedOrderStatus} = useOrderStore(
    state => ({
      selectedOrderStatus: state.selectedOrderStatus,
    }),
    shallow,
  );
  //* render list

  const renderItem = useCallback(
    (props: {item: Order; index: number}) =>
      Boolean(
        selectedOrderStatus &&
          selectedOrderStatus.statusId === props.item.status,
      ) ? (
        <OrderItem orderItem={props.item} />
      ) : null,
    [selectedOrderStatus],
  );

  const keyExtractor = useCallback(
    (item: Order, index: number) => item.orderId,
    [],
  );
  const layoutList = Layout.springify().damping(16);
return (
  {isSuccessFetchingOrderList && (
          <Animated.FlatList
            style={{flex: 1}}
            contentContainerStyle={{flexGrow: 1}}
            ListEmptyComponent={
              <DoxleEmptyPlaceholder
                headTitleText="No Orders!"
                subTitleText="Add more items to manage your work..."
                wrapperStyle={{paddingBottom: 42}}
              />
            }
            keyExtractor={keyExtractor}
            itemLayoutAnimation={layoutList}
            data={ordersList}
            extraData={selectedOrderStatus}
            renderItem={renderItem}
            initialNumToRender={14}
            maxToRenderPerBatch={4}
            updateCellsBatchingPeriod={400}
            ListFooterComponent={<OrderListFooter />}
            automaticallyAdjustContentInsets
            automaticallyAdjustKeyboardInsets
            keyboardDismissMode="interactive"
            keyboardShouldPersistTaps="handled"
            showsVerticalScrollIndicator={false}
          />
        )}
</StyledDocketOrdersMainScreen>
  );
  
  //********

basically when the list items get mounted again, this warning show

Pipi144 avatar Sep 14 '23 02:09 Pipi144

And sometimes i also experienced the transition animation remains on the screen, even though i do a reload in flipper, the transition will still be there until i quit the app and open

Pipi144 avatar Sep 14 '23 02:09 Pipi144

it's n not working at all...

i just created fresh new app to test this feature, with newest versions of reanimated, navigation, screens etc...

and with the example usage code but seems like did not work at all..

    "@react-navigation/native": "^6.1.8",
    "@react-navigation/native-stack": "^6.9.14",
    "@react-navigation/stack": "^6.3.18",
    "react": "18.2.0",
    "react-native": "0.72.5",
    "react-native-gesture-handler": "^2.13.1",
    "react-native-reanimated": "^3.5.4",
    "react-native-safe-area-context": "^4.7.2",
    "react-native-screens": "^3.25.0"

Bayramito avatar Sep 29 '23 15:09 Bayramito

After so many hours, I noticed that in my case it was related to the Expo + Firebase setup and the following expo plugin:

[
  "expo-build-properties",
  {
    "ios": {
      "useFrameworks": "static"
    }
  }
]

I cannot just remove it because it's a required step to make Firebase Auth to work as described in https://rnfirebase.io/#expo-managed-workflow.

If I completely remove firebase and all firebase related plugins from the project, the shared transitions just works and the warn "Duplicate shared tag "itemID" on the same screen" was solved.

diego-rangel avatar Sep 30 '23 00:09 diego-rangel

@diego-rangel Yeah, just realized that it has stopped working since I used use_frameworks! :linkage => :static in my Podfile. And it is a mandatory step of Firebase installation

AlirezaHadjar avatar Sep 30 '23 11:09 AlirezaHadjar

I’ve even tried changing my auth provider to another one who provides native integration via dev client and does not require this step like auth0 but I had no lucky, the shared transition again stops working

diego-rangel avatar Sep 30 '23 13:09 diego-rangel

I'm also using use_frameworks! linkage: :static, so this must be the culprit

lukebars avatar Sep 30 '23 13:09 lukebars

Anyone has any idea? I'd really love to have them both working together

diego-rangel avatar Oct 04 '23 16:10 diego-rangel

+1 same here

Bayramito avatar Oct 09 '23 14:10 Bayramito

Following the solution posted: https://github.com/software-mansion/react-native-reanimated/issues/4425. I believe you can setup the following plugin:

app.plugin.js

const plugins = require('@expo/config-plugins');
const generateCode = require('@expo/config-plugins/build/utils/generateCode');
const fs = require('fs');
const path = require('path');
const data = `
  $static_framework = ['RNScreens']

  pre_install do |installer|
    Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
    installer.pod_targets.each do |pod|
      if $static_framework.include?(pod.name)
        def pod.build_type;
          Pod::BuildType.static_library
        end
      end
    end
  end
`;
const withStaticRNScreen = config => {
  return plugins.withDangerousMod(config, [
    'ios',
    async config => {
      const filePath = path.join(config.modRequest.platformProjectRoot, 'Podfile');
      const contents = fs.readFileSync(filePath, 'utf-8');
      const mergeResults = generateCode.mergeContents({
        tag: 'static-rnscreen',
        src: contents,
        newSrc: data,
        anchor: /post_install\sdo\s\|installer\|/,
        offset: 0,
        comment: '#',
      });
      if (!mergeResults.didMerge) {
        console.log(
          "ERROR: Cannot add the fix for the RNScreens to the project's ios/Podfile because it's malformed. Please report this with a copy of your project Podfile.",
        );
        return config;
      }
      fs.writeFileSync(filePath, mergeResults.contents);
      return config;
    },
  ]);
};
exports.default = withStaticRNScreen;

And use in your app.config.js/app.json

...
  "plugins": [
    ...
    './app.plugin',
    ...
  ]
...

bruno-de-queiroz avatar Oct 10 '23 21:10 bruno-de-queiroz

In my case using the plugin proposed by @bruno-de-queiroz solved the warning "Duplicate shared tag XXX on the same screen" but the shared transition animation still doesn't work

diego-rangel avatar Oct 12 '23 15:10 diego-rangel

Hi @diego-rangel, here are some versions I'm using:

    "react-native-reanimated": "~3.3.0",
    "react-native-screens": "~3.22.0",
    "react-native": "0.72.5",
    "expo": "^49.0.13",
    "expo-router": "2.0.9",
    "@react-native-firebase/app": "^18.5.0",
    "@react-native-firebase/auth": "^18.5.0",

With those, it works just as normally as before.

bruno-de-queiroz avatar Oct 12 '23 20:10 bruno-de-queiroz

add this to your Podfile, pod update , re-build please


target 'xProject' do
// 
  $static_framework += [
    'RNScreens'
  ]

  pre_install do |installer|

    Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
      installer.pod_targets.each do |pod|
        if $static_framework.include?(pod.name)
          def pod.build_type;
          Pod::BuildType.static_library # >= 1.9
        end
      end
    end
  end

end

Bayramito avatar Oct 12 '23 20:10 Bayramito