React native paper DataTable.Cell overflow text causes hide full text - react-native

Below code using DataTable.Cell.
If text bigger than column width it hide text
Please help need to display text if text bigger than column width need to break text in next line.
<DataTable.Row
style={{ flex: 1, flexWrap: 'wrap', paddingLeft: 1, borderColor: 'green', borderWidth: 2 }}>
<DataTable.Cell
style={{
flex: 3,
flexWrap: 'wrap',
borderColor: 'yellow',
borderWidth: 2,
height: auto,
overflow: 'visible',
}}>
<View style={styles.rowbox}>
<Text style={styles.stnname}>Test 1</Text>
<Text>Day:1</Text>
<Text>Distance:0</Text>
</View>
</DataTable.Cell>
<DataTable.Cell numeric>Cell 1 2</DataTable.Cell>
<DataTable.Cell numeric>Cell 1 3</DataTable.Cell>
</DataTable.Row>
<DataTable.Row
style={{ flex: 1, flexWrap: 'wrap', paddingLeft: 1, borderColor: 'green', borderWidth: 2 }}>
<DataTable.Cell
style={{
flex: 3,
flexWrap: 'wrap',
borderColor: 'yellow',
borderWidth: 2,
height: auto,
overflow: 'visible',
}}>
<View style={styles.rowbox}>
<Text style={styles.stnname}>Test 2 Test 2 Test 2</Text>
<Text>Day:1</Text>
<Text>Distance:0</Text>
</View>
</DataTable.Cell>
<DataTable.Cell numeric>Cell 2 2</DataTable.Cell>
<DataTable.Cell numeric>Cell 2 3</DataTable.Cell>
</DataTable.Row>
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 16,
marginTop: 20,
zIndex:1
},
autocompleteContainer: {
flex: 1,
},
descriptionContainer: {
flex: 1,
justifyContent: 'center',
width:'100%',
alignItems: 'stretch'
},
itemText: {
fontSize: 15,
paddingTop: 5,
paddingBottom: 5,
margin: 6,
color: '#000',
},
infoText: {
textAlign: 'center',
fontSize: 16,
},
autodropsection:{
backgroundColor: "#fff",
flex:1,
},
containerMain: {
flex: 1,
padding: 0,
marginTop: 0,
},
datrow1:{
flex: 4,
flexDirection: 'column',
},
tableheader:{
backgroundColor : "#2375b3",
color:'#ffffff',
fontSize: 24,
fontWeight: '700',
flex: 2,
},
tableheadertitle:{
fontSize: 14,
fontWeight: '500',
color:'#fff',
textAlign:"center"
},
tableheadercell:{
color:"#fff",
fontSize:24,
},
cell:{
color:'#fff',
fontSize:24,
flexDirection:'column'
},
stnname:{
fontSize: 12,
fontWeight: '700',
color:'#333',
textAlign:"left",
flexWrap:'wrap',
alignContent:'flex-start'
},
rowbox:{
paddingTop:10,
paddingBottom:10,
paddingLeft:0,
paddingRight:0,
flexDirection:'column',
textAlign:'left',
justifyContent:'flex-start',
flex: 1,
borderWidth:2,
borderColor:'red',
flexWrap:'wrap',
width:'100%'
}
});

Use a View (with justifyContent: 'center') instead of DataTable.Cell to achieve the multilined cell
Source: https://github.com/callstack/react-native-paper/issues/2381#issuecomment-734155600

I Get the same issue, after big search i simply abandon this idea and start to use.
https://github.com/GeekyAnts/react-native-easy-grid/
Is realy simple to construct the same structure, like a table, after o just need to set border if you want, and done, simple and easy like Html.

Related

How to center text vertically in its own frame in React Native?

The text is sticking to the top. How do we center it vertically
<View style={styles.formContainer}>
<View style={styles.textInputBackground}>
<Text style={styles.textInputLabelText}>Name</Text>
<TextInput style={styles.textInput} />
</View>
<View style={styles.textInputBackground}>
<Text style={styles.textInputLabelText}>Email</Text>
<TextInput style={styles.textInput} />
</View>
</View>
const styles = StyleSheet.create({
formContainer: {
marginTop: 130,
},
textInputBackground: {
marginTop: 12,
backgroundColor: 'rgba(0, 0, 0, 0.08)',
flexDirection: 'row',
height: 46,
marginLeft: 16,
marginRight: 16,
borderRadius: 8,
},
textInputLabelText: {
backgroundColor: 'blue',
color: 'red',
justifyContent: 'center',
alignItems: 'center',
textAlign: 'center',
textAlignVertical: 'center',
flex: 2,
},
textInput: {
flex: 12,
},
})
Hi there I've updated your style. this will center your input
textInputBackground: {
marginTop: 12,
backgroundColor: 'rgba(0, 0, 0, 0.08)',
flexDirection: 'row',
height: 46,
marginLeft: 16,
marginRight: 16,
borderRadius: 8,
alignItems:"center", // **<--- add this line**
},
To make text center change style to this
textInputLabelText: {
backgroundColor: 'blue',
color: 'red',
justifyContent: 'center',
alignSelf: 'center', //just change alignItem to alignSelf
textAlign: 'center',
textAlignVertical: 'center',
flex: 2,
},

