react native platform code example

Example 1: what is react native

React Native is an open-source mobile application framework created by Facebook.

It is used to develop applications for Android, iOS, Web and UWP by enabling
developers to use React along with native platform capabilities.

Example 2: react native styles for both platforms

import { Platform, StyleSheet } from 'react-native';

const styles = StyleSheet.create({
  container: {
    flex: 1,
    ...Platform.select({
      ios: {
        backgroundColor: 'red'
      },
      android: {
        backgroundColor: 'green'
      },
      default: {
        // other platforms, web for example
        backgroundColor: 'blue'
      }
    })
  }
});

Example 3: Platform react native

import {Platform} from 'react-native';
    st styles = StyleSheet.create({
      container: {
        flex: 1,
        ...Platform.select({
          ios: {
            backgroundColor: 'red',
          },
          android: {
            backgroundColor: 'blue',
          },
        }),
      },
    });


//OR
import {Platform, StyleSheet} from 'react-native';

const styles = StyleSheet.create({
  height: Platform.OS === 'ios' ? 200 : 100,
});

Example 4: react native get OS

const design = Platform.select({
    android: {
      header: true
    },
    ios: {
	  header: false
    },
  });

Example 5: react native

simple emulator android cli for running react native, flutter and more
here -> https://github.com/restuwahyu13/bangjago-emulator