错误:无法将 NSstring 类型的 JSON 值转换为 YGValue。您是否忘记了 % 或 pt 后缀

cha*_*i86 6 javascript reactjs react-native react-navigation

为什么我不能使用: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
      },
      
    }
    
  );

Run Code Online (Sandbox Code Playgroud)

高度不会用变量设置global.App_BottomTabBarHeight = '8%'。

我也试过这样做: height: Dimensions.get('window').height * global.App_BottomTabBarHeight, where 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.是否存在导致问题的百分比?

ant*_*129 0

我遇到了同样的问题,这是由于需求周期造成的。

确保在加载此文件之前定义了全局变量,否则您的全局变量global.App_BottomTabBarHeight可能是""或undefined.