forked from vergnet/application-amicale
		
	Fix tab navigator render loop
This commit is contained in:
		
							parent
							
								
									94a0ca33a4
								
							
						
					
					
						commit
						9e6fee467f
					
				
					 5 changed files with 30 additions and 19 deletions
				
			
		
							
								
								
									
										8
									
								
								App.tsx
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								App.tsx
									
									
									
									
									
								
							|  | @ -53,9 +53,9 @@ type StateType = { | ||||||
| export default class App extends React.Component<{}, StateType> { | export default class App extends React.Component<{}, StateType> { | ||||||
|   navigatorRef: { current: null | NavigationContainerRef }; |   navigatorRef: { current: null | NavigationContainerRef }; | ||||||
| 
 | 
 | ||||||
|   defaultHomeRoute: string | null; |   defaultHomeRoute: string | undefined; | ||||||
| 
 | 
 | ||||||
|   defaultHomeData: { [key: string]: string }; |   defaultHomeData: { [key: string]: string } | undefined; | ||||||
| 
 | 
 | ||||||
|   urlHandler: URLHandler; |   urlHandler: URLHandler; | ||||||
| 
 | 
 | ||||||
|  | @ -67,8 +67,8 @@ export default class App extends React.Component<{}, StateType> { | ||||||
|     }; |     }; | ||||||
|     initLocales(); |     initLocales(); | ||||||
|     this.navigatorRef = React.createRef(); |     this.navigatorRef = React.createRef(); | ||||||
|     this.defaultHomeRoute = null; |     this.defaultHomeRoute = undefined; | ||||||
|     this.defaultHomeData = {}; |     this.defaultHomeData = undefined; | ||||||
|     this.urlHandler = new URLHandler(this.onInitialURLParsed, this.onDetectURL); |     this.urlHandler = new URLHandler(this.onInitialURLParsed, this.onDetectURL); | ||||||
|     this.urlHandler.listen(); |     this.urlHandler.listen(); | ||||||
|     setSafeBounceHeight(Platform.OS === 'ios' ? 100 : 20); |     setSafeBounceHeight(Platform.OS === 'ios' ? 100 : 20); | ||||||
|  |  | ||||||
|  | @ -313,18 +313,25 @@ function MainStackComponent(props: { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type PropsType = { | type PropsType = { | ||||||
|   defaultHomeRoute: string | null; |   defaultHomeRoute?: string; | ||||||
|   defaultHomeData: { [key: string]: string }; |   defaultHomeData?: { [key: string]: string }; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| export default function MainNavigator(props: PropsType) { | function MainNavigator(props: PropsType) { | ||||||
|   const { preferences } = usePreferences(); |   const { preferences } = usePreferences(); | ||||||
|   const showIntro = getPreferenceBool(PreferenceKeys.showIntro, preferences); |   const showIntro = getPreferenceBool(PreferenceKeys.showIntro, preferences); | ||||||
| 
 |   const createTabNavigator = () => <TabNavigator {...props} />; | ||||||
|   return ( |   return ( | ||||||
|     <MainStackComponent |     <MainStackComponent | ||||||
|       showIntro={showIntro !== false} |       showIntro={showIntro !== false} | ||||||
|       createTabNavigator={() => <TabNavigator {...props} />} |       createTabNavigator={createTabNavigator} | ||||||
|     /> |     /> | ||||||
|   ); |   ); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | export default React.memo( | ||||||
|  |   MainNavigator, | ||||||
|  |   (pp: PropsType, np: PropsType) => | ||||||
|  |     pp.defaultHomeRoute === np.defaultHomeRoute && | ||||||
|  |     pp.defaultHomeData === np.defaultHomeData | ||||||
|  | ); | ||||||
|  |  | ||||||
|  | @ -136,8 +136,8 @@ function PlanningStackComponent() { | ||||||
| const HomeStack = createStackNavigator(); | const HomeStack = createStackNavigator(); | ||||||
| 
 | 
 | ||||||
| function HomeStackComponent( | function HomeStackComponent( | ||||||
|   initialRoute: string | null, |   initialRoute?: string, | ||||||
|   defaultData: { [key: string]: string } |   defaultData?: { [key: string]: string } | ||||||
| ) { | ) { | ||||||
|   let params; |   let params; | ||||||
|   if (initialRoute) { |   if (initialRoute) { | ||||||
|  | @ -232,8 +232,8 @@ function PlanexStackComponent() { | ||||||
| const Tab = createBottomTabNavigator<TabStackParamsList>(); | const Tab = createBottomTabNavigator<TabStackParamsList>(); | ||||||
| 
 | 
 | ||||||
| type PropsType = { | type PropsType = { | ||||||
|   defaultHomeRoute: string | null; |   defaultHomeRoute?: string; | ||||||
|   defaultHomeData: { [key: string]: string }; |   defaultHomeData?: { [key: string]: string }; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| const ICONS: { | const ICONS: { | ||||||
|  | @ -264,7 +264,7 @@ const ICONS: { | ||||||
|   }, |   }, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| export default function TabNavigator(props: PropsType) { | function TabNavigator(props: PropsType) { | ||||||
|   const { preferences } = usePreferences(); |   const { preferences } = usePreferences(); | ||||||
|   let defaultRoute = getPreferenceString( |   let defaultRoute = getPreferenceString( | ||||||
|     PreferenceKeys.defaultStartScreen, |     PreferenceKeys.defaultStartScreen, | ||||||
|  | @ -324,6 +324,13 @@ export default function TabNavigator(props: PropsType) { | ||||||
|   ); |   ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | export default React.memo( | ||||||
|  |   TabNavigator, | ||||||
|  |   (pp: PropsType, np: PropsType) => | ||||||
|  |     pp.defaultHomeRoute === np.defaultHomeRoute && | ||||||
|  |     pp.defaultHomeData === np.defaultHomeData | ||||||
|  | ); | ||||||
|  | 
 | ||||||
| export enum TabRoutes { | export enum TabRoutes { | ||||||
|   Services = 'services', |   Services = 'services', | ||||||
|   Proxiwash = 'proxiwash', |   Proxiwash = 'proxiwash', | ||||||
|  |  | ||||||
|  | @ -139,9 +139,6 @@ const generateNewsFeed = (rawFeed: RawNewsFeedType): Array<FeedItemType> => { | ||||||
|   return finalFeed; |   return finalFeed; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| /** |  | ||||||
|  * Class defining the app's home screen |  | ||||||
|  */ |  | ||||||
| function HomeScreen(props: Props) { | function HomeScreen(props: Props) { | ||||||
|   const theme = useTheme(); |   const theme = useTheme(); | ||||||
|   const navigation = useNavigation(); |   const navigation = useNavigation(); | ||||||
|  |  | ||||||
|  | @ -15,8 +15,8 @@ import { CustomDarkTheme, CustomWhiteTheme } from '../utils/Themes'; | ||||||
| import { setupStatusBar } from '../utils/Utils'; | import { setupStatusBar } from '../utils/Utils'; | ||||||
| 
 | 
 | ||||||
| type Props = { | type Props = { | ||||||
|   defaultHomeRoute: string | null; |   defaultHomeRoute?: string; | ||||||
|   defaultHomeData: { [key: string]: string }; |   defaultHomeData?: { [key: string]: string }; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| function MainApp(props: Props, ref?: Ref<NavigationContainerRef>) { | function MainApp(props: Props, ref?: Ref<NavigationContainerRef>) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue