I want to make a design like given in below image.
https://imgur.com/a/ehRthSS "image"
Here is my code for what is have tried uptil now
const NotificationTab = createMaterialTopTabNavigator({
NotificationsActivity: NotificationsActivity,
NotificationsList: NotificationsList,
},
{
initialRouteName: 'NotificationsActivity',
tabBarOptions: {
style: {
backgroundColor: 'red'
}
},
tabBarPosition: 'top',
})
I have two screens for the two tabs.
Here is my drawer navigator which calls that stack
const memberdrawerNavigator = createDrawerNavigator(
{
Notifications : { screen: NotificationTab},
ResetPassword : { screen: ResetPassword},
},
{
gesturesEnabled: true,
contentComponent: props => <DrawerMember {...props} />
},
{
contentOptions: {
}
}
);
Here is the main container for the main naviagator of the application
const AppNavigator = createAppContainer(RootStack)
export default AppNavigator;
Please help me how can i make the design given in the image? Just give me blueprint for the desing and i will make it.
Thanks in advance
You can make the MaterialTopTabNavigator as follows by adding some props to it.
const NotificationTab = createMaterialTopTabNavigator({
NotificationsActivity: NotificationsActivity,
NotificationsList: NotificationsList,
},
{
initialRouteName: 'NotificationsActivity',
tabBarOptions: {
//use this for change the color of active tab's label.
activeTintColor: "red",
//use this for change the color of inactive tabs' label.
inactiveTintColor: "black",
//use this for change the label styles.
labelStyle: {
fontSize: 30,
},
//use this for change the color of inactive tab.
inactiveBackgroundColor: "white",
//use this for change the style of vanigation bar.
style: {
backgroundColor: 'white',
},
//use this for change the style of indicator.
indicatorStyle: {
backgroundColor: 'white'
}
},
tabBarPosition: 'top',
})
for more info, https://reactnavigation.org/docs/en/material-top-tab-navigator.html
Related
I am using tabs in my react native project. I wanted to update Header text and show/hide left, right button on tab click in react native.
I am using this code for Tabs Navigation and StackNavigator for Tabs Screens:
const TabScreen = createMaterialTopTabNavigator(
{
AllChallenges: {
screen: AllChallenges,
navigationOptions: {
title: 'All CHALLENGES',
fontFamily: Fonts.medium,
header: null,
}
},
YourProgress: {
screen: YourProgress,
navigationOptions: {
title: 'YOUR PROGRESS',
fontFamily: Fonts.medium,
header: null,
}
},
},
{
tabBarPosition: 'top',
header: null,
swipeEnabled: false,
animationEnabled: true,
tabBarOptions: {
activeTintColor: 'rgb(94,94,95)',
inactiveTintColor: 'rgb(221,221,221)',
style: {
backgroundColor: '#ffffff',
height: 40,
},
labelStyle: {
marginTop: 5,
textAlign: 'center',
fontFamily: Fonts.medium,
fontSize: 12,
},
indicatorStyle: {
borderBottomColor: 'rgb(32,186,113)',
borderBottomWidth: 2,
},
},
}
);
//making a StackNavigator to export as default
const Challenges = createStackNavigator({
TabScreen: {
screen: TabScreen,
header: null,
navigationOptions: ({ navigation }) => {
// ListAisle.headerList()
return {
title: "CHALLENGES",
headerTintColor: 'white',
headerTitleStyle: {
textAlign: 'center',
flexGrow: 2,
alignSelf: 'center',
marginLeft: 12,
fontFamily: Fonts.summerNormal,
fontSize: 25,
},
headerStyle: {
backgroundColor: '#ff6500'
},
tabBarOnPress: () => Alert.alert('hello')
}
},
},
});
In below screenshot on tapped checkbox button, I want to show delete button in the header
Any idea how to update the title and show hide header buttons?
enter image description here
I have spend a lot of time solving this issue...
Finally I found a solution to change a header text and get header response in Tabs Stack.
Added this line in YourProgress class constructor:
this.props.navigation.navigate('AllChallenges', { title: 'Challenge',isEditClick: 0})
In Challenge class you have to add this code in NavigationOptions to check the parameters and then use these parameters to set in :
const titles =navigation.state.routes[navigation.state.index].params != null ? navigation.state.routes[navigation.state.index].params.title : 'Challenge'
In case you want to get value in YourProgress Stack on clicking YourProgress Tabs Header then add this code on Edit Button press:
this.props.navigation.navigate('AllChallenges', { title: 'Challenge',isEditClick: 1)
You can get isEditClick value 1 in YourProgress screen in componentDidUpdatefunction:
componentDidUpdate() {
const { navigation } = this.props;
var isEditValue = this.props.navigation.state.params != null ? this.props.navigation.state.params.isEditClick : ''
})
}
I am using this library with bottom tabs:
https://github.com/wix/react-native-navigation
for navigation, I have 3 tabs at the bottom, one of them is for home, the thing is I move from home screen to another screen it gets added to the stack, I want to be able to reset the stack whenever I click to the home icon again at bottom tabs.
The route.js is sth like this for the home icon at bottomTab:
stack: {
children: [
{
component: {
name: home,
}
},
],
options: {
bottomTab: {
iconInsets: {top: 6, left: 0, bottom: -6, right: 0},
titleDisplayMode: 'alwaysHide',
icon: require('../assets/images/home.png'),
selectedIconColor: colors.primary,
}
First you have to add listener if user click the bottom tab . With help of registerbottomtabselectedlistener you can achieve this . You can use popToRoot to send user to root of stack
// Subscribe
const bottomTabEventListener = Navigation.events().registerBottomTabSelectedListener(({ selectedTabIndex, unselectedTabIndex }) => {
Navigation.popTo(componentId); // check selectedTabIndex and send to home
});
...
// Unsubscribe
bottomTabEventListener.remove();
Not sure from the snippet you posted but I think you are trying to get bottom tabs to work. This is incomplete but hopefully this gets you on track.
const AppTabs = createBottomTabNavigator({
App: AppStack, // stack navigator
Contacts: ContactsStack, // stack navigator
Settings: {
screen: SettingsScreen, // single component import
navigationOptions: {
tabBarLabel: 'Settings',
tabBarIcon: ({ focused }) => (
<Ionicons
size={26}
name={Platform.OS === 'ios' ? 'ios-settings' : 'settings'}
style={{ marginBottom: -3 }}
color={focused ? "red" : "gray"}
/>
),
}
},
}, {
initialRouteName: 'App',
tabBarPosition: 'bottom',
swipeEnabled: true,
tabBarOptions: {
activeTintColor: 'green',
inactiveTintColor: 'gray',
labelStyle: {
fontSize: 16,
},
tabStyle: { marginBottom: -10 }
}
});
export default createAppContainer(createSwitchNavigator({
AuthLoading: AuthLoadingScreen,
App: AppTabs,
Auth: AuthStack,
}, {
initialRouteName: 'AuthLoading',
}));
I tried to customise the width of the tab bar. I managed to successfully do so, but the indicator is still consuming the whole width of the screen. Any idea on how to change the indicator width to follow the tab width? I know I can fully customise the tab bar, but is there any other way?
This is the current behaviour.
This is my configurations
const PersonalInfoTabs = createMaterialTopTabNavigator(
{
PersonalData: {
screen: PersonalData,
navigationOptions: {
title: 'A'
}
},
AccountSet: {
screen: AccountSet,
navigationOptions: {
title: 'B'
}
},
ModifyPassword: {
screen: ModifyPassword,
navigationOptions: {
title: 'C'
}
}
},
{
tabBarOptions: {
activeTintColor: 'black',
inactiveTintColor: 'black',
style: {
backgroundColor: 'yellow',
width: 300
}
}
}
);
From the documentation for React Navigation for React-Native, it looks like you also have to set the style for the tabs in the tabStyle field:
{
tabBarOptions: {
activeTintColor: 'black',
inactiveTintColor: 'black',
style: {
backgroundColor: 'yellow',
width: 300
},
tabStyle: {
width: 100
}
}
}
Thanks to #ValdaXD to point out the 100 width.
<Tab.Navigator
screenOptions={{
tabBarLabelStyle: { fontSize: 12 },
tabBarItemStyle: { width: 100 },
tabBarStyle: { backgroundColor: 'powderblue' },
}}
>
{/* ... */}
</Tab.Navigator>
tabBarItemStyle did the trick for me
I have a tab Navigation and Navigation bar in one of the tab. I would like to navigate to the next screen. I tried out the tutorial in the https://snack.expo.io/#react-navigation/stacks-in-tabs and added this line in the code:
static navigationOptions = ({navigate, navigation}) => ({
title: "NOTIFICATION HISTORY",
headerTitleStyle: {
fontWeight: "bold",
color: Colors.tintColor,
alignSelf: "center"
},
headerStyle: {
backgroundColor: "white",
shadowOpacity: 0,
shadowOffset: {
height: 0
},
shadowRadius: 0,
borderBottomWidth: 0,
elevation: 0
}
});
export const NotiStackNavigator = StackNavigator(
{
Noti: {
screen: NotiScreen
},
NotiHistory: {
screen: NotiHistScreen
}
},
{
navigationOptions: () => ({
// gesturesEnabled: false,
headerTitleStyle: {
fontWeight: "bold",
color: Colors.tintColor,
alignSelf: "left"
},
headerStyle: {
backgroundColor: "white",
shadowOpacity: 0,
shadowOffset: {
height: 0
},
shadowRadius: 0,
borderBottomWidth: 0,
elevation: 0
}
})
}
export const MainTabNavigator = TabNavigator(
{
Home: {
screen: HomeStackNavigator
},
Noti: {
screen: NotiStackNavigator
},
Settings: {
screen: SettingsScreen
}
},
{
navigationOptions: ({ navigation }) => ({
// Set the tab bar icon
tabBarIcon: ({ focused }) => {
const { routeName } = navigation.state;
let iconName;
switch (routeName) {
case "Home":
iconName = "home";
break;
case "Noti":
iconName = "bell-o";
break;
case "Settings":
iconName = "cog";
}
return (
<FontAwesome
name={iconName}
size={24}
color={focused ? Colors.tabIconSelected : Colors.tabIconDefault}
/>
);
}
}),
// Put tab bar on bottom of screen on both platforms
tabBarComponent: TabBarBottom,
tabBarPosition: "bottom",
// Disable animation so that iOS/Android have same behaviors
animationEnabled: false,
swipeEnabled: false,
// Show the labels
tabBarOptions: {
showLabel: true,
activeTintColor: Colors.tabIconSelected,
inactiveTintColor: Colors.tabIconDefault,
style: {
backgroundColor: Colors.tabBar
}
}
}
);
I can have the tab and navigation going. When the navigation went to the next screen, the tabs still there and the name of the tab change to the new
screen's name. How do I get rid of the tab when going to the next screen?
In your details screen for your StackNavigator replace with this line :
Details: { screen: DetailsScreen, navigationOptions: { tabBarVisible: false } },
or set it as a prop for the specific screen in navigationOptions
I am a newbie to react native. I am using a tab navigator for my home screen and couldn't understand how to change the active and inactive tab colour styling.
export const MyApp = TabNavigator({
Asset: {
screen: AssetScreen
},
Sensors: {
screen: sensorsStack
},
Settings: {
screen: settingStack
},
},{
tabBarPosition: 'bottom',
animationEnabled: true,
swipeEnabled:false,
tabBarOptions: {
upperCaseLabel: false,
showIcon: true,
activeBackgroundColor:'#2394C7',
inactiveBackgroundColor:'grey',
tabStyle:{
marginTop:10,
height :53,
borderRightWidth:1
},
labelStyle: {
fontSize: 15,
fontWeight:'bold',
marginTop: 0,
color :'#ffffff'
},
},
});
Any suggestion will be greatly appreciate.
You can use activeBackgroundColor and inactiveBackgroundColor property under tabBarOptions to set colour for active and inactive tabs.
Please see the document for more info here.