-
Notifications
You must be signed in to change notification settings - Fork 15
App initialization flow
Christopher David edited this page Jun 12, 2023
·
30 revisions
-
index.js- Entry point- Loads polyfills
isomorphic-webcrypto,text-encoding-polyfill,react-native-url-polyfill,react-native-get-random-values - Imports App from
./app/app.tsxand connects to RNBootSplash as IgniteApp - Registers the IgniteApp component with react-native and exports App as default
- Loads polyfills
-
app/app.tsx- The root component of the application- Initializes internationalization (
./i18n) and sets up warnings handling (./utils/ignoreWarnings) - Manages custom fonts loading via
useFontsfromexpo-font - Sets up a safety area for the app using
SafeAreaProviderfromreact-native-safe-area-context - Sets up deep linking for the app using
Linkingfromexpo-linkingand provides a configuration for screens and paths - Uses
useInitialRootStorehook for initializing and rehydrating the root store of the application - Manages navigation state persistence with
useNavigationPersistenceand uses the state to initializeAppNavigator - Sets up an
ErrorBoundaryto catch and handle any unhandled errors occurring in the app - Incorporates
RelayProviderfor handling data fetching with GraphQL andGestureHandlerRootViewfor managing user gesture interactions - Checks if the app state is ready (fonts loaded, root store rehydrated, navigation state restored), if not, returns null to prevent rendering
- Once everything is ready, the app renders the
AppNavigatorinsideGestureHandlerRootView,RelayProvider, andErrorBoundary - Also includes setup for
Reactotrondebugging tool with configurations like clearing on load, monitoring AsyncStorage, and logging the initial state and snapshots - Exports the
Appfunction as default
- Initializes internationalization (
-
app/navigators/AppNavigator.tsx- Main app navigation configuration- Imports necessary modules, components, and screens
- Defines
AppStackParamListtype for available routes - Creates
StackusingcreateNativeStackNavigator - Defines
AppStackcomponent- Uses
observerto make it reactive - Fetches
isLoggedInstate fromuserStore - Renders screens conditionally based on
isLoggedInstate
- Uses
- Defines
NavigationPropstype for navigation component props - Defines
AppNavigatorcomponent- Uses
observerto make it reactive - Retrieves color scheme using
useColorScheme - Uses
useBackButtonHandlerto handle back navigation - Returns
NavigationContainerwrappingAppStackwith theme and props
- Uses
- Exports
AppNavigatorcomponent
-
app/navigators/TabNavigator.tsx- Tab-based navigation configuration- Imports necessary modules, components, and screens
- Defines
DemoTabParamListandDemoTabScreenPropstypes - Creates a
TabusingcreateBottomTabNavigator - Defines the
TabNavigatorcomponent- Returns the
Tab.Navigatorwith options- Hides the header and tab bar on keyboard
- Sets the initial route as "Home"
- Renders three
Tab.Screencomponents for each tab-
Contactsscreen: RendersContactsScreenwith icon -
Homescreen: RendersHomeMessagesScreenwith icon -
Profilescreen: RendersProfileScreenwith icon
-
- Defines styles for tab icons using
StyleSheet.create
- Returns the
- Exports the
TabNavigatorcomponent
-
app/screens/HomeMessagesScreen.tsx- Home messages screen component- Imports necessary modules, components, and hooks
- Defines colors object for styling
- Defines
HomeMessagesScreenfunction component- Uses
observerto make it reactive - Retrieves Relay context and channel manager
- Retrieves channels and private messages from user store
- Uses
useFocusEffectto fetch private messages on focus - Defines AI rooms data
- Combines channels, private messages, and AI rooms data
- Defines
renderItemfunction to render item components based on kind - Returns screen component with sidebar, status bar, and flash list
- Uses
- Defines styles using
StyleSheet.create
-
app/screens/ChatScreen.tsx- Chat screen component- Imports necessary modules, components, and hooks
- Defines
ChatScreenfunction component- Uses
observerto make it reactive - Retrieves Relay context and channel manager
- Pulls in navigation via hook
- Retrieves stores and channel from models
- Defines
leaveJoinedChannelfunction to prompt for leaving channel - Defines
backfunction to handle back navigation - Uses
useLayoutEffectto set navigation options - Uses
useFocusEffectto handle new messages and subscription- Defines
handleNewMessagefunction to handle incoming messages - Subscribes to channel updates using
channelManager.sub- Sets the callback to
handleNewMessageto handle new messages - Sets a filter to receive messages since the current timestamp
- Includes the private key if available
- Sets the callback to
- Unsubscribes from channel updates on cleanup using
pool.unsub
- Defines
- Uses
useEffectto fetch messages- Fetches messages for the channel using
channel.fetchMessagesandchannelManager- Retrieves messages from the channel by calling
getChannel(id)on the channel store - Fetches the messages using
channel.fetchMessageswith the channel manager
- Retrieves messages from the channel by calling
- Fetches messages for the channel using
- Defines
renderItemfunction to render message items - Returns screen component with header, flash list, and channel message form
- Uses
- Defines styles using
$variables andStyleSheet.create