I am new in react native and I have problem.
In my application a have 3 scenes and custom navbar. I need diffrent image on different scene. If I only change background it's work perfect, but I need more its mean image
//router.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 - in this file, I need that my dynamicLogo was props like navigationBarStyle. How to do this?
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>
);
}
I did it by using 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'),
};
Related
Hi Guys i have very basic implementation of routing with tab but when i am using tabs i couldn't enable swipe functionality with React-native-router-flux.
Following is my route file
Router sceneStyle={[styles.scene, { backgroundColor: Color.Blue10 }]}>
<Stack key="root" hideNavBar navigationBarStyle={styles.navBar} titleStyle={styles.title}>
<Tabs
key="tabbar"
>
<Scene
key="SignIn"
component={SignIn}
titleStyle={{
display: 'none',
}}
swipeEnabled
/>
<Scene
key="SignIn"
titleStyle={{
display: 'none',
}}
swipeEnabled
component={SignIn}
/>
</Tabs>
</Stack>
</Router>
I am trying to get the the data I filled in the input to the chat screen but I am getting the key scene name of that screen. How can I fix it?
Heading
<Router>
<Scene key="root" style={{paddingTop:Platform.OS==='ios'? 64:54}}>
<Scene key="Login" component={Login} hideNavBar={true} hideTabBar={true} />
<Scene key="tabbar" tabs={true} tabBarStyle={{backgroundColor:'#fff'}} hideNavBar={true}
>
<Scene key="Home" component={CardList} title="Home" iconName="ios-home" icon={TabIcon}/>
<Scene key="contacts" component={Contacts} iconName="ios-contacts" icon={TabIcon} />
<Scene key='chat' component={Chat} hideTabBar={true} title='Chat'iconName="ios-chatbubbles" icon={TabIcon} />
<
</Scene>
</Scene>
</Router>
<View style={style.container}>
<Text> hello{this.props.name}</Text>
</View>
contract
state={ name:'',};
render() { return (
<View style={style.container}>
<Text> Enter your name </Text>
<TextInput style={style.textInput} onChangeText={(text)=>{ this.setState({ name: text, }); }} value={this.state.name} />
<TouchableOpacity onPress={()=>{ Actions.chat({ name: this.state.name, }) }} >
<Text> Next </Text>
</TouchableOpacity>
chat
This was a matter of name. Name was saving the name of the router. That's why you have to change the parameter name.
You can use this to turn over the data. If you want pass data in chat
Actions.chat({passname: this.state.name})
You can recover your data in chat Screen like this:
<TextInput
style={{height: 40, borderColor: 'gray', borderWidth: 1}}
value={this.props.passname}
Example I created
i can't remove text under TabIcon in TabBar of react-native-router-flux. It is screen of my TabBar:
enter image description here
And it is my code of router:
const TabBar = ({focused}) => (
<View>
<Icon name="search" type="MaterialIcons" style={{fontSize: 28, color: focused ? 'red': 'white'}} />
</View>
)
export default () => (
<Router>
<Scene hideNavBar>
<Scene key="tabbar" tabs tabBarStyle={{backgroundColor: '#000'}}>
<Scene key="list" title="Ahlo" component={List} hideNavBar icon={TabBar} />
<Scene key="search" component={search} hideNavBar icon={TabBar} />
<Scene key="account" component={account} hideNavBar icon={TabBar} />
</Scene>
<Scene key="article" component={article} />
<Scene key="comment" component={comment} />
<Scene key="register" component={register} />
<Scene key="auth" component={auth} />
</Scene>
</Router>
)
In every tutorials i see that text under TabIcon is missing but i have it. What do i do wrong here?
You can try by adding the showLabel props to parent or particular child Scene to false, (By default its value is true)
So your tabbar Scene code will be like:
<Scene key="tabbar" showLabel={false} tabs tabBarStyle={{backgroundColor: "#000"}}>
<Scene key="list" component={List} showLabel={false} hideNavBar icon={TabBar} />
<Scene key="search" component={search} showLabel={false} hideNavBar icon={TabBar} />
<Scene key="account" component={account} showLabel={false} hideNavBar icon={TabBar} />
</Scene>
Hope this will help.
I am using react-native with react-native-router-flux and I want to use both Drawer sidemenu and also tabbar. But it only shows the one I put on top. My code is below. If I put Drawer first then it only shows Drawer.
import React from 'react';
import { StyleSheet, Text, View, Image } from 'react-native';
import { Router, Scene, Stack, Tabs, Drawer } from 'react-native-router-flux';
import ScarletScreen from './component/ScarletScreen';
import ProfileScreen from './component/ProfileScreen';
import WhiteScreen from './component/WhiteScreen';
import BlackScreen from './component/BlackScreen';
import SideMenu from './component/SideMenu';
const TabIcon = ({ selected, title }) => { return (
<Text style={{color: selected ? 'red' :'black'}}>{title}</Text> ); }
export default class App extends React.Component { render() {
return (
<Router>
<Scene key="root" hideNavBar>
{/* Drawer and it's scenes */}
<Drawer key="drawer" drawerImage={require('./img/hamburger.png')} contentComponent={SideMenu}>
<Scene key="main">
<Scene
key="scarlet"
component={ScarletScreen}
title="Scarlet Screen"
initial
/>
<Scene
key="profile"
component={ProfileScreen}
title="Profile"
/>
<Scene
key="white"
component={WhiteScreen}
title="White Screen"
/>
<Scene
key="black"
component={BlackScreen}
title="Black Screen"
/>
</Scene>
</Drawer>
{/* Tab and it's scenes */}
<Tabs
key="tabbar"
tabBarStyle={{ backgroundColor: '#FFFFFF' }}
>
{/* Tab and it's scenes */}
<Scene key="osu" title="OSU" icon={TabIcon}>
<Scene
key="scarlet"
component={ScarletScreen}
title="Scarlet Screen"
/>
<Scene
key="white"
component={WhiteScreen}
title="White Screen"
/>
</Scene>
{/* Tab and it's scenes */}
<Scene key="um" title="UM" icon={TabIcon}>
<Scene
key="white"
component={WhiteScreen}
title="White"
/>
<Scene
key="black"
component={BlackScreen}
title="Black"
/>
</Scene>
</Tabs>
</Scene>
</Router>
); } }
If I put tabbar first, then it shows the tabbar only and the hamburger menu icon is gone.
{/* Tab and it's scenes */}
<Tabs
key="tabbar"
tabBarStyle={{ backgroundColor: '#FFFFFF' }}
>
{/* Tab and it's scenes */}
<Scene key="osu" title="OSU" icon={TabIcon}>
<Scene
key="scarlet"
component={ScarletScreen}
title="Scarlet Screen"
/>
<Scene
key="white"
component={WhiteScreen}
title="White Screen"
/>
</Scene>
{/* Tab and it's scenes */}
<Scene key="um" title="UM" icon={TabIcon}>
<Scene
key="white"
component={WhiteScreen}
title="White"
/>
<Scene
key="black"
component={BlackScreen}
title="Black"
/>
</Scene>
</Tabs>
{/* Drawer and it's scenes */}
<Drawer key="drawer" drawerImage={require('./img/hamburger.png')} contentComponent={SideMenu}>
<Scene key="main">
<Scene
key="scarlet"
component={ScarletScreen}
title="Scarlet Screen"
initial
/>
<Scene
key="profile"
component={ProfileScreen}
title="Profile"
/>
<Scene
key="white"
component={WhiteScreen}
title="White Screen"
/>
<Scene
key="black"
component={BlackScreen}
title="Black Screen"
/>
</Scene>
</Drawer>
I use create-react-native-app to create my react-native app
I'm using react-native-router-flux in my app and want to pass in paths to png images for my TabIcon components. I know I could just make a different tab icon component for each tab, but these icons would be exactly the same except for the image source and I want to find a DRY way to accomplish my goal. Where in my scenes can I pass in the image path?
Here is my TabIcon component:
const TabIcon = ({ selected, title, image }) => {
const tabStyle = selected ? styles.selected : styles.unselected
return (
<View style={tabStyle}>
<Image
style={{height: 35, width: 35}}
source={require(image)}
/>
</View>
)
}
My scenes:
const Scenes = Actions.create(
<Scene key='root'>
<Scene key='tabbar' tabs={true} tabBarStyle={styles.tabBarStyle}>
<Scene key='tab1' title='Feed' icon={TabIcon}>
<Scene
key='Feed'
component={Feed}
title='Feed'
initial={true}
/>
</Scene>
<Scene key='tab2' title='Create' icon={TabIcon}>
<Scene
key='Create'
component={Create}
title='Create'
/>
</Scene>
<Scene key='tab3' title='Leaderboard' icon={TabIcon}>
<Scene
key='leaderboard'
component={Leaderboard}
title='Leaderboard'
/>
</Scene>
</Scene>
</Scene>
)
EDIT
I have tried passing in the image like so
const Scenes = Actions.create(
<Scene key='root'>
<Scene key='tabbar' tabs={true} tabBarStyle={styles.tabBarStyle}>
//HERE
<Scene key='tab1' title='Feed' icon={TabIcon} image={'../images/feed.png'}>
<Scene
key='matchupsFeed'
component={MatchupsFeed}
title='Feed'
initial={true}
/>
</Scene>
...
...
...
Within my TabIcon component if I console.log(image) it prints out "../images/feed.png" but I get this error in the simulator:
Unknown named module: '../images/feed.png'
After taking a look at this SO question, I figured it out:
const TabIcon = ({ selected, title, image }) => {
const selectColor = selected ? '#ED1B25' : '#FFF'
return (
<View style={[styles.tabStyle, {borderBottomColor: selectColor}]}>
<Image
style={{height: 35, width: 35}}
// Change HERE
source={image}
/>
</View>
)
}
Scenes
const Scenes = Actions.create(
<Scene key='root'>
<Scene key='tabbar' tabs={true} tabBarStyle={styles.tabBarStyle}>
//Change HERE
<Scene key='tab1' title='Feed' icon={TabIcon} image={require('../images/feed.png')}>