Update BottomBar for react navigation
This commit is contained in:
+26
-9
@@ -12,6 +12,8 @@ import {
|
|||||||
State,
|
State,
|
||||||
} from 'lib/routes/types'
|
} from 'lib/routes/types'
|
||||||
|
|
||||||
|
import {BottomBar} from './shell/BottomBar'
|
||||||
|
|
||||||
import {HomeScreen} from './screens/Home'
|
import {HomeScreen} from './screens/Home'
|
||||||
import {SearchScreen} from './screens/Search'
|
import {SearchScreen} from './screens/Search'
|
||||||
import {NotificationsScreen} from './screens/Notifications'
|
import {NotificationsScreen} from './screens/Notifications'
|
||||||
@@ -167,7 +169,7 @@ function HomeDrawerNavigator() {
|
|||||||
return (
|
return (
|
||||||
<HomeDrawer.Navigator
|
<HomeDrawer.Navigator
|
||||||
drawerContent={DrawerContent}
|
drawerContent={DrawerContent}
|
||||||
screenOptions={{swipeEdgeWidth: 300}}>
|
screenOptions={{swipeEdgeWidth: 300, headerShown: false}}>
|
||||||
<HomeDrawer.Screen name="HomeInner" component={HomeScreen} />
|
<HomeDrawer.Screen name="HomeInner" component={HomeScreen} />
|
||||||
</HomeDrawer.Navigator>
|
</HomeDrawer.Navigator>
|
||||||
)
|
)
|
||||||
@@ -176,7 +178,11 @@ function HomeDrawerNavigator() {
|
|||||||
function HomeStackNavigator() {
|
function HomeStackNavigator() {
|
||||||
return (
|
return (
|
||||||
<HomeStack.Navigator
|
<HomeStack.Navigator
|
||||||
screenOptions={{gestureEnabled: true, fullScreenGestureEnabled: true}}>
|
screenOptions={{
|
||||||
|
gestureEnabled: true,
|
||||||
|
fullScreenGestureEnabled: true,
|
||||||
|
headerShown: false,
|
||||||
|
}}>
|
||||||
<HomeStack.Screen name="Home" component={HomeDrawerNavigator} />
|
<HomeStack.Screen name="Home" component={HomeDrawerNavigator} />
|
||||||
{commonScreens(HomeStack)}
|
{commonScreens(HomeStack)}
|
||||||
</HomeStack.Navigator>
|
</HomeStack.Navigator>
|
||||||
@@ -187,7 +193,7 @@ function NotificationsDrawerNavigator() {
|
|||||||
return (
|
return (
|
||||||
<NotificationsDrawer.Navigator
|
<NotificationsDrawer.Navigator
|
||||||
drawerContent={DrawerContent}
|
drawerContent={DrawerContent}
|
||||||
screenOptions={{swipeEdgeWidth: 300}}>
|
screenOptions={{swipeEdgeWidth: 300, headerShown: false}}>
|
||||||
<NotificationsDrawer.Screen
|
<NotificationsDrawer.Screen
|
||||||
name="NotificationsInner"
|
name="NotificationsInner"
|
||||||
component={NotificationsScreen}
|
component={NotificationsScreen}
|
||||||
@@ -199,7 +205,11 @@ function NotificationsDrawerNavigator() {
|
|||||||
function NotificationsStackNavigator() {
|
function NotificationsStackNavigator() {
|
||||||
return (
|
return (
|
||||||
<NotificationsStack.Navigator
|
<NotificationsStack.Navigator
|
||||||
screenOptions={{gestureEnabled: true, fullScreenGestureEnabled: true}}>
|
screenOptions={{
|
||||||
|
gestureEnabled: true,
|
||||||
|
fullScreenGestureEnabled: true,
|
||||||
|
headerShown: false,
|
||||||
|
}}>
|
||||||
<NotificationsStack.Screen
|
<NotificationsStack.Screen
|
||||||
name="Notifications"
|
name="Notifications"
|
||||||
component={NotificationsDrawerNavigator}
|
component={NotificationsDrawerNavigator}
|
||||||
@@ -213,7 +223,7 @@ function SearchDrawerNavigator() {
|
|||||||
return (
|
return (
|
||||||
<SearchDrawer.Navigator
|
<SearchDrawer.Navigator
|
||||||
drawerContent={DrawerContent}
|
drawerContent={DrawerContent}
|
||||||
screenOptions={{swipeEdgeWidth: 300}}>
|
screenOptions={{swipeEdgeWidth: 300, headerShown: false}}>
|
||||||
<SearchDrawer.Screen name="SearchInner" component={SearchScreen} />
|
<SearchDrawer.Screen name="SearchInner" component={SearchScreen} />
|
||||||
</SearchDrawer.Navigator>
|
</SearchDrawer.Navigator>
|
||||||
)
|
)
|
||||||
@@ -222,7 +232,11 @@ function SearchDrawerNavigator() {
|
|||||||
function SearchStackNavigator() {
|
function SearchStackNavigator() {
|
||||||
return (
|
return (
|
||||||
<SearchStack.Navigator
|
<SearchStack.Navigator
|
||||||
screenOptions={{gestureEnabled: true, fullScreenGestureEnabled: true}}>
|
screenOptions={{
|
||||||
|
gestureEnabled: true,
|
||||||
|
fullScreenGestureEnabled: true,
|
||||||
|
headerShown: false,
|
||||||
|
}}>
|
||||||
<SearchStack.Screen name="Search" component={SearchDrawerNavigator} />
|
<SearchStack.Screen name="Search" component={SearchDrawerNavigator} />
|
||||||
{commonScreens(SearchStack)}
|
{commonScreens(SearchStack)}
|
||||||
</SearchStack.Navigator>
|
</SearchStack.Navigator>
|
||||||
@@ -230,9 +244,13 @@ function SearchStackNavigator() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function TabsNavigator() {
|
function TabsNavigator() {
|
||||||
|
const tabBar = React.useCallback(props => <BottomBar {...props} />, [])
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<Tab.Navigator
|
||||||
<Tab.Navigator initialRouteName="HomeStack" backBehavior="initialRoute">
|
initialRouteName="HomeStack"
|
||||||
|
backBehavior="initialRoute"
|
||||||
|
screenOptions={{headerShown: false}}
|
||||||
|
tabBar={tabBar}>
|
||||||
<Tab.Screen name="HomeStack" component={HomeStackNavigator} />
|
<Tab.Screen name="HomeStack" component={HomeStackNavigator} />
|
||||||
<Tab.Screen
|
<Tab.Screen
|
||||||
name="NotificationsStack"
|
name="NotificationsStack"
|
||||||
@@ -240,7 +258,6 @@ function TabsNavigator() {
|
|||||||
/>
|
/>
|
||||||
<Tab.Screen name="SearchStack" component={SearchStackNavigator} />
|
<Tab.Screen name="SearchStack" component={SearchStackNavigator} />
|
||||||
</Tab.Navigator>
|
</Tab.Navigator>
|
||||||
</React.Fragment>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import {
|
|||||||
TouchableOpacity,
|
TouchableOpacity,
|
||||||
View,
|
View,
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
|
import {StackActions} from '@react-navigation/native'
|
||||||
|
import {BottomTabBarProps} from '@react-navigation/bottom-tabs'
|
||||||
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
||||||
import {observer} from 'mobx-react-lite'
|
import {observer} from 'mobx-react-lite'
|
||||||
import {Text} from 'view/com/util/text/Text'
|
import {Text} from 'view/com/util/text/Text'
|
||||||
@@ -26,7 +28,15 @@ import {
|
|||||||
import {colors} from 'lib/styles'
|
import {colors} from 'lib/styles'
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
|
|
||||||
export const BottomBar = observer(() => {
|
function currentRoute(state) {
|
||||||
|
let node = state.routes[state.index]
|
||||||
|
while (node.state?.routes && typeof node.state?.index === 'number') {
|
||||||
|
node = node.state?.routes[node.state?.index]
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
export const BottomBar = observer(({navigation}: BottomTabBarProps) => {
|
||||||
const store = useStores()
|
const store = useStores()
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const minimalShellInterp = useAnimatedValue(0)
|
const minimalShellInterp = useAnimatedValue(0)
|
||||||
@@ -54,62 +64,40 @@ export const BottomBar = observer(() => {
|
|||||||
transform: [{translateY: Animated.multiply(minimalShellInterp, 100)}],
|
transform: [{translateY: Animated.multiply(minimalShellInterp, 100)}],
|
||||||
}
|
}
|
||||||
|
|
||||||
const onPressHome = React.useCallback(() => {
|
const onPressTab = React.useCallback(
|
||||||
track('MobileShell:HomeButtonPressed')
|
(tab: string) => {
|
||||||
if (store.nav.tab.fixedTabPurpose === TabPurpose.Default) {
|
track(`MobileShell:${tab}ButtonPressed`)
|
||||||
if (!store.nav.tab.canGoBack) {
|
const state = navigation.getState()
|
||||||
|
const curr = currentRoute(state).name
|
||||||
|
if (curr === tab || curr === `${tab}Stack`) {
|
||||||
store.emitScreenSoftReset()
|
store.emitScreenSoftReset()
|
||||||
|
} else if (state.routes[state.index].name === `${tab}Stack`) {
|
||||||
|
navigation.dispatch(StackActions.popToTop())
|
||||||
} else {
|
} else {
|
||||||
store.nav.tab.fixedTabReset()
|
navigation.navigate(`${tab}Stack`)
|
||||||
}
|
}
|
||||||
} else {
|
},
|
||||||
store.nav.switchTo(TabPurpose.Default, false)
|
[store, track, navigation],
|
||||||
if (store.nav.tab.index === 0) {
|
)
|
||||||
store.nav.tab.fixedTabReset()
|
const onPressHome = React.useCallback(() => onPressTab('Home'), [onPressTab])
|
||||||
}
|
const onPressSearch = React.useCallback(
|
||||||
}
|
() => onPressTab('Search'),
|
||||||
}, [store, track])
|
[onPressTab],
|
||||||
const onPressSearch = React.useCallback(() => {
|
)
|
||||||
track('MobileShell:SearchButtonPressed')
|
const onPressNotifications = React.useCallback(
|
||||||
if (store.nav.tab.fixedTabPurpose === TabPurpose.Search) {
|
() => onPressTab('Notifications'),
|
||||||
if (!store.nav.tab.canGoBack) {
|
[onPressTab],
|
||||||
store.emitScreenSoftReset()
|
)
|
||||||
} else {
|
|
||||||
store.nav.tab.fixedTabReset()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
store.nav.switchTo(TabPurpose.Search, false)
|
|
||||||
if (store.nav.tab.index === 0) {
|
|
||||||
store.nav.tab.fixedTabReset()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [store, track])
|
|
||||||
const onPressNotifications = React.useCallback(() => {
|
|
||||||
track('MobileShell:NotificationsButtonPressed')
|
|
||||||
if (store.nav.tab.fixedTabPurpose === TabPurpose.Notifs) {
|
|
||||||
if (!store.nav.tab.canGoBack) {
|
|
||||||
store.emitScreenSoftReset()
|
|
||||||
} else {
|
|
||||||
store.nav.tab.fixedTabReset()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
store.nav.switchTo(TabPurpose.Notifs, false)
|
|
||||||
if (store.nav.tab.index === 0) {
|
|
||||||
store.nav.tab.fixedTabReset()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [store, track])
|
|
||||||
const onPressProfile = React.useCallback(() => {
|
const onPressProfile = React.useCallback(() => {
|
||||||
track('MobileShell:ProfileButtonPressed')
|
track('MobileShell:ProfileButtonPressed')
|
||||||
store.nav.navigate(`/profile/${store.me.handle}`)
|
navigation.navigate('Profile', {name: store.me.handle})
|
||||||
}, [store, track])
|
}, [navigation, track, store.me.handle])
|
||||||
|
|
||||||
const isAtHome =
|
const curr = currentRoute(navigation.getState()).name
|
||||||
store.nav.tab.current.url === TabPurposeMainPath[TabPurpose.Default]
|
const isAtHome = curr === 'HomeStack' || curr === 'Home'
|
||||||
const isAtSearch =
|
const isAtSearch = curr === 'SearchStack' || curr === 'Search'
|
||||||
store.nav.tab.current.url === TabPurposeMainPath[TabPurpose.Search]
|
|
||||||
const isAtNotifications =
|
const isAtNotifications =
|
||||||
store.nav.tab.current.url === TabPurposeMainPath[TabPurpose.Notifs]
|
curr === 'NotificationsStack' || curr === 'Notifications'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Animated.View
|
<Animated.View
|
||||||
Reference in New Issue
Block a user