You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.native.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // @flow
  2. import { Dimensions } from 'react-native';
  3. import Platform from './Platform';
  4. const IPHONEX_HEIGHT = 812;
  5. const IPHONEX_WIDTH = 375;
  6. const IPHONE_OFFSET = 20;
  7. const IPHONEX_OFFSET = 44;
  8. /**
  9. * Determines the offset to be used for the device. This uses a custom
  10. * implementation to minimize empty area around screen, especially on iPhone X.
  11. *
  12. * @returns {number}
  13. */
  14. export function getSafetyOffset() {
  15. if (Platform.OS === 'android') {
  16. // Android doesn't need offset, except the Essential phone. Should be
  17. // addressed later with a generic solution.
  18. return 0;
  19. }
  20. return isIPhoneX() ? IPHONEX_OFFSET : IPHONE_OFFSET;
  21. }
  22. /**
  23. * Determines if the device is an iPad or not.
  24. *
  25. * @returns {boolean}
  26. */
  27. export function isIPad() {
  28. const { height, width } = Dimensions.get('window');
  29. return (
  30. Platform.OS === 'ios'
  31. && (Math.max(height, width) / Math.min(height, width)) < 1.6);
  32. }
  33. /**
  34. * Determines if it's an iPhone X or not.
  35. *
  36. * @returns {boolean}
  37. */
  38. export function isIPhoneX() {
  39. const { height, width } = Dimensions.get('window');
  40. return (
  41. Platform.OS === 'ios'
  42. && ((height === IPHONEX_HEIGHT && width === IPHONEX_WIDTH)
  43. || (height === IPHONEX_WIDTH && width === IPHONEX_HEIGHT)));
  44. }