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 platform component #18058

Merged
merged 13 commits into from
Oct 24, 2019
1 change: 1 addition & 0 deletions packages/element/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './react';
export * from './react-platform';
export * from './utils';
export { default as Platform } from './platform';
koke marked this conversation as resolved.
Show resolved Hide resolved
export { default as renderToString } from './serialize';
export { default as RawHTML } from './raw-html';
9 changes: 9 additions & 0 deletions packages/element/src/platform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Platform = {
SergioEstevao marked this conversation as resolved.
Show resolved Hide resolved
OS: 'web',
select: ( obj ) => ( 'web' in obj ? obj.web : obj.default ),
SergioEstevao marked this conversation as resolved.
Show resolved Hide resolved
};
/**
* Component used to detect the current Platform being used. Use Platform.OS === 'web' to detect if running on web enviroment.
* This is the same concept as the React-Native implementation found here: https://facebook.github.io/react-native/docs/platform-specific-code#platform-module
SergioEstevao marked this conversation as resolved.
Show resolved Hide resolved
*/
export default Platform;
Copy link
Member

Choose a reason for hiding this comment

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

It would be great to include an example in the docs as well, since this implementation differs a bit, right? Regardless, it can change upstream, so we should document it.

Can we add simple unit tests that would also act like documentation? I personally, often look at unit tests when trying to learn some 3rd party software.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gziolo just added both, give it a look to see if it's ok now :)

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, I sent a PR upstream

facebook/react-native#26966

I was going to suggest we could get the unit tests from there, but you added them faster 😅

6 changes: 6 additions & 0 deletions packages/element/src/platform.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* External dependencies
*/
import { Platform } from 'react-native';

export default Platform;