flex direction row items overflow how to fix this? - reactjs

I have two rows, 1st one contains image and second one text. So when I use flexDirection: 'row' the text overflow the width and ellipsis not showing. Please have a look into my code.
<View style={styles.boxContainer}>
<View style={{marginRight: 10}}>
<Text style={{textAlign: 'left'}}>
<Image
style={styles.eventImg}
source={{uri: item.image}}
/>
</Text>
</View>
<View>
<Text style={{fontSize: 16, fontWeight: '500'}}>{item.title}</Text>
<Text style={{fontSize: 12, color: '#878787'}}>{item.formatted_date}</Text>
<Text style={{fontSize: 10}} numberOfLines={1} ellipsizeMode='tail'>{item.descr}</Text>
<View style={{flexDirection: 'row'}}>
<TouchableOpacity
onPress={() =>
this.onPressReadMore(item.id)
}
>
<Text style={{fontSize: 12, padding: 5, backgroundColor: '#76ac42', color: '#ffffff', borderRadius: 3, textAlign: 'center', marginTop: 10, width: 80}}>Read More</Text>
</TouchableOpacity>
<Text style={{alignSelf: 'center', textAlign: 'right'}}>Registered</Text>
</View>
</View>
</View>
styles
const styles = StyleSheet.create({
container: {
backgroundColor: '#ffffff'
},
tabContainer: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
marginTop: 10,
marginBottom: 10,
marginLeft: 10,
marginRight: 10
},
tabSingle: {
flex: 1,
marginBottom: 5
},
titleText: {
fontSize: 20,
fontWeight: 'bold',
textAlign: 'left',
paddingTop: 20,
paddingLeft: 20,
paddingRight: 20
},
boxContainer: {
backgroundColor: '#f6f6f6',
padding: 10,
marginBottom: 10,
marginLeft: 10,
marginRight: 10,
flexDirection: 'row',
borderRadius: 5
},
eventImg: {
width: 80,
height: 80,
resizeMode: 'cover',
borderRadius: 5
}
});
Where am going wrong. I have tried many article and none of them seems working. Is there any way to fix this. Please have a look into the design,

Try this code:
<View style={{flexDirection:'row'}}>
<Text style={{fontSize: 10, flex: 1, flexWrap: 'wrap', flexShrink: 1}} ellipsizeMode='tail'>
{item.descr}
</Text>
</View>

Set the horizontal value in View, which contains the ellipsis.
<View style={{width: 200}} >
....
<Text style={{fontSize: 10}} numberOfLines={1} ellipsizeMode='tail'>{item.descr}
</Text>
Here's an example of a word-for-word abbreviation I've simplified.

Related

React native app crash when app more layers of view components

when ever I add this line of code in my react native app it
crashes.The expo app closes with out no error being thrown to the
console and its quite hard to debug because I don't see anything wrong
with the code.
What am thinking is it is wrong to have many views inside of a view component but I have not seen anyone complain about such error
<View>
<View style={styles.sameRowContainer}>
<View style={[styles.iconContainer, { backgroundColor: "#0CCE6B" }]}>
<Feather name="repeat" size={14} color="white" />
</View>
<Text style={styles.title}>Goal</Text>
</View>
<View>
<Text style={styles.title}>hello</Text>
</View>
</View>
this is the code that is render for the screen
return (
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<ScrollView
showsVerticalScrollIndicator={false}
style={styles.container}
// contentContainerStyle={{ alignItems: "center" }}
>
<View style={styles.habitNameContainer}>
<Text style={styles.title}>Habit Name</Text>
<TextInput
style={styles.input}
onChangeText={onChangeTitle}
value={title}
placeholder={"Learn photography..."}
placeholderTextColor={"hsla(224, 100%, 10%, 0.343)"}
/>
</View>
<View style={styles.timeOfDay}>
<Text style={styles.title}>Select time of day to complete habit</Text>
<TimeOfDay
currentView={currentView}
setCurrentView={setCurrentView}
/>
</View>
<View>
<View style={styles.sameRowContainer}>
<View
style={[styles.iconContainer, { backgroundColor: "#0CCE6B" }]}
>
<Feather name="repeat" size={14} color="white" />
</View>
<Text style={styles.title}>Goal</Text>
</View>
<View>
<Text style={styles.title}>hello</Text>
</View>
</View>
<View style={styles.dummyView}></View>
</ScrollView>
</TouchableWithoutFeedback>
);
this is the style for the component as well
const styles = StyleSheet.create({
container: {
backgroundColor: "white",
paddingHorizontal: 20,
paddingVertical: 20,
},
dummyView: {
height: 50,
},
habitNameContainer: {
// width: "90%",
marginBottom: 40,
},
title: {
marginLeft: 10,
fontSize: 16,
marginBottom: 5,
color: "hsl(0, 0%, 50%)",
},
input: {
flexDirection: "row",
fontSize: 18,
paddingLeft: 15,
height: 50,
borderRadius: 30,
backgroundColor: "hsl(224, 100%, 98%)",
fontWeight: "500",
},
timeOfDay: {
// flexDirection: "row",
marginBottom: 40,
},
sameRowContainer: {
flexDirection: "row",
alignItems: "baseline",
},
iconContainer: {
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
height: 26,
width: 26,
borderRadius: 8,
backgroundColor: "#0CCE6B",
},
});

