react-native - 自定义导航栏 - 不同场景下的不同图像
问题描述
我是反应原生的新手,我有问题。在我的应用程序中有 3 个场景和自定义导航栏。我需要不同场景的不同图像。如果我只改变背景,它的工作很完美,但我需要更多它的平均图像
//路由器.js
<Scene key="root" navBar={Navbar} drawer contentComponent={Drawer}>
<Scene key="home" component={Home} initial={true} hideNavBar={true} />
<Scene key="op" ref="Op" component={Op}
navigationBarStyle = {styles.sceneOp}
/>
<Scene key="about" component={About}
navigationBarStyle = {styles.sceneAbout}
/>
</Scene>
...
const styles = StyleSheet.create({
sceneOp: {
backgroundColor: 'grey',
},
sceneAbout: {
backgroundColor: 'yellow',
}
});
//navbar.js - 在这个文件中,我需要我的 dynamicLogo 是像 navigationBarStyle 这样的道具。这个怎么做?
render() {
let dynamicLogo = navStyle.assets.img;
return (
<View style={styles.outerContainer, this.props.navigationBarStyle}>
<View style={styles.innerContainer}>
<TouchableOpacity
onPress={() => {
Actions.drawerOpen();
}}
style={styles.sideElementContainer}
>
<Image style={styles.burger} source={require('../assets/burger-icon.png')} />
</TouchableOpacity>
<View style={styles.logoContainer}>
<Image style={styles.logo} source={dynamicLogo} />
</View>
<View style={styles.sideElementContainer} />
</View>
</View>
);
}
解决方案
我通过使用 renderTitle 做到了
//Routers.js
<Scene key="root" navBar={Navbar} drawer contentComponent={Drawer}>
<Scene key="home" component={Home} initial={true} hideNavBar={true} />
<Scene key="op" ref="Op" component={Op}
navigationBarStyle = {styles.sceneOp}
renderTitle={navImage.imgExto}
/>
<Scene key="about" component={About}
navigationBarStyle = {styles.sceneAbout}
renderTitle={navImage.imgMe}
/>
</Scene>
...
const navImage = {
imgExto: require('./assets/e-logo.png'),
imgMe: require('./assets/m-logo.png'),
};
推荐阅读
- spring-boot - jms连接失败后Springboot应用无法恢复
- ebpf - eBPF 验证器中的 func_info 是什么?
- sql-server - PowerBI Report Builder 与 AWS Redshift 的集成
- c++ - 索引 2^21 处的执行时间开销
- kubernetes - 如何通过api或其他交互连接kubernetes pods(终端)?
- php - php 在嵌套数组中使用 array_slice
- c# - Fluent Nhibernate 在连接到 Oracle 数据库时抛出错误
- excel - Excel 找不到数据
- azure - Azure 数据工厂 - 如何从 azure 函数返回 JSON 作为参数并将其传递给 Databricks 服务?
- java - Java 8 在 HTTPS 请求中找不到受信任的证书