From c8c85c07463979a79330aa0fdef19908672b1353 Mon Sep 17 00:00:00 2001 From: Leon Date: Tue, 24 Sep 2024 15:37:35 +0800 Subject: [PATCH] fix: Android tabs issue on v5.2.1 (#5910) * fix: some tab issues on android (#5888) * fix: the tab issues on android (#5895) --------- Co-authored-by: hublot --- .../TabView/StickyTabComponent/index.native.tsx | 17 +++++++++++++---- .../kit/src/components/TokenListView/index.tsx | 3 +-- .../kit/src/views/Home/pages/HomePageView.tsx | 1 + packages/kit/src/views/Market/MarketHome.tsx | 1 - 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/components/src/layouts/TabView/StickyTabComponent/index.native.tsx b/packages/components/src/layouts/TabView/StickyTabComponent/index.native.tsx index a1850aa13f3..85fae764bf3 100644 --- a/packages/components/src/layouts/TabView/StickyTabComponent/index.native.tsx +++ b/packages/components/src/layouts/TabView/StickyTabComponent/index.native.tsx @@ -26,7 +26,7 @@ export const TabComponent = ( tabContentContainerStyle, style, onRefresh: onRefreshCallBack, - initialHeaderHeight = 250, + initialHeaderHeight = 0, }: ITabProps, // fix missing forwardRef warnings. // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -172,9 +172,18 @@ export const TabComponent = ( ); const onIndexChange = useCallback(() => {}, []); - const onLayout = useCallback(({ nativeEvent }: LayoutChangeEvent) => { - setHeaderHeight(nativeEvent.layout.height); - }, []); + const onLayout = useCallback( + ({ nativeEvent }: LayoutChangeEvent) => { + if (nativeEvent.layout.height === headerHeight) { + return; + } + if (platformEnv.isNativeAndroid && initialHeaderHeight > 0) { + return; + } + setHeaderHeight(nativeEvent.layout.height); + }, + [headerHeight, initialHeaderHeight], + ); return ( // @ts-expect-error diff --git a/packages/kit/src/views/Home/pages/HomePageView.tsx b/packages/kit/src/views/Home/pages/HomePageView.tsx index 1bbe211357e..ef0b2362617 100644 --- a/packages/kit/src/views/Home/pages/HomePageView.tsx +++ b/packages/kit/src/views/Home/pages/HomePageView.tsx @@ -140,6 +140,7 @@ export function HomePageView({ data={tabs} ListHeaderComponent={} initialScrollIndex={0} + initialHeaderHeight={220} contentItemWidth={CONTENT_ITEM_WIDTH} contentWidth={screenWidth} showsVerticalScrollIndicator={false} diff --git a/packages/kit/src/views/Market/MarketHome.tsx b/packages/kit/src/views/Market/MarketHome.tsx index b1f8fb986e9..18c643b0fca 100644 --- a/packages/kit/src/views/Market/MarketHome.tsx +++ b/packages/kit/src/views/Market/MarketHome.tsx @@ -153,7 +153,6 @@ function MarketHome() { return (