Why is the modal view not appearing for mobile browser?

am using React native web and I have a Modal view as follows:
(am quoting only the return part as mostly it is a design related issue)
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<View>
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}>
<View
style={{
backgroundColor: 'white',
height: '400px',
width: '450px',
}}>
<Text
style={{
fontFamily: 'Roboto',
fontWeight: 'bold',
fontSize: 18,
textAlign: 'center',
padding: 20,
}}>
{name}
</Text>
<View
style={{
borderBottomColor: '#18D0E4',
borderBottomWidth: 1,
}}
/>
<View
style={{
flexDirection: 'row',
justifyContent: 'space-between',
marginTop: '5%',
padding: 20,
margin: '5%',
}}>
{reminder == 6 && toggle == 6 ? (
<TouchableOpacity style={{flexDirection: 'row'}}>
<Image
source={Images.circle}
style={{
height: 15,
width: 15,
marginTop: '2%',
paddingRight: '1%',
}}
/>
<Text
style={{
fontFamily: 'Roboto',
fontSize: 17,
color: '#000',
marginLeft: 5,
}}>
Set Different reminder
</Text>
</TouchableOpacity>
) : (
<TouchableOpacity
style={{flexDirection: 'row'}}
onPress={() => reminderSet()}>
<Image
source={Images.circle_o}
style={{
height: 15,
width: 15,
marginTop: '2%',
paddingRight: '1%',
}}
/>
<Text
style={{
fontFamily: 'Roboto',
fontSize: 17,
marginLeft: 5,
color: '#000',
}}>
Set Different reminder
</Text>
</TouchableOpacity>
)}
{vaccinatedOn == 1 && toggle == 1 ? (
<TouchableOpacity style={{flexDirection: 'row'}}>
<Image
source={Images.circle}
style={{
height: 15,
width: 15,
marginTop: '2%',
// paddingRight: '1%',
}}
/>
<Text
style={{
fontFamily: 'Roboto',
fontSize: 17,
marginLeft: 5,
color: '#000',
}}>
Vaccinated on
</Text>
</TouchableOpacity>
) : (
<TouchableOpacity
style={{flexDirection: 'row'}}
onPress={() => vaccinationSet()}>
<Image
source={Images.circle_o}
style={{
height: 15,
width: 15,
marginTop: '2%',
// paddingRight: '1%',
}}
/>
<Text
style={{
fontFamily: 'Roboto',
fontSize: 17,
marginLeft: 5,
color: '#000',
}}>
Vaccinated on
</Text>
</TouchableOpacity>
)}
</View>
<View
style={{
justifyContent: 'center',
alignItems: 'center',
}}>
<DatePicker selected={date} onChange={(date) => setDate(date)} />
</View>
</View>
</View>
<View
style={{
flexDirection: 'row',
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
width: '82%',
paddingTop: 20,
}}>
<TouchableOpacity
style={{
flex: 1,
borderTopColor: '#C0C0C0',
borderTopWidth: 1,
borderRightColor: '#C0C0C0',
borderRightWidth: 1,
justifyContent: 'center',
alignItems: 'center',
padding: 10,
}}
onPress={() => navigation.goBack()}>
<Text
style={{
fontFamily: 'Roboto',
fontSize: 17,
fontWeight: 'bold',
color: '#000',
}}>
Cancel
</Text>
</TouchableOpacity>
<TouchableOpacity
style={{
flex: 1,
borderTopColor: '#C0C0C0',
borderTopWidth: 1,
borderLeftColor: '#C0C0C0',
borderLeftWidth: 1,
justifyContent: 'center',
alignItems: 'center',
padding: 10,
}}
onPress={() => SaveData(id)}>
<Text
style={{
fontFamily: 'Roboto',
fontSize: 17,
fontWeight: 'bold',
color: '#000',
}}>
OK
</Text>
</TouchableOpacity>
</View>
</View>
</View>
the web view is appearing as follows:
However, as soon as I switch to mobile view, the modal disappears like follows:
Kindly let me know, where I have gone wrong, any lead would be appreciated, thank you in advance.
Let me know if anything else is required.
<View style={{ height: "100vh", width: "100vw" }}> should be added at Root to make it responsive over all platforms

How can i achieve below design in react native

can you some one help me to achieve below design i'm not be able to achieve the same design
bellow is my code
<View style={{ position: 'absolute', padding:8, borderColor: 'gray', borderWidth: 1, marginLeft: 30, width: '25%', top: 120, backgroundColor: 'transparent' }}>
<Text>From</Text>
</View>
<View style={{padding:10, borderColor: 'gray', borderWidth: 1, width: '95%', alignSelf: 'center', borderRadius: 7, marginTop: 25 }}>
<Text>MAPLIN STORE</Text>
<Text>12 Kwame Nkrumah Bvd</Text>
<Text>Pune, INDIA</Text>
</View>
Thanks
Something like this works for you?
<View>
<View style={{padding:10, borderColor: 'gray', borderWidth: 1, width: '95%', alignSelf: 'center', borderRadius: 7, marginTop: 25 }}>
<View style={{ position: 'relative', padding:8, borderColor: 'gray', borderWidth: 1, marginLeft: 20, width: '25%', backgroundColor: 'white',bottom: 33}}>
<Text>From</Text>
</View>
<Text>MAPLIN STORE</Text>
<Text>12 Kwame Nkrumah Bvd</Text>
<Text>Pune, INDIA</Text>
</View>
</View>
<View style={{padding:10, borderColor: 'gray', borderWidth: 1, width: '95%', alignSelf: 'center', borderRadius: 7, marginTop: 25 }}>
<View style={{ padding: 8, borderColor: 'gray', borderWidth: 1, marginLeft: 20, width: '25%', backgroundColor: 'white',bottom: 33}}>
<Text>From</Text>
</View>
<Text>MAPLIN STORE</Text>
<Text>12 Kwame Nkrumah Bvd</Text>
<Text>Pune, INDIA</Text>
</View>
try this code it's simple and nit code no need to extra main view and position
hope it would be help
Please check the link https://snack.expo.io/B1inoHHVV you already got your answer may hope it will also help you
<View style={{flex:1,justifyContent:'center'}}>
<View style={{padding:10,margin:5,borderColor:'black',borderWidth:2}}>
<View style=
{{borderColor:'black',
borderWidth:1,width:120,
bottom:30,
backgroundColor:'white'}}>
<Button title="From"/>
</View>
<View style={{margin:10}}>
<Text style={{fontWeight: 'bold'}}>MAPLIN STORE</Text>
<Text style={{fontWeight: 'bold'}}>12 Kwame Nkrumah Bvd</Text>
<Text style={{fontWeight: 'bold'}}>PUNE INDIA</Text>
</View>
</View>
</View>

each child in an array unique key with react native swipe out

