From 91a9df52d30a7448a51bb18af6972108388f1ac6 Mon Sep 17 00:00:00 2001 From: quguiren Date: Sat, 9 Aug 2025 14:03:51 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=80=E5=90=AF?= =?UTF-8?q?=E6=97=A0=E9=9A=9C=E7=A2=8D=E6=97=B6=E5=B1=8F=E5=B9=95=E6=9C=97?= =?UTF-8?q?=E8=AF=BB=E6=97=A0=E6=B3=95=E9=80=89=E4=B8=AD=E5=AF=BC=E8=88=AA?= =?UTF-8?q?=E6=9D=A1=E6=8C=89=E9=92=AEbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: quguiren --- .../stack/src/views/Header/HeaderContainer.tsx | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/stack/src/views/Header/HeaderContainer.tsx b/packages/stack/src/views/Header/HeaderContainer.tsx index cbfd6b5d95..443bee7105 100644 --- a/packages/stack/src/views/Header/HeaderContainer.tsx +++ b/packages/stack/src/views/Header/HeaderContainer.tsx @@ -63,11 +63,12 @@ export default function HeaderContainer({ headerStyleInterpolator, } = scene.descriptor.options; - if (headerMode !== mode || !headerShown) { + if ((headerMode !== mode || !headerShown) && focusedRoute.key !== scene.descriptor.route.key) { return null; } const isFocused = focusedRoute.key === scene.descriptor.route.key; + const shouldHideHeader = (headerMode !== mode || !headerShown) && isFocused; const previousScene = getPreviousScene({ route: scene.descriptor.route, }); @@ -154,17 +155,14 @@ export default function HeaderContainer({ : undefined } pointerEvents={isFocused ? 'box-none' : 'none'} - accessibilityElementsHidden={!isFocused} + accessibilityElementsHidden={!isFocused || shouldHideHeader} importantForAccessibility={ - isFocused ? 'auto' : 'no-hide-descendants' - } - style={ - // Avoid positioning the focused header absolutely - // Otherwise accessibility tools don't seem to be able to find it - (mode === 'float' && !isFocused) || headerTransparent - ? styles.header - : null + (isFocused && !shouldHideHeader) ? 'auto' : 'no-hide-descendants' } + style={[ + ((mode === 'float' && !isFocused) || headerTransparent) ? styles.header : null, + shouldHideHeader ? { opacity: 0, height: 0, overflow: 'hidden' } : null + ]} > {header !== undefined ? header(props) :
} From 57b39972e92b792f2c358f02c431d6f9e4f981f6 Mon Sep 17 00:00:00 2001 From: lianglianghuang <413516392@qq.com> Date: Thu, 14 Aug 2025 20:04:40 +0800 Subject: [PATCH 2/2] Update HeaderContainer.tsx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化逻辑 --- .../src/views/Header/HeaderContainer.tsx | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/packages/stack/src/views/Header/HeaderContainer.tsx b/packages/stack/src/views/Header/HeaderContainer.tsx index 443bee7105..899afc46ba 100644 --- a/packages/stack/src/views/Header/HeaderContainer.tsx +++ b/packages/stack/src/views/Header/HeaderContainer.tsx @@ -6,7 +6,7 @@ import { Route, } from '@react-navigation/native'; import * as React from 'react'; -import { Animated, StyleProp, StyleSheet, View, ViewStyle } from 'react-native'; +import { Animated, StyleProp, StyleSheet, View, ViewStyle, Platform } from 'react-native'; import { forNoAnimation, @@ -36,6 +36,18 @@ export type Props = { style?: Animated.WithAnimatedValue>; }; +function compareVersion(v1: string, v2: string) { + const a = v1.split('.').map(Number); + const b = v2.split('.').map(Number); + for (let i = 0; i < Math.max(a.length, b.length); i++) { + const num1 = a[i] || 0; + const num2 = b[i] || 0; + if (num1 > num2) return 1; + if (num1 < num2) return -1; + } + return 0; +} + export default function HeaderContainer({ mode, scenes, @@ -63,12 +75,18 @@ export default function HeaderContainer({ headerStyleInterpolator, } = scene.descriptor.options; - if ((headerMode !== mode || !headerShown) && focusedRoute.key !== scene.descriptor.route.key) { + const rawVersion = typeof Platform.Version === 'string' ? Platform.Version : String(Platform.Version); + const match = rawVersion.match(/(\d+\.\d+\.\d+)/); + const version = match ? match[1] : '0.0.0'; + const isHarmony = (Platform.OS as string) === 'harmony'; + + let shouldHideHeader = isHarmony && compareVersion(version, '6.0.0') >= 0 ? !headerShown && focusedRoute.key !== scene.descriptor.route.key : headerMode !== mode || !headerShown; + + if (shouldHideHeader) { return null; } const isFocused = focusedRoute.key === scene.descriptor.route.key; - const shouldHideHeader = (headerMode !== mode || !headerShown) && isFocused; const previousScene = getPreviousScene({ route: scene.descriptor.route, }); @@ -155,14 +173,17 @@ export default function HeaderContainer({ : undefined } pointerEvents={isFocused ? 'box-none' : 'none'} - accessibilityElementsHidden={!isFocused || shouldHideHeader} + accessibilityElementsHidden={!isFocused} importantForAccessibility={ - (isFocused && !shouldHideHeader) ? 'auto' : 'no-hide-descendants' + isFocused ? 'auto' : 'no-hide-descendants' + } + style={ + // Avoid positioning the focused header absolutely + // Otherwise accessibility tools don't seem to be able to find it + (mode === 'float' && !isFocused) || headerTransparent + ? styles.header + : null } - style={[ - ((mode === 'float' && !isFocused) || headerTransparent) ? styles.header : null, - shouldHideHeader ? { opacity: 0, height: 0, overflow: 'hidden' } : null - ]} > {header !== undefined ? header(props) :
}