Dyo*_*obi 4 react-native react-navigation
只想使地图组件滑动禁用,但在使用“swipeEnabled”时应用了整个屏幕。
我能怎么做?
const Tab = createMaterialTopTabNavigator();
const Tabs = () => {
return (
<Tab.Navigator
swipeEnabled={false} // <- Screens can be swiped but it is applied to every screen.
{...}
>
<Tab.Screen
name="Home"
component={Home}
/>
<Tab.Screen
name="Map"
component={Map}
/>
</Tab.Navigator>
);
}
const App = () => {
return (
<NavigationContainer>
<SafeAreaView style={styles.safeAreaView} />
<Tabs />
</NavigationContainer>
);
}
Run Code Online (Sandbox Code Playgroud)
如果您在屏幕上,则可以将状态值传递给swipeEnabled并将该值更新为:falseMap
const Tab = createMaterialTopTabNavigator();
const Tabs = () => {
const [swipeEnabled, setSwipeEnabled] = useState(true);
return (
<NavigationContainer>
<Tab.Navigator
swipeEnabled={swipeEnabled}
screenOptions={({ navigation, route }) => {
if (route.name === 'Map' && navigation.isFocused()) {
setSwipeEnabled(false);
} else if (route.name !== 'Map' && navigation.isFocused()) {
setSwipeEnabled(true);
}
}}>
<Tab.Screen name="Home" component={Home} />
<Tab.Screen name="Map" component={Map} />
</Tab.Navigator>
</NavigationContainer>
);
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7644 次 |
| 最近记录: |