react native navigation shared element code example
Example 1: react native navigation shared element
import { createSharedElementStackNavigator } from 'react-navigation-shared-element';
const stackNavigator = createSharedElementStackNavigator(
{
List: ListScreen,
Detail: DetailScreen,
},
{
initialRouteName: 'List',
}
);
const AppContainer = createAppContainer(stackNavigator);
Example 2: react native navigation shared element
// DetailScreen.js
const DetailScreen = (props) => {
const item = props.navigation.getParam('item');
return (
);
};
DetailScreen.sharedElements = (navigation, otherNavigation, showing) => {
const item = navigation.getParam('item');
return [`item.${item.id}.photo`];
};
Example 3: react native navigation shared element
// ListScreen.js
import { SharedElement } from 'react-navigation-shared-element';
class ListScreen extends React.Component {
renderItem(item) {
const { navigation } = this.props;
return (
navigation.push('Detail', { item })}>
);
}
}