From 5f21e4c5b650642ef2bc8ef90cd9422780cba9b3 Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Sun, 15 Jan 2017 12:09:52 -0600 Subject: [PATCH] Introduce Platform in React React Native provides Platform. --- react/features/app/components/App.native.js | 4 +++- .../native/RTCPeerConnection.js | 7 ++----- .../base/media/components/native/Video.js | 4 +++- react/features/base/react/Platform.native.js | 4 ++++ react/features/base/react/Platform.web.js | 20 +++++++++++++++++++ react/features/base/react/index.js | 1 + 6 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 react/features/base/react/Platform.native.js create mode 100644 react/features/base/react/Platform.web.js diff --git a/react/features/app/components/App.native.js b/react/features/app/components/App.native.js index a4a3d8092..db57f023c 100644 --- a/react/features/app/components/App.native.js +++ b/react/features/app/components/App.native.js @@ -1,9 +1,11 @@ /* global __DEV__ */ import React from 'react'; -import { Linking, Navigator, Platform } from 'react-native'; +import { Linking, Navigator } from 'react-native'; import { Provider } from 'react-redux'; +import { Platform } from '../../base/react'; + import { _getRouteToRender } from '../functions'; import { AbstractApp } from './AbstractApp'; diff --git a/react/features/base/lib-jitsi-meet/native/RTCPeerConnection.js b/react/features/base/lib-jitsi-meet/native/RTCPeerConnection.js index 964f39fae..5fd450fef 100644 --- a/react/features/base/lib-jitsi-meet/native/RTCPeerConnection.js +++ b/react/features/base/lib-jitsi-meet/native/RTCPeerConnection.js @@ -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'; // XXX At the time of this writing extending RTCPeerConnection using ES6 'class' diff --git a/react/features/base/media/components/native/Video.js b/react/features/base/media/components/native/Video.js index 290bd99c0..a933c7aa9 100644 --- a/react/features/base/media/components/native/Video.js +++ b/react/features/base/media/components/native/Video.js @@ -1,7 +1,9 @@ import React, { Component } from 'react'; -import { Platform, View } from 'react-native'; +import { View } from 'react-native'; import { RTCView } from 'react-native-webrtc'; +import { Platform } from '../../../react'; + import { styles } from './styles'; /** diff --git a/react/features/base/react/Platform.native.js b/react/features/base/react/Platform.native.js new file mode 100644 index 000000000..1710b20d3 --- /dev/null +++ b/react/features/base/react/Platform.native.js @@ -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; diff --git a/react/features/base/react/Platform.web.js b/react/features/base/react/Platform.web.js new file mode 100644 index 000000000..e09dda133 --- /dev/null +++ b/react/features/base/react/Platform.web.js @@ -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 +}; diff --git a/react/features/base/react/index.js b/react/features/base/react/index.js index fd27aa0de..398bb49d7 100644 --- a/react/features/base/react/index.js +++ b/react/features/base/react/index.js @@ -1,3 +1,4 @@ export * from './components'; export * from './functions'; +export { default as Platform } from './Platform'; export { default as Symbol } from './Symbol';