React Native

This document provides instructions to create a WebView using React Native.

Dependencies

Add react-native-webview to your dependencies

yarn add react-native-webview

or

npm install --save react-native-webview

Android Manifest

Add these lines to the AndroidManifest.xml file in your Android app module:

<uses-feature
    android:name="android.hardware.camera"
    android:required="true" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

iOS Info.plist

Add these lines to the Info.plist file in you iOS module:

<key>NSCameraUsageDescription</key>
<string>Camera Permission</string>
<key>NSMotionUsageDescription</key>
<string>Motion Permission</string>

React Native WebView

import React, { useEffect } from "react";
import {
  SafeAreaView,
  StyleSheet,
  PermissionsAndroid,
  Platform,
} from "react-native";
import { WebView } from "react-native-webview";

function App(): React.JSX.Element {
  return (
    <SafeAreaView style={styles.container}>
      <WebView
        style={styles.container}
        mediaPlaybackRequiresUserAction={false}
        allowsFullscreenVideo
        allowsInlineMediaPlayback
        source={{
          uri: "https://cadastro.io/:token",
        }}
      />
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

export default App;

Last updated

Logo

2023 © Caf. - All rights reserved