Skip to content
This repository was archived by the owner on Dec 2, 2021. It is now read-only.

A simple app that demonstrates how to use react-navigation-shared-element in react-native

Notifications You must be signed in to change notification settings

IjzerenHein/react-navigation-shared-element-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ab0bf47 · Dec 1, 2021

History

28 Commits
Sep 2, 2019
Jan 16, 2020
May 25, 2020
May 25, 2020
Sep 2, 2019
Sep 2, 2019
Jan 16, 2020
Sep 2, 2019
Sep 2, 2019
Sep 2, 2019
Sep 2, 2019
Dec 1, 2021
Sep 2, 2019
Sep 2, 2019
May 25, 2020
Sep 2, 2019
May 25, 2020
Sep 3, 2019
May 25, 2020

Repository files navigation

THIS REPOSITORY IS NO LONGER MAINTAINED

For demo's and examples see the example app in react-navigation-shared-element.

react-navigation-shared-element-demo

A simple app that demonstrates how to use react-native-shared-element and React Navigation binding in react-native.

MagicMoveGif

Usage

# Installation
yarn install
cd ios && pod install && cd ..

# Run on iOS
npx react-native run-ios

# Run on Android
npx react-native run-android

Example code

Appv4.js

import {createAppContainer} from 'react-navigation';
import {createSharedElementStackNavigator4} from 'react-navigation-shared-element';
import {enableScreens} from 'react-native-screens';
import {MainScreen} from './MainScreen';
import {DetailScreen} from './DetailScreen';
import {springyFadeIn} from './transitions';

enableScreens();

// Instead of calling `createStackNavigator`, wrap it using `createSharedElementStackNavigator`
const StackNavigator = createSharedElementStackNavigator4(
  {
    Main: MainScreen,
    Detail: DetailScreen,
  },
  {
    transitionConfig: () => springyFadeIn(),
  },
);

export default createAppContainer(StackNavigator);

Main.js

import * as React from 'react';
import {View, StyleSheet, Text, TouchableOpacity, Image} from 'react-native';
import {SharedElement} from 'react-navigation-shared-element';
import TouchableScale from 'react-native-touchable-scale';

const styles = StyleSheet.create({});

export class MainScreen extends React.Component {
  render() {
    // Wrap the component that you want to transition in <SharedElement>
    return (
      <TouchableScale
        style={styles.flex}
        activeScale={0.9}
        tension={50}
        friction={7}
        useNativeDriver
        onPress={this.onPress}>
        <View style={styles.container}>
          <SharedElement id="image">
            <Image style={styles.image} source={require('./theboys.jpg')} />
          </SharedElement>
          <SharedElement id="text">
            <Text style={styles.text}>The Boys</Text>
          </SharedElement>
          <Text style={styles.caption}>tap me</Text>
        </View>
      </TouchableScale>
    );
  }

  onPress = () => {
    this.props.navigation.navigate('Detail');
  };
}

Detail.js

import * as React from 'react';
import {View, StyleSheet, Text, Image} from 'react-native';
import {SharedElement} from 'react-navigation-shared-element';

const styles = StyleSheet.create({});

export const DetailScreen = ({navigation}) => (
  <View style={styles.container}>
    <SharedElement id="image" style={StyleSheet.absoluteFill}>
      <Image
        style={styles.image}
        resizeMode="cover"
        source={require('./theboys.jpg')}
      />
    </SharedElement>
    <SharedElement id="text">
      <Text style={styles.text}>The Boys</Text>
    </SharedElement>
  </View>
);

// Add the `sharedElements` function to the component, which
// should return a list of shared-elements to transition.
// The `sharedElements` function is called whenever you navigate
// to or from this screen. You can use the provided navigation
// states or trigger or disable animations.
DetailScreen.sharedElements = (route, otherRoute, showing) => [
  {id: 'image'},
  {id: 'text', animation: 'fade'},
];

About

A simple app that demonstrates how to use react-navigation-shared-element in react-native

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published