React Native: text going out of screen - react-native

I have an issue with the text going out of the screen and not wrapping.
Here is the code and stylesheet. Appreciate if someone can let me know what's going on and how to fix.
Referred to this post but couldn't get it to work.
<View style={styles.columnContainer}>
<View style={styles.rowDetails}>
<Text style={styles.header}>Customer Details</Text>
</View>
<View style={styles.rowItem}>
<Icon name="user-o" style={styles.userIcon}/>
<Text style={styles.textCustomer}>
{this.props.currentTask.customer.title} {this.props.currentTask.customer.first_name} {this.props.currentTask.customer.last_name}
</Text>
<View style={{flex: 0.1, backgroundColor: 'orange'}}/>
</View>
<View style={styles.rowItem}>
<Icon name="map-marker" style={styles.addressIcon}/>
<View style={styles.row}>
{
this.props.currentTask.address ? (
<Text style={styles.textCustomer}>
{ this.props.currentTask.address.street ? `${this.props.currentTask.address.street}, ` : null }
{ this.props.currentTask.address.landmark ? `${this.props.currentTask.address.landmark}, ` : null }
{ this.props.currentTask.address.area ? `${this.props.currentTask.address.area}, ` : null }
{ city ? `${city}, ` : null }
{ state ? `${state}, ` : null }
{ country }
</Text>
) : (
<Text style={styles.textCustomer}>(No Address Selected)</Text>
)
}
</View>
{
this.props.currentTask.address ?
<Icon name="chevron-right" onPress={this.onPressAddress.bind(this)} style={styles.rightIcon}/> :
<Icon name="plus" onPress={this.onPressAddress.bind(this)} style={styles.rightIcon}/>
}
</View>
<View style={styles.rowItem}>
<Icon name="phone" style={styles.phoneIcon}/>
<View style={styles.row}>
{
this.props.currentTask.phone ? (
<Text style={styles.textCustomer}>
{this.props.currentTask.phone.phone_number} ({this.props.currentTask.phone.phone_type})
</Text>
) : (
<Text style={styles.textCustomer}>(No Phone Selected)</Text>
)
}
</View>
{
this.props.currentTask.phone ?
<Icon name="chevron-right" onPress={this.onPressPhone.bind(this)} style={styles.rightIcon}/> :
<Icon name="plus" onPress={this.onPressPhone.bind(this)} style={styles.rightIcon}/>
}
</View>
</View>
Stylesheet:
columnContainer:{
flex: 1,
flexDirection: 'column',
alignItems: 'flex-start',
justifyContent: 'flex-start',
},
rowDetails:{
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-start',
alignItems: 'flex-start',
},
//section header like Customer Details / Task Details
header:{
flex: 1,
paddingVertical: 8,
paddingHorizontal: 10
},
//every row item
rowItem:{
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-start',
alignItems: 'flex-start',
paddingVertical: 8,
paddingLeft: 7,
paddingRight: 3,
marginBottom: 2,
backgroundColor: COLOR_TASK_DETAILS_ROW,
},
row: {
flex: 0.8,
flexDirection: 'column',
//flexWrap: 'wrap',
//backgroundColor: 'blue',
},
//right chevron icon
rightIcon: {
flex: 0.1,
//width: 20,
fontSize: 15,
color: COLOR_TASK_DETAILS_ICON_ARROW,
alignSelf: 'center',
backgroundColor: 'orange'
},
//***************************** customer details ****************************
userIcon: {
flex: 0.1,
//width: 20,
fontSize: 15,
color: COLOR_TASK_DETAILS_ICON,
//marginRight: 2,
marginLeft: 5,
alignSelf: 'center',
backgroundColor: 'orange'
},
textCustomer: {
flex: 1,
marginLeft: 5,
flexWrap: 'wrap',
textAlign: 'left',
backgroundColor: 'red',
},
addressIcon: {
flex: 0.1,
//width: 20,
fontSize: 18,
color: COLOR_TASK_DETAILS_ICON,
marginLeft: 7,
//marginRight: 2,
alignSelf: 'center',
backgroundColor: 'orange'
},
phoneIcon: {
flex: 0.1,
//width: 20,
fontSize: 18,
color: COLOR_TASK_DETAILS_ICON,
//marginRight: 2,
marginLeft: 5,
alignSelf: 'center',
backgroundColor: 'orange'
},

