<commit_before>import React, { ReactElement, Suspense } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

import getTranslations from '@utils/locales';

import FallbackLoader from '@shared/FallbackLoader';

import * as Pages from './pages';
import { RootStackParamList } from './routes.types';

const Stack = createStackNavigator<RootStackParamList>();

const RootStack = (): ReactElement => (
  <NavigationContainer>
    <Suspense fallback={<FallbackLoader />}>
      <Stack.Navigator
        initialRouteName="Home"
        screenOptions={{ gestureEnabled: true }}
      >
        <Stack.Screen
          name="Home"
          component={Pages.Home}
          options={{ title: 'Home', headerShown: false }}
        />
        <Stack.Screen
          name="OtherPage"
          component={Pages.OtherPage}
          options={{ title: getTranslations('otherPage', 'page_name') }}
          initialParams={{ someProps: 'Some value' }}
        />
        {/* inject screens before this */}
      </Stack.Navigator>
    </Suspense>
  </NavigationContainer>
);

export default RootStack;<commit_msg>feat: add screen tracking<commit_after>import React, { ReactElement, Suspense, useRef, useCallback } from 'react';
import {
  NavigationContainer,
  NavigationContainerRef,
} from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import analytics from '@react-native-firebase/analytics';

import getTranslations from '@utils/locales';

import FallbackLoader from '@shared/FallbackLoader';

import * as Pages from './pages';
import { RootStackParamList } from './routes.types';

const Stack = createStackNavigator<RootStackParamList>();

const RootStack = (): ReactElement => {
  const routeNameRef = useRef<string>();
  const navigationRef = useRef<NavigationContainerRef>(null);

  const onReady = useCallback(() => {
    routeNameRef.current = navigationRef?.current?.getCurrentRoute()?.name;
  }, []);

  const onStateChange = useCallback(() => {
    const previousRouteName = routeNameRef.current;
    const currentRouteName =
      navigationRef?.current?.getCurrentRoute()?.name || '';

    if (previousRouteName !== currentRouteName) {
      analytics().setCurrentScreen(currentRouteName);
    }

    routeNameRef.current = currentRouteName;
  }, []);

  return (
    <NavigationContainer
      ref={navigationRef}
      onReady={onReady}
      onStateChange={onStateChange}
    >
      <Suspense fallback={<FallbackLoader />}>
        <Stack.Navigator
          initialRouteName="Home"
          screenOptions={{ gestureEnabled: true }}
        >
          <Stack.Screen
            name="Home"
            component={Pages.Home}
            options={{ title: 'Home', headerShown: false }}
          />
          <Stack.Screen
            name="OtherPage"
            component={Pages.OtherPage}
            options={{ title: getTranslations('otherPage', 'page_name') }}
            initialParams={{ someProps: 'Some value' }}
          />
          {/* inject screens before this */}
        </Stack.Navigator>
      </Suspense>
    </NavigationContainer>
  );
};

export default RootStack;
{'fraction_non_alphanumeric': 0.13003095975232198, 'fraction_numerical': 0.0, 'mean_word_length': 3.179818887451488, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4081785', 'n_tokens_mistral': 871, 'n_tokens_neox': 868, 'n_words': 187}