mirror of
https://github.com/status-im/react-native.git
synced 2025-02-23 06:38:13 +00:00
Summary: This change adds type information for `Platform.select` to make sure things are properly typed. This is the last diff in a stack that actually enables the newly fixed/added annotations and it will only land once all the type errors (320+) are fixed. Reviewed By: sahrens Differential Revision: D13318805 fbshipit-source-id: af0475d1a2f1e5ace4d513be48827e3659bd7f62
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const NativeModules = require('NativeModules');
|
|
|
|
export type PlatformSelectSpec<D, I> = {
|
|
default?: D,
|
|
ios?: I,
|
|
};
|
|
|
|
const Platform = {
|
|
OS: 'ios',
|
|
get Version() {
|
|
const constants = NativeModules.PlatformConstants;
|
|
return constants && constants.osVersion;
|
|
},
|
|
get isPad() {
|
|
const constants = NativeModules.PlatformConstants;
|
|
return constants ? constants.interfaceIdiom === 'pad' : false;
|
|
},
|
|
/**
|
|
* Deprecated, use `isTV` instead.
|
|
*/
|
|
get isTVOS() {
|
|
return Platform.isTV;
|
|
},
|
|
get isTV() {
|
|
const constants = NativeModules.PlatformConstants;
|
|
return constants ? constants.interfaceIdiom === 'tv' : false;
|
|
},
|
|
get isTesting(): boolean {
|
|
if (__DEV__) {
|
|
const constants = NativeModules.PlatformConstants;
|
|
return constants && constants.isTesting;
|
|
}
|
|
return false;
|
|
},
|
|
select: <D, I>(spec: PlatformSelectSpec<D, I>): D | I =>
|
|
'ios' in spec ? spec.ios : spec.default,
|
|
};
|
|
|
|
module.exports = Platform;
|