Related

How do I make one <View> take all available space when there is something else on the same row?

Im trying to make a flatlist with some data and a button on each row.
I have tried to do it in a typical "web" fashion, with nested views and formating the elements relative to their parent, but with no success.
this is the current structure of the list:
<View style={styles.row}>
<View style={styles.rowinfo}>
<View>
<Text style={styles.primaryID}>{item.name ? item.name : item.phoneNumber}</Text>
<Text style={styles.secondaryID}>{item.name ? item.phoneNumber : 'Ukjent innringer'}</Text>
</View>
<View>
<Text style={styles.textalignRight}>Varighet: {item.durationDisplay}</Text>
<Text style={styles.textalignRight}>{item.dateStringTime}</Text>
</View>
</View>
<TouchableOpacity style={styles.rowicon}>
<View style={styles.ban_icon}>
<Icon
name='ban'
type='font-awesome'
color='#FFF'
/>
</View>
</TouchableOpacity>
</View>
And here is my styling:
const styles = StyleSheet.create({
row: {
flex: 1,
marginTop: 1,
paddingVertical: 10,
paddingHorizontal: 15,
flexDirection: "row",
justifyContent: "space-between",
borderBottomWidth: 1,
borderBottomColor: '#f9f9f9'
},
rowinfo:{
flexDirection: "row",
alignSelf: 'stretch'
},
primaryID: {
fontWeight: 'bold'
},
textalignRight: {
textAlign: 'right'
},
rowbt: {
justifyContent: "center",
alignItems: "center",
backgroundColor: 'red'
},
ban_icon: {
color: '#FFF',
fontWeight: 'bold',
fontSize: 14,
marginHorizontal: 8
}
});
I im trying to make it look like this:
But i keep getting this:
import * as React from 'react';
import { Text, View, StyleSheet, TouchableOpacity } from 'react-native';
import Constants from 'expo-constants';
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<View style={styles.row}>
<View style={styles.rowinfo}>
<View>
<Text style={styles.primaryID}>{'Phone Number'}</Text>
<Text style={styles.secondaryID}>{'Ukjent innringer'}</Text>
</View>
</View>
<View style={{ flexDirection: 'row'}}>
<View>
<Text style={styles.textalignRight}>Varighet: {'1m og 20s'}</Text>
<Text style={styles.textalignRight}>{'13:23:11'}</Text>
</View>
<TouchableOpacity style={styles.ban_icon}>
<View style={styles.ban_icon} />
</TouchableOpacity>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: Constants.statusBarHeight,
},
row: {
backgroundColor: 'green',
width: '100%',
marginTop: 1,
paddingVertical: 10,
paddingHorizontal: 15,
flexDirection: "row",
justifyContent: "space-between",
borderBottomWidth: 1,
borderBottomColor: '#f9f9f9'
},
rowinfo:{
flex: 1,
flexDirection: "row",
},
primaryID: {
fontWeight: 'bold'
},
textalignRight: {
textAlign: 'right'
},
ban_icon: {
padding: 10,
backgroundColor: 'red',
marginLeft: 10,
}
});
Check the snack: https://snack.expo.io/#legowtham/43c687
I was able to get my desired result by using absolute positioning.

Margins when using multiple views in RN

