Skip to content

[Idea: JS] Add way to detect react-native (and platform) without require(). #1331

@mikelehen

Description

@mikelehen

Motivation

I have a 3rd-party library that needs to work in react-native (as well as node.js, web, etc.). I want to detect when it's used in react-native, for analytics purposes. I can't use require('react-native') or similar because if somebody uses my library with a tool like browserify, it will try to statically satisfy all require() statements and fail on react-native.

Suggestion

  • Set navigator.product to 'ReactNative' (it is currently 'Gecko')
  • Set navigator.platform to 'iPhone', 'iPad', or 'Android' as appropriate (it is currently 'MacIntel', at least in the iOS emulator).

Implementing

Code in question is here:

Related IRC Conversation: https://gist.github.com/mikelehen/822a82a37bf30431a104

Metadata

Metadata

Assignees

Labels

Good first issueInterested in collaborating? Take a stab at fixing one of these issues.Resolution: LockedThis issue was locked by the bot.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions