gpt4 book ai didi

react 原生 Material 顶部选项卡导航器滑动禁用取决于屏幕

转载 作者:行者123 更新时间:2023-12-04 08:59:52 25 4
gpt4 key购买 nike

只想禁用 Map 组件滑动,但在使用“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>
);
}

最佳答案

您可以将状态值传递给 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>
);
};

关于 react 原生 Material 顶部选项卡导航器滑动禁用取决于屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63611393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com