mirror of
https://github.com/tooot-app/app
synced 2025-02-20 13:50:49 +01:00
Fixed #442
This commit is contained in:
parent
6a90557d2b
commit
b196d87cb1
@ -4,6 +4,7 @@ import Timeline from '@components/Timeline'
|
|||||||
import TimelineDefault from '@components/Timeline/Default'
|
import TimelineDefault from '@components/Timeline/Default'
|
||||||
import { createNativeStackNavigator } from '@react-navigation/native-stack'
|
import { createNativeStackNavigator } from '@react-navigation/native-stack'
|
||||||
import { ScreenTabsScreenProps, TabLocalStackParamList } from '@utils/navigation/navigators'
|
import { ScreenTabsScreenProps, TabLocalStackParamList } from '@utils/navigation/navigators'
|
||||||
|
import usePopToTop from '@utils/navigation/usePopToTop'
|
||||||
import { useListsQuery } from '@utils/queryHooks/lists'
|
import { useListsQuery } from '@utils/queryHooks/lists'
|
||||||
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
||||||
import layoutAnimation from '@utils/styles/layoutAnimation'
|
import layoutAnimation from '@utils/styles/layoutAnimation'
|
||||||
@ -26,6 +27,8 @@ const TabLocal = React.memo(
|
|||||||
|
|
||||||
const [queryKey, setQueryKey] = useState<QueryKeyTimeline>(['Timeline', { page: 'Following' }])
|
const [queryKey, setQueryKey] = useState<QueryKeyTimeline>(['Timeline', { page: 'Following' }])
|
||||||
|
|
||||||
|
usePopToTop()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
|
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
|
@ -5,6 +5,7 @@ import TimelineNotifications from '@components/Timeline/Notifications'
|
|||||||
import navigationRef from '@helpers/navigationRef'
|
import navigationRef from '@helpers/navigationRef'
|
||||||
import { createNativeStackNavigator } from '@react-navigation/native-stack'
|
import { createNativeStackNavigator } from '@react-navigation/native-stack'
|
||||||
import { TabNotificationsStackParamList } from '@utils/navigation/navigators'
|
import { TabNotificationsStackParamList } from '@utils/navigation/navigators'
|
||||||
|
import usePopToTop from '@utils/navigation/usePopToTop'
|
||||||
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
||||||
import React, { useCallback, useMemo } from 'react'
|
import React, { useCallback, useMemo } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@ -21,9 +22,7 @@ const TabNotifications = React.memo(
|
|||||||
() => ({
|
() => ({
|
||||||
title: t('tabs.notifications.name'),
|
title: t('tabs.notifications.name'),
|
||||||
...(Platform.OS === 'android' && {
|
...(Platform.OS === 'android' && {
|
||||||
headerCenter: () => (
|
headerCenter: () => <HeaderCenter content={t('tabs.notifications.name')} />
|
||||||
<HeaderCenter content={t('tabs.notifications.name')} />
|
|
||||||
)
|
|
||||||
}),
|
}),
|
||||||
headerRight: () => (
|
headerRight: () => (
|
||||||
<HeaderRight
|
<HeaderRight
|
||||||
@ -57,6 +56,8 @@ const TabNotifications = React.memo(
|
|||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
usePopToTop()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
|
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
|
@ -4,15 +4,13 @@ import Timeline from '@components/Timeline'
|
|||||||
import TimelineDefault from '@components/Timeline/Default'
|
import TimelineDefault from '@components/Timeline/Default'
|
||||||
import SegmentedControl from '@react-native-community/segmented-control'
|
import SegmentedControl from '@react-native-community/segmented-control'
|
||||||
import { createNativeStackNavigator } from '@react-navigation/native-stack'
|
import { createNativeStackNavigator } from '@react-navigation/native-stack'
|
||||||
import {
|
import { ScreenTabsScreenProps, TabPublicStackParamList } from '@utils/navigation/navigators'
|
||||||
ScreenTabsScreenProps,
|
import usePopToTop from '@utils/navigation/usePopToTop'
|
||||||
TabPublicStackParamList
|
|
||||||
} from '@utils/navigation/navigators'
|
|
||||||
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import React, { useCallback, useMemo, useState } from 'react'
|
import React, { useCallback, useMemo, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { Dimensions, StyleSheet, View } from 'react-native'
|
import { Dimensions } from 'react-native'
|
||||||
import { TabView } from 'react-native-tab-view'
|
import { TabView } from 'react-native-tab-view'
|
||||||
import TabSharedRoot from './Shared/Root'
|
import TabSharedRoot from './Shared/Root'
|
||||||
|
|
||||||
@ -44,10 +42,8 @@ const TabPublic = React.memo(
|
|||||||
appearance={mode}
|
appearance={mode}
|
||||||
values={pages.map(p => p.title)}
|
values={pages.map(p => p.title)}
|
||||||
selectedIndex={segment}
|
selectedIndex={segment}
|
||||||
onChange={({ nativeEvent }) =>
|
onChange={({ nativeEvent }) => setSegment(nativeEvent.selectedSegmentIndex)}
|
||||||
setSegment(nativeEvent.selectedSegmentIndex)
|
style={{ flexBasis: '65%' }}
|
||||||
}
|
|
||||||
style={styles.segmentsContainer}
|
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
headerRight: () => (
|
headerRight: () => (
|
||||||
@ -84,9 +80,7 @@ const TabPublic = React.memo(
|
|||||||
queryKey={queryKey}
|
queryKey={queryKey}
|
||||||
lookback={page}
|
lookback={page}
|
||||||
customProps={{
|
customProps={{
|
||||||
renderItem: ({ item }: any) => (
|
renderItem: ({ item }: any) => <TimelineDefault item={item} queryKey={queryKey} />
|
||||||
<TimelineDefault item={item} queryKey={queryKey} />
|
|
||||||
)
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@ -108,13 +102,11 @@ const TabPublic = React.memo(
|
|||||||
[segment]
|
[segment]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
usePopToTop()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
|
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
|
||||||
<Stack.Screen
|
<Stack.Screen name='Tab-Public-Root' options={screenOptionsRoot} children={children} />
|
||||||
name='Tab-Public-Root'
|
|
||||||
options={screenOptionsRoot}
|
|
||||||
children={children}
|
|
||||||
/>
|
|
||||||
{TabSharedRoot({ Stack })}
|
{TabSharedRoot({ Stack })}
|
||||||
</Stack.Navigator>
|
</Stack.Navigator>
|
||||||
)
|
)
|
||||||
@ -122,10 +114,4 @@ const TabPublic = React.memo(
|
|||||||
() => true
|
() => true
|
||||||
)
|
)
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
segmentsContainer: {
|
|
||||||
flexBasis: '65%'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
export default TabPublic
|
export default TabPublic
|
||||||
|
@ -3,7 +3,6 @@ import { NavigatorScreenParams } from '@react-navigation/native'
|
|||||||
import { NativeStackScreenProps } from '@react-navigation/native-stack'
|
import { NativeStackScreenProps } from '@react-navigation/native-stack'
|
||||||
import { StackNavigationProp } from '@react-navigation/stack'
|
import { StackNavigationProp } from '@react-navigation/stack'
|
||||||
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
||||||
import React from 'react'
|
|
||||||
|
|
||||||
export type RootStackParamList = {
|
export type RootStackParamList = {
|
||||||
'Screen-Tabs': NavigatorScreenParams<ScreenTabsStackParamList>
|
'Screen-Tabs': NavigatorScreenParams<ScreenTabsStackParamList>
|
||||||
|
17
src/utils/navigation/usePopToTop.ts
Normal file
17
src/utils/navigation/usePopToTop.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { StackActions, useNavigation } from '@react-navigation/native'
|
||||||
|
import { getInstanceActive } from '@utils/slices/instancesSlice'
|
||||||
|
import { useEffect } from 'react'
|
||||||
|
import { useSelector } from 'react-redux'
|
||||||
|
|
||||||
|
// Mostly used when switching account and sub pages were still querying the old instance
|
||||||
|
|
||||||
|
const usePopToTop = () => {
|
||||||
|
const navigation = useNavigation()
|
||||||
|
const instanceActive = useSelector(getInstanceActive)
|
||||||
|
|
||||||
|
return useEffect(() => {
|
||||||
|
navigation.dispatch(StackActions.popToTop())
|
||||||
|
}, [instanceActive])
|
||||||
|
}
|
||||||
|
|
||||||
|
export default usePopToTop
|
Loading…
x
Reference in New Issue
Block a user