目前,我正在尝试在react-native-router-flux导航栏中实现一个徽标,这是一个png文件。我不确定这是否可能,因为我还没有在网上找到任何例子。我尝试使用react-native-router-flux中的'navigationBarBackgroundImage‘属性。在下面的代码中,sceneStyle和navigationBarStyle属性起作用,但是背景图像不起作用。有什么建议吗?
<Router
sceneStyle={{ paddingTop: 60 }}
navigationBarStyle={{ backgroundColor: '#80ffbf' }}
navigationBarBackgroundImage={{src:'./Resources/GiftIt_Logo_Green.png' }}
>发布于 2016-12-02 02:39:24
我在根场景中使用renderTitle道具向NavBy添加了一个徽标,并渲染了一个自定义组件:
const AppLogo = () => {
return (
<View style={{ alignItems: 'center', marginTop: 26 }}>
<Image source={require('./app/assets/images/appLogo.png')}
style={{ width: 84, height: 27 }} />
</View>
);
};
const MyApp = React.createClass({
render() {
<Provider store={store}>
<RouterWithRedux hideNavBar={true}>
<Scene key="root" renderTitle={() => { return <AppLogo />; }}>
<Scene key="home" component={HomePage} title="My App" initial={true} />
...
});发布于 2017-05-04 23:55:33
构建场景时,将renderTitle()方法传递到场景组件中,然后可以在其中插入图像。确保您获取的是图像文件的正确相对路径。
import React from 'react';
import { View, Image } from 'react-native';
import { Scene, Router } from 'react-native-router-flux';
import Feed from './components/Feed';
import LogoText from './assets/logo-text.png';
const RouterComponent = () => {
return (
<Router>
<Scene
key="Feed"
renderTitle={() => (
<View>
<Image style={styles.headerLogo} source={LogoText} />
</View>
)}
renderBackButton={() => (null)}
navigationBarStyle={styles.header}
component={Feed}
/>
</Router>
);
};
const styles = {
header: {
backgroundColor: 'lightgrey',
padding: 25,
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'row',
height: 64,
},
headerLogo: {
height: 14,
width: 90,
},
};
export default RouterComponent;发布于 2016-10-21 05:38:36
查看github页面上的问题部分。
尝尝这个
navigationBarBackgroundImage={{
uri: 'navbar-background', // reference to resource
width: Dimensions.get('window').width, // make sure the image stretches all the way
height: 64, // height of the navbar
}}https://stackoverflow.com/questions/40164230
复制相似问题