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