react-navigation-shared-element icon indicating copy to clipboard operation
react-navigation-shared-element copied to clipboard

encounter blink effect when navigate screens

Open chj-damon opened this issue 2 years ago • 9 comments

Thanks for this amazing library to help improve user experience especially after upgrade to the latest version. But I also encountered some trouble when using it on android.

issue 1: when I navigate from ListScreen to DetailScreen, if the image is half on screen, then it will blink. issue 2: when I navigate back from DetailScreen to ListScreen, it will blink and I can clearly see there's a blank area goes from left to right.

here is the reproduce repository: sharedElementExample

thank you very much.

chj-damon avatar Jan 12 '22 07:01 chj-damon

https://user-images.githubusercontent.com/4902684/149084186-ab7171c8-82a6-41bd-b90a-dcaae2f573cd.mp4

chj-damon avatar Jan 12 '22 07:01 chj-damon

Navigator:

<Navigator initialRouteName="List" screenOptions={commonStackOptions}>
      <Screen name="List" component={ListScreen} options={{ headerShown: false }} />
      <Screen
        name="Detail"
        component={DetailScreen}
        options={{ headerShown: false }}
        sharedElements={route => {
          const { item } = route.params;
          return [`item.${item.id}.photo`];
        }}
      />
    </Navigator>

ListScreen:

export default function ListScreen() {
  const navigation = useNavigation<StackNavigationProp<any>>();

  const renderItem = ({ item }: any) => {
    return (
      <TouchableOpacity activeOpacity={1} onPress={() => navigation.push('Detail', { item })}>
        <SharedElement id={`item.${item.id}.photo`}>
          <Image source={item.image} style={styles.image} />
        </SharedElement>
      </TouchableOpacity>
    );
  };

  return <FlatList style={styles.container} data={items} renderItem={renderItem} keyExtractor={item => item.id} />;
}

DetailScreen:

export default function DetailScreen() {
  const navigation = useNavigation();
  const route = useRoute();
  const { item } = route.params as any;
  return (
    <TouchableOpacity activeOpacity={1} onPress={navigation.goBack}>
      <SharedElement id={`item.${item.id}.photo`}>
        <Image source={item.image} style={styles.image} />
      </SharedElement>
    </TouchableOpacity>
  );
}

chj-damon avatar Jan 12 '22 07:01 chj-damon

https://user-images.githubusercontent.com/4902684/149093957-06034fa7-0056-4c33-9bea-469c2e82bbf4.mp4

chj-damon avatar Jan 12 '22 08:01 chj-damon

issue 1 does not exist on ios issue 2 still exists on ios

chj-damon avatar Jan 12 '22 08:01 chj-damon

Same problem

tharyckgusmao avatar Mar 10 '22 03:03 tharyckgusmao

I think that the problem is relative to the position of the element in the prev and next screen, but I don't know why.

I've a working example where if the element in the next screen is positioned lower than the element in the previous screen, then the blink doesn't happen.

Even for me the problem is only on Android.

pietroanello avatar Mar 25 '22 20:03 pietroanello

try cardStyle: {backgroundColor: 'transparent'}, cardStyleInterpolator: ({current: {progress}}) => ({ gestureEnabled: false, cardStyle: {opacity: progress}, }),

on Stack.Navigator.screenOptions or Stack.Screen.options

dirmich avatar May 26 '22 05:05 dirmich

try cardStyle: {backgroundColor: 'transparent'}, cardStyleInterpolator: ({current: {progress}}) => ({ gestureEnabled: false, cardStyle: {opacity: progress}, }),

on Stack.Navigator.screenOptions or Stack.Screen.options

tried, not working. it still blinks...

chj-damon avatar May 26 '22 08:05 chj-damon

This is also happening to me, it's kind of frustrating, as it loses all the smoothness.

It would be really nice if someone come up with a solution for this.

CCPablo avatar Oct 14 '22 16:10 CCPablo