Skip to content

Instantly share code, notes, and snippets.

@wachunei
Last active December 12, 2019 06:01
Show Gist options
  • Save wachunei/79a576f9a80f135274c396d8d98e2f51 to your computer and use it in GitHub Desktop.
Save wachunei/79a576f9a80f135274c396d8d98e2f51 to your computer and use it in GitHub Desktop.

Revisions

  1. wachunei revised this gist Feb 14, 2018. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion AnimatedGate.jsx
    Original file line number Diff line number Diff line change
    @@ -109,7 +109,6 @@ const styles = {
    backgroundColor: 'transparent',
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'transparent',
    },
    logo: {
    width: 62,
  2. wachunei revised this gist Feb 14, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion AnimatedGate.jsx
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ class AnimatedGate extends Component {
    toValue: 100,
    duration,
    easing: Easing.bezier(0.42, 0, 0.42, 1),
    }).start(() => this.setState({ displayed: false }));
    }).start();
    }

    render() {
  3. wachunei revised this gist Feb 13, 2018. No changes.
  4. wachunei revised this gist Feb 13, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions _DEMO.md
    Original file line number Diff line number Diff line change
    @@ -2,3 +2,4 @@

    Demo is included in [this tweet](https://twitter.com/wachunei/status/963536535479115778)

    ![](https://media.giphy.com/media/xUOwG3sy6yGYbJFtTi/giphy.gif)
  5. wachunei renamed this gist Feb 13, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. wachunei created this gist Feb 13, 2018.
    120 changes: 120 additions & 0 deletions AnimatedGate.jsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,120 @@
    import React, { Component } from 'react';
    import { Animated, Easing, StatusBar, MaskedViewIOS, View } from 'react-native';

    class AnimatedGate extends Component {
    constructor(props) {
    super(props);
    this.beginAnimation = this.beginAnimation.bind(this);
    this.state = {
    animation: new Animated.Value(0),
    };
    }

    componentDidMount() {
    StatusBar.setHidden(true);
    }

    componentWillReceiveProps(nextProps) {
    if (!this.props.bootstraped && nextProps.bootstraped) {
    setTimeout(() => this.beginAnimation(), 1000);
    }
    }

    beginAnimation() {
    const duration = 1300;
    setTimeout(() => StatusBar.setHidden(false, 'fade'), 0.6 * duration);
    Animated.timing(this.state.animation, {
    toValue: 100,
    duration,
    easing: Easing.bezier(0.42, 0, 0.42, 1),
    }).start(() => this.setState({ displayed: false }));
    }

    render() {
    const { animation } = this.state;

    const opacity = animation.interpolate({
    inputRange: [0, 30, 70],
    outputRange: [0, 0, 1],
    extrapolate: 'clamp',
    });

    const MainApp = (
    <View style={styles.mainContainer}>
    <Animated.View
    style={{
    flex: 1,
    opacity,
    transform: [
    {
    scale: animation.interpolate({
    inputRange: [0, 50, 100],
    outputRange: [1.05, 1.05, 1],
    }),
    },
    ],
    }}
    >
    {this.props.children}
    </Animated.View>
    </View>
    );

    const MaskElement = (
    <View style={styles.maskElementContainer}>
    <Animated.Image
    source={require('./twitter_logo.png')}
    style={[
    styles.logo,
    {
    transform: [
    {
    scale: animation.interpolate({
    inputRange: [0, 30, 100],
    outputRange: [1, 0.8, 40],
    extrapolate: 'clamp',
    }),
    },
    ],
    },
    ]}
    />
    </View>
    );

    return (
    <View style={styles.gateContainer}>
    <MaskedViewIOS style={styles.maskedView} maskElement={MaskElement}>
    {MainApp}
    </MaskedViewIOS>
    </View>
    );
    }
    }

    const styles = {
    gateContainer: {
    flex: 1,
    backgroundColor: 'rgb(29, 161, 242)',
    },
    mainContainer: {
    flex: 1,
    backgroundColor: 'white',
    },
    maskedView: {
    flex: 1,
    },
    maskElementContainer: {
    flex: 1,
    backgroundColor: 'transparent',
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'transparent',
    },
    logo: {
    width: 62,
    height: 62,
    },
    };

    export default AnimatedGate;
    28 changes: 28 additions & 0 deletions App.jsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # App is a regular redux app, but PersistGate
    # takes a function as a child component.
    # (see https://github.com/rt2zz/redux-persist/pull/718)

    import React, { Component } from 'react';
    import { Provider } from 'react-redux';
    import { PersistGate } from 'redux-persist/src/integration/react';
    import Main from './Main';
    import AnimatedGate from './AnimatedGate';

    import configureStore from './configureStore';
    const { store, persistor } = configureStore();

    export default class App extends Component {
    render() {
    return (
    <Provider store={store}>
    <PersistGate persistor={persistor}>
    {bootstraped => (
    <AnimatedGate bootstraped={bootstraped}>
    <Main />
    </AnimatedGate>
    )}
    </PersistGate>
    </Provider>
    );
    }
    }
    4 changes: 4 additions & 0 deletions DEMO.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    # Demo

    Demo is included in [this tweet](https://twitter.com/wachunei/status/963536535479115778)

    27 changes: 27 additions & 0 deletions Main.jsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    # Twitter UI mockup (is an image)
    import React from 'react';
    import { View, Image, StatusBar } from 'react-native';

    const Main = () => (
    <View style={styles.container}>
    <StatusBar barStyle="light-content" />
    <Image
    source={require('./twitterimage.jpeg')}
    style={styles.image}
    resizeMode="contain"
    />
    </View>
    );

    const styles = {
    container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    },
    image: {
    flex: 1,
    },
    };

    export default Main;