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

Support for Rotated elements

Open josh0707 opened this issue 4 years ago • 8 comments

Hi, Thank you for this library and the React Navigation binding.

Currently the library supports transition when element was scaled. Could it also support transition when element was rotated ?

Current behavior: The element jumps from a rotated position to the next position without any transition.

Expected behavior: During the transition, the element rotates to its new position, then on back button pressed, the element rotates back to its previous position.

Example:

// Main Screen

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#C14534',
  },
  paper: {
    backgroundColor: '#EC806E',
    position: 'absolute',
    left: 10,
    top: Dimensions.get('window').height * 0.5 - 150,
    width: Dimensions.get('window').width * 0.65,
    height: Dimensions.get('window').height * 0.45,

    transform: [{ rotate: '-20deg' }],

    shadowColor: '#000',
    shadowRadius: 5,
    shadowOffset: { width: 0, height: 5 },
    shadowOpacity: 0.4,
  },
});

export const MainScreen = (props: IMainProps) => {
  return(
    <TouchableOpacity activeOpacity={1} style={styles.container}  
      onPress={()=> props.navigation.navigate('Details')}>

      <SharedElement id='paper' style={styles.paper}>
        <View />
      </SharedElement >

    </TouchableOpacity>
  );
}

// Details Screen

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#C14534',
  },
  paper: {
    backgroundColor: '#FFFFFF',
    position: 'absolute',
    left: 0,
    top: Dimensions.get('window').height * 0.5,
    bottom: 0,
    right: 0,
    alignItems: 'center',
    justifyContent: 'flex-start',
    paddingTop: 70,
    padding: 10,
  },
});

export const DetailsScreen = (props: IMainProps) => {
  return (
    <TouchableOpacity activeOpacity={1} style={styles.container} 
      onPress={()=> props.navigation.goBack()}>

      <SharedElement id='paper' style={styles.paper}>
        <View />
      </SharedElement >

    </TouchableOpacity>
  );
}

josh0707 avatar Mar 30 '20 12:03 josh0707

Hi, can you share a Video demonstrating the problem?

IjzerenHein avatar Mar 30 '20 12:03 IjzerenHein

slow-demo

As you can see, the shared elements scale but don't rotate to their new position.

josh0707 avatar Mar 30 '20 13:03 josh0707

Here is the expected result: expected

josh0707 avatar Mar 30 '20 13:03 josh0707

Yup I'm seeing it. This one will be a bit tricky to implement. Will try to take it into consideration for the next update.

IjzerenHein avatar Mar 30 '20 13:03 IjzerenHein

@josh0707 I trying to do this same approach here. Is there any way to just add that right now?

GIF-TRYING-TO-ROTATE

Jojr avatar Apr 08 '20 19:04 Jojr

@IjzerenHein would love to see this as an enhancement for transitioning shared elements that rotate at the destination. Thanks for the library so far!

amak07 avatar Apr 22 '20 03:04 amak07

Same here!

jp928 avatar Oct 08 '21 04:10 jp928

As a workaround, I am using when detail screen enters in

useFocusEffect(
  React.useCallback(() => {
    const task = InteractionManager.runAfterInteractions(() => {
      // rotate animation
    });

    return () => task.cancel();
  }, [])
);

and

React.useEffect(() => {
    const unsubscribe = navigation.addListener('beforeRemove', (data) => {
      // rotate animation
    });

    return unsubscribe;
  }, [navigation]);

when detail screen moves out

jp928 avatar Oct 08 '21 05:10 jp928