为什么我不能使用:
global.App_BottomTabBarHeight
下面来设置React Navigation createBottomTabNavigator中的高度?哪里 global.App_BottomTabBarHeight = '8%'
。这是在另一个类中定义的。我正在使用 0.63.3 开发一个 iOS 应用程序
//Tabs across the bottom of the screen
const MainScreenTabNavigator = createBottomTabNavigator(
{
HomeStack,
OtherStack,
},
{
tabBarOptions: {
activeTintColor: 'orange',
inactiveTintColor: 'black', //white
style: {
backgroundColor: '#ff8278',
height: global.App_BottomTabBarHeight // DOESN'T WORK but manually typing '8%' or 0.08 does
},
indicatorStyle: {
backgroundColor: 'black'
},
showLabel: false
},
}
);
高度不会用变量
global.App_BottomTabBarHeight = '8%'
来设置。
我也尝试过这样做:
height: Dimensions.get('window').height * global.App_BottomTabBarHeight
,哪里global.App_BottomTabBarHeight = 0.08
,但还是什么都没有
如果我手动输入
height: '8%'
,效果很好。
有时我会收到此错误:
JSON value '8%' of type NSstring cannot be converted of a YGValue. Did you forget the % or pt suffix.
% 是否有导致问题的原因?
我遇到了同样的问题,这是由于需求周期造成的。
确保您的全局在加载此文件之前已定义,否则您的
global.App_BottomTabBarHeight
可能是 ""
或 undefined
。