new platform util (#5791)
This commit is contained in:
@@ -1,25 +1,62 @@
|
|||||||
import {isAndroid, isIOS, isNative, isWeb} from 'platform/detection'
|
import {Platform} from 'react-native'
|
||||||
|
|
||||||
|
import {isAndroid, isIOS, isNative, isWeb} from '#/platform/detection'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identity function on web. Returns nothing on other platforms.
|
||||||
|
*
|
||||||
|
* Note: Platform splitting does not tree-shake away the other platforms,
|
||||||
|
* so don't do stuff like e.g. rely on platform-specific imports. Use
|
||||||
|
* platform-split files instead.
|
||||||
|
*/
|
||||||
export function web(value: any) {
|
export function web(value: any) {
|
||||||
if (isWeb) {
|
if (isWeb) {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identity function on iOS. Returns nothing on other platforms.
|
||||||
|
*
|
||||||
|
* Note: Platform splitting does not tree-shake away the other platforms,
|
||||||
|
* so don't do stuff like e.g. rely on platform-specific imports. Use
|
||||||
|
* platform-split files instead.
|
||||||
|
*/
|
||||||
export function ios(value: any) {
|
export function ios(value: any) {
|
||||||
if (isIOS) {
|
if (isIOS) {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identity function on Android. Returns nothing on other platforms..
|
||||||
|
*
|
||||||
|
* Note: Platform splitting does not tree-shake away the other platforms,
|
||||||
|
* so don't do stuff like e.g. rely on platform-specific imports. Use
|
||||||
|
* platform-split files instead.
|
||||||
|
*/
|
||||||
export function android(value: any) {
|
export function android(value: any) {
|
||||||
if (isAndroid) {
|
if (isAndroid) {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identity function on iOS and Android. Returns nothing on web.
|
||||||
|
*
|
||||||
|
* Note: Platform splitting does not tree-shake away the other platforms,
|
||||||
|
* so don't do stuff like e.g. rely on platform-specific imports. Use
|
||||||
|
* platform-split files instead.
|
||||||
|
*/
|
||||||
export function native(value: any) {
|
export function native(value: any) {
|
||||||
if (isNative) {
|
if (isNative) {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: Platform splitting does not tree-shake away the other platforms,
|
||||||
|
* so don't do stuff like e.g. rely on platform-specific imports. Use
|
||||||
|
* platform-split files instead.
|
||||||
|
*/
|
||||||
|
export const platform = Platform.select
|
||||||
|
|||||||
Reference in New Issue
Block a user