react-native-navigation的迁移库

Constants.ts 953B

123456789101112131415161718192021222324252627282930313233
  1. import { NativeModules } from 'react-native';
  2. export interface NavigationConstants {
  3. statusBarHeight: number;
  4. backButtonId: string;
  5. topBarHeight: number;
  6. bottomTabsHeight: number;
  7. }
  8. export class Constants {
  9. static async get(): Promise<NavigationConstants> {
  10. if (!this.instance) {
  11. const constants: NavigationConstants = await NativeModules.RNNBridgeModule.getConstants();
  12. this.instance = new Constants(constants);
  13. }
  14. return this.instance;
  15. }
  16. private static instance: Constants;
  17. public readonly statusBarHeight: number;
  18. public readonly backButtonId: string;
  19. public readonly topBarHeight: number;
  20. public readonly bottomTabsHeight: number;
  21. private constructor(constants: NavigationConstants) {
  22. this.statusBarHeight = constants.statusBarHeight;
  23. this.topBarHeight = constants.topBarHeight;
  24. this.backButtonId = constants.backButtonId;
  25. this.bottomTabsHeight = constants.bottomTabsHeight;
  26. }
  27. }