react-native-tab-view width not getting 100% with two tab bars - react-native

When two custom tab bars are used in react-native-tab-view, the width is not getting 100%, ie; in the image shown, there is an extra space after the 2nd tab(On Riding). When more than 2 tabs are there, it works fine. What I expect is to get 50% width for both tab bars without any red space. Screenshot of tab view
---------- TabView
<TabView
navigationState={{index, routes}}
renderScene={renderScene}
onIndexChange={setIndex}
initialLayout={{width: layout.width}}
renderTabBar={(props) => (
<TabBar
{...props}
scrollEnabled
style={{
borderRadius: 20,
elevation: 0,
backgroundColor: 'red',
}}
renderIndicator={() => null}
onTabLongPress={(scene) => {
const {route} = scene;
props.jumpTo(route.key);
}}
renderTabBarItem={({route, focused, color, scene}) => {
return (
<Pressable
onPress={() => {
props.jumpTo(route.key);
}}
style={[
route.key === props.navigationState.routes[index].key
? Styles.tabBarActive
: Styles.tabBarInActive,
Styles.tabBar,
]}>
<Text
style={[
route.key === props.navigationState.routes[index].key
? Styles.activeTabText
: Styles.inActiveTabText,
]}>
{route.title}
</Text>
</Pressable>
);
}}
/>
---------- Styles.js
tabBar: {
paddingHorizontal: '5%',
paddingVertical: '2%',
alignItems: 'center',
flex: 1,
},
tabBarActive: {
borderRadius: RFValue(25),
backgroundColor: Colors.AppPrimaryThemeColor,
justifyContent: 'center',
},
tabBarInActive: {
backgroundColor: 'green',
justifyContent: 'center',
},
activeTabText: {
color: Colors.AppMainColor,
fontFamily: Fonts.FONT_BOLD,
fontSize: RFPercentage(1.8),
},
inActiveTabText: {
color: Colors.AppPrimaryThemeColor,
fontFamily: Fonts.FONT_MEDIUM,
fontSize: RFPercentage(1.6),
},

Do you really need to scroll between the tabs?
if not, try deleting "ScrollEnabled".
renderTabBar={(props) => (
<TabBar
{...props}
style={{
borderRadius: 20,
elevation: 0,
backgroundColor: 'red',
}}

Related

How to show different tags, depending on the user logged. Expo react

I need to show different tags depending on which user is logged.
Franchisee will see: 'Central' 'Empleados' 'Clientes'.
Employee: 'Store' 'Clientes'
User: none. just the generic info.
Here is my code:
(this is the array that states the scrollview)
const Chats = (props) => {
const TAGS = [
"store",
"Clientes",
"Central",
"Empleados",
]
and this is the component:
import React, { useState } from "react";
import { StyleSheet, FlatList, TouchableOpacity, ScrollView, Image } from 'react-native';
import { SimpleHeader, View, Text } from '../../elements/index';
const Chatstores = ({ chatsstore, navigation }) => (
<View>
<TouchableOpacity onPress={() => navigation.navigate("ChatPersonal")}>
<View style={styles.list} >
<Image source={chatsstore.img} style={styles.iconimg} />
<View style={styles.dataText}>
<View style={styles.nametime}>
<Text style={styles.text}>{chatsstore.name} </Text>
<Text >{chatsstore.time}</Text>
</View>
<Text style={styles.msg}>{chatsstore.msg} </Text>
</View>
</View>
</TouchableOpacity>
</View>
);
const ChatClients = ({ chatsClients, navigation }) => (
<View>
<TouchableOpacity onPress={() => navigation.navigate("ChatPersonal")}>
<View style={styles.list}>
<Image source={chatsClients.img} style={styles.iconimg} />
<View style={styles.dataText}>
<View style={styles.nametime}>
<Text style={styles.text}>{chatsClients.name} </Text>
<Text >{chatsClients.time}</Text>
</View>
<Text style={styles.msg}>{chatsClients.msg} </Text>
</View>
</View>
</TouchableOpacity>
</View>
);
const Chats = (props) => {
const { TAGS, chatsstore, chatsClients, navigation } = props;
const [selectedTag, setSelectedTag] = useState(null)
const [routeDistance, setRouteDistance] = useState(0);
return (
<View style={styles.wrapper}>
<SimpleHeader
style={styles.head}
titleLeft="Chats"
onSearchPress
onAddPress
/>
{/**shows horizontal, scrollview of Tags. */}
<View style={styles.scrollview}>
<ScrollView horizontal showsHorizontalScrollIndicator={false} >
<View style={styles.viewcontainer}>
{TAGS.map((tag) => (
<TouchableOpacity
onPress={() =>
setSelectedTag(tag === selectedTag ? null : tag)
}>
<View
style={[
styles.tag,
selectedTag === tag ? styles.selectedTag : {}
]}>
<Text style={styles.textTag}>{tag}</Text>
</View>
</TouchableOpacity>
))}
</View>
</ScrollView>
</View>
{/**If tag is store, shows its data, otherwise the rest */}
{selectedTag === "store" ? (
<View style={styles.chat}>
<FlatList
data={chatsstore}
renderItem={({ item, index }) => (
<Chatstores
chatsstore={item}
index={index}
navigation={navigation}
/>
)}
keyExtractor={(chatsstore) => chatsstore.name}
ListEmptyComponent={() => (
<Text center bold>No hay ningĂșn mensaje de clientes</Text>
)}
/>
</View>
) :
<View style={styles.chat}>
<FlatList
data={chatsClients}
renderItem={({ item, index }) => (
<ChatClients
chatsClients={item}
index={index}
navigation={navigation}
/>
)}
keyExtractor={(chatsClients) => chatsClients.name}
ListEmptyComponent={() => (
<Text center bold>No hay ningĂșn mensaje de clientes</Text>
)}
/>
</View>
}
</View>
);
};
const styles = StyleSheet.create({
wrapper: {
backgroundColor: "#ffffff",
display: "flex",
flex: 1,
},
head: {
height: 80,
display: "flex",
alignItems: "center",
zIndex: 1,
top: 5,
},
scrollview: {
display: "flex",
alignItems: "center",
justifyContent: "space-evenly",
},
viewcontainer: {
display: "flex",
flexDirection: "row",
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 1,
right: 10,
},
list: {
bottom: 15,
flexWrap: "wrap",
alignContent: "space-between",
position: "relative",
marginVertical: 2,
backgroundColor: "#fff",
shadowColor: "#000",
elevation: 2,
flexDirection: "row",
}, dataText: {
alignSelf: "center",
flexDirection: "column",
width: "80%",
},
nametime: {
display: "flex",
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
},
iconimg: {
display: "flex",
height: 43,
width: 43,
alignSelf: "center",
flexDirection: "column",
},
chat: {
margin: 10,
},
text: {
margin: 10,
fontFamily: "Montserrat_700Bold",
paddingHorizontal: 10,
},
msg: {
margin: 10,
fontFamily: "Montserrat_400Regular",
fontSize: 15,
paddingHorizontal: 10,
bottom: 10
},
map: {
display: "flex",
height: "100%",
},
tag: {
display: "flex",
alignSelf: "center",
marginBottom: 1,
width: 225,
padding: 10,
},
selectedTag: {
borderBottomColor: '#F5BF0D',
borderBottomWidth: 2,
},
textTag: {
fontFamily: "Montserrat_700Bold",
alignItems: "center",
textAlign: "center",
fontSize: 15,
},
buttonContainer: {
marginHorizontal: 20
},
button: {
backgroundColor: "#000000",
top: Platform.OS === 'ios' ? 12 : 20,
height: 60,
marginBottom: 40,
marginRight: 10,
},
});
export default Chats;
So I guess that in my "show horizontal tags" I should write some kind of if, that gets the role from the user token?
Or would it be better to write different routes into the navigation and handle it in 3 different components?

React-Native make ScrollView childs take the width of the screen

I have a component with a ScrollView that works, and I want to add a scenario where for an example I want to fit all content on the screen width, and for other scenarios I want to scroll through them. How Can I achieve that ?
Here is my current Implementation:
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
style={styles.container}
contentContainerStyle={styles.containerContainer}
>
<View>
<View style={styles.tabs}>
{Object.keys(tabs).map((item, index) => {
const isSelected = item === selectedTab;
return (
<Tab
key={item}
item={tabs[item]}
select={() => select(index, item)}
setMeasures={(width) => setWidth(width, index)}
isSelected={isSelected}
gap={gap}
/>
);
})}
</View>
<Animated.View
style={[
styles.indicator,
{
transform: [{ translateX: value }],
},
measures[selectedIndex]
? { width: measures[selectedIndex] - gap }
: null,
]}
/>
</View>
</ScrollView>
and here is the stylings
indicator: {
backgroundColor: BURNING_ORANGE,
height: hp(2),
width: 0,
},
label: {
alignItems: 'center',
color: CLOUD_BURST,
fontFamily: CIRCULARMEDIUM,
marginVertical: hp(10),
},
selectedLabel: {
alignItems: 'center',
color: BURNING_ORANGE,
fontFamily: CIRCULARMEDIUM,
marginVertical: hp(10),
},
tab: {
alignItems: 'center',
flex: 1,
flexDirection: 'row',
paddingEnd: wp(20),
},
tabs: {
flexDirection: 'row',
},
Also, If I added flex: 1 to contentContainerStyle of my ScrollView the View just dissappear

How to close dropdown box view on open another? [React - Native]

I am using this library to implement dropdown option. I have multiple dropdown view in a screen. All are showing nicely but the problem is when one box view is opened I am going to open another dropdown. In that time both boxes are in open state.
What I want to achieve? - When one box is opened and I clicked another dropdown to open previous dropdox box will automatically get closed. How could I achieve that?
Below is my code of two dropdown-
<View style={{ marginRight: 8, marginLeft: 8, marginBottom: 3 }}>
<View style={{ width: '100%', justifyContent: 'center', marginTop: 12 }}>
<View style={{ width: '100%', height: CONSTANTS.windowHeight * 0.0755, }}>
</View>
<DropDownPicker
zIndex={3000}
zIndexInverse={1000}
searchable={true}
onOpen={() => { this.setState({ dropdown_visible: false }), console.log("opened"), this.stateOpen() }}
// onClose={() => this.setState({ dropdown_visible: false })}
// style = {{marginTop: 50}}
open={this.state.state_open}
containerStyle={{ position: 'absolute', height: CONSTANTS.windowHeight * 0.07, alignSelf: 'center', left: 1, right: 1 }}
itemStyle={{ justifyContent: 'flex-start' }}
dropDownStyle={{ borderColor: CONSTANTS.COLOR.BASE_COLOR, backgroundColor: CONSTANTS.COLOR.DROPDOWN_BACKGROUND, textAlign: 'flext-start' }}
items={states}
placeholder="Select State"
placeholderStyle={{
color: 'gray',
textAlign: 'left'
}}
controller={instance => this.controller = instance}
onChangeList={(states, callback) => {
this.setState({
states // items: items
}, callback);
}}
defaultValue={this.state.value}
onChangeItem={(item, index) => (this.setState({
state_name: item.value, state_id: states_with_id[index].id
}), this.getCity(states_with_id[index].id))}
/>
</View>
</View>
<View style={{ marginRight: 8, marginLeft: 8, marginBottom: 3 }}>
<View style={{ width: '100%', justifyContent: 'center', marginTop: 12 }}>
<View style={{ width: '100%', height: CONSTANTS.windowHeight * 0.0755 }}>
</View>
<DropDownPicker
zIndex={2000}
zIndexInverse={2000}
controller={instance => controller = instance}
searchable={true}
onOpen={() => { this.setState({ dropdown_visible: false }), this.cityOpen() }}
// onClose={() => this.setState({ dropdown_visible: false })}
// style = {{marginTop: 50}}
open={this.state.city_open}
containerStyle={{ position: 'absolute', height: CONSTANTS.windowHeight * 0.0755, alignSelf: 'center', left: 1, right: 1 }}
itemStyle={{ justifyContent: 'flex-start' }}
dropDownStyle={{ borderColor: CONSTANTS.COLOR.BASE_COLOR, backgroundColor: CONSTANTS.COLOR.DROPDOWN_BACKGROUND, textAlign: 'flext-start' }}
items={cities}
placeholder="Select City"
placeholderStyle={{
color: 'gray',
textAlign: 'left'
}}
controller={instance => this.controller = instance}
onChangeList={(cities, callback) => {
this.setState({
cities // items: items
}, callback);
}}
defaultValue={this.state.value}
onChangeItem={(item, index) => this.setState({
city_name: item.value, city_id: cities_with_id[index].id
})}
/>
</View>
</View>
You could use variables in your state that relate directly to the opening of the dropdown menus.
For example: dropdown1, dropdown2. In your first render, they should be set to false.
Now, whenever opening a dropdown with the function onOpen(), you should set the state of the dropdown you want to open to true, and the rest to false:
Dropdown 1 example
onOpen={() => { this.setState({ dropdown1: true, dropdown2: false }), this.cityOpen() }}
And then only show the dropdown that you need by using conditions.

How to Use icon map for RichEditor Tool bar in react-native-pell-richeditor?

I want to add underline and left, right, centre alignment for text in RichEditor but there is only default buttons in the toolbar.
There is a prop call icon map but don't know how to use it.
<View style={{
height: 250, width: '90%', borderRadius: 5, borderWidth: 0.6, borderColor: 'lightgrey',
alignItems: 'flex-start', flexDirection: 'column', justifyContent: 'center', backgroundColor: 'rgb(242,240,244)', marginLeft: 20
}}>
<View style={{ flex: 1, }}>
<RichEditor
ref={(r) => this.richtext = r}
initialContentHTML={this.bizDetailsEditorVal}
keyboardDisplayRequiresUserAction={true}
onMessage={(s) => {
console.log(s)
}}
style={{
// minHeight:Platform.OS === 'ios' ? 30 : 40,
// maxHeight:Platform.OS === 'ios' ? 100: 40,
height: '100%',
backgroundColor: 'white',
flex: 1, justifyContent: 'center',
minWidth: '100%', width: '100%'
}}
/>
</View>
<View style={{ width: '100%' }}>
<RichToolbar
getEditor={() => this.richtext} />
</View>
You can do somethings like below
RichToolbar editor={richText}
actions={[
actions.keyboard,
actions.setBold,
actions.setItalic,
actions.setUnderline,
actions.setStrikethrough,
actions.heading1,
actions.heading2,
actions.heading3,
actions.insertBulletsList,
actions.insertOrderedList,
actions.undo,
actions.redo,
actions.removeFormat
]}
iconMap={{
[actions.heading1]: ({ tintColor }) => (<Text style={[styles.tib, { color: tintColor }]}>H1</Text>),
[actions.heading2]: ({ tintColor }) => (<Text style={[styles.tib, { color: tintColor }]}>H2</Text>),
[actions.heading3]: ({ tintColor }) => (<Textstyle={[styles.tib, { color: tintColor }]}>H3</Text>),
}}
/>

how to vertically align to center navigation options on react native?

this is my code:
Welcome.navigationOptions = {
headerTitle: <Text style={theme.fonts.header}>Welcome</Text>,
headerTitleStyle: {
alignSelf: "center",
textAlignVertical: "center"
},
headerRight: (
<TouchableOpacity style={{ alignSelf: "center" }}>
<Block flex={false}>
<Image
resizeMode="contain"
source={require("../../assets/images/Icon/Menu.png")}
style={{ width: 20, height: 24 }}
/>
<Badge
size={13}
color={theme.colors.accent}
style={{ position: "absolute", top: -4, right: -4 }}
/>
</Block>
</TouchableOpacity>
)
};
You see i have used textVerticalAlign & alignSelf to center for headerTitleStyle and used alignSelf
center for headerRight, still no effect and this is the result of the code which you it's like aligned on bottom:
I also tried this still not working:
headerStyle: {
alignItems: 'center'
}
give [flex : 1] to header title style
Here is the code for Navigation Options:
static navigationOptions = ({ navigation }) => {
const params = navigation.state.params || {};
return {
title: "Title",
headerTintColor: 'white',
headerTitleStyle: {
textAlign: 'center',
flex:1,
alignSelf: 'center',
},
headerStyle: {
backgroundColor: '#ff6500'
},
headerLeft:(<View></View>),
headerRight: (<View style={{ flexDirection: 'row', justifyContent: 'flex-end',marginRight:15 }}>
<Text style={{justifyContent:"center"}}>btn</Text>
</View>)
}
};
Code ScreenShot:
You would do this in headerTitleContainerStyle instead of headerTitleStyle.
Vertically center:
headerTitleContainerStyle: { alignSelf: 'center' }