How to set two buttons stick together?

I set two half oval buttons and try to set the position on center.
But I found they don't stick together, I try to change justifyContent: 'space-between' or 'space-around' is not working.
How to let Left button and Right button stick together ?
Here is my code:
return (
<View style={{ justifyContent: 'center', marginTop: 50, flexDirection: 'row', backgroundColor: 'blue' }}>
<TouchableOpacity style={[styles.buttonStyle, { width: 150, height: 50, borderBottomLeftRadius: 50, borderBottomRightRadius: 0, borderTopLeftRadius: 50, borderTopRightRadius: 0 }]}>
<Text>Left</Text>
</TouchableOpacity>
<TouchableOpacity style={[styles.buttonStyle, { backgroundColor: 'orange', width: 150, height: 50, borderBottomLeftRadius: 0, borderBottomRightRadius: 50, borderTopLeftRadius: 0, borderTopRightRadius: 50 }]}>
<Text>Right</Text>
</TouchableOpacity>
</View>
);
const styles = StyleSheet.create({
buttonStyle: {
alignSelf: 'stretch',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'pink',
borderWidth: 1,
borderColor: 'transparent',
marginLeft: 5,
marginRight: 5
},
});
remove margins,
buttonStyle: {
alignSelf: 'stretch',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'pink',
borderWidth: 1,
borderColor: 'transparent',
marginLeft: 5,//this
marginRight: 5// this
},

Flex:1 not making parent <View> element cover entire screen, instead shrinks all elements to top of the screen

I am learning react-native, and want a Parent to take up the entire screen dynamically with flex instead of a static height/width value. It works fine with {height:714, width:393}, but when I replace them with flex:1, all the elements shrink to the top of the screen.
Code
Styles:
const styles = StyleSheet.create({
container: {
backgroundColor: 'purple',
padding: 5,
// flex: 1,
height: 714,
width: 393,
},
bigBlackText: {
color: 'black',
fontSize: 18,
},
bigWhiteText: {
color: 'white',
fontSize: 19,
},
col1: {
backgroundColor: 'yellow',
flexDirection: 'row',
flex: 1,
},
col11: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
margin: 5,
backgroundColor: 'orange',
},
col12: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
margin: 5,
backgroundColor: 'orange',
},
col13: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
margin: 5,
backgroundColor: 'orange',
},
col2: {
flex: 1,
backgroundColor: 'red',
},
col21: {
flex: 1,
justifyContent: 'space-around',
alignItems: 'center',
backgroundColor: 'brown',
margin: 5
},
col22: {
flex: 1,
justifyContent: 'space-around',
alignItems: 'center',
backgroundColor: 'brown',
margin: 5
},
col23: {
flex: 1,
justifyContent: 'space-around',
alignItems: 'center',
backgroundColor: 'brown',
margin: 5
},
col3: {
flex: 1,
backgroundColor: 'cyan',
flexDirection: 'column',
},
col31: {
flexDirection: 'row',
flex: 1,
},
col31r1: {
flex: 1,
justifyContent: 'space-around',
alignItems: 'center',
backgroundColor: 'green',
margin: 5,
},
col31r2: {
flex: 1,
justifyContent: 'space-around',
alignItems: 'center',
backgroundColor: 'green',
margin: 5,
},
col32: {
flexDirection: 'row',
flex: 1,
},
col32r1: {
flex: 1,
justifyContent: 'space-around',
alignItems: 'center',
backgroundColor: 'green',
margin: 5,
},
col32r2: {
flex: 1,
justifyContent: 'space-around',
alignItems: 'center',
backgroundColor: 'green',
margin: 5,
},
});
Expected Output
Actual Output
I find no problem exists.Do not use justifycontent or alignitems props in container stylesheet.
try to set width and height
mainView: {
width: "100%",
height: "100%"
}
or,
mainView: {
width: deviceWidht,
height: deviceHeight
}
I hope this works.
import React from 'react';
import { View, StyleSheet, Text } from 'react-native';
export default class ViewDemo extends React.Component {
render() {
return (
<View style={styles.container}>
<View style={{ flex: 1, backgroundColor: 'yellow', flexDirection: 'row', justifyContent: 'space-around' ,flexWrap: 'wrap'}}>
<View style={styles.h1}></View>
<View style={styles.h1}></View>
<View style={styles.h1}></View>
</View>
<View style={{ flex: 1, backgroundColor: 'red', flexDirection: 'column', justifyContent: 'space-around' }}>
<View style={styles.h2}></View>
<View style={styles.h2}></View>
<View style={styles.h2}></View>
</View>
<View style={{ flex: 1, alignItem:'center' , backgroundColor: '#3CAEA3', flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'space-around' }}>
<View style={styles.h3}></View>
<View style={styles.h3}></View>
<View style={styles.h3}></View>
<View style={styles.h3}></View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
h1: {
backgroundColor: '#f79c1d',
width: 100,
justifyContent : 'space-around',
margin: 10
},
h2: {
backgroundColor: '#9c2c2c',
height: 50,
justifyContent: 'space-around',
margin: 10
},
h3: {
backgroundColor: '#616f39',
height: 90,
width: 180,
margin: 10
},
});
you can directly use this code

How to show dropdown list when an image is clicked in react-native-modal-dropdown

I want to implement react-native-modal-dropdown functionality in my app,
here is the code
<View style={styles.viewStyle}>
<Text style={styles.textStyle}>{Strings.Location}</Text>
<View style={styles.input}>
<Image
style={styles.mapIcon}
source={require('../assets/map_pic_icon.png')}
/>
<ModalDropdown
onSelect={(index, value) => { this.setState({ selected: value }) }}
options={['option 1', 'option 2', 'option 3', 'option 4']}
defaultValue={Strings.Gaston}
dropdownTextStyle={{ backgroundColor: '#fff', fontSize: 18, color: colors.black }}/*Style here*/
textStyle={{ fontSize: 18, color: colors.gunmetal, alignSelf: 'flex-start', marginLeft: 10 }}
dropdownStyle={{ flex: 1, width: '90%', marginVertical: 10, borderWidth: 1, borderColor: colors.light_gray }}
style={{ flex: 1, width: '100%', backgroundColor: colors.white, justifyContent: 'center' }}
/>
<Image
style={styles.iconStyle}
source={require('../assets/down_arrow_blue.png')}
/>
</View>
</View>
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: colors.white,
},
viewStyle: {
margin: 10,
},
input: {
height: 50,
width: '100%',
marginTop: 8,
borderRadius: 2,
borderColor: colors.light_gray,
fontSize: 20,
borderWidth: 1,
flexDirection: 'row',
justifyContent: 'space-around'
},
iconStyle: {
margin: 20,
alignSelf: 'flex-end'
},
mapIcon: {
margin: 10,
alignSelf: 'center',
},
});
using this code my screen looks like this
my problem is when i click on blue color down arrow image then drodown is not opening it is only opening when i click on text .
How to solve this
And one more issue is dropdown width is not aligning properly to parent.
It is coming like this
Can anyone please tell me how to show dropdown list when icon is clicked and how to align the drodownlist list width properly.

