feat: frosted floating tab bar and updated icon colors
This commit is contained in:
@@ -21,7 +21,8 @@ function matchTab(path: string): string {
|
||||
}
|
||||
|
||||
function currentTabPath(): string {
|
||||
const path = Taro.getCurrentInstance().router?.path || 'pages/index/index'
|
||||
const router = Taro.getCurrentInstance().router
|
||||
const path = router && router.path ? router.path : 'pages/index/index'
|
||||
return matchTab(path)
|
||||
}
|
||||
|
||||
@@ -42,7 +43,9 @@ export default function CustomTabBar() {
|
||||
// 其它入口(如页面内部调用 switchTab)也会回到 tabBar,收到事件后重新同步选中态
|
||||
useEffect(() => {
|
||||
const handler = (path?: string) => {
|
||||
setActiveTab(matchTab(path || Taro.getCurrentInstance().router?.path || 'pages/index/index'))
|
||||
const router = Taro.getCurrentInstance().router
|
||||
const currentPath = router && router.path ? router.path : 'pages/index/index'
|
||||
setActiveTab(matchTab(path || currentPath))
|
||||
}
|
||||
Taro.eventCenter.on('tabBarChange', handler)
|
||||
return () => {
|
||||
@@ -59,7 +62,7 @@ export default function CustomTabBar() {
|
||||
const switchTab = (url: string) => {
|
||||
setActiveTab(matchTab(url))
|
||||
Taro.switchTab({ url })
|
||||
Taro.eventCenter?.trigger('tabBarChange', url)
|
||||
Taro.eventCenter.trigger('tabBarChange', url)
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user