software-mansion-labs / react-native-shared-webview

A webview that detects mounting/unmounting and focus changes and keeps a single instance mounted.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

shared-webview

A webview that detects mounting/unmounting and focus changes and keeps a single instance mounted. Only works on iOS for now.

output.mp4

Example

Check out the example app for expo-router integration.

import { useRouter } from "expo-router";
import { SharedWebviewView } from "shared-webview";
import { useIsFocused } from "@react-navigation/native";

const ORIGIN = "https://swmansion.com";

export default ({ pathname = "/" }: { pathname: string }) => {
  const { navigate } = useRouter();
  const isFocused = useIsFocused();
  return (
    <SharedWebviewView
      style={{ flex: 1 }}
      options={{
        url: (ORIGIN + "/" + pathname).replaceAll("//", "/"),
        focused: isFocused,
      }}
      onNavigation={(event: any) => {
        const { url } = event.nativeEvent;
        if (url.startsWith(ORIGIN) === false) return navigate(url);
        const urlObject = new URL(url);
        navigate(urlObject.pathname);
      }}
    />
  );
};

Installation in managed Expo projects

For managed Expo projects, please follow the installation instructions in the API documentation for the latest stable release. If you follow the link and there is no documentation available then this library is not yet usable within managed projects — it is likely to be included in an upcoming Expo SDK release.

Installation in bare React Native projects

For bare React Native projects, you must ensure that you have installed and configured the expo package before continuing.

Add the package to your npm dependencies

npm install shared-webview

Configure for iOS

Run npx pod-install after installing the npm package.

Configure for Android

Android is not supported yet.

Contributing

Contributions are very welcome! Please refer to guidelines described in the contributing guide.

About

A webview that detects mounting/unmounting and focus changes and keeps a single instance mounted.


Languages

Language:Kotlin 29.6%Language:Swift 23.3%Language:Ruby 13.8%Language:TypeScript 11.9%Language:Objective-C++ 11.8%Language:JavaScript 7.7%Language:Objective-C 1.4%Language:C 0.4%