首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react-native-router-flux场景间导航方向

react-native-router-flux场景间导航方向
EN

Stack Overflow用户
提问于 2018-10-07 18:25:33
回答 1查看 947关注 0票数 0

版本: react-native-router-flux: v4.0.5,react: v16.4.2,react-native: v0.56.0

我有一种在场景之间导航的情况,如下所示:

场景A(参数: xA) ->场景B(参数: xB) ->场景A(参数: yA) ->场景B(参数: yB)

这是一种循环。我也应该能够返回到上一个场景与后退按钮在NavBar中。

问题来自于动画的方向。通常是从右到左。但是,当从场景B(参数: xB)转到场景A(参数: yA)时,方向是从左到右的(感觉像是轻敲后退按钮)。我希望这是从右到左的法线方向。

有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2018-11-04 18:27:21

您可以使用您的自定义过渡效果,如下所示,并根据需要进行修改:

代码语言:javascript
复制
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 }
            //     ]
            // };
        }
    });

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52687579

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档