this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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