A webview that detects mounting/unmounting and focus changes and keeps a single instance mounted. Only works on iOS for now.
output.mp4
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);
}}
/>
);
};
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.
For bare React Native projects, you must ensure that you have installed and configured the expo
package before continuing.
npm install shared-webview
Run npx pod-install
after installing the npm package.
Android is not supported yet.
Contributions are very welcome! Please refer to guidelines described in the contributing guide.