在本机反应中,我有这个类(来自kitchenTricks):

  import {Platform} from 'react-native';

export class UIConstants {
  static AppbarHeight = Platform.OS === 'ios' ? 44 : 56;
  static StatusbarHeight = Platform.OS === 'ios' ? 20 : 0;
  static HeaderHeight = UIConstants.AppbarHeight + UIConstants.StatusbarHeight;
}


类的名称:AppConstants.js

问题是当我尝试导出此类时。我收到此错误:

undefined is not an object(evaluating 'UIConstants.AppbarHeight')

最佳答案

您不能在声明时引用同一个类。尝试更早定义高度:

const appbarHeight = Platform.OS === 'ios' ? 44 : 56;
const statusbarHeight = Platform.OS === 'ios' ? 20 : 0;

export class UIConstants {
  static AppbarHeight = appbarHeight;
  static StatusbarHeight = statusbarHeight;
  static HeaderHeight = appbarHeight + statusbarHeight;
}

10-07 23:56