-
Notifications
You must be signed in to change notification settings - Fork 16
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.tsx
and 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
useFonts
fromexpo-font
- Sets up a safety area for the app using
SafeAreaProvider
fromreact-native-safe-area-context
- Sets up deep linking for the app using
Linking
fromexpo-linking
and provides a configuration for screens and paths - Uses
useInitialRootStore
hook for initializing and rehydrating the root store of the application - Manages navigation state persistence with
useNavigationPersistence
and uses the state to initializeAppNavigator
- Sets up an
ErrorBoundary
to catch and handle any unhandled errors occurring in the app - Incorporates
RelayProvider
for handling data fetching with GraphQL andGestureHandlerRootView
for 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
AppNavigator
insideGestureHandlerRootView
,RelayProvider
, andErrorBoundary
- Also includes setup for
Reactotron
debugging tool with configurations like clearing on load, monitoring AsyncStorage, and logging the initial state and snapshots - Exports the
App
function as default
- Initializes internationalization (
-
app/navigators/AppNavigator.tsx
- Main app navigation configuration- Imports necessary modules, components, and screens
- Defines
AppStackParamList
type for available routes - Creates
Stack
usingcreateNativeStackNavigator
- Defines
AppStack
component- Uses
observer
to make it reactive - Fetches
isLoggedIn
state fromuserStore
- Renders screens conditionally based on
isLoggedIn
state
- Uses
- Defines
NavigationProps
type for navigation component props - Defines
AppNavigator
component- Uses
observer
to make it reactive - Retrieves color scheme using
useColorScheme
- Uses
useBackButtonHandler
to handle back navigation - Returns
NavigationContainer
wrappingAppStack
with theme and props
- Uses
- Exports
AppNavigator
component
-
app/navigators/TabNavigator.tsx
- Tab-based navigation configuration- Imports necessary modules, components, and screens
- Defines
DemoTabParamList
andDemoTabScreenProps
types - Creates a
Tab
usingcreateBottomTabNavigator
- Defines the
TabNavigator
component- Returns the
Tab.Navigator
with options- Hides the header and tab bar on keyboard
- Sets the initial route as "Home"
- Renders three
Tab.Screen
components for each tab-
Contacts
screen: RendersContactsScreen
with icon -
Home
screen: RendersHomeMessagesScreen
with icon -
Profile
screen: RendersProfileScreen
with icon
-
- Defines styles for tab icons using
StyleSheet.create
- Returns the
- Exports the
TabNavigator
component
-
app/screens/HomeMessagesScreen.tsx
- Home messages screen component- Imports necessary modules, components, and hooks
- Defines colors object for styling
- Defines
HomeMessagesScreen
function component- Uses
observer
to make it reactive - Retrieves Relay context and channel manager
- Retrieves channels and private messages from user store
- Uses
useFocusEffect
to fetch private messages on focus - Defines AI rooms data
- Combines channels, private messages, and AI rooms data
- Defines
renderItem
function 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
ChatScreen
function component- Uses
observer
to make it reactive - Retrieves Relay context and channel manager
- Pulls in navigation via hook
- Retrieves stores and channel from models
- Defines
leaveJoinedChannel
function to prompt for leaving channel - Defines
back
function to handle back navigation - Uses
useLayoutEffect
to set navigation options - Uses
useFocusEffect
to handle new messages and subscription- Defines
handleNewMessage
function to handle incoming messages - Subscribes to channel updates using
channelManager.sub
- Sets the callback to
handleNewMessage
to 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
useEffect
to fetch messages- Fetches messages for the channel using
channel.fetchMessages
andchannelManager
- Retrieves messages from the channel by calling
getChannel(id)
on the channel store - Fetches the messages using
channel.fetchMessages
with the channel manager
- Retrieves messages from the channel by calling
- Fetches messages for the channel using
- Defines
renderItem
function to render message items - Returns screen component with header, flash list, and channel message form
- Uses
- Defines styles using
$
variables andStyleSheet.create