【发布时间】:2021-10-22 16:18:18
【问题描述】:
我正在使用 Drawer.Navigator 在 react native 中创建一个切换菜单,希望根据某些条件打开/关闭抽屉。它不能正常工作。
<Drawer.Navigator
drawerContentOptions={{
activeTintColor: "#e91e63",
itemStyle: { marginVertical: 5 },
}}
drawerContent={(props) => <CustomDrawerContent {...props} />}
initialRouteName="Home"
openByDefault={storedCredentials.isDrawerOpen}
>
当我控制storedCredentials.isDrawerOpen 时,它按预期给出true 或false,但它没有打开/关闭抽屉。 我们将不胜感激。
更新
const DrawerRoutes = ({ navigation }) => {
const { storedCredentials, setStoredCredentials } =
useContext(CredentialsContext);
useLayoutEffect(() => {
storedCredentials.data &&
storedCredentials.data.flats &&
storedCredentials.data.flats.length === 1
? setStoredCredentials(
{
...storedCredentials,
flat: storedCredentials.data.flats[0],
isDrawerOpen: false,
}
)
: setStoredCredentials(
{
...storedCredentials,
isDrawerOpen: true,
}
);
console.log(storedCredentials);
}, []);
这是我设置上下文的地方,然后在 openByDefault 属性中使用它。
【问题讨论】:
标签: react-native react-navigation-v5