I am extremely new in React Native, tried to adding a testing screen in drawer, but I couldn't.
import { createDrawerNavigator, createStackNavigator } from "react-navigation"
/* Some imports here neglected...*/
/*
* icon size
* */
const iconSize = 18
const IntegratedNavigation = createStackNavigator({
bottomNavigator: { screen: BottomNavigator, navigationOptions: { header: null } },
something: { screen: Something, navigationOptions: { header: null } },
something2: { screen: SomethingElse, navigationOptions: { header: null } },
})
export const DrawerNavigator = createDrawerNavigator({
Tabs: {
screen: IntegratedNavigation,
navigationOptions: {
drawerLabel: "Explore",
drawerIcon: ({ tintColor, focused }) => (
<Icon icon={"search"} size={iconSize} color={tintColor}/>
),
header: null,
},
},
PartnersScreen: {
screen: PartnersScreen,
navigationOptions: {
drawerLabel: "Partners",
drawerIcon: ({ tintColor, focused }) => (
<Icon icon={"safety"} size={iconSize} color={tintColor}/>
),
},
},
HelloScreen: {
screen: PartnersScreen, /*This is a testing new drawer tab that never appear!*/
navigationOptions: {
drawerLabel: "Test!",
drawerIcon: ({ tintColor, focused }) => (
<Icon icon={"test"} size={iconSize} color={tintColor}/>
),
},
},
}, {
contentOptions: {
inactiveTintColor: color.palette.lightBlack,
activeTintColor: color.primary,
},
contentComponent: props => (<MenuUserInfo drawerItemsProps={props}/>),
drawerWidth: 240,
},
)
As a test, I just wanted to duplicate "PartnersScreen" as another tab. But the new route never appear. I couldn't figure out which other file I need to modify. Any idea?
Related
I have a material top tab bar with 5 tabs. But all 5 tabs could't fit to a screen. in the screenshot below only 4 tabs visible.
I need a behavior where tab bar shift automatically to the left when 3rd tab has been clicked. I searched the docs couldn't find anything similar.
here is app.js
class App extends Component {
render() {
return (
<View style={{ flex: 1 }}>
<AppContainer />
</View>
);
}
}
const AppTabNavigator = createMaterialTopTabNavigator(
{
Home: {
screen: HomeScreen,
navigationOptions: {
tabBarLabel: 'Home'
}
},
Settings: {
screen: SettingsScreen,
navigationOptions: {
tabBarlabel: 'Settings'
}
},
Orders: {
screen: OrdersScreen,
navigationOptions: {
tabBarlabel: 'Order List'
}
},
Cancelled: {
screen: CancelledItemsScreen,
navigationOptions: {
tabBarlabel: 'Cancelled Items'
}
},
Others: {
screen: OthersScreen,
navigationOptions: {
tabBarlabel: 'Others'
}
}
},
{
initialRouteName: 'Home',
tabBarOptions: {
tabStyle: {
width: 100,
overflow: 'hidden'
}
}
}
);
const AppContainer = createAppContainer(AppTabNavigator);
export default App;
You can try this code.
renderScene = ({ route }) => {
if (Math.abs(this.state.index - this.state.routes.indexOf(route)) > 5) {
return <View />;
}
return <MySceneComponent route={route} />;
};
I have two Nagigators 1:StackNavigator and 2:DrawerNavigator
my react native and react navigation version
"react-native": "0.55.4",
"react-navigation": "^1.0.0-beta.11",
my root navigator is the StackNavigator from which i call the DrawerNavigator.
when i call the navigation.navigate('DrawerOpen') my screen returns to the initialRouteName .
my StackNavigator
import DrawerNavigatorScreen from "./src/DrawerNavigator";
const myApp = StackNavigator({
Home: {
screen: App,
navigationOptions: {
header: null
}
},
HomeChildData: {
screen: DrawerNavigatorScreen,
navigationOptions: {
header:null,
}
},
otp: {
screen: otp,
navigationOptions: ({ navigation }) => ({
header: null
})
}
});
my DrawerNavigator (/src/DrawerNavigator)
const DrawerNavigatorScreen = DrawerNavigator(
{
social: {
screen: socialstack,
navigationOptions: {
header: null
}
},
profile: {
screen: profilescreen,
navigationOptions: ({ navigation }) => ({
header: null
})
},
{
initialRouteName: "social",
contentOptions: {
labelStyle: {
alignSelf: "center",
fontFamily: "Avenir-Light",
fontSize: 15,
color: "#3B3B3B"
},
activeTintColor: "#3B3B3B",
activeBackgroundColor: "#ffc34d", //rgba(255,181,14,0.1)
// inactiveTintColor: 'black',
inactiveBackgroundColor: "#fff"
},
});
export default DrawerNavigatorScreen
where my problem occurs
static navigationOptions = ({ navigation }) => ({
header:null,
headerTitleStyle: {
alignSelf: 'center',
marginLeft: margintLeftValue,
color: '#2F2E2F',
fontFamily: 'Avenir-Medium'
},
headerLeft: <TouchableOpacity onPress={() => navigation.navigate('DrawerOpen')}>
<Image
source={require('./../images/menu.png')}
style={styles.drawerIcon} />
</TouchableOpacity>,
})
I want to simply open or toggle the drawer .
I think what you're looking for is navigation.toggleDrawer();.
You can read more here.
I want to show an initial screen when the user logs into my react native app.But i don't want to show the screen on the drawer component as i have used drawer component for other screens from react navigation. When the user goes to different screens from the drawer component,i want to make them come to the previous initial screen on pressing back button.
const AppStackNavigator = createStackNavigator({
Map: {
screen: Maps,
navigationOptions: () => ({
header: null
})
},
UpdateProfile: {
screen: UpdateProfileScreen,
navigationOptions: () => ({
header: null
})
},
SearchDetails: {
screen: SearchDetails,
navigationOptions: () => ({
header: null
})
},
})
const AppDrawerNavigator = createDrawerNavigator({
Home: {
screen : AppStackNavigator,
navigationOptions: () => ({
title: `Map`,
drawerIcon: ({tintColor}) => (
<Image source={require('./assets/img/s_logo.png')} style={{height: 24, width: 24}}/>
)
})
},
Search: {
screen: SearchScreen,
navigationOptions: () => ({
title: `Search by`
})
},
Vendor: {
screen: HomeScreen,
navigationOptions: () => ({
title: `Vendor List`,
})
},
Notifications: {
screen: NotificationScreen
},
Events: EventsScreen,
Venue : {
screen: VenueAvailabilityScreen,
navigationOptions: () => ({
title: `Venue Availability`,
})
},
Settings: {
screen: SettingsScreen
}
}, {
drawerPosition: 'left',
contentComponent: customDrawerContentComponent,
drawerOpenRoute: 'DrawerOpen',
drawerCloseRoure: 'DrawerClose',
drawerToggleRoute: 'DrawerToggle',
drawerWidth: 320,
contentOptions: {
activeTintColor: '#fff',
inactiveTintColor: '#030303',
activeBackgroundColor: '#B90066',
inactiveBackgroundColor: '#fff',
itemsContainerStyle: {
marginHorizontal: 10
},
itemStyle: {
height: 40,
borderRadius: 60,
},
activeLabelStyle: {
fontSize: 20,
fontWeight: 'normal'
}
}
})
const AuthStackNavigator = createStackNavigator({
SplashScreen: { screen: SplashScreen },
ModalScreen:{
screen: ModalScreen
},
LocationNotification: {
screen: LocationNotificationScreen,
navigationOptions: () => ({
header: null
})
},
LoginScreen: {
screen : LoginScreen,
navigationOptions: () => ({
header: null
})
},
SignUpScreen: {
screen : SignUpScreen,
navigationOptions: () => ({
header: null
})
},
SignUpStepTwo: {
screen : SignUpStepTwo,
navigationOptions: () => ({
header: null
})
},
ForgotPassword: {
screen: ForgotPassword,
navigationOptions: () => ({
header: null
})
}
})
const AppSwitchNavigator = createSwitchNavigator({
AuthLoadingScreen: AuthLoadingScreen,
Auth: AuthStackNavigator,
App: {
screen: AppDrawerNavigator
}
})
const MyAppDrawer = createAppContainer(AppSwitchNavigator)
class App extends Component {
render() {
return <MyAppDrawer />
}
I want to set the map screen as initial but don't want to show that on drawer. How could i do that?
You can't ... at least it's not easy. You need to create a custom contentcomponent yourself and implement the navigation. Tutorial here. Another approach is to make your appdrawernavigator ,a child of a stacknavigator with the initial screen
const AppSwitchNavigator = createSwitchNavigator({
AuthLoadingScreen: AuthLoadingScreen,
Auth: AuthStackNavigator,
App: MainStackNavigator
})
//the main stack
const MainStackNavigator= createStackNavigator({
InitialScreen: {screen: InitialScreen},
DrawerNav: {screen:AppDrawerNavigator}
},{headerMode: 'none'})
I have react native problem with react navigation v2 and drawerNavigator. Actually, I want drawerNavigator (header) to showup on screen, but I don't want that page in drawer to show.
There is my main drawer and I want to display it also on ActionPage, but I don't want Action inside it.
const MainDrawer = DrawerNavigator(
{
Home: {
screen: HomeStack,
navigationOptions: {
title: 'POČETNA',
}
},
OrderP: {
screen: OrderStack,
navigationOptions: {
title: 'NARUČI',
}
},
CatalogP: {
screen: CatalogStack,
navigationOptions: {
title: 'KATALOZI',
}
},
InstructionP: {
screen: InstructionStack,
navigationOptions: {
title: 'UPUTSTVO ZA PORUČIVANJE',
}
},
InfoP: {
screen: InfoStack,
navigationOptions: {
title: 'INFORMACIJE O APLIKACIJI'
}
},
ActionP: {
screen: ActionStack,
navigationOptions: {
header: null,
title: ''
}
}
}
);
And root stack:
const RootStack = StackNavigator(
{
MainDrawer: {
screen: MainDrawer,
},
Contact: {
screen: ContactPage
},
ActionP: {
screen: ActionPage
},
News: {
screen: NewsPage
}
},
{
headerMode: 'none'
}
);
In order to hide the pages you want, you can adapt this code:
// this const is used to hide desired pages
const hiddenDrawerItems = [
'Home',
'Profile',
]
const MainDrawer = createDrawerNavigator(
{
Home: { screen: HomePage },
Profile: { screen: ProfilePage },
// other pages
},
{
// this entry is used to actually hide you pages
contentComponent: (props) => {
const clonedProps = {
...props,
items: props.items.filter(item => !hiddenDrawerItems.includes(item.key)),
}
return <DrawerPage {...clonedProps} />
},
},
)
I'm facing an issue in which header component does not change. It's same on all the screen even if I have defined separately in Stacknavigator navigationOptions.
<Header
leftComponent={{ icon: 'menu', color: '#fff' }}
centerComponent={{ text: 'MY TITLE', style: { color: '#fff' } }}
rightComponent={{ icon: 'home', color: '#fff' }}
/>
Even if I have added in each screen separately but it's showing home (first header component) as attached.
I have also override navigation options on each screen as well but same header issue.
static navigationOptions = ({ navigation, screenProps }) => ({
title: 'User List',
headerTitle:'User List',
headerTintColor :'#ffffff',
});
Below is my complete code
const AppNavigator = StackNavigator({
Login: {
screen: LoginScreen,
navigationOptions: {
header: null,
headerMode: 'none'
}
},
Home: {
screen: AppDrawerNavigation,
navigationOptions: ({
navigation
}) => ({
header: < Header
outerContainerStyles={{ backgroundColor: '#1999CE' }}
leftComponent = {
<Icon name='menu' color='#ffffff' onPress={() => navigation.navigate('DrawerToggle')}/>
}
centerComponent = {
{
text: 'Home',
style: {
color: '#fff'
}
}
}
rightComponent = {
{
icon: 'home',
color: '#fff'
}
}
/>,
}),
},
WebViews: {
screen: AppDrawerNavigation,
navigationOptions: {
header: null,
headerMode: 'none'
}
},
Profile: {
screen: ProfileScreen,
navigationOptions: {
headerStyle: {
backgroundColor: '#1999CE',
},
}
},
UserList :{
screen:AppDrawerNavigation,
navigationOptions: ({
navigation
}) => ({
title: 'List User',
headerTitle:'List User',
header: < Header
outerContainerStyles={{ backgroundColor: '#1999CE' }}
leftComponent = {
<Icon name='menu' color='#ffffff' onPress={() => navigation.navigate('DrawerToggle')}/>
}
centerComponent = {
{
text: 'List User',
style: {
color: '#fff'
}
}
}
rightComponent = {
{
icon: 'home',
color: '#fff'
}
}
/>,
}),
}
},
{ navigationOptions: {
headerMode: 'screen'
},
}
);
const AppDrawerNavigation = DrawerNavigator({
Home: {
screen: HomeScreen,
},
WebViews: {
screen: WebViewScreen,
},
UserList: {
screen: UserListScreen,
},
},
{
navigationOptions: {
headerMode: 'none'
},
drawerPosition: 'left',
drawerWidth: 200,
contentOptions: {
activeTintColor: '#000000',
activeTintColor :'#ffffff',
activeBackgroundColor :'#1999CE',
inactiveTintColor :'#1999CE',
inactiveBackgroundColor :'#ffffff',
}
}
);
Can you suggest a possible fix that would address this issue?
You can use withHeaders from this package react-navigation-utils to make custom headers for each screen.
Try this
Home: {
screen: HomeScreen,
navigationOptions: {
title:'Home',}
},
WebViews: {
screen: WebViewScreen,
navigationOptions: {
title:'Web Views',}
},
UserList: {
screen: UserListScreen,
navigationOptions: {
title:'User List',}
},
hope it'll hepls you....