use*_*734 2 react-native react-navigation react-navigation-stack
如何在 React-native 中为 Stacked Screes 添加过渡效果?
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerShown: false,
}}
>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Stocks" component={StocksScreen} />
</Stack.Navigator>
</NavigationContainer>
Run Code Online (Sandbox Code Playgroud)
是否有实现淡入/淡出效果的默认方法?
Vad*_*sky 11
最简单的实现淡入淡出效果的方法:
const forFade = ({ current }) => ({
cardStyle: {
opacity: current.progress,
},
});
Run Code Online (Sandbox Code Playgroud)
如果要为整个导航器应用淡入淡出效果:
<Stack.Navigator
screenOptions={{
headerShown: false,
cardStyleInterpolator: forFade,
}}>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Stocks" component={StocksScreen} />
</Stack.Navigator>
Run Code Online (Sandbox Code Playgroud)
您也可以cardStyleInterpolator通过设置选项申请单屏:
<Stack.Screen
name="Home"
component={HomeScreen}
options={{ cardStyleInterpolator: forFade }}/>
Run Code Online (Sandbox Code Playgroud)
您可以自定义forFade函数以实现其他效果,也可以使用一些预制的插值器,例如:
import { CardStyleInterpolators } from '@react-navigation/stack';
<Stack.Screen
name="Profile"
component={Profile}
options={{
cardStyleInterpolator: CardStyleInterpolators.forFadeFromBottomAndroid,
}}
/>;
Run Code Online (Sandbox Code Playgroud)
更多信息在这里:https : //reactnavigation.org/docs/stack-navigator/#animations
对于 React Navigation 6.xx,您可以使用动画选项:
<Stack.Screen
name="Profile"
component={Profile}
options={{ animation: 'fade' }}
/>
Run Code Online (Sandbox Code Playgroud)
支持的值:
| 归档时间: |
|
| 查看次数: |
4133 次 |
| 最近记录: |