@@ -33,31 +33,23 @@ const getActiveRouteName = state => {
33
33
};
34
34
35
35
export default function App () {
36
- const navigationRef = React .useRef ();
37
36
const routeNameRef = React .useRef ();
38
37
39
38
return (
40
39
< NavigationNativeContainer
41
40
ref= {navigationRef}
42
- onStateChange= {() => {
43
- const navigation = navigationRef .current ;
44
-
45
- if (navigation) {
46
- const previousRouteName = routeNameRef .current ;
47
- const currentRouteName = getActiveRouteName (
48
- // Get the root navigator state to find the active route
49
- navigation .getRootState ()
50
- );
51
-
52
- if (previousRouteName !== currentRouteName) {
53
- // The line below uses the @react-native-firebase/analytics tracker
54
- // Change this line to use another Mobile analytics SDK
55
- analytics ().setCurrentScreen (currentRouteName, currentRouteName);
56
- }
57
-
58
- // Save the current route name for later comparision
59
- routeNameRef .current = currentRouteName;
41
+ onStateChange= {state => {
42
+ const previousRouteName = routeNameRef .current ;
43
+ const currentRouteName = getActiveRouteName (state);
44
+
45
+ if (previousRouteName !== currentRouteName) {
46
+ // The line below uses the @react-native-firebase/analytics tracker
47
+ // Change this line to use another Mobile analytics SDK
48
+ analytics ().setCurrentScreen (currentRouteName, currentRouteName);
60
49
}
50
+
51
+ // Save the current route name for later comparision
52
+ routeNameRef .current = currentRouteName;
61
53
}}
62
54
>
63
55
{/* ... */ }
0 commit comments