仅想禁用地图组件的滑动功能,而是在使用“ 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>
);
}
答案 0 :(得分:1)
如果您处于swipeEnabled
屏幕上,则可以将状态值传递给false
并将其更新为Map
:
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>
);
};