当我键入时,标题中的图像不断闪烁。请问如何在右上角或accessoryRight中停止这种闪烁?我正在使用 UI Kitten UI 库中的这个TopNavigation 组件。我认为这不正常,根本不应该发生。我一定是做错了什么。
https://youtu.be/fQppQn-RzeE(我如何嵌入这个?编辑,提前谢谢你!)
闪烁发生在导航标题的标题和右侧。
我为 TopNavigation 制作了一个单独的组件,然后在各自的屏幕中调用它。
我尝试过的事情:
- 由于 Header 的结果依赖于
navigation props
,我尝试使用useState
anduseEffect
(以 navProps 作为依赖项)来保存道具而不是直接从 读取props
,但无济于事 - 直接将 jsx 添加到 TopNavigation 的
accessoryLeft/Right
和title
选项中
欢迎任何意见,不胜感激!
顶部导航:
const NavHeader = ({ navProps }) => {
const navigateBack = () => {
navProps.navigation.goBack();
};
const [type, setType] = React.useState('');
React.useEffect(() => {
setType(navProps.type);
}, [navProps]);
const BackIcon = props => <Icon {...props} name='arrow-back' />;
const BackAction = () => (
<TopNavigationAction icon={BackIcon} onPress={navigateBack} />
);
const renderBrand = () => (
<View style={styles.titleContainer}>
<Image source={require('../../assets/images/brand.png')} />
</View>
);
const renderLogo = () => (
<Image source={require('../../assets/images/logo.png')} />
);
return (
<TopNavigation
style={styles.topNav}
accessoryLeft={navProps.backNav && BackAction}
accessoryRight={
type === 'register' || type === 'profile' ? renderLogo : null
}
title={type === 'landing' || type === 'auth' ? renderBrand : null}
alignment='center'
/>
);
};
导入示例:
<KeyboardAvoidingView
style={styles.kbContainer}
behavior={Platform.OS === 'ios' ? 'padding' : null}
>
<SafeAreaView style={styles.parentContainer}>
<NavHeader navProps={navProps} /> // Imported custom Header component here
<ScrollView>
{other content}
</ScrollView>
</SafeAreaView>
</KeyboardAvoidingView>