Platform.android.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow
  9. */
  10. 'use strict';
  11. import NativePlatformConstantsAndroid from './NativePlatformConstantsAndroid';
  12. export type PlatformSelectSpec<A, N, D> = {
  13. android?: A,
  14. native?: N,
  15. default?: D,
  16. ...
  17. };
  18. const Platform = {
  19. __constants: null,
  20. OS: 'android',
  21. get Version(): number {
  22. return this.constants.Version;
  23. },
  24. get constants(): {|
  25. isTesting: boolean,
  26. reactNativeVersion: {|
  27. major: number,
  28. minor: number,
  29. patch: number,
  30. prerelease: ?number,
  31. |},
  32. Version: number,
  33. Release: string,
  34. Serial: string,
  35. Fingerprint: string,
  36. Model: string,
  37. ServerHost?: string,
  38. uiMode: string,
  39. |} {
  40. if (this.__constants == null) {
  41. this.__constants = NativePlatformConstantsAndroid.getConstants();
  42. }
  43. return this.__constants;
  44. },
  45. get isTesting(): boolean {
  46. if (__DEV__) {
  47. return this.constants.isTesting;
  48. }
  49. return false;
  50. },
  51. get isTV(): boolean {
  52. return this.constants.uiMode === 'tv';
  53. },
  54. select: <A, N, D>(spec: PlatformSelectSpec<A, N, D>): A | N | D =>
  55. 'android' in spec
  56. ? spec.android
  57. : 'native' in spec
  58. ? spec.native
  59. : spec.default,
  60. };
  61. module.exports = Platform;