React Native TabNavigator is hiding when ScrollView is long - react-native

I'm using TabNavigator from this library https://reactnavigation.org/docs/navigators/tab
and on screen I have ScrollView it is really long and my Tabs are hiding, what to do in order to not hide tabs?
here is the code:
const TabNav = TabNavigator({
Home: {
screen: Home,
navigationOptions: {
title: 'Home',
headerLeft: null
}
},
Notes: {
screen: Notes,
navigationOptions: {
title: 'Notes',
headerLeft: null
}
},
Tasks: {
screen: Tasks,
navigationOptions: {
title: 'Tasks',
headerLeft: null
}
},
Events: {
screen: Events,
navigationOptions: {
title: 'Events',
headerLeft: null
}
}
}, {
tabBarOptions: {
activeTintColor: 'green'
},
});
const plannings = StackNavigator({
Login: {
screen: Login,
navigationOptions: {
header: null
}
},
Register: {
screen: Register,
navigationOptions: {
header: null
}
},
Home: {
screen: TabNav
}
}, {
headerMode: 'screen'
});

I found this solution and it works for me:
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'blue'}}>
<View style={{height: 400, width: 400}}>
<ScrollView>
<View style={{backgroundColor: 'green'}}>
// Your data here
</View>
</ScrollView>
<TextInput style={{backgroundColor: '#c4c4c4dd', position: 'absolute', bottom: 0, left: 0, right: 0}} />
</View>
</View>

Related

AsyncStorage access in Material Top Tab Navigator React Native

