嗨,我正在使用 react-native expo-cli。我创建了一个自定义底部导航栏。现在我创建了一个新组件,在屏幕底部我有导航栏,其余屏幕有我的屏幕。当应用程序。在第一次渲染时加载它完美地显示主屏幕(主页是导航堆栈)但是当它移动到购物车屏幕时我隐藏底部导航栏并在屏幕顶部显示一个后退箭头按钮我可以返回主堆栈。但在这里我面临的问题是,当按下箭头按钮返回时,它通过激活 hometab 图标显示底部导航但不显示 homestack 屏幕。
所以我尝试在我正在做这一切的文件上使用useIsFocused,useFocusEffect,但我得到这个错误 navigation.isfocused is not a function navigation.isfocused is undefined
如果有人有任何想法要解决,我从过去两周开始就被困住了,那么我感谢你的帮助。
const Screen = ({ navigation, route }) => {
const { screen, setScreen, navVisibility, setNavVisibility } =
useContext(Context);
return (
<View style={[styles.newContainer]}>
<View style={{ flex: 1 }}>
{
screen == 'Home' ?
<HomeStackScreen/>
:
screen == "Category" ?
<CategoriesScreen/>
:
screen == "Inbox" ?
<Inbox/>
:
screen == "Cart" ?
<CartStackScreen/>
:
screen == "Profile" ?
<LoginScreen/>
:
<HomeStackScreen/>
}
</View>
<View
style={{
position: "absolute",
bottom: 0,
backgroundColor: "transparent",
}}
>
{screen == "Cart" || navVisibility == "ProductShowScreen" ? null : (
<BottomNav navigation={navigation} />
)}
</View>
</View>
);
};
const styles = StyleSheet.create({
newContainer: {
flexGrow: 1,
backgroundColor: "transparent",
},
});
export default Screen;
当我从购物车-> 家回来时,这部分会完美更新:
{screen == "Cart" || navVisibility == "ProductShowScreen" ? null : (
<BottomNav navigation={navigation} />
)}
但这部分不起作用但屏幕值为 Home 但它显示购物车屏幕:
{
screen == 'Home' ?
<HomeStackScreen/>
:
screen == "Category" ?
<CategoriesScreen/>
:
screen == "Inbox" ?
<Inbox/>
:
screen == "Cart" ?
<CartStackScreen/>
:
screen == "Profile" ?
<LoginScreen/>
:
<HomeStackScreen/>
}