PlatformConstants Module

Use the PlatformConstants module to retrieve:

  • your app’s target platform (useful for implementing platform-specific code)
  • the You.i Platform version used by the app
  • the React Native version used by You.i Platform

Methods

getOsVersion()

  • Description: Returns the You.i Platform version used by the app
  • Return Type: String
  • Method Usage Example: PlatformConstants.getOsVersion()
  • Platforms Supported: All

getPlatform()

  • Description: Returns the platform the app is running on: androidfor Android, iosfor iOS, tvosfor tvOS, osxfor macOS, uwpfor Xbox, ps4for PS4, cloud for Roku, and tizenfor tizen-nacl. You can use this method to implement platform-specific code.
  • Return Type: A promise object of the string type
  • Method Usage Example: PlatformConstants.getPlatform()
  • Platforms Supported: All

getReactNativeVersion()

  • Description: Returns the version of React Native used by the app (currently 0.63.4)
  • Return Type: String
  • Method Usage Example: PlatformConstants.getReactNativeVersion()
  • Platforms Supported: All

Usage

import { NativeModules } from 'react-native';

NativeModules.PlatformConstants.platform : null;

if (NativeModules.PlatformConstants.osVersion === {{ page.version }}) {
  console.log('Running on {{ page.engine-name }} {{ page.version }}!');
}

if (NativeModules.PlatformConstants.platform === 'ios') {

  // code itself, or maybe even a require('codeForIOS.js');

} else if (NativeModules.PlatformConstants.platform === 'android') {

  // code itself, or maybe even a require('codeForAndroid.js');

}

console.log('Running on Facebook's React-Native ${NativeModules.PlatformConstants.reactNativeVersion}!');