Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for native pseudo-OS to Platform.select #26966

Closed
wants to merge 2 commits into from

Conversation

koke
Copy link
Contributor

@koke koke commented Oct 23, 2019

Summary

When you write platform-specific code using file extensions, you can specify .ios.js, .android.js, or the catch-all .native.js when you are sharing code with a web project.

This native shortcut is missing for the Platform.select method, and this PR is adding support for that.

Changelog

[General] [Added] - Platform.select now supports native as an option.

Test Plan

Added relevant passing unit tests for Platform module.

@facebook-github-bot
Copy link
Contributor

Hi koke! Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

Copy link

@analysis-bot analysis-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code analysis results:

  • eslint found some issues. Run yarn lint --fix to automatically fix problems.

Libraries/Utilities/Platform.android.js Show resolved Hide resolved
@react-native-bot react-native-bot added the Type: Enhancement A new feature or enhancement of an existing feature. label Oct 23, 2019
@koke
Copy link
Contributor Author

koke commented Oct 23, 2019

Note that running yarn lint --fix seems to change all the double quotes into single quotes in docs/generatedComponentApiDocs.js, but I haven't committed that change, since it looks unrelated to this PR.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 23, 2019
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@cpojer
Copy link
Contributor

cpojer commented Nov 4, 2019

Hey @koke! Thanks for this PR. I think it makes sense to support this via Platform.select(). However, before we merge this, we need to add support for this in Metro as well. Metro inlines Platform.select() calls in order to not increase the bundle size with unnecessary code. For this, we should change it so that it inlines native calls if there is no platform item in the object and drop it if the platform is web. Once you submit a PR, please tag me and I'll review and merge it, and then get back to the PR here.

Copy link
Contributor

@cpojer cpojer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comment.

Copy link
Contributor

@cpojer cpojer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for submitting the Metro PR!

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

facebook-github-bot pushed a commit to facebook/metro that referenced this pull request Nov 5, 2019
Summary:
**Summary**

In facebook/react-native#26966 I propose adding a `native` variant to `Platform.select`, similar to the existing platform-specific extensions. This PR adds supports for that in Metro's inline plugin.

**Test plan**

Added a couple unit tests. `yarn test inline` is passing, `yarn test` is failing some seemingly unrelated tests (some issues with package.json in metro-babel7-plugin-react-transform)

cc cpojer
Pull Request resolved: #480

Differential Revision: D18323629

Pulled By: cpojer

fbshipit-source-id: 15ef01df5e31ab744bf9e9829928f96908f8c4ce
@facebook-github-bot
Copy link
Contributor

@cpojer merged this pull request in a6fc089.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Type: Enhancement A new feature or enhancement of an existing feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants