[英]react-native-router-flux: implement animation in scene transition in react-native-router-flux
我一直在使用react-native-router-flux在我的React本机应用程序中使用默认场景更改样式。 但是我试图在两个页面之间的场景转换中使用不同的动画效果。 我们该怎么做?
为此,您需要实现自己的动画样式功能, 路由器的DefaultRenderer包含动画代码-如果从复制动画开始,您会发现可以更改每个场景的位置,比例和不透明度。
需要一些练习才能获得想要的效果,但是有用的行是:
const inputRange = [index - 1, index, index + 1]
可以将其传递给interpolate
以生成转换,例如:
let opacity = position.interpolate({
inputRange,
outputRange: [0, 1, 0.5]
})
告诉现场:
这种简单的结构使您可以定义所有类型的效果。
获得功能后,您可以满意的在定义路由器时指定它:
<RouterWithRedux
scenes={scenes}
animationStyle={myAnimationStyle}
/>
您可以这样设置自定义过渡效果:
////other imports import StackViewStyleInterpolator from 'react-navigation-stack'; 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 }, // ], // }; } }); <Router> <Scene key='main' hideNavBar transitionConfig={transitionConfig} > ...more scenes </Scene> </Router>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.