底部导航

This commit is contained in:
liu
2026-07-01 21:58:27 +08:00
parent d909d376f9
commit 137db25b49
6 changed files with 11 additions and 24 deletions
+1 -2
View File
@@ -26,12 +26,11 @@ interface PublishPopupProps {
export default function PublishPopup({ visible, onClose, onSelect }: PublishPopupProps) { export default function PublishPopup({ visible, onClose, onSelect }: PublishPopupProps) {
return ( return (
<Popup <Popup
visible={visible} show={visible}
position='bottom' position='bottom'
round round
onClose={onClose} onClose={onClose}
closeable closeable
customStyle={{ background: 'transparent' }}
> >
<View className='publish-popup'> <View className='publish-popup'>
<View className='popup-header'> <View className='popup-header'>
+6 -18
View File
@@ -20,24 +20,13 @@ const TAB_LIST: TabItem[] = [
{ key: 'profile', label: '我的', icon: '👤', pagePath: '/pages/profile/index' }, { key: 'profile', label: '我的', icon: '👤', pagePath: '/pages/profile/index' },
] ]
/** interface CustomTabBarProps {
* 根据当前页面路由推导激活的 tab。 /** 当前激活的 tab key,由页面传入 */
* 不使用 useState —— Taro 在每次切换 tab 时都会重建 custom-tab-bar 实例, activeKey: string
* 因此直接从 getCurrentPages() 实时计算即可保证正确性。
*/
function useActiveKey(): string {
const pages = Taro.getCurrentPages()
if (pages.length > 0) {
const route = pages[pages.length - 1].route || ''
for (const tab of TAB_LIST) {
if (route.includes(tab.key)) return tab.key
}
}
return 'index'
} }
/** 获取底部安全距离 */ /** 获取底部安全距离 */
function useSafeBottom(): number { function getSafeBottom(): number {
try { try {
const info = Taro.getSystemInfoSync() const info = Taro.getSystemInfoSync()
if (info.safeArea) { if (info.safeArea) {
@@ -47,9 +36,8 @@ function useSafeBottom(): number {
return 0 return 0
} }
export default function CustomTabBar() { export default function CustomTabBar({ activeKey }: CustomTabBarProps) {
const activeKey = useActiveKey() const safeBottom = getSafeBottom()
const safeBottom = useSafeBottom()
const [publishVisible, setPublishVisible] = useState(false) const [publishVisible, setPublishVisible] = useState(false)
/** 切换 Tab —— 使用 Taro.switchTab 与原生 tabBar 行为一致 */ /** 切换 Tab —— 使用 Taro.switchTab 与原生 tabBar 行为一致 */
+1 -1
View File
@@ -165,7 +165,7 @@ export default function Index() {
<View className='bottom-safe' /> <View className='bottom-safe' />
</ScrollView> </ScrollView>
<CustomTabBar /> <CustomTabBar activeKey='index' />
</View> </View>
) )
} }
+1 -1
View File
@@ -10,7 +10,7 @@ export default function Messages() {
<Text className='placeholder-text'></Text> <Text className='placeholder-text'></Text>
<Text className='placeholder-desc'>线</Text> <Text className='placeholder-desc'>线</Text>
</View> </View>
<CustomTabBar /> <CustomTabBar activeKey='messages' />
</View> </View>
) )
} }
+1 -1
View File
@@ -10,7 +10,7 @@ export default function Profile() {
<Text className='placeholder-text'></Text> <Text className='placeholder-text'></Text>
<Text className='placeholder-desc'>线</Text> <Text className='placeholder-desc'>线</Text>
</View> </View>
<CustomTabBar /> <CustomTabBar activeKey='profile' />
</View> </View>
) )
} }
+1 -1
View File
@@ -10,7 +10,7 @@ export default function Tasks() {
<Text className='placeholder-text'></Text> <Text className='placeholder-text'></Text>
<Text className='placeholder-desc'>线</Text> <Text className='placeholder-desc'>线</Text>
</View> </View>
<CustomTabBar /> <CustomTabBar activeKey='tasks' />
</View> </View>
) )
} }