Vertical centering in React Native doesn't work

I use a ScrollView and I am not able to center an icon in one of inner Views.
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
<ScrollView>
...
<View style={styles.detailRowContainer}>
<View style={{flex: 1}}>
<Text style={styles.label} numberOfLines={1}>
{'Phone Number'}
</Text>
<Text style={styles.value} numberOfLines={1}>
{phone}
</Text>
</View>
<View style={styles.round}>
<TouchableWithoutFeedback onPress={this._onPressPhone}>
<Icon size={22} name="phone" />
</TouchableWithoutFeedback>
</View>
</View>;
...
</ScrollView>
detailRowContainer: {
flexDirection: 'row',
justifyContent: 'center',
flex: 1,
marginTop: 10,
paddingBottom: 10,
borderBottomWidth: 1,
borderBottomColor: Colors.lightGray,
},
label: {
color: Colors.glofoxDark,
marginBottom: 3,
},
value: {
color: Colors.glofoxDark,
fontWeight: '800',
borderBottomWidth: 1,
borderBottomColor: Colors.lightGray,
},
round: {
backgroundColor: Colors.lightBlue,
width: 30,
height: 30,
borderRadius: 30,
overflow: 'hidden',
justifyContent: 'center',
alignItems: 'flex-end',
flexDirection: 'row',
padding: 4,
},
The styles need to be modified in this way.
Right now you're doing
flexDirection: row along justifyContent: center. Since your first child element is taking complete parent flex, therefore it does not show its effect
paddingBottom is given but , for centering an equivalent paddingTop must be given
padding for the round style should be replaced with margin, otherwise it affects the position of the inner elements
alignItems in round , must not be flex-end, it should be replaced with center
Here are the styles that will fix the vertical centering
detailRowContainer: {
flexDirection: 'row',
alignItems: 'center',
flex: 1,
marginTop: 10,
paddingTop: 10,
paddingBottom: 10,
borderBottomWidth: 1,
borderBottomColor: Colors.lightGray,
},
round: {
backgroundColor: Colors.lightBlue,
width: 30,
height: 30,
borderRadius: 30,
overflow: 'hidden',
justifyContent: 'center',
alignItems: 'center',
margin: 4
},