I use react navigation to handle my app navigate. I have one problem. I have 5 navigation file. I have createMaterialTopTabNavigator that use it on StackNavigator. but I cant navigation between them.
my createMaterialTopTabNavigator
import React, { Component } from 'react';
import {
StyleSheet,
View,
Dimensions,
} from 'react-native';
import { createMaterialTopTabNavigator ,createAppContainer} from 'react-navigation';
import OneWay from '../Components/MainSearch/OneWay' ;
import TwoWay from '../Components/MainSearch/TwoWay';
import SeveralWay from '../Components/MainSearch/SeveralWay';
const FlightOptions = createMaterialTopTabNavigator({
'چندمقصده':{
screen: SeveralWay,
navigationOptions:{
header: null, headerMode: 'none',swipeEnabled:true}
},
'یک طرفه':{
screen: OneWay,
navigationOptions:{
header: null, headerMode: 'none',swipeEnabled:true}
},
'رفت و برگشت':{
screen: TwoWay,
navigationOptions:{
header: null, headerMode: 'none',swipeEnabled:true}
}
},
{
tabBarOptions: {
labelStyle: {
fontSize: 15,
color: '#15479F',
fontFamily : 'Sahel-Bold',
textDecorationLine: 'underline',
},
style: {
shadowOpacity: 0,
shadowOffset: {
height: 0,
},
shadowRadius: 0,
elevation: 0,
backgroundColor: '#fff',
},
tabStyle:{
},
indicatorStyle :{
opacity: 0
}
}
},
{
headerMode: 'none',
navigationOptions: {
headerVisible: false,
}
}
);
export default createAppContainer(FlightOptions);
and my stackNavigator:
import React, { Component } from 'react';
import {
StyleSheet,
View,
} from 'react-native';
import { createStackNavigator ,createAppContainer} from 'react-navigation';
import Calendar from '../Components/MainSearch/Calendar';
import AirLineSearchResult from '../Components/MainSearch/AirLineSearchResult';
import OneWay from '../Components/MainSearch/OneWay' ;
import TwoWay from '../Components/MainSearch/TwoWay';
import SeveralWay from '../Components/MainSearch/SeveralWay';
const Detail = createStackNavigator(
{
OneWay:{
screen : OneWay,
navigationOptions: {
header: null, headerMode: 'none'
}
},
TwoWay:{
screen : TwoWay,
navigationOptions: {
header: null, headerMode: 'none'
}
},
SeveralWay:{
screen : SeveralWay,
navigationOptions: {
header: null, headerMode: 'none'
}
},
Calendar:{
screen : Calendar,
navigationOptions: {
header: null, headerMode: 'none'
}
},
AirLineSearchResult:{
screen : AirLineSearchResult,
navigationOptions: {
header: null, headerMode: 'none'
}
},
},
{
headerMode: 'none',
navigationOptions: {
headerVisible: false,
}
}
);
export default createAppContainer(Detail);
my main navigation on app:
import { createStackNavigator, createAppContainer } from 'react-navigation';
import Splash from '../Components/Splash';
import WalkThrough from '../Components/WalkThrough';
import Login from '../Components/Login/Login';
import Validation from '../Components/Login/Validation';
import MainSearchNavigation from './MainSearchNavigation';
import OneWay from '../Components/MainSearch/OneWay';
import AirLineNavigation from './AirLineNavigation';
import HotelSearchNavigation from './HotelSearchNavigation';
const AppNavigator = createStackNavigator(
{
Splash: Splash,
WalkThrough: WalkThrough,
Login : Login,
Validation : Validation,
OneWay : OneWay,
MainSearchNavigation :{
screen : MainSearchNavigation,
navigationOptions: {
header: null, headerMode: 'none'
}
},
AirLineNavigation:{
screen :AirLineNavigation,
navigationOptions: {
header: null, headerMode: 'none'
}
},
HotelSearchNavigation:{
screen :HotelSearchNavigation,
navigationOptions: {
header: null, headerMode: 'none'
}
},
},
{
initialRouteName: "Splash"
},
{
headerMode: 'none',
navigationOptions: {
headerVisible: false,
}
}
);
export default createAppContainer(AppNavigator);
and the code of OneWay that didnt work.
<TouchableOpacity
style={styles.buttonText}
onPress={()=>this.props.navigation.navigate('AirLineSearchResult')}
>
<View style={styles.buttonContainer}>
<Text
style={styles.okBotton}
>جست و جو</Text>
</View>
</TouchableOpacity>
You have more than one StackNavigator in your app. You are trying to navigate to a screen that it's in a different Stack. Therefore you should pass also the name of the stack. Assuming that you have a main StackNavigator that you are exporting to your app.js, your would have something like this:
-Main Navigator
-ChildNavigator1
-Screen1
-Screen2
-ChildNavigator2
-Screen3
-Screen4
Then, if you are on Screen4 and want to navigate to Screen1:
this.props.navigation.navigate('ChildNavigator1', {}, NavigationActions.navigate({ routeName: 'Screen1' }))
Also dont forget to import NavigationActions from react-navigation.
Related
I am trying to implement drawer navigator in my react native application. I have used the openDrawer() function in the component that should open the drawer. However on clicking the component the drawer is directly launching the screen inside the drawer rather than simply opening the drawer. Is the way i am using the navigator wrong? Any help would be appreciated.
Navigator.js
import React from 'react';
import { createAppContainer,createSwitchNavigator} from 'react-navigation';
import {createDrawerNavigator } from 'react-navigation-drawer';
import { createStackNavigator } from 'react-navigation-stack';
import {View,Platform,StatusBar} from 'react-native';
import LoginForm from './Components/LoginForm';
import TheatreList from './Components/TheatreList';
import Menu from './Components/Menu';
import EmployeeEdit from './Components/EmployeeEdit';
import CartScreen from './Components/CartScreen';
import Screen from './Components/Screen';
import ShoppingCartIcon from './Components/ShoppingCartIcon';
import PaymentScreen from './Components/PaymentScreen';
import Screen1 from './Screen/Screen1';
import Screen2 from './Screen/Screen2';
import * as Expo from 'expo';
const Navigator = createStackNavigator({
TheatreList:{
screen:TheatreList
} ,
Login: {
screen:LoginForm
},
Menu: {
screen:Menu
},
Cart: {
screen:CartScreen
},
PaymentScreen:{
screen:PaymentScreen
},
},
{
headerMode: 'none',
navigationOptions: {
header: null,
},
},
{
initialRouteName: 'TheatreList'
}
);
const AppDrawerNavigator=createDrawerNavigator(
{
Navigator,
Screen1:{
screen:Screen1
},
Screen2:{
screen:Screen2
}
});
const RootNav=createSwitchNavigator({
Navigator,
AppDrawerNavigator
});
export default createAppContainer(RootNav);
ProfileIcon.js
import React, { Component } from 'react';
import { View, Text, Picker,Button } from 'react-native';
import { connect } from 'react-redux';
import Icon from 'react-native-vector-icons/Entypo';
import { Actions } from 'react-native-router-flux';
import { DrawerActions } from 'react-navigation-drawer';
const ProfileIcon = (props) => (
<View style ={{
position:'absolute',
top:0,
left:0,
right:5,
// padding:7,
width: 40,
height: 40,
borderRadius: 40/2,
border: '1px solid #c45653',
justifyContent: 'center',
marginLeft: 15,padding:7}}>
<Icon name="menu" onPress={() => props.navi.dispatch(DrawerActions.openDrawer())} style ={{fontSize:50, position:'absolute', top:0, right:0,width:40, color:'#fe003a'}} />
</View>
)
export default ProfileIcon;
You need to make nested stacknavigators. Inside AppDrawerNavigator ,call your Navigator stack
Try This
const RootNavigator = createStackNavigator({
DrawerMenu: { screen: DrawerMenu },
Home: { screen: Home },
},
{
initialRouteName: 'Home',
navigationOptions: ({ navigation }) => ({
})
});
const Drawer = createDrawerNavigator({
RootNavigator: {
screen: RootNavigator, //rootNavigator
navigationOptions: { title: 'titleHere' },
},
},
{
initialRouteName: 'RootNavigator',
drawerPosition: 'Left',
backBehavior: 'none',
contentComponent: props => <DrawerMenu {...props} />,
drawerOpenRoute: 'DrawerOpen',
},
);
const LoginNavigator = createStackNavigator({
Login: {
screen: Login,
navigationOptions: {
drawerLockMode: 'locked-closed',
headerStyle: { },
headerTitleStyle: { },
title: 'Title'
}
},
})
export default createSwitchNavigator({
AuthLoading: AuthLoadingScreen, //SplashScreen
LoginNavigator: LoginNavigator,
Drawer: Drawer,
},
{
initialRouteName: 'AuthLoading',
})
export default DrawerNavigator({
MainScreen: {
screen: MainScreen,
},
CreateItem:{
screen: CreateItem,
},
MyitemScreen: {
screen: MyitemScreen,
},
Settings: {
screen: Settings,
},
Buying: {
screen: Buying,
},
Messages: {
screen: Messages,
},
Notifications: {
screen: Notifications,
}, Profile: {
screen: Profile,
}, Logout: {
screen: Logout,
},
},
{
drawerPosition:'left',
initialRouteName:'MainScreen',
drawerBackgroundColor:'white',
drawerWidth:250,
});
then
export default class MainScreen extends Component {
static navigationOptions =
{
title:'Home',
headerMode:"float",
headerStyle: {
backgroundColor: 'green',
elevation: null
},
headerTitleStyle: {
fontWeight: '300',
color: '#ffffff',
fontSize: 20,
flex:1,
textAlign:"center"
},
};
background header of mainscreen changed to green but still white color is appearing in the header
I assuming you are using 'React-Navigation'
try this prop for your static navigationOptions
static navigationsOptions = ({navigation}) = {
return{
title : 'My title',
headerStyle = {background : 'green'
}
}
I could be misunderstanding your questions btw. Posting an image might make it more clear.
I have created a basic react-native app which consists of a few buttons that are used to render different screens. After the user has logged in, I render a TabNavigator item but for some reason the no tabs appear and the screen is completely blank. I have comparing my code to others without any luck. Any suggestions?
import React from 'react';
import { StyleSheet, Text, View, Image, Button, ImageBackground } from 'react-native';
import { TabNavigator } from 'react-navigation';
import {Electric} from './Sub-bills/Electric';
import {Web} from './Sub-bills/WebBill';
import {Water} from './Sub-bills/Water';
import {OtherBills} from './Sub-bills/OtherBills';
import {Personal} from './Sub-bills/Personal';
export const Tabs = TabNavigator(
{
Electric: {
screen: Electric,
navigationOptions: {
tabBarLabel: 'Electric'
}
},
Web: {
screen: Web,
navigationOptions: {
tabBarLabel: 'Web'
}
},
Water: {
screen: Water,
navigationOptions: {
tabBarLabel: 'Water'
}
},
OtherBills: {
screen: OtherBills,
navigationOptions: {
tabBarLabel: 'Other'
}
},
Personal: {
screen: Personal,
navigationOptions: {
tabBarLabel: 'Personal'
}
}
},
);
export class HouseholdBills extends React.Component{
render(){
return (
<Tabs />
);
}
}
const styles = StyleSheet.create({
container: {
width: '100%',
height: '100%',
backgroundColor:'transparent',
justifyContent: 'center',
alignItems: 'center',
position: 'absolute'
},
});
A component is rendered by pressing a button
In new version of ReactNavigation putting TabNavigator under a SafeAreaView will cause it not to show, since react navigation is already handling it,
If in your case you are using SafeAreaView component on top of TabNavigator, maybe removing it will help you.
I use the following as extra configuration to the Tab Nav. You possibly can strip some stuff out, but what worked was to at least define the order.
import { TabNavigator, TabBarBottom } from 'react-navigation';
export const Tabs = TabNavigator(
{
... Your tabs here...
}
{
tabBarOptions: {
activeTintColor: 'red',
inactiveTintColor: 'grey',
style: {
backgroundColor: 'white',
borderTopColor: 'red',
},
labelStyle: {
fontSize: 12,
fontWeight: 'normal'
},
indicatorStyle: {
borderBottomColor: 'red,
borderBottomWidth: 4,
},
},
initialRouteName: 'Electric',
order: ['Electric', 'Web', 'Water', 'OtherBills', 'Personal'],
tabBarComponent: TabBarBottom,
tabBarPosition: 'bottom',
},
{
...TabNavigator.Presets,
animationEnabled: false,
swipeEnabled: false,
showIcon: false,
}
};
I've integrated my MainNavigator with all screens imported while when I ma running it on my ios simulator it shows just white screen and nothing else. It means there is not any error with running an app. I don't know why navigation is not visible.
Here is the code.
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { TabNavigator, DrawerNavigator, StackNavigator } from 'react-navigation';
import WelcomeScreen from './screens/WelcomeScreen';
import SigninScreen from './screens/SigninScreen';
import SignupScreen from './screens/SignupScreen';
import HomeScreen from './screens/HomeScreen';
import BusinessScreen from './screens/BusinessScreen';
import TechScreen from './screens/TechScreen';
import EducationScreen from './screens/EducationScreen';
import LifestyleScreen from './screens/LifestyleScreen';
import ProfileScreen from './screens/ProfileScreen';
import FavoritesScreen from './screens/FavoritesScreen';
import SettingsScreen from './screens/SettingsScreen';
export default class App extends React.Component {
render() {
const MainNavigator = TabNavigator({
welcome: { screen: WelcomeScreen },
signin: { screen: SigninScreen },
signup: { screen: SignupScreen },
main: {
screen: DrawerNavigator({
home: { screen: HomeScreen },
business: { screen: BusinessScreen },
tech: { screen: TechScreen },
education: { screen: EducationScreen },
lifestyle: { screen: LifestyleScreen },
profile: {
screen: StackNavigator({
profile: { screen: ProfileScreen },
settings: { screen: SettingsScreen },
}),
},
}),
},
})
return (
<View style={styles.container}>
<MainNavigator />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Here are the versions that I am using in my app:
expo 18.0.4
react 16.0.0-alpha.12
react-native seems the latest version at the moment. In
package.json shows this link generated by Expo
https://github.com/expo/react-native/archive/sdk-18.0.1.tar.gz"
react-navigation 1.0.0-beta.11
Hi friends I am scratching my head with react-navigation from last 2 days, I tried many things(documentation doesn't seems that clear for a beginner), so right now I am facing few problem that seems little complex to me and hence I seek advice and help to proceed further.following are the cases/problem/scenario I seek help for -
react-navigation does not cover the header and statusbar, I wanted to achieve something like gmail but I ended up with like this
I used following code blocks to reach to this point
import React, {Component} from 'react';
import { AppRegistry, View, BackAndroid, StatusBar,} from 'react-native';
import {
NavigationActions,
addNavigationHelpers,
StackNavigator,
DrawerNavigator
} from 'react-navigation';
import LandingScreen from 'src/screens/landingScreen';
import Login from 'src/screens/login'
import SignUp from 'src/screens/signUp'
import ForgotPassword from 'src/screens/forgotPassword'
import Dashboard from 'src/screens/dashboard'
import UserProfile from 'src/screens/userProfile'
export const Drawer = DrawerNavigator({
Dashboard:{
path:'/',
screen:Dashboard,
},
UserProfile:{
path:'/'
screen:UserProfile
},
}, {
initialRouteName: 'Dashboard',
contentOptions: {
activeTintColor: '#e91e63',
},
headerMode: 'screen',
});
const routesConfig = {
Landing:{screen:LandingScreen},
Login: { screen: Login },
SignUp: { screen: SignUp },
ForgotPassword: { screen: ForgotPassword },
Drawer:{screen:Drawer}
};
export const AppNavigator = StackNavigator(routesConfig, {
initialRouteName: 'Drawer'
});
AppRegistry.registerComponent('Riduk', () => AppNavigator);
Other problem is how should I add 2 drawers in my app at the same screen
Here is a simplified example:
const FooStackNavigator = StackNavigator({
Foo: {
screen: FooScreen,
navigationOptions: {
title: 'Foo',
}
},
});
const BarStackNavigator = StackNavigator({...});
const MyDrawerNavigator = DrawerNavigator({
FooStack: {
screen: FooStackNavigator,
navigationOptions: {
drawer: () => ({
label: 'Foo',
})
},
},
BarStack: {
screen: BarStackNavigator,
navigationOptions: {
drawer: () => ({
label: 'Bar',
})
},
}
});
const AppNavigator = StackNavigator({
Drawer: { screen: MyDrawerNavigator },
}, {
headerMode: 'none',
});
There is an issue for Header in DrawerNavigator.
But you can fix by using StackNavigator inside DrawerNavigator
export const Drawer = DrawerNavigator({
Dashboard:{
path:'/',
screen: StackNavigator( { Screen1: {
screen: Dashboard
}})
},
UserProfile:{
path:'/',
screen: StackNavigator( { Screen1: {
screen: UserProfile
}})
},
}});
Then set headerMode: 'none' to root StackNavigator
export const AppNavigator = StackNavigator(routesConfig, {
headerMode: 'none'
});
Here, AppNavigator is root StackNavigator and routesConfig has above DrawerNavigator and other screens.
Is this the issue you're trying to resolve?
https://blog.callstack.io/android-drawer-statusbar-done-right-for-react-native-7e85f01fc099
As per my knowledge, you have to do 2 things:
1. Put drawer control at the top of navigation stack.
2. Set translucent propery of StatusBar
<StatusBar
translucent
backgroundColor="rgba(0, 0, 0, 0.24)"
animated
/>
{ Platform.OS === 'android' && Platform.Version >= 20 ?
<View
style={{
height: 24,
backgroundColor: "#512DA8",
}}
/>
: null }
Kindly let me know if it does work.
DrawerNavigator must over on StackNavigator, this is my way to fix this:
const navStack = StackNavigator({
Home: { screen: Main, },
Example01: { screen: Example01, },
Example02: { screen: Example02, },
});
const navDrawer = DrawerNavigator({
Home: {
screen: navStack, // Drawer over on StackNavigator
navigationOptions: {
drawerLabel: 'Home',
header: null,
}
},
Example03: {
screen: Example03,
navigationOptions: {
drawerLabel: 'Example03',
}
},
},
{
headerMode: 'none',
headerVisible: false,
navigationOptions: {
header: null
}
});
Hope this helps.