I want to the change user profile pic, when user log into the system. User avator in left side corner in the Material Tab navigator. When user log in to the system I store the image url in AsyncStorage as profilePic.
I want to access AsyncStorage and get the profile pic here.
<Image
source={{
uri:
'https://cdn.apparelconnects.com/users_2_a34456c8-6d69-4b80-98f2-d184ff9f504d_img.png',
}}
I try to many ways. but I can not do this. Here I attached my code. Anyone know the access AsyncStorage here, please help me..
const TabNavigator = createMaterialTopTabNavigator(
{
Profile: {
screen: Logout,
navigationOptions: {
title: 'Home',
tabBarIcon: ({tintColor}) => (
<Image
source={{
uri:
'https://cdn.apparelconnects.com/users_2_a34456c8-6d69-4b80-98f2-d184ff9f504d_img.png',
}}
style={{
width: tabBarConfiguration.icon_size,
height: tabBarConfiguration.icon_size,
borderRadius: 40 / 2,
overflow: 'hidden',
borderWidth: tintColor == colors.orange ? 2 : 0,
borderColor: tintColor,
}}
/>
),
},
},
Home: {
screen: Home,
navigationOptions: {
title: 'Home',
tabBarIcon: ({tintColor}) => (
<Image
source={require('../asserts/images/home_icon.png')}
style={{
width: tabBarConfiguration.icon_size,
height: tabBarConfiguration.icon_size,
tintColor: tintColor,
}}
/>
),
},
},
{
initialRouteName: 'Home',
activeColor: '#f0edf6',
inactiveColor: '#3e2465',
barStyle: {backgroundColor: '#694fad'},
tabBarPosition: 'top',
swipeEnabled: true,
lazy: true,
tabBarOptions: {
showIcon: true,
showLabel: false,
activeTintColor: colors.orange,
inactiveTintColor: '#a1a1a1',
style: {
backgroundColor: '#ffffff',
height: hp('10%'),
},
labelStyle: {
textAlign: 'center',
fontWeight: 'bold',
},
indicatorStyle: {
backgroundColor: 'transparent',
},
},
defaultNavigationOptions: ({navigation}) => ({
tabBarOnPress: ({navigation, defaultHandler}) => {
if (
navigation.state.routeName === 'Profile' ||
navigation.state.routeName === 'More'
) {
return null;
}
defaultHandler();
},
}),
},
);
export default createAppContainer(TabNavigator);

React Native - making a second tab bar navigator for a modal screen

Building out a relatively simple app on React Native, I currently have a tabBarNavigator where one of the icons on the tab bar opens a pop-up modal. I'm then trying to create another, separate, tab bar at the bottom of the modal.
However although I have created a tabBarNavigator and appContainer in my root App.js and have exported this container (passing it through my modal component), the modal then loads the base stack rather than the modal stack which I created - obviously not desired behavior!
The relevant portion of App.js:
const ModalNavigator = createBottomTabNavigator({
Photo: { screen: PrivacySettings,
navigationOptions: {
headerMode: false,
tabBarIcon: ({ tintColor }) => <Feather name="camera" size={24} color="black" />
}
},
Camera: { screen: HelpSettings,
navigationOptions: {
headerMode: false,
tabBarIcon: ({ tintColor }) => <Feather name="type" size={24} color="black" />
}
},
Text: { screen: ContactUs,
navigationOptions: {
headerMode: false,
tabBarIcon: ({ tintColor }) => <Feather name="type" size={24} color="black" />
}
}
});
export const ModalContainer = createAppContainer(ModalNavigator);
const AppContainer = createStackNavigator({
default: createBottomTabNavigator({
Home: { screen: Home,
navigationOptions: {
headerMode: false,
tabBarIcon: ({ tintColor }) => <FontAwesomeIcon size={30} icon={faHome} color={tintColor}/>
}
},
Search: { screen: Contacts,
navigationOptions: {
headerMode: false,
tabBarIcon: ({ tintColor }) => <FontAwesomeIcon size={30} icon={faSearch} color={tintColor}/>
}
},
AddPhoto: { screen: () => null,
navigationOptions: {
headerTitle: "Upload Photo",
tabBarIcon: <AddPhotoButton/>,
headerMode: 'none',
}
},
Likes: {screen: Vault,
navigationOptions: {
headerMode: false,
tabBarIcon: ({ tintColor }) => <FontAwesomeIcon size={30} icon={faHeart} color={tintColor}/>
}
},
Settings: {screen: Me,
navigationOptions: {
headerMode: false,
tabBarIcon: ({ tintColor }) => <FontAwesomeIcon size={30} icon={faUser} color={tintColor}/>
}
}
},
{
defaultNavigationOptions: {
tabBarOnPress: ({ navigation, defaultHandler }) => {
if (navigation.state.key === 'AddPhoto') {
navigation.navigate('addPhotoModal')
} else {
defaultHandler()
}
},
cardStyle: {
backgroundColor: "transparent",
opacity: 1
}
},
tabBarOptions: {
showLabel: false,
activeTintColor: '#1A86CB',
inactiveTintColor: 'black'
},
initialRouteName: "Home",
}),
addPhotoModal: {
screen: AddPhotoModal }
}, {
mode: 'modal',
headerMode: 'none',
transparentCard: true,
}
)
const Routes = createStackNavigator({
Home: { screen: AppContainer,
navigationOptions: {
headerShown: false }
},
SignIn: { screen: SignIn },
AddContact: { screen: AddContact,
navigationOptions: {
headerTitle: "Add Contact" }
},
ContactDetails: {screen: ContactDetails },
PrivacySettings: {screen: PrivacySettings,
navigationOptions: {
headerTitle: "Privacy",
headerStyle: {
backgroundColor: 'white',
shadowColor: 'transparent'
}}
},
NotificationSettings: {screen: NotificationSettings,
navigationOptions: {
headerTitle: "Notifications",
headerStyle: {
backgroundColor: 'white',
shadowColor: 'transparent'
}}
},
HelpSettings: {screen: HelpSettings,
navigationOptions: {
headerTitle: "Help",
headerStyle: {
backgroundColor: 'white',
shadowColor: 'transparent'
}}
},
InviteSettings: {screen: InviteSettings,
navigationOptions: {
headerTitle: "Invite Friends",
headerStyle: {
backgroundColor: 'white',
shadowColor: 'transparent'
}}
},
ContactUs: {screen: ContactUs,
navigationOptions: {
headerTitle: "Contact Us",
headerStyle: {
backgroundColor: 'white',
shadowColor: 'transparent'
}}
},
},
{ initialRouteName: "Home",
});
const AuthStack = createStackNavigator({
Login: SignIn,
})
export default createAppContainer(
createSwitchNavigator(
{
Loading: LoadingScreen,
App: Routes,
Auth: AuthStack
},
{
initalRouteName: LoadingScreen
}
)
)
The relevant portion of the Modal Component:
import ModalContainer from '../../App'
export default class AddPhotoModal extends React.Component {
render() {
return(
<View style={{backgroundColor:"#000000CC", flex:1}}>
<View style={{ backgroundColor:"#ffffff", marginLeft: 0, marginRight: 0, marginTop: 240, padding: 20, borderRadius: 20, flex: 1, }}>
<View style={styles.header}>
<TouchableOpacity style={{position: 'absolute'}} onPress={() => this.props.navigation.goBack()}>
<Text style={styles.buttonFont}>Back</Text>
</TouchableOpacity>
<TouchableOpacity style={{position: 'absolute', right: 0}} onPress={() => this.props.navigation.navigate('UploadScreen')}>
<Text style={styles.buttonFont}>Continue</Text>
</TouchableOpacity>
</View>
<ModalContainer/>
</View>
</View>
);
}
}
Edit:
With the below answer, I'm now getting this. Is there a way to place the tabbar as a child of the modal component?
https://ibb.co/kcTq0X3
'ModalContainer' is not a part of the 'Routes', So it is not known to the SwitchNavigator.
Add ModalContainer as a part of 'Routes' stack.
And to show the ModalContainer bottomTabs, navigate to ModalContainer on click of the tabIcon

How can i import the defaultNavigationOptions property on a screen?

I'm trying to import the react-navigation property into my screens the problem is that I always import the same defaultNavigationOptions for the different Stacks then to optimize the code I want to create as a kind of function so I only import it once on each screen without having to write it many times as I did, then my code so they understand more.
const BloquesStack = createStackNavigator(
{
BLOQUES: {
screen: ScreenBloquesRedux,
navigationOptions: ({ navigation }) => {
return {
headerLeft: <ButtonMenu navigation={navigation} />,
headerRight: <ButtonHome navigation={navigation} />
};
}
},
DetalleBloques: {
screen: DetalleBloque
},
IntegrantesBloque: {
screen: IntegrantesBloque
}
},
{
defaultNavigationOptions: {
headerBackTitle: "Atras",
headerTitleStyle: {
fontFamily: "RobotoCondensed-Regular",
fontWeight: "100",
fontSize: 20,
textAlign: "center",
color: white,
flex: 1
},
headerStyle: { backgroundColor: blue, height: 60 },
headerTintColor: white
}
}
);
export { BloquesStack };
const ComisionesStack = createStackNavigator(
{
COMISIONES: {
screen: ComisionesRedux,
navigationOptions: ({ navigation }) => {
return {
headerLeft: <ButtonMenu navigation={navigation} />,
headerRight: <ButtonHome navigation={navigation} />
};
}
}
},
{
defaultNavigationOptions: {
headerBackTitle: "Atras",
headerTitleStyle: {
fontFamily: "RobotoCondensed-Regular",
fontWeight: "100",
fontSize: 20,
textAlign: "center",
color: white,
flex: 1
},
headerStyle: { backgroundColor: blue, height: 60 },
headerTintColor: white
}
}
export { ComisionesStack };
const DrawerNavigator = createDrawerNavigator(
{
Diputados: { screen: DiputadosStack },
Bloques: { screen: BloquesStack },
Interbloques: { screen: InterBloquesStack },
Comisiones: { screen: ComisionesStack },
Autoridades: { screen: AutoridadesStack },
"Sesion En Vivo": { screen: SesionEnVivoStack },
"Diputados TV": { screen: DiputadosTVStack },
"Reglamentos HCDN": { screen: PDFReglamentosStack }
},
{
contentComponent: CustomDrawerContentComponent,
drawerWidth: width / 2,
contentOptions: {
activeTintColor: white,
activeBackgroundColor: Gris_Drawer,
inactiveTintColor: "rgb(105,105,104)",
itemsContainerStyle: {
textAlign: "center"
},
labelStyle: {
fontFamily: "RobotoCondensed-Regular",
fontWeight: "100",
fontSize: 17,
marginTop: 8,
marginLeft: 10
}
},
iconContainerStyle: {
opacity: 1
}
}
);
I just want to import default Navigation Options I do not intend to modify my navigation, I just want to know if it can be done. Thank you very much already
Create a separate object with the defaultNavigationOptions
const defaultNavigationOptions = {
headerBackTitle: "Atras",
headerTitleStyle: {
fontFamily: "RobotoCondensed-Regular",
fontWeight: "100",
fontSize: 20,
textAlign: "center",
color: white,
flex: 1
},
headerStyle: { backgroundColor: blue, height: 60 },
headerTintColor: white
}
const BloquesStack = createStackNavigator(
{ /* routes */ },
{ defaultNavigationOptions }
)
const ComisionesStack = createStackNavigator(
{ /* routes */ },
{ defaultNavigationOptions }
)

I couldn't use react-navigation tab bar. How to use this?

Now I am trying to create React Native app on Expo and use React-Navigation Tab Bar but I could't.
Actually I don't get any error but this code below doesn't work.
No warning as well.
import { createBottomTabNavigator, createAppContainer } from 'react-
navigation';
import Icon from 'react-native-vector-icons/FontAwesome';
import Home from './src/Screens/Home';
import Help from './src/Screens/Help';
const App = createBottomTabNavigator(
{
Home: {
screen: Home,
defaultNavigationOptions: {
tabBarIcon: ({ tintColor }) => {
<Icon name="home" style={{ width: 25, height: 25, tintColor:
tintColor}}/>
},
title: 'Home',
},
},
Help: { screen: Help },
},
{
swipeEnabled: false, //Android用
tabBarOptions: {
activeTintColor: '#DE628D',
inactiveTintColor: '#707070',
},
},
);
export default createAppContainer(App);
the tab works fine, but if you meant, there's no icon, try this instead
navigationOptions: {
tabBarIcon: ({ tintColor, activeTintColor }) => (
<Icon name="home" size={24} color={tintColor} />)
},
Please try to implement this way. This is copy of my tabNavigator. Hope this will be helpful for you.
const TabRouter = createBottomTabNavigator(
{
HomeAfterLoginScreen: { screen: A },
ShowListAlertScreen: { screen: B },
ShowListProfessionScreen: { screen: C },
MyAccountScreen: { screen: F }
},
{
tabBarPosition: "bottom",
tabBarOptions: {
style: { backgroundColor: "#50bcb8" },
showIcon: true,
showLabel: true,
gesturesEnabled: true,
indicatorStyle: { borderBottomWidth: 3, borderBottomColor: Style.color },
inactiveTintColor: "#fff",
activeTintColor: "#fff",
tabStyle: { justifyContent: "center", alignItems: "center" }
}
});
I got it. I have solved this issue.
const App = createBottomTabNavigator(
{
Favorite: {
screen: FavoriteShops,
navigationOptions: {
tabBarLabel: 'お気に入り',
tabBarIcon: ({ tintColor }) => (
<Icon name="heart" size={25} color={tintColor} />
),
},
},
Home: {
screen: Home,
navigationOptions: {
tabBarLabel: 'ホーム',
tabBarIcon: ({ tintColor }) => (
<Icon name="home" size={30} color={tintColor} />
),
},
},
Help: {
screen: Help,
navigationOptions: {
tabBarLabel: 'その他',
tabBarIcon: ({ tintColor }) => (
<Icon name="bars" size={25} color={tintColor} />
),
},
},
},
{
swipeEnabled: false, //Android用
tabBarOptions: {
showIcon: true,
showLabel: true,
activeTintColor: '#DE628D',
inactiveTintColor: '#707070',
style: {
width: '100%',
height: 70,
},
tabStyle: {
paddingTop: 20,
},
},
},
);

React native navigation custom tabbar icon

Is this possible to have custom component ( Button or what ever ) instead of simple icon in tab bar?
I need to set my tab bar icon dynamically like this
this.props.navigator.setTabButton({
tabIndex: 0,
icon: <Icon name="heart" size={28} /> <--- not appear
});
OR we can use only icons? Any solutions?
Yes, it is possible. I am sharing my solution as code below:
const renderNav = (routeName, focused) => {
return (
<View style={{
flex: 1,
width: 90,
justifyContent: 'center',
alignItems: 'center',
borderTopColor: StylesGeneric.COLORS.primary,
borderTopWidth: focused ? 4 : 0,
}}>
<Text
style={[StylesGeneric.STYLES.footerText]}>
{routeName}
</Text>
</View>
);
};
const customTabs = ({navigation}) => ({
tabBarIcon: ({focused}) => {
const {routeName} = navigation.state;
if (routeName === 'Home') {
return renderNav('Home', focused);
} else if (routeName === 'Profile') {
return renderNav('Profile', focused);
} else if (routeName === 'ProfileOther') {
return renderNav('ProfileOther', focused);
}
},
});
const nav = createBottomTabNavigator(
{
Home: {
screen: Home,
},
Profile: {
screen: Profile,
},
ProfileOther: {
screen: ProfileOther,
},
},
{
defaultNavigationOptions: customTabs,
animationEnabled: true,
swipeEnabled: true,
tabBarPosition: 'bottom',
initialRouteName: 'Home',
tabBarOptions: {
showLabel: false,
style: {
borderTopColor: 'transparent',
backgroundColor: StylesGeneric.COLORS.white,
height: StylesGeneric.FOOTER_HEIGHT,
},
},
},
);
const AppContainer = createAppContainer(nav);