Hide bottom tab naivgation - react-native

I have a bottom tab bar that locates in app.js. And I have the class where I want to hide the bottom bar. In page home.js I have 2 classes. 1st one is main (is the list of articles), the second one is for button page navigation (in this class I display articles). How I can hide bottom tab navigation in the second page (where articles are displayed). I have tried tabBarVisible: false, but this does not work. Help me, please.
Code:
// app.js
const TabNavigator = createBottomTabNavigator({
Home:{
screen:Home,
navigationOptions:{
tabBarLabel:'Главная',
tabBarIcon:({tintColor})=>(
<Icon name="ios-home" color={tintColor} size={24} />
)
}
},
Courses:{
screen:Courses,
navigationOptions:{
tabBarLabel:'Courses',
tabBarIcon:({tintColor})=>(
<Icon name="ios-school" color={tintColor} size={24} />
)
}
},
Editor:{
screen:Editor,
navigationOptions:{
tabBarLabel:'Editor',
tabBarIcon:({tintColor})=>(
<Icon name="ios-document" color={tintColor} size={24} />
)
}
},
},{
tabBarOptions:{
activeTintColor:'#db0202',
inactiveTintColor:'grey',
style:{
fontSize:3,
height:45,
backgroundColor:'white',
borderTopWidth:0,
elevation: 5
}
}
});
export default createAppContainer(TabNavigator);
// home.js
import React from 'react';
import { Font } from 'expo';
import { Button, View, Text, SafeAreaView, ActivityIndicator, ListView, StyleSheet, Image, Dimensions,
ScrollView } from 'react-native';
import { createStackNavigator, createAppContainer } from 'react-navigation'; // Version can be specified in package.json
import Icon from 'react-native-vector-icons/Ionicons'
import Courses from './Courses'
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Home',
};
const { navigate } = this.props.navigation;
return (
<SafeAreaView style={styles.MainContainer}>
<ScrollView
>
<ListView
dataSource={this.state.dataSource}
renderSeparator={this.ListViewItemSeparator}
renderRow={rowData => (
<>
<Text
onPress={() => {
/* 1. Navigate to the Details route with params */
this.props.navigation.navigate("Articles", {
otherParam: rowData.article_title,
});
}}
>
{rowData.article_title}
</Text>
</>
)}
/>
</ScrollView
>
</SafeAreaView>
);
}
}
class ArticleScreen extends React.Component {
static navigationOptions = ({ navigation, navigationOptions }) => {
const { params } = navigation.state;
return {
title: params ? params.otherParam : '',
};
};
render() {
const { params } = this.props.navigation.state;
const article_title = params ? params.otherParam : '';
return (
<Text>{article_title}</Text>
);
}
}
const RootStack = createStackNavigator(
{
Home: {
screen: HomeScreen,
},
Courses: {
screen: Courses,
navigationOptions: {
header: null,
}
},
Articles: {
screen: ArticleScreen,
},
},
{
initialRouteName: 'Home',
}
);
const AppContainer = createAppContainer(RootStack);
export default class App extends React.Component {
render() {
return <AppContainer />;
}
}
const AppContainer = createAppContainer(RootStack);
export default class App extends React.Component {
render() {
return <AppContainer />;
}
}

You have to make StackNavigator as main Navigator and TabBar as a sub navigator:
const TabBar = createBottomTabNavigator(RouteConfigs, TabNavigatorConfig);
const MainNavigator = createStackNavigator(
{
TabBar,
WelcomeScene: { screen:Scenes.WelcomeScene },
HomeScene: { screen: HomeScene }
}
Using this when you go the second screen Tabbar will hide automatically.

Can you try this?
class ArticleScreen extends React.Component {
static navigationOptions = ({ navigation }) => {
return {
title: params ? params.otherParam : '',
tabBarVisible: false
};
};
...

How about something like this. Create Tab navigator and pass it down to Stack navigator as one of the screen, when you navigate to the Articles, it will hide the tab bar...
const TabNavigator = createBottomTabNavigator({
Home: {
screen: Home,
navigationOptions: {
tabBarLabel: 'Главная',
tabBarIcon: ({ tintColor }) => (
<Icon name="ios-home" color={tintColor} size={24} />
),
},
},
Courses: {
screen: Courses,
navigationOptions: {
tabBarLabel: 'Courses',
tabBarIcon: ({ tintColor }) => (
<Icon name="ios-school" color={tintColor} size={24} />
),
},
},
Editor: {
screen: Editor,
navigationOptions: {
tabBarLabel: 'Editor',
tabBarIcon: ({ tintColor }) => (
<Icon name="ios-document" color={tintColor} size={24} />
),
},
},
}, {
tabBarOptions: {
activeTintColor: '#db0202',
inactiveTintColor: 'grey',
style: {
fontSize: 3,
height: 45,
backgroundColor: 'white',
borderTopWidth: 0,
elevation: 5,
},
},
});
const stackNavigator = createStackNavigator({
Home: {
screen: TabNavigator,
navigationOptions: {
header: null,
},
},
Articles: {
screen: ArticleScreen,
},
// add screens here which you want to hide the tab bar
});
export default createAppContainer(stackNavigator);

Related

How do i pass arguments in the screens of drawernavigation?

import {ProfileScreen} from './ProfileScreen';
import {DashboardScreen} from './DashboardScreen';
import {
DrawerNavigator,
createSwitchNavigator,
createAppContainer,
} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import {
createDrawerNavigator,
DrawerNavigatorItems,
} from 'react-navigation-drawer';
import {NotificationScreen} from './NotificationScreen';
export class A_HomePage extends Component {
static navigationOptions = {
header: null,
};
state = {
email: '',
};
render() {
this.setState({
email: 'qwerty#gmail.com',
});
return <AppContainer />;
}
}
const ProfileStackNavigator = createStackNavigator(
{
ProfileNavigator: ProfileScreen,
},
{
defaultNavigationOptions: ({navigation}) => {
return {
headerLeft: (
<Icon2
style={{paddingLeft: 10}}
onPress={() => navigation.openDrawer()}
name="menu"
size={30}
/>
),
};
},
},
);
const NotificationScreenStackNavigator = createStackNavigator(
{
NotificationScreenNavigator: NotificationScreen,
},
{
defaultNavigationOptions: ({navigation}) => {
return {
headerLeft: (
<Icon2
style={{paddingLeft: 10}}
onPress={() => navigation.openDrawer()}
name="menu"
size={30}
/>
),
};
},
},
);
const AppDrawerNavigator = createDrawerNavigator(
{ Profile: {
screen: ProfileStackNavigator,
navigationOptions: {
drawerLabel: 'Profile',
drawerIcon: ({tintColor}) => (
<Icon name="glass" size={25} color="#00b33c" />
),
},
},Notification: {
screen:NotificationScreenStackNavigator ,
navigationOptions: {
drawerLabel: 'Notifications',
drawerIcon: ({tintColor}) => (
<Icon4 name="notification" size={25} color="#cc0099" />
),
},
},
},);
const AppSwitchNavigator = createSwitchNavigator(
{
Profile: {screen: ProfileScreen},
Notification: {screen:NotificationScreen},
},);
const AppContainer = createAppContainer(AppSwitchNavigator);
**
here i have created the two drawernavigation and homescreen contains all the stack of
drawernavigator screen how do i pass this.state.email to the profile and notification screen of the drawernavigation or how can i access the states(here is email) in the screens profile and notification screens pls help this can improve my project work i have searched it in google and docs but didnt got any idea **
Use React Redux with Redux
Redux is central state management system which also available for React-Native
React Redux Getting Started

React Navigation - undefined is not an object (evaluating 'this.navigation.navigate')

I am following this tutorial to implement a switch navigator for user authentication: https://snack.expo.io/#react-navigation/auth-flow-v3.
However, this.navigation.navigate appears to undefined when I try to navigate to the next screen.
undefined is not an object (evaluating 'this.props.navigation.navigate')
I am using expo for my app, and I've already looked at the solutions posted to a similar question at React Native - navigation issue "undefined is not an object (this.props.navigation.navigate)" to no avail.
import * as React from 'react';
import { createBottomTabNavigator } from 'react-navigation-tabs';
import profile from './app/screens/profile.js'
import home from './app/screens/home.js'
import createCompetition from './app/screens/create.js'
import explore from './app/screens/explore.js'
import Icon from 'react-native-vector-icons/MaterialIcons'
import login from './app/screens/login.js';
import { f } from './config/config.js';
import { ActivityIndicator, AsyncStorage, Button, StatusBar, StyleSheet, View } from 'react-native';
import { createStackNavigator } from 'react-navigation-stack';
import { createAppContainer, createSwitchNavigator } from 'react-navigation';
/**
* Tab Stack is the Bottom Navigator for the different pages
*/
const TabStack = createBottomTabNavigator(
{
Home: {
screen: home,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon name="home" size={25} style={{ color: tintColor }} />
),
},
},
Explore: {
screen: explore,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon name="search" size={25} style={{ color: tintColor }} />
),
}
},
Profile: {
screen: profile,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon name="person" size={25} style={{ color: tintColor }} />
),
}
},
Create: {
screen: createCompetition,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon name="add" size={25} style={{ color: tintColor }} />
),
}
},
},
{
tabBarOptions: {
showIcon: true,
showLabel: false,
activeTintColor: 'black',
style: { backgroundColor: 'white', }
},
},
)
/**
* Loading Screen during authorization process
*/
class AuthLoadingScreen extends React.Component {
constructor() {
super();
this._bootstrapAsync();
}
// Fetch the token from storage then navigate to our appropriate place
_bootstrapAsync = async () => {
f.auth().onAuthStateChanged(function (user) { //checks if user is signed in or out
this.props.navigation.navigate(user ? 'App' : 'Auth');
})
};
// Render any loading content that you like here
render() {
return (
<View style={styles.container}>
<ActivityIndicator />
<StatusBar barStyle="default" />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
});
const AppStack = createStackNavigator({ Home: TabStack });
const AuthStack = createStackNavigator({ Login: login });
const RootStack = createSwitchNavigator(
{
AuthLoading: AuthLoadingScreen,
App: AppStack,
Auth: AuthStack,
},
{
initialRouteName: 'AuthLoading',
}
);
const App = createAppContainer(RootStack);
export default App;
You are not giving access to this to your _bootstrapAsync function and your onAuthStateChanged callback. Just pass the callback inside of it using arrow function, as it autobinds the current function to the current app this
_bootstrapAsync = async () => {
f.auth().onAuthStateChanged((user) => { //checks if user is signed in or out
this.props.navigation.navigate(user ? 'App' : 'Auth');
})
};
The problem is with function keyword, which doesnt bind this keyword. Better replace it with ES6 arrow functions which implictly binds this to the inner scope :
f.auth().onAuthStateChanged((user) => { //checks if user is signed in or out
this.props.navigation.navigate(user ? 'App' : 'Auth');
})
Hope it helps .feel free for doubts

React Navigation drawer doesn't display the title of the current page

I created 2 pages namely Home and Profile and added these two pages to createDrawerNavigation. And then added this drawer navigation to a stack navigator. Now when I try to display the title on the header of the current page. I'm unable to do it.
Here is my code.
Tried DefaultNavigationOptions and got the props value of navigator but doesn't work that way.
const MenuStack = createDrawerNavigator(
{
HomePage: {
screen: Home
},
ProfilePage: {
screen: Profile
}
},
{
drawerWidth: Math.round(Dimensions.get("window").width) * 0.75,
contentOptions: {
activeTintColor: theme.colors.accent
}
}
);
const AppStack = createStackNavigator(
{
MenuStack: {
screen: MenuStack
}
},
{
defaultNavigationOptions: ({ navigation }) => {
return {
headerLeft: (
<Icon
style={{ paddingLeft: 10 }}
onPress={() => navigation.toggleDrawer()}
name="bars"
size={30}
/>
),
headerRight: (
<Icon
style={{ paddingRight: 10 }}
onPress={() => navigation.toggleDrawer()}
name="search"
size={30}
/>
),
headerTitle: navigation.state.routeName,
headerStyle: {
backgroundColor: theme.colors.accent
}
};
}
}
);
export const createRootNavigator = (signedIn = false) => {
return createAppContainer(
createSwitchNavigator(
{
SignedIn: {
screen: AppStack
},
SignedOut: {
screen: WelcomeStack
},
SignInAndOut: {
screen: AuthStack
}
},
{
initialRouteName: signedIn ? "SignedIn" : "SignedOut"
}
)
);
};
I added a headerTitle property in the createStackNavigator but I tell the "menustack" as the title for every page.
Expected the title of the page on the header.
You have 2 options:
1. Render your own header component in each screen
You can render a header inside your screens, either a custom one or one from a component library such as react native paper.
function Home() {
return (
<React.Fragment>
<MyCustomHeader title="Home" />
{{ /* screen content */ }}
</React.Fragment>
);
}
2. Create a stack navigator for each screen that needs to have header
const MenuStack = createDrawerNavigator({
HomePage: {
screen: createStackNavigator({ Home })
},
ProfilePage: {
screen: createStackNavigator({ Profile })
}
});
Keep in mind that while this requires less code, it's also less performant.

React Native Bottom NavigationBar

I am trying to build a bottom navigation bar, everything works but the navigation bar does not show up. I am kinda new to react native too. I feel like the problem is the export default as it was not taking the object as the App registry.
The other files work too, like there is no error but the navigation bar does not show up
import React, { Component } from "react";
import { AppRegistry, Text, View, StyleSheet } from "react-native";
import Icon from "react-native-vector-icons/FontAwesome";
import { NavigationComponent } from "react-native-material-bottom-
navigation";
import { TabNavigator } from "react-navigation";
import Home from "./app/components/home.js";
import BackgroundImage from "./app/components/BackgroundImage.js";
import FadeAnimation from
"./app/components/animations/fadeAnimation.js";
class HomeScreen extends React.Component {
static navigationOptions = {
tabBarLabel: "Home",
tabBarIcon: () => <Icon size={24} color="white" name="home" />
};
render() {
return (
<BackgroundImage>
<Home />
</BackgroundImage>
);
}
}
class Announcements extends React.Component {
static navigationOptions = {
tabBarLabel: "Announcements",
tabBarIcon: () => <Icon size={24} color="white" name="bullhorn" />
};
render() {
return (
<View>
<Text>This is announcement page</Text>
</View>
);
}
}
class Calendar extends React.Component {
static navigationOptions = {
tabBarLabel: "Calendar",
tabBarIcon: () => <Icon size={24} color="white" name="calendar" />
};
render() {
return (
<View>
<Text>This is announcement page</Text>
</View>
);
}
}
class Contact extends React.Component {
static navigationOptions = {
tabBarLabel: "Contact",
tabBarIcon: () => <Icon size={24} color="white" name="comments" />
};
render() {
return (
<View>
<Text>This is announcement page</Text>
</View>
);
}
}
const MyApp = TabNavigator(
{
HomeScreen: { screen: HomeScreen },
Announcements: { screen: Announcements },
Calendar: { screen: Calendar },
Contact: { screen: Contact }
},
{
tabBarComponent: NavigationComponent,
tabBarPosition: "bottom",
tabBarOptions: {
bottomNavigationOptions: {
labelColor: "white",
rippleColor: "white",
tabs: {
HomeScreen: {
barBackgroundColor: "#3C2538"
},
Announcements: {
barBackgroundColor: "#388E3C"
},
Calendar: {
barBackgroundColor: "#E64A19",
labelColor: "#434343",
activeLabelColor: "#212121",
activeIcon: <Icon size={24} color="#212121" name="calendar" />
},
Contact: {
barBackgroundColor: "#a0c4ff"
}
}
}
}
}
);
export default MyApp;
AppRegistry.registerComponent("MyApp", () => MyApp);
Maybe my case may help you, so in App.js create the bottom tab navigator, just import the createBottomTabNavigator, then import some screen that you want to put on my bottom tab navigation, this is the example of my code :
import { createBottomTabNavigator, createAppContainer } from 'react-navigation';
import Users from './Users';
import Vehicles from './Vehicles';
import Home from './Home';
import MyAccount from './MyAccount';
export default class Dashboard extends Component {
static navigationOptions = {
header: null,
};
render() {
return (
<AppContainer/>
);
}
}
const TabScreens = createBottomTabNavigator({
Home:{
screen: Home
},
Users:{
screen: Users,
},
Vehicles:{
screen: Vehicles
},
MyAccount:{
screen: MyAccount
},
},{
tabBarOptions:{
labelStyle: {
fontSize: 12,
marginBottom:10,
},
style:{
elevation:5
}
}
})
const AppContainer = createAppContainer(TabScreens);
Hope it will help you

Nesting multiple navigators

I'm trying to integrate StackNavigator, TabNavigator and DrawerNavigator like this:
class TestApp extends Component {
render() {
return (
<MyApp />
);
}
}
const Tabs = TabNavigator({
Home1: { screen:Home1 },
Home2: { screen:Home2 },
},
{
tabBarPosition: 'bottom',
});
const Drawer = DrawerNavigator({
First:{
screen: DrawerScreen1
},
Second:{
screen: DrawerScreen2
}
},{
initialRouteName:'First',
drawerPosition: 'left'
});
const MyApp = StackNavigator({
Screen1: {screen:Screen1},
Screen2: {screen:Screen2},
Tabs: {
screen: Tabs
},
Drawer:{
screen: Drawer
}
}, {
initialRouteName: "Tabs"
});
AppRegistry.registerComponent('TestApp', () => TestApp);
Calling the drawer:
<Button
onPress={() => this.props.navigation.navigate('DrawerOpen')}
title="Show Drawer"
/>
It does not open the drawer. It opens the DrawerScreen1 as if I'm calling it from StackNavigator. It opens the component with a back button. I want to open the drawer.
DrawerScreen1:
export default class DrawerScreen1 extends Component{
static navigationOptions = {
drawerLabel: 'Home',
drawerIcon: ({ tintColor }) => (
<Image
source={require('./myImage.png')}
style={height:100, width: 100}
/>
),
};
render() {
return (
<Button
onPress={() => this.props.navigation.navigate('DrawerOpen')}
title="DrawerOpen"
/>
);
}
}
DrawerScreen2 is similar. What am I missing? Please help.