Skip to content

Custom animations for scenes (disabling transition animation) #2042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ywongweb opened this issue Jul 16, 2017 · 10 comments
Closed

Custom animations for scenes (disabling transition animation) #2042

ywongweb opened this issue Jul 16, 2017 · 10 comments

Comments

@ywongweb
Copy link
Contributor

ywongweb commented Jul 16, 2017

In v3 we can use duration={0} to diable the transition aimation. V4 no longer has the duration prop and the doc suggest we should implement custom navigator now instead and pass it as ‘navigator’ prop. Being not familiar with React Navigation, I was wondering if anyone have an example on how to do this?

Thanks 👍

@aksonov
Copy link
Owner

aksonov commented Jul 16, 2017

Very good question. Probably we will implement some workaround soon if ReactNavigation doesn't allow it. What is your use case? You could try to use 'tabs' with tabbar hidden to avoid animation or you could try type 'reset' (check Example/Register UI, or it doesn't allow animation too?)

Check related issue:
react-navigation/react-navigation#175

@ywongweb
Copy link
Contributor Author

ywongweb commented Jul 17, 2017

@aksonov Thanks for the link, I will check it out.

My use case is that my app has a static background image that doesn't change or move when you navigate between screens.

In V3 this was achieved by wrapping the Router component with an Image and setting a transpararent background for every scene. Because the default visual effect for transition is to slide in the new scene while fading out the old one, having a duration means that we can see both scenes durings parts of the transition.

In the past I have tried using 'reset' as an alternative and it mostly worked, but I had to manually implement every scene's back behaviour, this can get out of hand very quickly.

@aksonov
Copy link
Owner

aksonov commented Jul 17, 2017

@ywongweb Maybe you could implement own custom navigator for your use case - probably you could just copy & past StackNavigator and remove transitions from there. I will also investigate how to solve this problem...

@aksonov
Copy link
Owner

aksonov commented Jul 17, 2017

Looks like we could add this functionality to RNRF using transitionConfig
react-navigation/react-navigation#1490

PR is welcome!

@aksonov
Copy link
Owner

aksonov commented Jul 17, 2017

@alexwasner
Copy link

@aksonov I created a simple PR for adding transitionConfig to the Navigator. #2062

@JoshStaff
Copy link

Did this get resolved? Interested in contributing to this.

@aksonov aksonov marked this as a duplicate of #2135 Jul 29, 2017
@aksonov aksonov mentioned this issue Jul 29, 2017
@aksonov
Copy link
Owner

aksonov commented Aug 16, 2017

@JoshStaff Feel free to submit PR

@aksonov aksonov changed the title Disable transition animation Custom animations for scenes (disabling transition animation) Aug 16, 2017
@aksonov
Copy link
Owner

aksonov commented Aug 21, 2017

Okey, closing this ticket for now. As I found nice workaround by passing transitionConfig for needed container - this way you can create very customisable transitions:
react-navigation/react-navigation#1759

Also I will add duration support using the trick from react-navigation/react-navigation#1254

P.S. I've just updated Example to make 'Login' animation as standard android 'fade' animation.

@aksonov aksonov closed this as completed Aug 21, 2017
@ajaykumar97
Copy link

You an use your custom transition effects like as follow:

import StackViewStyleInterpolator from 'react-navigation-stack';

<Scene
key='main'
hideNavBar
transitionConfig={transitionConfig}
>

...more scenes

</Scene>

const MyTransitionSpec = ({
    duration: 1000,
    // easing: Easing.bezier(0.2833, 0.99, 0.31833, 0.99),
    // timing: Animated.timing,
});

const transitionConfig = () => ({
    transitionSpec: MyTransitionSpec,
    // screenInterpolator: StackViewStyleInterpolator.forFadeFromBottomAndroid,
    screenInterpolator: sceneProps => {
        const { layout, position, scene } = sceneProps;
        const { index } = scene;
        const width = layout.initWidth;

        //right to left by replacing bottom scene
        // return {
        //     transform: [{
        //         translateX: position.interpolate({
        //             inputRange: [index - 1, index, index + 1],
        //             outputRange: [width, 0, -width],
        //         }),
        //     }]
        // };

        const inputRange = [index - 1, index, index + 1];

        const opacity = position.interpolate({
            inputRange,
            outputRange: ([0, 1, 0]),
        });

        const translateX = position.interpolate({
            inputRange,
            outputRange: ([width, 0, 0]),
        });

        return {
            opacity,
            transform: [
                { translateX }
            ],
        };

        //from center to corners
        // const inputRange = [index - 1, index, index + 1];
        // const opacity = position.interpolate({
        //     inputRange,
        //     outputRange: [0.8, 1, 1],
        // });

        // const scaleY = position.interpolate({
        //     inputRange,
        //     outputRange: ([0.8, 1, 1]),
        // });

        // return {
        //     opacity,
        //     transform: [
        //         { scaleY }
        //     ]
        // };
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants