Component Init is hiding behind Navigation Bar after implementing Drawer to NavBar. Without Drawer I could easily add some paddingTop to Route (root) component and the problem would get solved.
<Router renderLeftButton={this.navBarButton}>
<Scene
key="drawer"
component={DrawerComponent}
open={false}
>
<Scene key="main" >
<Scene key="index" component={Init} title="First page!" />
<Scene key="counter" component={Counter} title="Counter" />
<Scene key="posts" component={Posts} title="Posts" />
</Scene>
</Scene>
</Router>
If I add paddingTop on root for global padding, it gives back extra padding on both Navbar and Coponent.
I do get the desired result by adding paddingTop to each children Scenes but that would be hectic. e.g.
<Scene key="index" component={Init} title="First page!" sceneStyle={{paddingTop: 64}} />
I have yet to see a solution that does not use any type of paddingTop to solve this issue. However, instead of adding the styles to each scene, you can add it to the Router that will apply to every scene.
<Router renderLeftButton={this.navBarButton} sceneStyle={{ paddingTop: 65 }}>
<Scene />
<Scene />
</Router>
Related
I am using react-native-router-flux react native library for navigation but type Property not working
<Route name="error" component={Error} title="Error" type="reset"/>
it give error like
_this2[type] is not a function.
react-native-router-flux version 4.0.0-beta.28
The thing is type should use in <Scene> not in <Route>
here the working example
import { Router, Scene, Actions } from 'react-native-router-flux';
<Router>
<Scene key="root">
<Scene key="login" component={LoginForm} hideNavBar={'true'} initial={true} />
<Scene key="signin" component={SigninForm} />
<Scene
type="reset"
key="dashboard"
component={NavigationView}
initial={props.isLogin}
hideNavBar={'true'}
/>
</Scene>
</Router>
well there is other way:
remove type from scene and use it as a param when moving to other screen.
Actions.error({ type:'reset' });
or
Actions.reset('KEY'); // this one is work, i just tested now.
or you can replace see this
https://github.com/aksonov/react-native-router-flux/issues/467
you can pass js files as
<Router hideNavBar={true}>
<Stack key="root" hideNavBar={true}>
<Scene key="splashscreen" component={SplashScreen} title="SplashScreen" initial={true}></Scene>
</Stack>
</Router>
and whichever page you want to go you can pass
Actions.splashscreen()
(need to pass key written in scene)
I am using react native router flux in my react native application.
I created some scenes in Route.
<Router>
<Scene key="root" hideNavBar={true} navigationBarStyle={{ backgroundColor: '#81b71a' }}>
<Scene key="auth">
<Scene key="login" component={LoginForm} title="Please Login" />
</Scene>
<Scene key="main" navigationBarStyle={{ backgroundColor: '#8fff1f' }}>
<Scene
key="mainScene1"
component={EmployeeList}
title="MainScene1"
/>
<Scene key="mainScene2" component={EmployeeCreate} title="MainScene1" />
<Scene key="MainScene3" component={EmployeeEdit} title="Edit Employee" />
</Scene>
</Scene>
</Router>
I want to navigate from mainScene3 to mainScene1 but getting error "Error: There is no route defined for key mainScene1. Must be one of: 'auth','main' "
How to tackle this issue? These two scene are in the same bucket.
Another query - How to navigate from login scene of auth to any scene say mainScene2 ? Is there any special method for that?
I word on react-native-router-flux and I have a problem ... I am reset my Stack navigation when I am changing of Tab navigation.
I try with backToInitial but I need to press two times on my tab for reset my stack ... I don't understand why.
My navigation :
-OSU
-Scarlet
-Gray
-VU
-Blue
-Black
So when I am on Blue and I press one time on OSU I when to access at Scarlet not gray
My code :
export default class App extends Component {
render() {
return (
<Router>
<Tabs
key="tabbar"
tabBarStyle={{ backgroundColor: '#FFFFFF' }}
backToInitial={true}
>
<Scene key="osu" title="OSU" icon={TabIcon} type='reset' backToInitial={true}>
<Scene
key="scarlet"
component={ScarletScreen}
title="Scarlet"
/>
<Scene
key="gray"
component={GrayScreen}
title="Gray"
/>
</Scene>
<Scene key="vu" title="VU" icon={TabIcon} backToInitial={true}>
<Scene
key="blue"
component={BlueScreen}
title="Blue"
/>
<Scene
key="black"
component={BlackScreen}
title="Black"
/>
</Scene>
</Tabs>
</Router>
);
}
}
I am trying to understand how to use router-flux and have multiple scenes/sub scenes similar to having multiple story boards, so that I can have a scene for the user sign up process, and then a scene for once the user is sign up and logged in.
At present I am doing this but it isn't given me the desired result
class NavigationRouter extends Component {
render () {
return (
<Router>
<Scene key='drawer' component={NavigationDrawer} open={false}>
<Scene key='root' tabs={true}>
<Scene key='account' hideNavBar={true} >
<Scene initial key='Login' component={Login} title='Login' />
<Scene key='SignUp' component={SignUp} title='SignUp' />
<Scene key='Account' component={Account} title='Account' />
<Scene key='Venue' component={Venue} title='Venue' />
</Scene>
<Scene key='auth' renderLeftButton={NavItems.hamburgerButton} navigationBarStyle={Styles.navBar} titleStyle={Styles.title} leftButtonIconStyle={Styles.leftButton} rightButtonTextStyle={Styles.rightButton} >
<Scene key='MenuItems' component={MenuItems} title='Your Menu' />
<Scene key='Orders' component={Orders} title='Orders' />
</Scene>
</Scene>
</Scene>
</Router>
)
}
}
The first part of the login/signup journey should not display the nav bar and allow the user to go back to the past step.
The second part should allow the logged in user to access the nav bar and side draw for the items which are defined in it
Even though grouping scenes with another scene looks more readable and correct, it makes Action not to work as expected, since Actions.SCENE() can only navigate within its siblings. In other words, two scenes should have the same parent.
Here's a modified version of your navigator tree. For example, you can start with Login scene, and route directly to tab1 by calling Actions.tabbar(). In your tabbar scene, there will be two subcomponents. User can manually navigate between tabs, or you can again call Actions.tab2(), since they're siblings too.
I prefer putting every scene sibling to another since it takes two chained actions. It looks a bit messy, but using spaces and comments help.
class NavigationRouter extends Component {
render () {
return (
<Router>
<Scene key='drawer' component={NavigationDrawer} open={false}>
<Scene key='root'>
{/* Authentications */}
<Scene initial key='Login' component={Login} title='Login' />
<Scene key='SignUp' component={SignUp} title='SignUp' />
<Scene key='Account' component={Account} title='Account' />
{/* Main */}
<Scene key='Venue' component={Venue} title='Venue' />
{/* Tabs... */}
<Scene key='tabbar' tabs={true} renderLeftButton={NavItems.hamburgerButton} navigationBarStyle={Styles.navBar} titleStyle={Styles.title} leftButtonIconStyle={Styles.leftButton} rightButtonTextStyle={Styles.rightButton} >
<Scene icon={Icon1} key='tab1' component={MenuItems} title='Your Menu' />
<Scene icon={Icon2} key='tab2' component={Orders} title='Orders' />
</Scene>
</Scene>
</Scene>
</Router>
)
}
}
If you want to jump directly to the sub-scene of a sibling, say tabbar1, combine two actions:
Actions.callback({key:'tabbar',type:'push'});
Actions.callback({key:'tab1',type:'jump'});
The ugliest part of the tree above is styling multiple scenes at once. Such as removing navbar from 5 siblings. And there you can define an object of props and add them into corresponding sub-scenes {...customProps}
Better way of organizing: Split your scenes to smaller parts if needed.
I have a tabbar component rendered within which I want to wrap with a custom native module for a custom style behavior not available within react's css (linear opacity gradience.)
<Scene key="video" tabs={true} tabBarStyle={styles.tabBarStyle}>
<Scene key="profile" title="profile" component={MyProfile} icon={TabIcon} hideNavBar />
<Scene key="trend" title="trend" component={TrendMenuScene} icon={TabIcon} hideNavBar />
<Scene key="home" title="home" component={MainMenuScene} initial icon={TabIcon} hideNavBar />
<Scene key="star" title="star" component={Favourite} icon={TabIcon} hideNavBar />
<Scene key="discover" title="discover" component={Search} icon={TabIcon} hideNavBar />
</Scene>
My first attempt and thought would be to add a component attribute to the top level that wraps the scene component. inside that component might be something like.
return (
<LinearGradient key="gradientWrap" colors={['transparent', 'rgba(0, 0, 0, 0.5)']} style={styles.linearGradient}>
{this.props.children}
</LinearGradient>
)
this does not work and throws a error. I have tried cloning props but I wrap everything and the entire pages is wrapped in the linear gradient :/
So how to wrap just the tabbar in the linear gradient? Or more generally any wrapping component.