Bluesky app fork with some witchin' additions 馃挮
at main 38 kB view raw
1import {type JSX, useCallback, useRef} from 'react' 2import {Linking} from 'react-native' 3import * as Notifications from 'expo-notifications' 4import {i18n, type MessageDescriptor} from '@lingui/core' 5import {msg} from '@lingui/macro' 6import { 7 type BottomTabBarProps, 8 createBottomTabNavigator, 9} from '@react-navigation/bottom-tabs' 10import { 11 CommonActions, 12 createNavigationContainerRef, 13 DarkTheme, 14 DefaultTheme, 15 type LinkingOptions, 16 NavigationContainer, 17 StackActions, 18} from '@react-navigation/native' 19 20import {timeout} from '#/lib/async/timeout' 21import {useColorSchemeStyle} from '#/lib/hooks/useColorSchemeStyle' 22import { 23 getNotificationPayload, 24 type NotificationPayload, 25 notificationToURL, 26 storePayloadForAccountSwitch, 27} from '#/lib/hooks/useNotificationHandler' 28import {useWebScrollRestoration} from '#/lib/hooks/useWebScrollRestoration' 29import {logger as notyLogger} from '#/lib/notifications/util' 30import {buildStateObject} from '#/lib/routes/helpers' 31import { 32 type AllNavigatorParams, 33 type BottomTabNavigatorParams, 34 type FlatNavigatorParams, 35 type HomeTabNavigatorParams, 36 type MessagesTabNavigatorParams, 37 type MyProfileTabNavigatorParams, 38 type NotificationsTabNavigatorParams, 39 type SearchTabNavigatorParams, 40} from '#/lib/routes/types' 41import {type RouteParams, type State} from '#/lib/routes/types' 42import {attachRouteToLogEvents, logEvent} from '#/lib/statsig/statsig' 43import {bskyTitle} from '#/lib/strings/headings' 44import {logger} from '#/logger' 45import {isNative, isWeb} from '#/platform/detection' 46import {useDisableVerifyEmailReminder} from '#/state/preferences/disable-verify-email-reminder' 47import {useUnreadNotifications} from '#/state/queries/notifications/unread' 48import {useSession} from '#/state/session' 49import { 50 shouldRequestEmailConfirmation, 51 snoozeEmailConfirmationPrompt, 52} from '#/state/shell/reminders' 53import {CommunityGuidelinesScreen} from '#/view/screens/CommunityGuidelines' 54import {CopyrightPolicyScreen} from '#/view/screens/CopyrightPolicy' 55import {DebugModScreen} from '#/view/screens/DebugMod' 56import {FeedsScreen} from '#/view/screens/Feeds' 57import {HomeScreen} from '#/view/screens/Home' 58import {ListsScreen} from '#/view/screens/Lists' 59import {ModerationBlockedAccounts} from '#/view/screens/ModerationBlockedAccounts' 60import {ModerationModlistsScreen} from '#/view/screens/ModerationModlists' 61import {ModerationMutedAccounts} from '#/view/screens/ModerationMutedAccounts' 62import {NotFoundScreen} from '#/view/screens/NotFound' 63import {NotificationsScreen} from '#/view/screens/Notifications' 64import {PostThreadScreen} from '#/view/screens/PostThread' 65import {PrivacyPolicyScreen} from '#/view/screens/PrivacyPolicy' 66import {ProfileScreen} from '#/view/screens/Profile' 67import {ProfileFeedLikedByScreen} from '#/view/screens/ProfileFeedLikedBy' 68import {Storybook} from '#/view/screens/Storybook' 69import {SupportScreen} from '#/view/screens/Support' 70import {TermsOfServiceScreen} from '#/view/screens/TermsOfService' 71import {BottomBar} from '#/view/shell/bottom-bar/BottomBar' 72import {createNativeStackNavigatorWithAuth} from '#/view/shell/createNativeStackNavigatorWithAuth' 73import {BookmarksScreen} from '#/screens/Bookmarks' 74import {SharedPreferencesTesterScreen} from '#/screens/E2E/SharedPreferencesTesterScreen' 75import HashtagScreen from '#/screens/Hashtag' 76import {LogScreen} from '#/screens/Log' 77import {MessagesScreen} from '#/screens/Messages/ChatList' 78import {MessagesConversationScreen} from '#/screens/Messages/Conversation' 79import {MessagesInboxScreen} from '#/screens/Messages/Inbox' 80import {MessagesSettingsScreen} from '#/screens/Messages/Settings' 81import {ModerationScreen} from '#/screens/Moderation' 82import {Screen as ModerationVerificationSettings} from '#/screens/Moderation/VerificationSettings' 83import {Screen as ModerationInteractionSettings} from '#/screens/ModerationInteractionSettings' 84import {NotificationsActivityListScreen} from '#/screens/Notifications/ActivityList' 85import {PostLikedByScreen} from '#/screens/Post/PostLikedBy' 86import {PostQuotesScreen} from '#/screens/Post/PostQuotes' 87import {PostRepostedByScreen} from '#/screens/Post/PostRepostedBy' 88import {ProfileKnownFollowersScreen} from '#/screens/Profile/KnownFollowers' 89import {ProfileFeedScreen} from '#/screens/Profile/ProfileFeed' 90import {ProfileFollowersScreen} from '#/screens/Profile/ProfileFollowers' 91import {ProfileFollowsScreen} from '#/screens/Profile/ProfileFollows' 92import {ProfileLabelerLikedByScreen} from '#/screens/Profile/ProfileLabelerLikedBy' 93import {ProfileSearchScreen} from '#/screens/Profile/ProfileSearch' 94import {ProfileListScreen} from '#/screens/ProfileList' 95import {SavedFeeds} from '#/screens/SavedFeeds' 96import {SearchScreen} from '#/screens/Search' 97import {AboutSettingsScreen} from '#/screens/Settings/AboutSettings' 98import {AccessibilitySettingsScreen} from '#/screens/Settings/AccessibilitySettings' 99import {AccountSettingsScreen} from '#/screens/Settings/AccountSettings' 100import {ActivityPrivacySettingsScreen} from '#/screens/Settings/ActivityPrivacySettings' 101import {AppearanceSettingsScreen} from '#/screens/Settings/AppearanceSettings' 102import {AppIconSettingsScreen} from '#/screens/Settings/AppIconSettings' 103import {AppPasswordsScreen} from '#/screens/Settings/AppPasswords' 104import {ContentAndMediaSettingsScreen} from '#/screens/Settings/ContentAndMediaSettings' 105import {DeerSettingsScreen} from '#/screens/Settings/DeerSettings' 106import {ExternalMediaPreferencesScreen} from '#/screens/Settings/ExternalMediaPreferences' 107import {FollowingFeedPreferencesScreen} from '#/screens/Settings/FollowingFeedPreferences' 108import {InterestsSettingsScreen} from '#/screens/Settings/InterestsSettings' 109import {LanguageSettingsScreen} from '#/screens/Settings/LanguageSettings' 110import {LegacyNotificationSettingsScreen} from '#/screens/Settings/LegacyNotificationSettings' 111import {NotificationSettingsScreen} from '#/screens/Settings/NotificationSettings' 112import {ActivityNotificationSettingsScreen} from '#/screens/Settings/NotificationSettings/ActivityNotificationSettings' 113import {LikeNotificationSettingsScreen} from '#/screens/Settings/NotificationSettings/LikeNotificationSettings' 114import {LikesOnRepostsNotificationSettingsScreen} from '#/screens/Settings/NotificationSettings/LikesOnRepostsNotificationSettings' 115import {MentionNotificationSettingsScreen} from '#/screens/Settings/NotificationSettings/MentionNotificationSettings' 116import {MiscellaneousNotificationSettingsScreen} from '#/screens/Settings/NotificationSettings/MiscellaneousNotificationSettings' 117import {NewFollowerNotificationSettingsScreen} from '#/screens/Settings/NotificationSettings/NewFollowerNotificationSettings' 118import {QuoteNotificationSettingsScreen} from '#/screens/Settings/NotificationSettings/QuoteNotificationSettings' 119import {ReplyNotificationSettingsScreen} from '#/screens/Settings/NotificationSettings/ReplyNotificationSettings' 120import {RepostNotificationSettingsScreen} from '#/screens/Settings/NotificationSettings/RepostNotificationSettings' 121import {RepostsOnRepostsNotificationSettingsScreen} from '#/screens/Settings/NotificationSettings/RepostsOnRepostsNotificationSettings' 122import {PrivacyAndSecuritySettingsScreen} from '#/screens/Settings/PrivacyAndSecuritySettings' 123import {SettingsScreen} from '#/screens/Settings/Settings' 124import {ThreadPreferencesScreen} from '#/screens/Settings/ThreadPreferences' 125import { 126 StarterPackScreen, 127 StarterPackScreenShort, 128} from '#/screens/StarterPack/StarterPackScreen' 129import {Wizard} from '#/screens/StarterPack/Wizard' 130import TopicScreen from '#/screens/Topic' 131import {VideoFeed} from '#/screens/VideoFeed' 132import {type Theme, useTheme} from '#/alf' 133import { 134 EmailDialogScreenID, 135 useEmailDialogControl, 136} from '#/components/dialogs/EmailDialog' 137import {router} from '#/routes' 138import {Referrer} from '../modules/expo-bluesky-swiss-army' 139import {useAccountSwitcher} from './lib/hooks/useAccountSwitcher' 140import {useNonReactiveCallback} from './lib/hooks/useNonReactiveCallback' 141import {useLoggedOutViewControls} from './state/shell/logged-out' 142import {useCloseAllActiveElements} from './state/util' 143 144const navigationRef = createNavigationContainerRef<AllNavigatorParams>() 145 146const HomeTab = createNativeStackNavigatorWithAuth<HomeTabNavigatorParams>() 147const SearchTab = createNativeStackNavigatorWithAuth<SearchTabNavigatorParams>() 148const NotificationsTab = 149 createNativeStackNavigatorWithAuth<NotificationsTabNavigatorParams>() 150const MyProfileTab = 151 createNativeStackNavigatorWithAuth<MyProfileTabNavigatorParams>() 152const MessagesTab = 153 createNativeStackNavigatorWithAuth<MessagesTabNavigatorParams>() 154const Flat = createNativeStackNavigatorWithAuth<FlatNavigatorParams>() 155const Tab = createBottomTabNavigator<BottomTabNavigatorParams>() 156 157/** 158 * These "common screens" are reused across stacks. 159 */ 160function commonScreens(Stack: typeof Flat, unreadCountLabel?: string) { 161 const title = (page: MessageDescriptor) => 162 bskyTitle(i18n._(page), unreadCountLabel) 163 164 return ( 165 <> 166 <Stack.Screen 167 name="NotFound" 168 getComponent={() => NotFoundScreen} 169 options={{title: title(msg`Not Found`)}} 170 /> 171 <Stack.Screen 172 name="Lists" 173 component={ListsScreen} 174 options={{title: title(msg`Lists`), requireAuth: true}} 175 /> 176 <Stack.Screen 177 name="Moderation" 178 getComponent={() => ModerationScreen} 179 options={{title: title(msg`Moderation`), requireAuth: true}} 180 /> 181 <Stack.Screen 182 name="ModerationModlists" 183 getComponent={() => ModerationModlistsScreen} 184 options={{title: title(msg`Moderation Lists`), requireAuth: true}} 185 /> 186 <Stack.Screen 187 name="ModerationMutedAccounts" 188 getComponent={() => ModerationMutedAccounts} 189 options={{title: title(msg`Muted Accounts`), requireAuth: true}} 190 /> 191 <Stack.Screen 192 name="ModerationBlockedAccounts" 193 getComponent={() => ModerationBlockedAccounts} 194 options={{title: title(msg`Blocked Accounts`), requireAuth: true}} 195 /> 196 <Stack.Screen 197 name="ModerationInteractionSettings" 198 getComponent={() => ModerationInteractionSettings} 199 options={{ 200 title: title(msg`Skeet Interaction Settings`), 201 requireAuth: true, 202 }} 203 /> 204 <Stack.Screen 205 name="ModerationVerificationSettings" 206 getComponent={() => ModerationVerificationSettings} 207 options={{ 208 title: title(msg`Verification Settings`), 209 requireAuth: true, 210 }} 211 /> 212 <Stack.Screen 213 name="Settings" 214 getComponent={() => SettingsScreen} 215 options={{title: title(msg`Settings`), requireAuth: true}} 216 /> 217 <Stack.Screen 218 name="LanguageSettings" 219 getComponent={() => LanguageSettingsScreen} 220 options={{title: title(msg`Language Settings`), requireAuth: true}} 221 /> 222 <Stack.Screen 223 name="Profile" 224 getComponent={() => ProfileScreen} 225 options={({route}) => ({ 226 title: bskyTitle(`@${route.params.name}`, unreadCountLabel), 227 })} 228 /> 229 <Stack.Screen 230 name="ProfileFollowers" 231 getComponent={() => ProfileFollowersScreen} 232 options={({route}) => ({ 233 title: title(msg`People following @${route.params.name}`), 234 })} 235 /> 236 <Stack.Screen 237 name="ProfileFollows" 238 getComponent={() => ProfileFollowsScreen} 239 options={({route}) => ({ 240 title: title(msg`People followed by @${route.params.name}`), 241 })} 242 /> 243 <Stack.Screen 244 name="ProfileKnownFollowers" 245 getComponent={() => ProfileKnownFollowersScreen} 246 options={({route}) => ({ 247 title: title(msg`Followers of @${route.params.name} that you know`), 248 })} 249 /> 250 <Stack.Screen 251 name="ProfileList" 252 getComponent={() => ProfileListScreen} 253 options={{title: title(msg`List`), requireAuth: true}} 254 /> 255 <Stack.Screen 256 name="ProfileSearch" 257 getComponent={() => ProfileSearchScreen} 258 options={({route}) => ({ 259 title: title(msg`Search @${route.params.name}'s skeets`), 260 })} 261 /> 262 <Stack.Screen 263 name="PostThread" 264 getComponent={() => PostThreadScreen} 265 options={({route}) => ({ 266 title: title(msg`Skeet by @${route.params.name}`), 267 })} 268 /> 269 <Stack.Screen 270 name="PostLikedBy" 271 getComponent={() => PostLikedByScreen} 272 options={({route}) => ({ 273 title: title(msg`Skeet by @${route.params.name}`), 274 })} 275 /> 276 <Stack.Screen 277 name="PostRepostedBy" 278 getComponent={() => PostRepostedByScreen} 279 options={({route}) => ({ 280 title: title(msg`Skeet by @${route.params.name}`), 281 })} 282 /> 283 <Stack.Screen 284 name="PostQuotes" 285 getComponent={() => PostQuotesScreen} 286 options={({route}) => ({ 287 title: title(msg`Skeet by @${route.params.name}`), 288 })} 289 /> 290 <Stack.Screen 291 name="ProfileFeed" 292 getComponent={() => ProfileFeedScreen} 293 options={{title: title(msg`Feed`)}} 294 /> 295 <Stack.Screen 296 name="ProfileFeedLikedBy" 297 getComponent={() => ProfileFeedLikedByScreen} 298 options={{title: title(msg`Liked by`)}} 299 /> 300 <Stack.Screen 301 name="ProfileLabelerLikedBy" 302 getComponent={() => ProfileLabelerLikedByScreen} 303 options={{title: title(msg`Liked by`)}} 304 /> 305 <Stack.Screen 306 name="Debug" 307 getComponent={() => Storybook} 308 options={{title: title(msg`Storybook`), requireAuth: true}} 309 /> 310 <Stack.Screen 311 name="DebugMod" 312 getComponent={() => DebugModScreen} 313 options={{title: title(msg`Moderation states`), requireAuth: true}} 314 /> 315 <Stack.Screen 316 name="SharedPreferencesTester" 317 getComponent={() => SharedPreferencesTesterScreen} 318 options={{title: title(msg`Shared Preferences Tester`)}} 319 /> 320 <Stack.Screen 321 name="Log" 322 getComponent={() => LogScreen} 323 options={{title: title(msg`Log`), requireAuth: true}} 324 /> 325 <Stack.Screen 326 name="Support" 327 getComponent={() => SupportScreen} 328 options={{title: title(msg`Support`)}} 329 /> 330 <Stack.Screen 331 name="PrivacyPolicy" 332 getComponent={() => PrivacyPolicyScreen} 333 options={{title: title(msg`Privacy Policy`)}} 334 /> 335 <Stack.Screen 336 name="TermsOfService" 337 getComponent={() => TermsOfServiceScreen} 338 options={{title: title(msg`Terms of Service`)}} 339 /> 340 <Stack.Screen 341 name="CommunityGuidelines" 342 getComponent={() => CommunityGuidelinesScreen} 343 options={{title: title(msg`Community Guidelines`)}} 344 /> 345 <Stack.Screen 346 name="CopyrightPolicy" 347 getComponent={() => CopyrightPolicyScreen} 348 options={{title: title(msg`Copyright Policy`)}} 349 /> 350 <Stack.Screen 351 name="AppPasswords" 352 getComponent={() => AppPasswordsScreen} 353 options={{title: title(msg`App Passwords`), requireAuth: true}} 354 /> 355 <Stack.Screen 356 name="SavedFeeds" 357 getComponent={() => SavedFeeds} 358 options={{title: title(msg`Edit My Feeds`), requireAuth: true}} 359 /> 360 <Stack.Screen 361 name="PreferencesFollowingFeed" 362 getComponent={() => FollowingFeedPreferencesScreen} 363 options={{ 364 title: title(msg`Following Feed Preferences`), 365 requireAuth: true, 366 }} 367 /> 368 <Stack.Screen 369 name="PreferencesThreads" 370 getComponent={() => ThreadPreferencesScreen} 371 options={{title: title(msg`Threads Preferences`), requireAuth: true}} 372 /> 373 <Stack.Screen 374 name="PreferencesExternalEmbeds" 375 getComponent={() => ExternalMediaPreferencesScreen} 376 options={{ 377 title: title(msg`External Media Preferences`), 378 requireAuth: true, 379 }} 380 /> 381 <Stack.Screen 382 name="AccessibilitySettings" 383 getComponent={() => AccessibilitySettingsScreen} 384 options={{ 385 title: title(msg`Accessibility Settings`), 386 requireAuth: true, 387 }} 388 /> 389 <Stack.Screen 390 name="DeerSettings" 391 getComponent={() => DeerSettingsScreen} 392 options={{ 393 title: title(msg`Experiments`), 394 requireAuth: true, 395 }} 396 /> 397 <Stack.Screen 398 name="AppearanceSettings" 399 getComponent={() => AppearanceSettingsScreen} 400 options={{ 401 title: title(msg`Appearance`), 402 requireAuth: true, 403 }} 404 /> 405 <Stack.Screen 406 name="AccountSettings" 407 getComponent={() => AccountSettingsScreen} 408 options={{ 409 title: title(msg`Account`), 410 requireAuth: true, 411 }} 412 /> 413 <Stack.Screen 414 name="PrivacyAndSecuritySettings" 415 getComponent={() => PrivacyAndSecuritySettingsScreen} 416 options={{ 417 title: title(msg`Privacy and Security`), 418 requireAuth: true, 419 }} 420 /> 421 <Stack.Screen 422 name="ActivityPrivacySettings" 423 getComponent={() => ActivityPrivacySettingsScreen} 424 options={{ 425 title: title(msg`Privacy and Security`), 426 requireAuth: true, 427 }} 428 /> 429 <Stack.Screen 430 name="NotificationSettings" 431 getComponent={() => NotificationSettingsScreen} 432 options={{title: title(msg`Notification settings`), requireAuth: true}} 433 /> 434 <Stack.Screen 435 name="ReplyNotificationSettings" 436 getComponent={() => ReplyNotificationSettingsScreen} 437 options={{ 438 title: title(msg`Reply notifications`), 439 requireAuth: true, 440 }} 441 /> 442 <Stack.Screen 443 name="MentionNotificationSettings" 444 getComponent={() => MentionNotificationSettingsScreen} 445 options={{ 446 title: title(msg`Mention notifications`), 447 requireAuth: true, 448 }} 449 /> 450 <Stack.Screen 451 name="QuoteNotificationSettings" 452 getComponent={() => QuoteNotificationSettingsScreen} 453 options={{ 454 title: title(msg`Quote notifications`), 455 requireAuth: true, 456 }} 457 /> 458 <Stack.Screen 459 name="LikeNotificationSettings" 460 getComponent={() => LikeNotificationSettingsScreen} 461 options={{ 462 title: title(msg`Like notifications`), 463 requireAuth: true, 464 }} 465 /> 466 <Stack.Screen 467 name="RepostNotificationSettings" 468 getComponent={() => RepostNotificationSettingsScreen} 469 options={{ 470 title: title(msg`Reskeet notifications`), 471 requireAuth: true, 472 }} 473 /> 474 <Stack.Screen 475 name="NewFollowerNotificationSettings" 476 getComponent={() => NewFollowerNotificationSettingsScreen} 477 options={{ 478 title: title(msg`New follower notifications`), 479 requireAuth: true, 480 }} 481 /> 482 <Stack.Screen 483 name="LikesOnRepostsNotificationSettings" 484 getComponent={() => LikesOnRepostsNotificationSettingsScreen} 485 options={{ 486 title: title(msg`Likes of your reskeets notifications`), 487 requireAuth: true, 488 }} 489 /> 490 <Stack.Screen 491 name="RepostsOnRepostsNotificationSettings" 492 getComponent={() => RepostsOnRepostsNotificationSettingsScreen} 493 options={{ 494 title: title(msg`Reskeets of your reskeets notifications`), 495 requireAuth: true, 496 }} 497 /> 498 <Stack.Screen 499 name="ActivityNotificationSettings" 500 getComponent={() => ActivityNotificationSettingsScreen} 501 options={{ 502 title: title(msg`Activity notifications`), 503 requireAuth: true, 504 }} 505 /> 506 <Stack.Screen 507 name="MiscellaneousNotificationSettings" 508 getComponent={() => MiscellaneousNotificationSettingsScreen} 509 options={{ 510 title: title(msg`Miscellaneous notifications`), 511 requireAuth: true, 512 }} 513 /> 514 <Stack.Screen 515 name="ContentAndMediaSettings" 516 getComponent={() => ContentAndMediaSettingsScreen} 517 options={{ 518 title: title(msg`Content and Media`), 519 requireAuth: true, 520 }} 521 /> 522 <Stack.Screen 523 name="InterestsSettings" 524 getComponent={() => InterestsSettingsScreen} 525 options={{ 526 title: title(msg`Your interests`), 527 requireAuth: true, 528 }} 529 /> 530 <Stack.Screen 531 name="AboutSettings" 532 getComponent={() => AboutSettingsScreen} 533 options={{ 534 title: title(msg`About`), 535 requireAuth: true, 536 }} 537 /> 538 <Stack.Screen 539 name="AppIconSettings" 540 getComponent={() => AppIconSettingsScreen} 541 options={{ 542 title: title(msg`App Icon`), 543 requireAuth: true, 544 }} 545 /> 546 <Stack.Screen 547 name="Hashtag" 548 getComponent={() => HashtagScreen} 549 options={{title: title(msg`Hashtag`)}} 550 /> 551 <Stack.Screen 552 name="Topic" 553 getComponent={() => TopicScreen} 554 options={{title: title(msg`Topic`)}} 555 /> 556 <Stack.Screen 557 name="MessagesConversation" 558 getComponent={() => MessagesConversationScreen} 559 options={{title: title(msg`Chat`), requireAuth: true}} 560 /> 561 <Stack.Screen 562 name="MessagesSettings" 563 getComponent={() => MessagesSettingsScreen} 564 options={{title: title(msg`Chat settings`), requireAuth: true}} 565 /> 566 <Stack.Screen 567 name="MessagesInbox" 568 getComponent={() => MessagesInboxScreen} 569 options={{title: title(msg`Chat request inbox`), requireAuth: true}} 570 /> 571 <Stack.Screen 572 name="NotificationsActivityList" 573 getComponent={() => NotificationsActivityListScreen} 574 options={{title: title(msg`Notifications`), requireAuth: true}} 575 /> 576 <Stack.Screen 577 name="LegacyNotificationSettings" 578 getComponent={() => LegacyNotificationSettingsScreen} 579 options={{title: title(msg`Notification settings`), requireAuth: true}} 580 /> 581 <Stack.Screen 582 name="Feeds" 583 getComponent={() => FeedsScreen} 584 options={{title: title(msg`Feeds`)}} 585 /> 586 <Stack.Screen 587 name="StarterPack" 588 getComponent={() => StarterPackScreen} 589 options={{title: title(msg`Starter Pack`)}} 590 /> 591 <Stack.Screen 592 name="StarterPackShort" 593 getComponent={() => StarterPackScreenShort} 594 options={{title: title(msg`Starter Pack`)}} 595 /> 596 <Stack.Screen 597 name="StarterPackWizard" 598 getComponent={() => Wizard} 599 options={{title: title(msg`Create a starter pack`), requireAuth: true}} 600 /> 601 <Stack.Screen 602 name="StarterPackEdit" 603 getComponent={() => Wizard} 604 options={{title: title(msg`Edit your starter pack`), requireAuth: true}} 605 /> 606 <Stack.Screen 607 name="VideoFeed" 608 getComponent={() => VideoFeed} 609 options={{ 610 title: title(msg`Video Feed`), 611 requireAuth: true, 612 }} 613 /> 614 <Stack.Screen 615 name="Bookmarks" 616 getComponent={() => BookmarksScreen} 617 options={{ 618 title: title(msg`Saved Skeets`), 619 requireAuth: true, 620 }} 621 /> 622 </> 623 ) 624} 625 626/** 627 * The TabsNavigator is used by native mobile to represent the routes 628 * in 3 distinct tab-stacks with a different root screen on each. 629 */ 630function TabsNavigator() { 631 const tabBar = useCallback( 632 (props: JSX.IntrinsicAttributes & BottomTabBarProps) => ( 633 <BottomBar {...props} /> 634 ), 635 [], 636 ) 637 638 return ( 639 <Tab.Navigator 640 initialRouteName="HomeTab" 641 backBehavior="initialRoute" 642 screenOptions={{headerShown: false, lazy: true}} 643 tabBar={tabBar}> 644 <Tab.Screen name="HomeTab" getComponent={() => HomeTabNavigator} /> 645 <Tab.Screen name="SearchTab" getComponent={() => SearchTabNavigator} /> 646 <Tab.Screen 647 name="MessagesTab" 648 getComponent={() => MessagesTabNavigator} 649 /> 650 <Tab.Screen 651 name="NotificationsTab" 652 getComponent={() => NotificationsTabNavigator} 653 /> 654 <Tab.Screen 655 name="MyProfileTab" 656 getComponent={() => MyProfileTabNavigator} 657 /> 658 </Tab.Navigator> 659 ) 660} 661 662function screenOptions(t: Theme) { 663 return { 664 fullScreenGestureEnabled: true, 665 headerShown: false, 666 contentStyle: t.atoms.bg, 667 } as const 668} 669 670function HomeTabNavigator() { 671 const t = useTheme() 672 673 return ( 674 <HomeTab.Navigator screenOptions={screenOptions(t)} initialRouteName="Home"> 675 <HomeTab.Screen name="Home" getComponent={() => HomeScreen} /> 676 <HomeTab.Screen name="Start" getComponent={() => HomeScreen} /> 677 {commonScreens(HomeTab as typeof Flat)} 678 </HomeTab.Navigator> 679 ) 680} 681 682function SearchTabNavigator() { 683 const t = useTheme() 684 return ( 685 <SearchTab.Navigator 686 screenOptions={screenOptions(t)} 687 initialRouteName="Search"> 688 <SearchTab.Screen name="Search" getComponent={() => SearchScreen} /> 689 {commonScreens(SearchTab as typeof Flat)} 690 </SearchTab.Navigator> 691 ) 692} 693 694function NotificationsTabNavigator() { 695 const t = useTheme() 696 return ( 697 <NotificationsTab.Navigator 698 screenOptions={screenOptions(t)} 699 initialRouteName="Notifications"> 700 <NotificationsTab.Screen 701 name="Notifications" 702 getComponent={() => NotificationsScreen} 703 options={{requireAuth: true}} 704 /> 705 {commonScreens(NotificationsTab as typeof Flat)} 706 </NotificationsTab.Navigator> 707 ) 708} 709 710function MyProfileTabNavigator() { 711 const t = useTheme() 712 return ( 713 <MyProfileTab.Navigator 714 screenOptions={screenOptions(t)} 715 initialRouteName="MyProfile"> 716 <MyProfileTab.Screen 717 // MyProfile is not in AllNavigationParams - asserting as Profile at least 718 // gives us typechecking for initialParams -sfn 719 name={'MyProfile' as 'Profile'} 720 getComponent={() => ProfileScreen} 721 initialParams={{name: 'me', hideBackButton: true}} 722 /> 723 {commonScreens(MyProfileTab as unknown as typeof Flat)} 724 </MyProfileTab.Navigator> 725 ) 726} 727 728function MessagesTabNavigator() { 729 const t = useTheme() 730 return ( 731 <MessagesTab.Navigator 732 screenOptions={screenOptions(t)} 733 initialRouteName="Messages"> 734 <MessagesTab.Screen 735 name="Messages" 736 getComponent={() => MessagesScreen} 737 options={({route}) => ({ 738 requireAuth: true, 739 animationTypeForReplace: route.params?.animation ?? 'push', 740 })} 741 /> 742 {commonScreens(MessagesTab as typeof Flat)} 743 </MessagesTab.Navigator> 744 ) 745} 746 747/** 748 * The FlatNavigator is used by Web to represent the routes 749 * in a single ("flat") stack. 750 */ 751const FlatNavigator = () => { 752 const t = useTheme() 753 const numUnread = useUnreadNotifications() 754 const screenListeners = useWebScrollRestoration() 755 const title = (page: MessageDescriptor) => bskyTitle(i18n._(page), numUnread) 756 757 return ( 758 <Flat.Navigator 759 screenListeners={screenListeners} 760 screenOptions={screenOptions(t)}> 761 <Flat.Screen 762 name="Home" 763 getComponent={() => HomeScreen} 764 options={{title: title(msg`Home`)}} 765 /> 766 <Flat.Screen 767 name="Search" 768 getComponent={() => SearchScreen} 769 options={{title: title(msg`Explore`)}} 770 /> 771 <Flat.Screen 772 name="Notifications" 773 getComponent={() => NotificationsScreen} 774 options={{title: title(msg`Notifications`), requireAuth: true}} 775 /> 776 <Flat.Screen 777 name="Messages" 778 getComponent={() => MessagesScreen} 779 options={{title: title(msg`Messages`), requireAuth: true}} 780 /> 781 <Flat.Screen 782 name="Start" 783 getComponent={() => HomeScreen} 784 options={{title: title(msg`Home`)}} 785 /> 786 {commonScreens(Flat, numUnread)} 787 </Flat.Navigator> 788 ) 789} 790 791/** 792 * The RoutesContainer should wrap all components which need access 793 * to the navigation context. 794 */ 795 796const LINKING = { 797 // TODO figure out what we are going to use 798 // note: `bluesky://` is what is used in app.config.js 799 prefixes: ['bsky://', 'bluesky://', 'https://bsky.app'], 800 801 getPathFromState(state: State) { 802 // find the current node in the navigation tree 803 let node = state.routes[state.index || 0] 804 while (node.state?.routes && typeof node.state?.index === 'number') { 805 node = node.state?.routes[node.state?.index] 806 } 807 808 // build the path 809 const route = router.matchName(node.name) 810 if (typeof route === 'undefined') { 811 return '/' // default to home 812 } 813 return route.build((node.params || {}) as RouteParams) 814 }, 815 816 getStateFromPath(path: string) { 817 const [name, params] = router.matchPath(path) 818 819 // Any time we receive a url that starts with `intent/` we want to ignore it here. It will be handled in the 820 // intent handler hook. We should check for the trailing slash, because if there isn't one then it isn't a valid 821 // intent 822 // On web, there is no route state that's created by default, so we should initialize it as the home route. On 823 // native, since the home tab and the home screen are defined as initial routes, we don't need to return a state 824 // since it will be created by react-navigation. 825 if (path.includes('intent/')) { 826 if (isNative) return 827 return buildStateObject('Flat', 'Home', params) 828 } 829 830 if (isNative) { 831 if (name === 'Search') { 832 return buildStateObject('SearchTab', 'Search', params) 833 } 834 if (name === 'Notifications') { 835 return buildStateObject('NotificationsTab', 'Notifications', params) 836 } 837 if (name === 'Home') { 838 return buildStateObject('HomeTab', 'Home', params) 839 } 840 if (name === 'Messages') { 841 return buildStateObject('MessagesTab', 'Messages', params) 842 } 843 // if the path is something else, like a post, profile, or even settings, we need to initialize the home tab as pre-existing state otherwise the back button will not work 844 return buildStateObject('HomeTab', name, params, [ 845 { 846 name: 'Home', 847 params: {}, 848 }, 849 ]) 850 } else { 851 const res = buildStateObject('Flat', name, params) 852 return res 853 } 854 }, 855} satisfies LinkingOptions<AllNavigatorParams> 856 857/** 858 * Used to ensure we don't handle the same notification twice 859 */ 860let lastHandledNotificationDateDedupe: number | undefined 861 862function RoutesContainer({children}: React.PropsWithChildren<{}>) { 863 const theme = useColorSchemeStyle(DefaultTheme, DarkTheme) 864 const {currentAccount, accounts} = useSession() 865 const {onPressSwitchAccount} = useAccountSwitcher() 866 const {setShowLoggedOut} = useLoggedOutViewControls() 867 const prevLoggedRouteName = useRef<string | undefined>(undefined) 868 const emailDialogControl = useEmailDialogControl() 869 const closeAllActiveElements = useCloseAllActiveElements() 870 871 const disableVerifyEmailReminder = useDisableVerifyEmailReminder() 872 873 /** 874 * Handle navigation to a conversation, or prepares for account switch. 875 * 876 * Non-reactive because we need the latest data from some hooks 877 * after an async call - sfn 878 */ 879 const handleChatMessage = useNonReactiveCallback( 880 (payload: Extract<NotificationPayload, {reason: 'chat-message'}>) => { 881 notyLogger.debug(`handleChatMessage`, {payload}) 882 883 if (payload.recipientDid !== currentAccount?.did) { 884 // handled in useNotificationHandler after account switch finishes 885 storePayloadForAccountSwitch(payload) 886 closeAllActiveElements() 887 888 const account = accounts.find(a => a.did === payload.recipientDid) 889 if (account) { 890 onPressSwitchAccount(account, 'Notification') 891 } else { 892 setShowLoggedOut(true) 893 } 894 } else { 895 // @ts-expect-error nested navigators aren't typed -sfn 896 navigate('MessagesTab', { 897 screen: 'Messages', 898 params: { 899 pushToConversation: payload.convoId, 900 }, 901 }) 902 } 903 }, 904 ) 905 906 async function handlePushNotificationEntry() { 907 if (!isNative) return 908 909 // deep links take precedence - on android, 910 // getLastNotificationResponseAsync returns a "notification" 911 // that is actually a deep link. avoid handling it twice -sfn 912 if (await Linking.getInitialURL()) { 913 return 914 } 915 916 /** 917 * The notification that caused the app to open, if applicable 918 */ 919 const response = await Notifications.getLastNotificationResponseAsync() 920 921 if (response) { 922 notyLogger.debug(`handlePushNotificationEntry: response`, {response}) 923 924 if (response.notification.date === lastHandledNotificationDateDedupe) 925 return 926 lastHandledNotificationDateDedupe = response.notification.date 927 928 const payload = getNotificationPayload(response.notification) 929 930 if (payload) { 931 notyLogger.metric( 932 'notifications:openApp', 933 {reason: payload.reason, causedBoot: true}, 934 {statsig: false}, 935 ) 936 937 if (payload.reason === 'chat-message') { 938 handleChatMessage(payload) 939 } else { 940 const path = notificationToURL(payload) 941 942 if (path === '/notifications') { 943 resetToTab('NotificationsTab') 944 notyLogger.debug(`handlePushNotificationEntry: default navigate`) 945 } else if (path) { 946 const [screen, params] = router.matchPath(path) 947 // @ts-expect-error nested navigators aren't typed -sfn 948 navigate('HomeTab', {screen, params}) 949 notyLogger.debug(`handlePushNotificationEntry: navigate`, { 950 screen, 951 params, 952 }) 953 } 954 } 955 } 956 } 957 } 958 959 function onReady() { 960 prevLoggedRouteName.current = getCurrentRouteName() 961 if (currentAccount && shouldRequestEmailConfirmation(currentAccount) && !disableVerifyEmailReminder) { 962 emailDialogControl.open({ 963 id: EmailDialogScreenID.VerificationReminder, 964 }) 965 snoozeEmailConfirmationPrompt() 966 } 967 } 968 969 return ( 970 <> 971 <NavigationContainer 972 ref={navigationRef} 973 linking={LINKING} 974 theme={theme} 975 onStateChange={() => { 976 logger.metric( 977 'router:navigate', 978 {from: prevLoggedRouteName.current}, 979 {statsig: false}, 980 ) 981 prevLoggedRouteName.current = getCurrentRouteName() 982 }} 983 onReady={() => { 984 attachRouteToLogEvents(getCurrentRouteName) 985 logModuleInitTime() 986 onReady() 987 logger.metric('router:navigate', {}, {statsig: false}) 988 handlePushNotificationEntry() 989 }} 990 // WARNING: Implicit navigation to nested navigators is depreciated in React Navigation 7.x 991 // However, there's a fair amount of places we do that, especially in when popping to the top of stacks. 992 // See BottomBar.tsx for an example of how to handle nested navigators in the tabs correctly. 993 // I'm scared of missing a spot (esp. with push notifications etc) so let's enable this legacy behaviour for now. 994 // We will need to confirm we handle nested navigators correctly by the time we migrate to React Navigation 8.x 995 // -sfn 996 navigationInChildEnabled> 997 {children} 998 </NavigationContainer> 999 </> 1000 ) 1001} 1002 1003function getCurrentRouteName() { 1004 if (navigationRef.isReady()) { 1005 return navigationRef.getCurrentRoute()?.name 1006 } else { 1007 return undefined 1008 } 1009} 1010 1011/** 1012 * These helpers can be used from outside of the RoutesContainer 1013 * (eg in the state models). 1014 */ 1015 1016function navigate<K extends keyof AllNavigatorParams>( 1017 name: K, 1018 params?: AllNavigatorParams[K], 1019) { 1020 if (navigationRef.isReady()) { 1021 return Promise.race([ 1022 new Promise<void>(resolve => { 1023 const handler = () => { 1024 resolve() 1025 navigationRef.removeListener('state', handler) 1026 } 1027 navigationRef.addListener('state', handler) 1028 1029 // @ts-ignore I dont know what would make typescript happy but I have a life -prf 1030 navigationRef.navigate(name, params) 1031 }), 1032 timeout(1e3), 1033 ]) 1034 } 1035 return Promise.resolve() 1036} 1037 1038function resetToTab( 1039 tabName: 'HomeTab' | 'SearchTab' | 'MessagesTab' | 'NotificationsTab', 1040) { 1041 if (navigationRef.isReady()) { 1042 navigate(tabName) 1043 if (navigationRef.canGoBack()) { 1044 navigationRef.dispatch(StackActions.popToTop()) //we need to check .canGoBack() before calling it 1045 } 1046 } 1047} 1048 1049// returns a promise that resolves after the state reset is complete 1050function reset(): Promise<void> { 1051 if (navigationRef.isReady()) { 1052 navigationRef.dispatch( 1053 CommonActions.reset({ 1054 index: 0, 1055 routes: [{name: isNative ? 'HomeTab' : 'Home'}], 1056 }), 1057 ) 1058 return Promise.race([ 1059 timeout(1e3), 1060 new Promise<void>(resolve => { 1061 const handler = () => { 1062 resolve() 1063 navigationRef.removeListener('state', handler) 1064 } 1065 navigationRef.addListener('state', handler) 1066 }), 1067 ]) 1068 } else { 1069 return Promise.resolve() 1070 } 1071} 1072 1073let didInit = false 1074function logModuleInitTime() { 1075 if (didInit) { 1076 return 1077 } 1078 didInit = true 1079 1080 const initMs = Math.round( 1081 // @ts-ignore Emitted by Metro in the bundle prelude 1082 performance.now() - global.__BUNDLE_START_TIME__, 1083 ) 1084 console.log(`Time to first paint: ${initMs} ms`) 1085 logEvent('init', { 1086 initMs, 1087 }) 1088 1089 if (isWeb) { 1090 const referrerInfo = Referrer.getReferrerInfo() 1091 if (referrerInfo && referrerInfo.hostname !== 'bsky.app') { 1092 logEvent('deepLink:referrerReceived', { 1093 to: window.location.href, 1094 referrer: referrerInfo?.referrer, 1095 hostname: referrerInfo?.hostname, 1096 }) 1097 } 1098 } 1099 1100 if (__DEV__) { 1101 // This log is noisy, so keep false committed 1102 const shouldLog = false 1103 // Relies on our patch to polyfill.js in metro-runtime 1104 const initLogs = (global as any).__INIT_LOGS__ 1105 if (shouldLog && Array.isArray(initLogs)) { 1106 console.log(initLogs.join('\n')) 1107 } 1108 } 1109} 1110 1111export { 1112 FlatNavigator, 1113 navigate, 1114 reset, 1115 resetToTab, 1116 RoutesContainer, 1117 TabsNavigator, 1118}