From 7331c58859e20bfb31fcd078c4cfda2987f9019f Mon Sep 17 00:00:00 2001 From: Cristian Date: Wed, 2 Jul 2025 13:48:15 +0200 Subject: [PATCH] feat: added 'persistOnUnmount' make MapView singleton to avoid re-rendering in StackNavigation integrations --- example/package.json | 6 +- example/src/App.tsx | 10 +- example/src/navigation/StackNavigator.tsx | 15 +++ example/src/navigation/types.tsx | 10 +- example/src/screens/HomeScreen.tsx | 8 +- example/src/screens/WayfindingScreen.tsx | 1 + plugin/src/wayfinding/components/MapView.tsx | 31 ++++++- plugin/src/wayfinding/index.ts | 3 + .../wayfinding/store/PersistentWebView.tsx | 28 ++++++ .../src/wayfinding/store/WebViewProvider.tsx | 74 +++++++++++++++ yarn.lock | 92 +++++++++++++++++-- 11 files changed, 259 insertions(+), 19 deletions(-) create mode 100644 example/src/navigation/StackNavigator.tsx create mode 100644 plugin/src/wayfinding/store/PersistentWebView.tsx create mode 100644 plugin/src/wayfinding/store/WebViewProvider.tsx diff --git a/example/package.json b/example/package.json index 7681e8e5..33aa7652 100644 --- a/example/package.json +++ b/example/package.json @@ -12,12 +12,14 @@ "dependencies": { "@react-navigation/bottom-tabs": "^7.3.10", "@react-navigation/native": "^7.1.6", + "@react-navigation/stack": "^7.4.2", "@situm/react-native": "workspace:plugin", "react": "19.0.0", "react-native": "0.79.1", + "react-native-gesture-handler": "^2.26.0", "react-native-paper": "^5.13.3", - "react-native-safe-area-context": "^5.3.0", - "react-native-screens": "^4.10.0", + "react-native-safe-area-context": "^5.5.0", + "react-native-screens": "^4.11.1", "react-native-vector-icons": "^10.2.0", "react-native-webview": "^13.13.5" }, diff --git a/example/src/App.tsx b/example/src/App.tsx index 47e1e722..0dc8b440 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -9,8 +9,10 @@ import React, { useEffect } from "react"; import { NavigationContainer } from "@react-navigation/native"; import { SafeAreaProvider } from "react-native-safe-area-context"; import { TabNavigator } from "./navigation/TabNavigator"; +import { StackNavigator } from "./navigation/StackNavigator"; import SitumPlugin from "@situm/react-native"; import { SITUM_API_KEY, SITUM_DASHBOARD_URL } from "./situm"; +import { WebViewProvider } from "@situm/react-native"; function App(): React.JSX.Element { useEffect(() => { @@ -27,9 +29,11 @@ function App(): React.JSX.Element { return ( - - - + + + + + ); } diff --git a/example/src/navigation/StackNavigator.tsx b/example/src/navigation/StackNavigator.tsx new file mode 100644 index 00000000..0a9e47ff --- /dev/null +++ b/example/src/navigation/StackNavigator.tsx @@ -0,0 +1,15 @@ +import React from "react"; +import { HomeScreen } from "../screens/HomeScreen"; +import { WayfindingScreen } from "../screens/WayfindingScreen"; +import { createStackNavigator } from "@react-navigation/stack"; + +const Stack = createStackNavigator(); + +export const StackNavigator = () => { + return ( + + + + + ); +}; diff --git a/example/src/navigation/types.tsx b/example/src/navigation/types.tsx index 9d6bad03..3eeb0610 100644 --- a/example/src/navigation/types.tsx +++ b/example/src/navigation/types.tsx @@ -2,10 +2,12 @@ export type RootTabsParamsList = { Home: undefined; - Wayfinding: { - poiIdentifier: string; - action: "select" | "navigate"; - }; + Wayfinding: + | { + poiIdentifier: string; + action: "select" | "navigate"; + } + | undefined; }; declare global { diff --git a/example/src/screens/HomeScreen.tsx b/example/src/screens/HomeScreen.tsx index 1ebfd32f..cf49992f 100644 --- a/example/src/screens/HomeScreen.tsx +++ b/example/src/screens/HomeScreen.tsx @@ -7,7 +7,7 @@ import SitumPlugin, { Building, } from "@situm/react-native"; import { PositioningCard } from "./cards/PositioningCard"; -import { Alert, ScrollView, StyleSheet } from "react-native"; +import { Alert, Button, ScrollView, StyleSheet } from "react-native"; import { FetchResourcesCard } from "./cards/FetchResourcesCard"; import { SITUM_BUILDING_ID } from "../situm"; import { MapInteractionCard } from "./cards/MapInteractionCard"; @@ -176,6 +176,12 @@ export const HomeScreen = () => { contentContainerStyle={styles.scrollContainer} showsVerticalScrollIndicator={true} > +