Introduce Platform in React

React Native provides Platform.
This commit is contained in:
Lyubomir Marinov 2017-01-15 12:09:52 -06:00
parent 28b44cf67c
commit 5f21e4c5b6
6 changed files with 33 additions and 7 deletions

View File

@ -1,9 +1,11 @@
/* global __DEV__ */ /* global __DEV__ */
import React from 'react'; import React from 'react';
import { Linking, Navigator, Platform } from 'react-native'; import { Linking, Navigator } from 'react-native';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { Platform } from '../../base/react';
import { _getRouteToRender } from '../functions'; import { _getRouteToRender } from '../functions';
import { AbstractApp } from './AbstractApp'; import { AbstractApp } from './AbstractApp';

View File

@ -1,9 +1,6 @@
import { Platform } from 'react-native'; import { RTCPeerConnection, RTCSessionDescription } from 'react-native-webrtc';
import {
RTCPeerConnection,
RTCSessionDescription
} from 'react-native-webrtc';
import { Platform } from '../../react';
import { POSIX } from '../../react-native'; import { POSIX } from '../../react-native';
// XXX At the time of this writing extending RTCPeerConnection using ES6 'class' // XXX At the time of this writing extending RTCPeerConnection using ES6 'class'

View File

@ -1,7 +1,9 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Platform, View } from 'react-native'; import { View } from 'react-native';
import { RTCView } from 'react-native-webrtc'; import { RTCView } from 'react-native-webrtc';
import { Platform } from '../../../react';
import { styles } from './styles'; import { styles } from './styles';
/** /**

View File

@ -0,0 +1,4 @@
// Re-export react-native's Platform because we want to provide a minimal
// equivalent on Web.
import { Platform } from 'react-native';
export default Platform;

View File

@ -0,0 +1,20 @@
const userAgent = navigator.userAgent;
let OS;
if (userAgent.match(/Android/i)) {
OS = 'android';
} else if (userAgent.match(/iP(ad|hone|od)/i)) {
OS = 'ios';
}
/**
* Provides a minimal equivalent of react-native's Platform abstraction.
*/
export default {
/**
* The operating system on which the application is executing.
*
* @type {string}
*/
OS
};

View File

@ -1,3 +1,4 @@
export * from './components'; export * from './components';
export * from './functions'; export * from './functions';
export { default as Platform } from './Platform';
export { default as Symbol } from './Symbol'; export { default as Symbol } from './Symbol';