Skip to content

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

Notifications You must be signed in to change notification settings

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

Repository files navigation

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published