I have a multiple Views, ImageBackground etc that are all nested.
Each time there is a View there is an additionnal margin that is added and my list is in a very restrictive area.
I set margin to 0 but it doesn't solve the problem.
Do you know how I can avoid useless margin around the list ?
I have tested to set margin to 0 and marginLeft, Right, etc but I dont understand way I still have margin
render() {
return (
<View style ={styles.container}>
<ImageBackground
source={require("./images/image1.jpg")}
style={styles.imageBackground}>
<View style ={{flex:14}}>
<View style={styles.flatListContainer}>
<View style={styles.List}>
<FlatList
data={[
{key: 'ab'},
{key: 'cd'},
{key: 'ef'},
]}
renderItem={({item}) => <Text style={styles.text}>{item.key}</Text>}
/>
</View>
<View style={styles.midList}>
<FlatList
data={[
{key: 'gh'},
{key: 'ij'},
{key: 'kl'},
]}
renderItem={({item}) => <Text style={styles.text}>{item.key}</Text>}
/>
</View>
<View style={styles.List}>
<FlatList
data={[
{key: 'mn'},
{key: 'op'},
{key: 'qr'},
]}
renderItem={({item}) => <Text style={styles.text}>{item.key}</Text>}
/>
</View>
</View>
</View>
</ImageBackground>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
margin: 0,
},
mainContainer: {
flex: 1,
alignItems: 'center',
},
flatListContainer: {
flex: 1,
alignItems: 'center',
flexDirection: 'row',
margin: 0
},
List: {
margin: 0
},
midList: {
borderLeftColor: '#00AABB',
borderLeftWidth: 1,
marginLeft: 0,
borderRightColor: '#00AABB',
borderRightWidth: 1,
marginRight: 0,
marginBottom: 33,
},
logo: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
},
imageContainer: {
flex: 1,
alignItems: 'center',
flexDirection: 'row',
//backgroundColor: '#fff',
//justifyContent: 'center',
alignItems: 'center',
},
touchOpacity: {
flex: 1,
alignItems: 'center',
resizeMode: "contain",
marginLeft: 0
},
imageBackground: {
width: '100%',
height: '100%',
alignItems: 'center',
justifyContent: 'center',
},
headText: {
flex: 1,
alignItems: 'center',
textAlign: 'center',
color: 'white',
},
safety: {
flex: 0.2,
alignItems: 'center',
color: 'greenyellow',
},
text: {
flex: 2,
textAlign: 'center',
color: 'white',
},
});
```
Can you try the following, I just updated the styles.
render() {
return (
<View style={styles.container}>
<ImageBackground
source={require("./images/image1.jpg")}
style={styles.imageBackground}
>
<View style={{ width: "100%", height: "100%" }}>
<View style={styles.flatListContainer}>
<View style={styles.List}>
<FlatList
style={{ flex: 1 }}
data={[{ key: "ab" }, { key: "cd" }, { key: "ef" }]}
renderItem={({ item }) => (
<Text style={styles.text}>{item.key}</Text>
)}
/>
</View>
<View style={styles.midList}>
<FlatList
data={[{ key: "gh" }, { key: "ij" }, { key: "kl" }]}
renderItem={({ item }) => (
<Text style={styles.text}>{item.key}</Text>
)}
/>
</View>
<View style={styles.List}>
<FlatList
data={[{ key: "mn" }, { key: "op" }, { key: "qr" }]}
renderItem={({ item }) => (
<Text style={styles.text}>{item.key}</Text>
)}
/>
</View>
</View>
</View>
</ImageBackground>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1
// alignItems: "center",
// margin: 0
},
mainContainer: {
flex: 1,
alignItems: "center"
},
flatListContainer: {
flex: 1,
// alignItems: "center",
flexDirection: "row"
// margin: 0
},
List: {
// margin: 0,
flex: 1
},
midList: {
flex: 1,
borderLeftColor: "#00AABB",
borderLeftWidth: 1,
// marginLeft: 0,
borderRightColor: "#00AABB",
borderRightWidth: 1,
marginRight: 0
// marginBottom: 33
},
logo: {
flex: 1,
flexDirection: "row",
alignItems: "center"
},
imageContainer: {
flex: 1,
alignItems: "center",
flexDirection: "row",
//backgroundColor: '#fff',
//justifyContent: 'center',
alignItems: "center"
},
touchOpacity: {
flex: 1,
alignItems: "center",
resizeMode: "contain",
marginLeft: 0
},
imageBackground: {
width: "100%",
height: "100%"
// alignItems: "center"
// justifyContent: "center"
},
headText: {
flex: 1,
alignItems: "center",
textAlign: "center",
color: "white"
},
safety: {
flex: 0.2,
alignItems: "center",
color: "greenyellow"
},
text: {
// flex: 2,
textAlign: "center",
color: "white",
backgroundColor: "red"
}
});

FlatList does not scroll down to the end

I have a flatlist in my react native code. It does not scroll all the way down. I want to scroll it down till the end, but when I tried scrolling it down, it came back up again. Below is my entire code with style sheets:
FlatListItemSeparator = () => {
return (
<View
style={{
height: .9,
width: "100%",
backgroundColor: "#607D8B",
}}
/>
);
}
_renderItem = ({item, index}) => {
var destUrl = 'https://www.google.com/maps/dir/Current+Location/' + item.addr;
var geodist = require('geodist')
var dist = geodist({lat: item.cLat, lon:item.cLong}, {lat: item.LatL, lon: item.Long2}, 'mi')
var imagevar = item.image;
if (isNaN(dist)) {
dist = 0;
}
return(
<View style={{ backgroundColor: index %2 ===0? '#DDBC95':'#EBDCB2'}} >
<View style={{ flexDirection: 'row', alignItems:'center' }}>
<Image source={Icons[imagevar]} style = {styles.imageView}/>
<View style={{ flex: 1, alignItems: "center"}}>
<Text style={styles.Address1}>{item.addr} </Text>
<View style={styles.phoneImg}>
<TouchableOpacity
onPress={() => { this.handleClick(`tel:${item.phone}`)}}>
<Image source={require('../images/Phone.png')} style={styles.actionImage}/>
</TouchableOpacity>
<Text style={styles.Address1}>{item.phone}</Text>
</View>
<View style={styles.AddressRow}>
{
item.Online != ''? <TouchableOpacity onPress={() => Linking.openURL( item.Online )}>
<Image source={require('../images/www-icon.png')} style={styles.actionImage1}/>
</TouchableOpacity>: null
}
<TouchableOpacity onPress={() => Linking.openURL(item.Online)}>
<Text style={styles.underLineText}>Online</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => Linking.openURL(destUrl)}>
<Text style={styles.underLineText}>Directions</Text>
</TouchableOpacity>
<Text style={styles.AddressSpace} >Miles:{dist}</Text>
</View>
</View>
</View>
</View>
);
}
componentDidCatch
render()
{
var x = this.props.navigation.state.params.item.id ;
var newList = ServiceDetails.filter(obj => obj.fk === x)
return(
<View >
<View>
<Text style={styles.title}>{this.props.navigation.state.params.item.ser}</Text>
<Text style={styles.SerContent} >Services are available in the following locations:</Text>
</View>
<View>
<FlatList
data={newList.sort((a, b) => {
var geodist = require('geodist')
const aDist = geodist(
{ lat: a.cLat, lon: a.cLong },
{ lat: a.LatL, lon: a.Long2 },
"mi"
);
const bDist = geodist(
{ lat: b.cLat, lon: b.cLong },
{ lat: b.LatL, lon: b.Long2 },
"mi"
);
return aDist - bDist;
})}
ItemSeparatorComponent = {this.FlatListItemSeparator}
renderItem={this._renderItem}
keyExtractor={(item, index) => index}
/>
</View>
</View>
)
}
}
const styles = StyleSheet.create({
MainContainer :{
// Setting up View inside content in Vertically center.
justifyContent: 'center',
flex:1,
margin: 10
},
item: {
padding: 10,
fontSize: 18,
height: 44,
},
container2:
{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 15
},
underLineText: {
fontSize: 17,
textDecorationLine: 'underline',
color: 'black',
alignSelf: 'center',
marginLeft: 20,
paddingTop:10
},
underLineTextOnline: {
fontSize: 17,
textDecorationLine: 'underline',
color: 'black',
alignSelf: 'center',
marginLeft: 20,
paddingTop:5
},
title:{
justifyContent: 'center',
paddingTop: 10,
alignItems: 'center',
alignSelf: 'center',
fontWeight: 'bold',
fontSize: 22,
color: 'black',
},
Address1:{
alignSelf: 'center',
marginRight: 20,
fontSize: 19,
fontWeight:'bold',
fontWeight: 'bold',
color: 'black'
},
SerContent:{
fontWeight: 'bold',
fontSize: 16,
paddingTop: 10,
alignSelf: 'center',
color: 'black',
paddingBottom: 10
},
Address1:{
alignSelf: 'center',
marginRight: 20,
fontSize: 15,
flexDirection:'column',
color: 'black',
marginLeft:10,
textAlignVertical:'center'
},
AddressRow:{
alignSelf: 'center',
marginRight: 20,
fontSize: 15,
flexDirection: 'row',
color: 'black'
},
phoneImg:{
flexDirection: 'row',
alignSelf: 'center',
textAlignVertical:'center'
},
AddressSpace:{
alignSelf: 'center',
marginLeft: 20,
fontSize: 15,
marginLeft: 20,
paddingTop:5,
color: 'black'
},
actionImage:{
flex:0,
height:30,
width:30,
backgroundColor:'transparent',
justifyContent:'center',
alignItems:'center',
marginTop:10,
alignSelf:'center',
flexDirection:'column',
textAlignVertical:'center'
},
sepBoxes:{
flex: 1,
flexDirection: 'column'
},
box: {
height: 55,
width:400,
},
box1: {
backgroundColor: 'white'
},
actionImage1:{
flex:0,
height:40,
width:40,
backgroundColor:'transparent',
justifyContent:'center',
alignItems:'center',
paddingLeft:5,
alignSelf:'center',
flexDirection:'column'
},
imageView:{
width:'30%',
height:100,
margin:7,
borderRadius: 7
},
textView: {
width:'50%',
textAlignVertical:'center',
padding:10,
color: '#000'
}
});
AppRegistry.registerComponent('ServiceListDetails', () => ServiceListDetails);
Above code has all the stylesheets and complete code.
Any help will be greatly appreciated.

RN Android: button takes too much space when text on 2 lines

I have this button
const TestButton = ({ text }) => (
<View
style={{
width: '100%',
marginTop: 10,
padding: 10,
backgroundColor: 'red',
flexDirection: 'row',
justifyContent: 'center',
}}>
<View
style={{
backgroundColor: 'green',
padding: 10,
flexDirection: 'row',
alignItems: 'center',
}}>
<Text numberOfLines={2}>{text}</Text>
</View>
</View>
);
I want the button to be the smallest possible, and centered.
Android
On Android, as you can see it's not really the case. For the 3 case we can clearly see that the button (green) is much larger than it should be and takes all available space.
iOS
On iOS as you can see it seems to work as I expect.
Is this a bug? Are there any workaround to solve this problem on Android?
Here is an Expo snack to reproduce.
Try this
const TestButton = ({ text }) => (
<View
style={{
width: '100%',
marginTop: 10,
padding: 10,
backgroundColor: 'red',
flexDirection: 'row',
justifyContent: 'center',
}}>
<View
style={{
padding: 10,
flexDirection: 'row',
alignItems: 'center',
}}>
<Text numberOfLines={2}
style = {{
backgroundColor: 'green',
padding:10
}}>
{text}
</Text>
</View>
</View>
);
I could solve my issue with wrapping my labels into container:
itemContainer: {
flex: 1,
marginHorizontal: 25,
paddingVertical: 15,
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center"
},
itemView: {
width: "100%"
},
newsTitle: {
fontSize: 20,
color: darkBlue,
paddingRight: 20,
fontFamily: "Helvetica-middle",
borderColor: darkBlue,
borderWidth: 1
},
newsChannel: {
paddingTop: 10,
fontSize: 16,
fontFamily: "Helvetica",
color: darkGrey
},
return (
<TouchableOpacity style={styles.itemContainer}>
<View style={styles.itemView}>
<Text style={styles.newsTitle}>{news.title}</Text>
<Text style={styles.newsChannel}>{newsChannelTitle}</Text>
</View>
<ArrowIcon />
</TouchableOpacity>
);

Update images of listView item on click in react-native

This is one item in my ListView
If you saw right side there is one grey circle. Here I want
when I tab on this Image it should became like this :
here I am able to do it seprately but it won't happen in list view here is my code :
constructor(props) {
super();
super(props);
const dataSource = new ListView.DataSource({rowHasChanged: (r1, r2) => r1.guid != r2.guid});
this.state = {
dataSource: dataSource.cloneWithRows(productArray),
isLoading: true,
item1Check: true,
item2Check: true
}
}
this is my renderFile :
<ListView
style={{paddingBottom: 40}}
dataSource={this.state.dataSource}
enderRow={(item, rowID) => this._renderMenuItem(item, rowID)}/>
this is item of listView
_renderMenuItem(item, rowID) {
var imgSource1 = this.state.item1Check? checkImg : crossImg;
var imgSource2 = this.state.item2Check? checkImg : crossImg;
console.log("sfsd1121212asas",rowID,this.state.item1Check,item.p1id)
return (
<View style={{
flex: 1, borderBottomWidth: 0, flexDirection: 'column', alignItems: 'center',
marginBottom: 25, marginRight: 10, marginLeft: 10
}}>
<Item style={[styles.squareLayout, {marginBottom: 8}]}>
<CachedImage source={{uri: '../orange.jpg'}}
style={{
width: 100, height: 100, borderRadius: 10, overflow: 'hidden',
borderColor: AppColors.grey2, borderWidth: 1
}}/>
<Item style={{
flex: 3,
flexDirection: 'column',
borderBottomWidth: 0,
justifyContent: 'center',
alignItems: 'center',
alignSelf: 'center'
}}>
<Text style={{
flex: 1, fontFamily: AppStyles.fontFamily, fontSize: 10, color: AppColors.grey1,
justifyContent: 'flex-start', alignItems: 'flex-start', alignSelf: 'flex-start',
paddingLeft: 8, paddingTop: 8
}} numberOfLines={1}>Our Apple fruit is Fresh, Delicious and crunchy. It is one of the most
popular fruit, favorite of health conscious, fitness lovers who believe in the concept
“health is wealth. The fresh Himachal apples are exported worldwide directly from farms at
very competitive prices.</Text>
<Text style={{
flex: 4, fontFamily: AppStyles.fontFamilyMedium, fontSize: 16, color: AppColors.black,
justifyContent: 'center', alignItems: 'center', alignSelf: 'flex-start',
paddingLeft: 8, paddingBottom: 8
}} numberOfLines={3}>Apple</Text>
</Item>
<Item style={{
flex: 1,
borderBottomWidth: 0,
justifyContent: 'flex-start',
alignItems: 'flex-start',
alignSelf: 'center'
}}>
<TouchableHighlight onPress={ () => this.setState({item1Check : !this.state.item1Check})}>
<Image source={this.state.item1Check ? require('../../assets/images/small_check_circle.png') : require('../../assets/images/small_x_circle.png')} />
</TouchableHighlight>
</Item>
</Item>
<Item style={[styles.squareLayout]}>
<CachedImage source={{uri:'../apple.jpg'}}
style={{
width: 100,
height: 100,
borderRadius: 10,
overflow: 'hidden',
borderWidth: 1,
borderColor: AppColors.grey2
}}/>
<Item style={{
flex: 3,
flexDirection: 'column',
borderBottomWidth: 0,
justifyContent: 'center',
alignItems: 'center',
alignSelf: 'center'
}}>
<Text style={{
flex: 1, fontFamily: AppStyles.fontFamily, fontSize: 10, color: AppColors.grey1,
justifyContent: 'flex-start', alignItems: 'flex-start', alignSelf: 'flex-start',
paddingLeft: 8, paddingTop: 8
}} numberOfLines={1}> 20 Carton/Cartons Navel Orange</Text>
<Text style={{
flex: 4, fontFamily: AppStyles.fontFamilyMedium, fontSize: 16, color: AppColors.black,
justifyContent: 'center', alignItems: 'center', alignSelf: 'flex-start',
paddingLeft: 8, paddingBottom: 8
}} numberOfLines={3}>Oranges</Text>
</Item>
<Item style={{
flex: 1,
borderBottomWidth: 0,
justifyContent: 'flex-start',
alignItems: 'flex-start',
alignSelf: 'center'
}}>
<TouchableHighlight onPress={ () => this.setState({item2Check : !this.state.item2Check})}>
<Image source={this.state.item2Check ? require('../../assets/images/small_x_circle.png') : require('../../assets/images/small_x_circle.png')} />
</TouchableHighlight>
</Item>
</Item>
</View>
);
}
}
this is my main code where I am trying to update my Images:
<TouchableHighlight onPress={ () => this.setState({item1Check : !this.state.item1Check})}>
<Image source={this.state.item1Check ? require('../../assets/images/small_check_circle.png') : require('../../assets/images/small_x_circle.png')} />
</TouchableHighlight>
How about adding ref to the image?
import resolveAssetSource from 'resolveAssetSource';
...
<TouchableHighlight onPress={ () => this.setState({item1Check : !this.state.item1Check})}>
<Image ref="list1img" source={this.state.item1Check ? require('../../assets/images/small_check_circle.png') : require('../../assets/images/small_x_circle.png')} />
</TouchableHighlight>
And detect changes to component and then change the image by the ref.
componentDidUpdate(){
this.handleCheck();
}
handleCheck(){
var img = this.state.item1Check ? require('pathforimage') : require('anotherpathforimage');
this.refs['list1img'].setNativeProps({
src: [resolveAssetSource(img)] //use source for ios instead of src
})
}