Skip to content

Commit

Permalink
Add isReactNative util function
Browse files Browse the repository at this point in the history
  • Loading branch information
eliperkins committed Feb 5, 2018
1 parent 531bd8e commit f16261a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ function isDOMElement(element) {
}
}

/**
* React Native sets `navigator.product` to a constant `ReactNative`.
* We can use this to determine if the target is React Native or not.
* See https://github.com/facebook/react-native/issues/10881 for more info.
* See https://github.com/facebook/react-native/blob/70c359000a2df091c3939f4c19db6024af992d43/Libraries/Core/InitializeCore.js#L194-L195 for more info.
* @return {Boolean} whether or not the platform is React native
*/
function isReactNative() {
return navigator.product === 'ReactNative'
}

/**
* @param {Object} element (P)react element
* @return {Object} the props
Expand Down Expand Up @@ -287,6 +298,7 @@ export {
getA11yStatusMessage,
unwrapArray,
isDOMElement,
isReactNative,
getElementProps,
noop,
requiredProp,
Expand Down

0 comments on commit f16261a

Please sign in to comment.