i'm using react native swipeout within a flat list. I'm pulling my data from a collection in firestore. I want to pull the items in the collection and apply a color to the item based on the item type. For instance, if someone has a car then it would be purple view and the bike would be green. I applied an if statement and then render method based on the if statement. Can someone help me on what i'm doing wrong?
if (collection.item.type == 'car') {
let that = this;
return (
<View style={{marginTop: 20}}>
{/* this is an empty view to space out the array items. was unable to figure out a more clever way to separate the views and keep the side buttons in line with the component.*/}
<Swipeout
key={collection.key}
onOpen={(itemID, ) => {
that.setState({
itemID,
});
}}
style={{backgroundColor: 'rgba(0,0,0,0)',}}
right={swipeoutBtns}>
<LinearGradient style={{justifyContent: 'center', borderRadius: 30, width: 250, height: 180, alignSelf: 'center'}} colors={['#ff00ff', '#0066ff']}>
<View style={{alignSelf: 'center', justifyContent: 'center', width: 60, height: 60, borderRadius: 60/2, backgroundColor: 'white'}}>
<Text style={{alignSelf: 'center'}}>
{car}
</Text>
</View>
<Text style={{fontWeight: 'bold', marginTop: 5, color: 'white', fontSize: 16, alignSelf: 'center', backgroundColor: 'rgba(0,0,0,0)',}}>
{collection.item.make}
</Text>
<Text style={{fontWeight: 'bold', marginTop: 5, color: 'white', fontSize: 16, alignSelf: 'center', backgroundColor: 'rgba(0,0,0,0)',}}>
{collection.item.model}
</Text>
<Text style={{fontWeight: 'bold', marginTop: 5, color: 'white', fontSize: 16, alignSelf: 'center', backgroundColor: 'rgba(0,0,0,0)',}}>
{collection.item.color}
</Text>
<Text style={{fontWeight: 'bold', marginTop: 5, color: 'white', fontSize: 16, alignSelf: 'center', backgroundColor: 'rgba(0,0,0,0)',}}>
{collection.item.year}
</Text>
<Text style={{fontWeight: 'bold', color: 'white', fontSize: 16, alignSelf: 'center', backgroundColor: 'rgba(0,0,0,0)',}}>
{collection.item.licensePlate}
</Text>
</LinearGradient>
</Swipeout>
</View>
);
}
I had to add item.key to the key extractor props. I'm answering this for anyone else that has this problem.
keyExtractor={(item, index) => item.key}

React Native FlexLayout: Alignment item right

I have a list of products and want to display the text "ITEM UNIT" at the right end of my infobox. It is however affected by the position of the text above it.
How do I solve this and put "ITEM UNIT" to the right end of the display?
<TouchableOpacity
onPress={() => this.props.onItemClicked(this.props.item)}
style={{ marginRight: 130 }}
>
<View style={styles.itemContent}>
<View>
<FadeIn>
<Image
resizeMode="contain"
style={{
height: 100,
width: 100,
marginTop: 10,
marginLeft: 10
}}
source={{ uri: url }}
/>
</FadeIn>
</View>
<View style={{ justifyContent: "space-around" }}>
<Text style={{ fontSize: 16, fontFamily: "System" }}>
{articleName}
</Text>
<View
style={{
flexDirection: "row",
justifyContent: "space-between"
}}
>
<View style={{ flexDirection: "row" }}>
<Text style={styles.itemPrice}>{originalprice} </Text>
<Text style={styles.itemPriceReduced}>{specialprice}€</Text>
</View>
<View>
<Text>ITEMUNIT</Text>
</View>
</View>
</View>
</View>
</TouchableOpacity>;
I crated a small demo for you. Please check it here:
https://snack.expo.io/#tarikfojnica/layout (Click Tap To Play on the right side)
Here are the code parts you should check:
<TouchableOpacity style={styles.container} onPress={() => this.props.onItemClicked(this.props.item)}>
<View style={styles.itemContent}>
<View style={styles.iconContainer}>
<Image source={Icon} style={styles.icon} />
</View>
<View style={styles.textContainer}>
<Text>This is the title </Text>
<View style={styles.downText}>
<View style={styles.priceText}>
<Text style={{marginRight: 10}}>$99.9</Text>
<Text>$99.9</Text>
</View>
<View style={styles.label}>
<Text>Label</Text>
</View>
</View>
</View>
</View>
</TouchableOpacity>
const styles = StyleSheet.create({
container: {
marginTop: 24,
},
itemContent: {
flexDirection: 'row',
borderBottomWidth: 1,
borderColor: 'e5e5e5'
},
iconContainer: {
padding: 10,
flex: 1,
},
icon: {
width: 40,
heigth: 40
},
textContainer: {
backgroundColor: 'whitesmoke',
flex: 7,
padding: 5
},
downText: {
marginTop: 10,
flexDirection: 'row',
justifyContent: 'space-between'
},
priceText: {
flexDirection: 'row',
},
label: {
textAlign: 'right',
backgroundColor: 'yellow',
padding: 3
}
});
For a reference, here is how it looks like:
PS: I would avoid writing inline styles.

Resources