Platform.ios.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 NativePlatformConstantsIOS from './NativePlatformConstantsIOS';
  12. export type PlatformSelectSpec<D, N, I> = {
  13. default?: D,
  14. native?: N,
  15. ios?: I,
  16. ...
  17. };
  18. const Platform = {
  19. __constants: null,
  20. OS: 'ios',
  21. get Version(): string {
  22. return this.constants.osVersion;
  23. },
  24. get constants(): {|
  25. forceTouchAvailable: boolean,
  26. interfaceIdiom: string,
  27. isTesting: boolean,
  28. osVersion: string,
  29. reactNativeVersion: {|
  30. major: number,
  31. minor: number,
  32. patch: number,
  33. prerelease: ?number,
  34. |},
  35. systemName: string,
  36. |} {
  37. if (this.__constants == null) {
  38. this.__constants = NativePlatformConstantsIOS.getConstants();
  39. }
  40. return this.__constants;
  41. },
  42. get isPad(): boolean {
  43. return this.constants.interfaceIdiom === 'pad';
  44. },
  45. /**
  46. * Deprecated, use `isTV` instead.
  47. */
  48. get isTVOS(): boolean {
  49. return Platform.isTV;
  50. },
  51. get isTV(): boolean {
  52. return this.constants.interfaceIdiom === 'tv';
  53. },
  54. get isTesting(): boolean {
  55. if (__DEV__) {
  56. return this.constants.isTesting;
  57. }
  58. return false;
  59. },
  60. select: <D, N, I>(spec: PlatformSelectSpec<D, N, I>): D | N | I =>
  61. 'ios' in spec ? spec.ios : 'native' in spec ? spec.native : spec.default,
  62. };
  63. module.exports = Platform;