GooglePlacesAutocomplete styling on the list content of places is not working,not able to do wrapping the places react-native - react-native

I m using GooglePlacesAutocomplete where while typing getting the list of places but some places text containing more than that,so I wanted to wrap the text there.
<GooglePlacesAutocomplete
placeholder='Where To ?'
minLength={4}
autoFocus={true}
listViewDisplayed="auto"
returnKeyType={'search'}
fetchDetails={true}
onPress={(data, details = null) => {
props.notifyChange(details.geometry.location,data);
}}
query={{
key: 'chghgdhgfhgfjhdhklkl',
language: 'en',
}}
nearbyPlacesAPI= 'GooglePlacesSearch'
debounce={200}
styles={ styles }>
</GooglePlacesAutocomplete>
and my styles for that is as follows
const styles = StyleSheet.create({
textInputContainer:{
backgroundColor: 'rgba(0,0,0,0)',
borderTopWidth: 0,
borderBottomWidth:0,
zIndex:999,
width:'90%',
},
textInput: {
marginLeft: 0,
marginRight: 0,
height: 45,
color: '#5d5d5d',
fontSize: 16,
borderWidth:1,
zIndex:999,
},
predefinedPlacesDescription: {
color: '#1faadb'
},
listView:{
top:45.5,
zIndex:10,
position: 'absolute',
color: 'black',
backgroundColor:"white",
width:'89%',
},
separator:{
flex: 1,
height: StyleSheet.hairlineWidth,
backgroundColor: 'blue',
},
description:{
flexDirection:"row",
flexWrap:"wrap",
fontSize:14,
maxWidth:'89%',
},
});
refer this link https://reactnativeexample.com/customizable-google-places-autocomplete-component-for-ios-and-android-react-native-apps/
but not able to find the solution.help would be appreciated

The width of the ListView showing the results has its width hardcoded to window.with. That is why you wrapping the text isn't working.
There is a potential workaround, and that would be to split the description into multiple lines. You can do this with the renderRow prop. Styling would need to be adjusted for your specific use case.
<GooglePlacesAutocomplete
placeholder='Where To ?'
minLength={4}
autoFocus={true}
listViewDisplayed="auto"
returnKeyType={'search'}
fetchDetails={true}
onPress={(data, details = null) => {
props.notifyChange(details.geometry.location,data);
}}
query={{
key: 'chghgdhgfhgfjhdhklkl',
language: 'en',
}}
nearbyPlacesAPI= 'GooglePlacesSearch'
debounce={200}
renderRow={(rowData) => {
const title = rowData.structured_formatting.main_text;
const address = rowData.structured_formatting.secondary_text;
return (
<View>
<Text style={{ fontSize: 14 }}>{title}</Text>
<Text style={{ fontSize: 14 }}>{address}</Text>
</View>
);
}}
styles={ styles }>
</GooglePlacesAutocomplete>
You would need to add row to your styles and you can description from styles, because it is being overwritten by renderRow
row: {
height: "100%",
},
Disclosure: I am the maintainer of this package.

You can even style the field too.
Follow official doc-
<GooglePlacesAutocomplete
placeholder='Enter Location'
minLength={2}
autoFocus={false}
returnKeyType={'default'}
fetchDetails={true}
styles={{
textInputContainer: {
backgroundColor: 'grey',
},
textInput: {
height: 38,
color: '#5d5d5d',
fontSize: 16,
},
predefinedPlacesDescription: {
color: '#1faadb',
},
}}
/>

Related

I am trying to implement text change and edit ends in TextInput using react-native but it's not quite working. Can any one help me?

I am trying to implement text change and edit ends in TextInput using react-native but it's not quite working.
See the Screenshot Here
Currently, when changing the price by touch input, the price is not affected when click off.
Here are my files
CartItem.js:
import React from "react";
import {
View,
TextInput,
Image,
TouchableOpacity,
StyleSheet,
Platform,
Alert,
} from "react-native";
//Colors
import Colors from "../../../utils/Colors";
//NumberFormat
import NumberFormat from "../../../components/UI/NumberFormat";
//Icon
import { MaterialCommunityIcons } from "#expo/vector-icons";
import CustomText from "../../../components/UI/CustomText";
//PropTypes check
import PropTypes from "prop-types";
export class CartItem extends React.PureComponent {
render() {
const { item, onAdd, onDes, onRemove } = this.props;
const AddItemHandler = async () => {
await onAdd();
};
const sum = +item.item.price * +item.quantity;
const checkDesQuantity = async () => {
if (item.quantity == 1) {
Alert.alert(
"Clear cart",
"Are you sure you want to remove the product from the cart?",
[
{
text: "Cancel",
},
{
text: "Yes",
onPress: onRemove,
},
]
);
} else {
await onDes();
}
};
return (
<View style={styles.container}>
<View style={styles.left}>
<Image
style={{
width: "100%",
height: 90,
resizeMode: "stretch",
borderRadius: 5,
}}
source={{ uri: item.item.thumb }}
/>
</View>
<View style={styles.right}>
<View
style={{ flexDirection: "row", justifyContent: "space-between" }}
>
<CustomText style={styles.title}>{item.item.filename}</CustomText>
<View>
<TouchableOpacity onPress={onRemove}>
<MaterialCommunityIcons name='close' size={20} color='#000' />
</TouchableOpacity>
</View>
</View>
<CustomText style={{ color: Colors.grey, fontSize: 12 }}>
Provided by Brinique Livestock LTD
</CustomText>
<NumberFormat price={sum.toString()} />
<View style={styles.box}>
<TouchableOpacity onPress={checkDesQuantity} style={styles.boxMin}>
<MaterialCommunityIcons name='minus' size={16} />
</TouchableOpacity>
Code that I would like to be fixed starts here.
<View>
<TextInput
keyboardType='numeric'
onEndEditing={AddItemHandler}
style={styles.boxText}>{item.quantity}</TextInput>
</View>
Code that I would like to be fixed ends here.
<TouchableOpacity
onPress={AddItemHandler}
style={styles.boxMin}>
<MaterialCommunityIcons name='plus' size={16} />
</TouchableOpacity>
</View>
</View>
</View>
);
}
}
CartItem.propTypes = {
item: PropTypes.object.isRequired,
onAdd: PropTypes.func.isRequired,
onRemove: PropTypes.func.isRequired,
onDes: PropTypes.func.isRequired,
};
const styles = StyleSheet.create({
container: {
flex: 1,
marginHorizontal: 10,
height: 110,
borderBottomWidth: 1,
borderBottomColor: Colors.light_grey,
flexDirection: "row",
paddingVertical: 10,
alignItems: "center",
backgroundColor: "#fff",
paddingHorizontal: 10,
borderRadius: 5,
marginTop: 5,
},
left: {
width: "35%",
height: "100%",
alignItems: "center",
},
right: {
width: "65%",
paddingLeft: 15,
height: 90,
// overflow: "hidden",
},
title: {
fontSize: 14,
},
box: {
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
height: Platform.OS === "ios" ? 30 : 25,
backgroundColor: Colors.grey,
width: 130,
borderRadius: 5,
paddingHorizontal: 15,
marginTop: 5,
},
boxMin: {
width: "30%",
alignItems: "center",
},
boxText: {
fontSize: 16,
backgroundColor: Colors.white,
padding: 5,
},
});
Use onBlur instead of onEndEditing.
How should the input end triggered?
After a time?
When user hits enter?
When user taps anywhere to close software keyboard?
Instead of
onEndEditing={AddItemHandler}
Use:
onBlur={(e) => {AddItemHandler(e.nativeEvent.text)}}
And ensure that AddItemHandler can handle the value in e.nativeEvent.text.

Style "currentLocationLabel" from react-native-google-places-autocomplete

I'm using react-native-google-places-autocomplete, and i would like to style currentlocation label to make it a marker icon + text,and i also want to make it visible once in the screen not till clicking on the textinput.
my code looks like this:
export default class VilleC extends React.Component {
render() {
loc = () => {
return(
<View style={{flexDirection:'row',marginLeft:10}}>
<EntypoI color={'grey'} size={20} name={'direction'} />
<Text style={{color:'black',marginLeft:10}}>Autour de moi</Text>
</View>);
}
return (
<View style={{flex:1}}>
<GooglePlacesAutocomplete
placeholder='Où ? (adresse,ville...)'
query={{
key: GOOGLE_PLACES_API_KEY,
language: 'fr', // language of the results
components: 'country:ma',
}}
fetchDetails = {true}
currentLocation={true}
>>>>>>>>>>< currentLocationLabel={// what's in function loc i would like to make it here }
GooglePlacesDetailsQuery = {{
fields: ['geometry']
}}
onPress={(data, details = null) => {console.log(details.geometry.location.lat);
console.log(data.description);
NavigationService.navigate('Résultat',{screen:'Résultats',params:{lien: this.props.route.params.lien, choice: this.props.route.params.choix,lat:details.geometry.location.lat,lng:details.geometry.location.lng,loc:data.description}})
}}
onFail={(error) => console.error(error)}
requestUrl={{
url:
'https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api',
useOnPlatform: 'web',
}} // this in only required for use on the web. See https://git.io/JflFv more for details. // variable styles can t find error
enablePoweredByContainer={false}
styles={{
textInputContainer: {
backgroundColor: 'rgba(0,0,0,0)',
borderTopWidth: 0,
borderBottomWidth: 0,
},
textInput: {
borderRadius:0,
marginLeft: 3,
marginRight: 3,
height: 38,
color: '#5d5d5d',
fontSize: 16,
paddingLeft:20,
shadowColor: "grey",
shadowOpacity: 0.8,
shadowRadius: 2,
shadowOffset: {
height: 1,
width: 0,
},
elevation: 3,
},
predefinedPlacesDescription: {
color: '#1faadb',
},
}}
/>
</View>
);
}
}
i would really appreciate your help!
You can use the renderRow prop to add an icon to the current location, and you can use the autFocus prop to open the input automatically.
Something like this:
export default class App extends React.Component {
render() {
return (
<View style={{ flex: 1 }}>
<GooglePlacesAutocomplete
placeholder="Où ? (adresse,ville...)"
query={{
key: 'GOOGLE_PLACES_API_KEY',
language: 'fr', // language of the results
components: 'country:ma',
}}
autoFocus={true}
fetchDetails={true}
currentLocation={true}
currentLocationLabel="Autour de moi"
renderRow={(row) =>
row.isCurrentLocation ? (
<View style={{ flexDirection: 'row', marginLeft: 10 }}>
<Text>icon</Text>
<Text style={{ color: 'black', marginLeft: 10 }}>
{row.description}
</Text>
</View>
) : (
<Text>{row.description}</Text>
)
}
GooglePlacesDetailsQuery={{
fields: ['geometry'],
}}
onPress={(data, details = null) => {
console.log(details.geometry.location.lat);
console.log(data.description);
}}
onFail={(error) => console.error(error)}
requestUrl={{
url:
'https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api',
useOnPlatform: 'web',
}} // this in only required for use on the web. See https://git.io/JflFv more for details. // variable styles can t find error
enablePoweredByContainer={false}
styles={{
textInputContainer: {
backgroundColor: 'rgba(0,0,0,0)',
borderTopWidth: 0,
borderBottomWidth: 0,
},
textInput: {
borderRadius: 0,
marginLeft: 3,
marginRight: 3,
height: 38,
color: '#5d5d5d',
fontSize: 16,
paddingLeft: 20,
shadowColor: 'grey',
shadowOpacity: 0.8,
shadowRadius: 2,
shadowOffset: {
height: 1,
width: 0,
},
elevation: 3,
},
predefinedPlacesDescription: {
color: '#1faadb',
},
}}
/>
</View>
);
}
}

react-native-google-places-autocomplete's onPress function is not working

I am trying to implement react-native-google-places-autocomplete in my react-native project and the onPress function would not work at all. I have already tried the other solutions on StackOverflow but it simply doesn't work. I have added "keyboardShouldPersistTaps='always' to the parent components as well. I use the "navigation.navigate("maps")" to get to this screen if that helps.
Here is the code.
class ChangeAddress extends PureComponent<Props> {
render() {
const { navigation } = this.props;
return (
<ScrollView
contentContainerStyle={{ flex: 1 }}
style={styles.modalContainer}
keyboardShouldPersistTaps="always">
<View style={styles.modalHeader}>
<Button onPress={() => navigation.goBack()} style={styles.backButton}>
<Image source={backLogo} />
</Button>
<View style={styles.searchBar}>
<View>
<Text style={styles.pickUpLocation}>Set Pickup Location</Text>
</View>
<GooglePlacesAutocomplete
placeholder="Search"
minLength={2}
autoFocus={false}
listViewDisplayed={false}
renderDescription={(row) => row.description}
fetchDetails={true}
onPress={(data, details = null) => {
console.log('HIIIIIIIIIIIIIIIIII', data, details);
}}
query={{
key: 'API',
language: 'en',
}}
styles={{
textInputContainer: {
backgroundColor: 'rgba(0,0,0,0)',
borderTopWidth: 0,
borderBottomWidth: 0,
width: '90%',
},
textInput: {
marginLeft: 0,
marginRight: 0,
height: 40,
color: '#5d5d5d',
fontSize: 14,
borderWidth: 1,
borderColor: '#778899',
},
predefinedPlacesDescription: {
color: '#1faadb',
},
description: {
fontWeight: 'bold',
borderTopWidth: 0,
borderBottomWidth: 0,
opacity: 0.9,
},
listView: {
color: 'black',
position: 'absolute',
top: 70,
left: -40,
width: dimens.width,
elevation: 1,
},
}}
/>
</View>
</View>
</ScrollView>
);
}
}
What am I missing? Thanks in advance.
I found a solution to it. For some reason, the onPress function would only work on addresses that are on the top/a part of the same View in which you are using component. In my case, I removed the top:70 from the listView, and to my surprise found that I could now select a few addresses. The onPress was working BUT only on those addresses of the listView which were falling on the parent View.
What I did to fix it was I gave the parent View a height of "100%" so that when listView opens, it falls INSIDE the parent View. And using "flex-start" I pushed it upwards. Works flawlessly now.
<GooglePlacesAutocomplete
placeholder='Informe sua rota de hoje'
keepResultsAfterBlur={true}
textInputProps={{ onBlur: () => { console.warn("Blur") } }}
onPress={(data, details) => {
// 'details' is provided when fetchDetails = true
console.warn(data, details);
}}
// listViewDisplayed={true}
// fetchDetails={true}
keyboardShouldPersistTaps={"always"}
// currentLocation={"Brazil"}
query={{
key: GOOGLE_MAPS_APIKEY,
language: 'pt-BR',
location: 'Brazil'
}}
/>
It worked for me after add keepResultsAfterBlur={True}
For resolve this issue add "keyboardShouldPersistTaps" property in "Scrollview" by adding this my issue resolve

Text component overlapping with the View above it

I'm practicing some react native code and I'm currently stuck with an overlapping problem.I've got this custom component:
const MobileNumberInput = ({ value, valueChanged, placeholder, valid }) => {
return (
<View style={{ flexDirection: "row", flex: 1 }}>
<TextInput
editable={false}
style={[styles.textBoxCountryCode, !valid ? styles.invalidTextBox : ""]}
value="+90"
/>
<TextInput
style={[styles.textBoxPhoneNumber, !valid ? styles.invalidTextBox : ""]}
placeholder={placeholder}
value={value}
onChangeText={valueChanged}
keyboardType="number-pad"
maxLength={9}
/>
</View>
);
};
export default MobileNumberInput;
onst styles = StyleSheet.create({
container: {
flexDirection: "row",
flex: 1,
height: 40
},
textBoxCountryCode: {
height: 40,
borderColor: "gray",
borderTopWidth: 1,
borderBottomWidth: 1,
borderLeftWidth: 1,
borderTopLeftRadius: 5,
borderBottomLeftRadius: 5,
padding: 5,
flex: 2
},
textBoxPhoneNumber: {
height: 40,
borderColor: "gray",
borderTopWidth: 1,
borderBottomWidth: 1,
borderRightWidth: 1,
borderTopRightRadius: 5,
borderBottomRightRadius: 5,
paddingTop: 5,
paddingRight: 5,
paddingBottom: 5,
marginBottom: 10,
flex: 11
},
invalidTextBox: {
borderColor: "red"
}
});
And here, I'm using that component:
renderError = id => {
const { validationErrors } = this.state;
if (validationErrors[id]) {
return (
<Text style={styles.validationError}>{validationErrors[id][0]}</Text>
);
}
return null;
};
render() {
const keyboardVerticalOffset = Platform.OS === "ios" ? 40 : 0;
return (
<View style={styles.container}>
<KeyboardAvoidingView
behavior="padding"
style={styles.textBoxContainerContainer}
keyboardVerticalOffset={keyboardVerticalOffset}
>
<View style={styles.textBoxContainer}>
<TextBoxMA
style={styles.textBox}
placeholder={Strings.USERNAME_PLACEHOLDER}
value={this.state.userName}
onChangeText={this.handleTextChange("userName")}
valid={this.fieldIsValid("userName")}
/>
{this.renderError("userName")}
</View>
<View style={styles.textBoxContainer}>
<MobileNumberInput
value={this.state.originalMobile}
valueChanged={this.handleTextChange("originalMobile")}
placeholder={Strings.ORIGINAL_MOBILE_PHONE_PLACEHOLDER}
valid={this.fieldIsValid("originalMobile")}
/>
{this.renderError("originalMobile")}
</View>
</KeyboardAvoidingView>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
padding: 20
},
textBoxContainerContainer: {
flex: 4,
justifyContent: "flex-end"
},
textBoxContainer: {
height: 40,
marginBottom: 20
},
validationError: {
fontSize: 12,
color: "red",
fontWeight: "bold",
paddingTop: 3
}
});
The {this.renderError("originalMobile")} portion is responsible for rendering an error text.
I put it there to get a small red warning just under the text box. But the warning stretches to inside mobile number component while the username warning is displayed correctly. Here's the output:
I've tried wrapping the error Text inside another View, didn't help. Wrapped the container View inside the MobileNumberInput component into yet another View with explicit flex-direction ="column". It didn't help either. I even changed the flex-direction of that container View to "column" just to see what would happen. But it didn't have any effect either. As you can see from the screenshot the problem is with the MobileNumberInput component part. The error text for the Username textinput is ok.
And if you wonder what the TextBoxMA looks like, it's just a TextInput component with predefined properties. Here it is:
export const TextBoxMA = props => {
return (
<TextInput
secureTextEntry={props.isPassword || false}
{...props}
style={[
props.style,
styles.textBox,
Platform.OS === "ios" ? styles.textBoxIos : styles.textBoxAndroid,
!props.valid ? styles.invalidTextBox : ""
]}
/>
);
};
const styles = StyleSheet.create({
textBox: {
height: 40,
borderColor: "gray",
borderWidth: 1,
borderRadius: 5,
padding: 5
},
invalidTextBox: {
borderColor: "red"
}
});
You've set your input height to 40, but then the View with style styles.textBoxContainer which wraps both input and error text, is also set to 40 height, squishing MobileNumberInput in half. You can't visually notice this effect because TextInputs inside MobileNumberInput go outside of the parent
To handle cases like this you need to create one container to wrap TextInputs and another container to wrap the first container and the error text. It's best to not set explicit height for containers but rather set their paddings to get desired size

React Native: Display FlatList data in Modal

I have a react native flat list that renders some data from a Wordpress website using wp rest api. The flat list is displaying the post correctly, and when clicked, it opens the modal, but I am having some trouble pushing the state to the modal.
Currently, when the modal opens, it shows the same (last post/item) for every item in the flat list. Any suggestions? Any help appreciated.
import React, { Component } from 'react';
import {
Image, Dimensions, View, ActivityIndicator, TouchableOpacity, TouchableHighlight,
WebView, ScrollView, StyleSheet, ImageBackground, FlatList, Text
} from 'react-native';
import Moment from 'moment';
import HTML from 'react-native-render-html';
import Modal from "react-native-modal";
export default class LatestNews extends Component {
constructor(props) {
super(props);
this.state = {
isModalVisible: false,
isLoading: true,
posts: [],
id: null,
};
}
componentDidMount() {
fetch(`http://mywebsite.com/wp-json/wp/v2/posts/?_embed&categories=113`)
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
posts: responseJson,
})
})
.catch((error) => {
console.error(error);
});
}
_toggleModal = () =>
this.setState({
isModalVisible: !this.state.isModalVisible,
});
_renderItem = ({item}) => {
return (
<TouchableOpacity onPress={() => this._onPressItem(item.id)} key={item.id}>
<View>
{item._embedded['wp:featuredmedia'].filter(
element => element.id == item.featured_media
).map((subitem, index) => (
<View style={{
margin: '5%',
borderWidth: 1,
borderColor: '#d8d8d8',
borderRadius: 10,
shadowColor: '#000',
shadowOffset: { width: 0, height: 5 },
shadowOpacity: 0.2,
shadowRadius: 8,
elevation: 1,
}}>
<ImageBackground
style={styles.news}
source={{ uri: subitem.media_details.sizes.medium.source_url }}
key={item.id}>
<View style={styles.itemTitle}>
<Text style={{ fontSize: 16, fontWeight: 'bold' }}>
{item.title.rendered}
</Text>
</View>
</ImageBackground>
</View>
))}
</View>
</TouchableOpacity>
)
};
_onPressItem(id) {
this.setState({
isModalVisible: true,
id: id,
});
};
render() {
if (this.state.isLoading == true) {
return (
<View style={{ flex: 1, flexDirection: 'column', justifyContent: 'center', alignItems: 'center', }}>
<ActivityIndicator size="large" color="#1C97F7" />
</View>
)
}
else {
Moment.locale('en');
return (
<View>
{this.state.posts.map((item, index) => (
<Modal isVisible={this.state.isModalVisible} id={this.state.id}>
{item._embedded['wp:featuredmedia'].filter(
element => element.id == item.featured_media
).map((subitem, index) => (
<ScrollView style={
{ flex: 1, backgroundColor: 'white', padding: 20, paddingBottom: 40,}
}>
<ImageBackground
style={styles.news}
source={{ uri: subitem.media_details.sizes.medium.source_url }}
key={item.id} />
<TouchableOpacity onPress={this._toggleModal}>
<Text>Hide me!</Text>
</TouchableOpacity>
<HTML
tagsStyles={{
body: {fontSize: 16, paddingBottom: 20,},
p: {fontSize: 16, fontWeight: "normal", marginTop: 10, marginBottom: 20},
strong: {fontSize: 20,},
blockquote: {fontSize: 20},
a: {fontSize: 16, color: "#0044e2"},
em: {fontSize: 20,},
img: {height: 250, width: 350},
}}
key={item.id}
styleName="paper md-gutter multiline"
html={item.content.rendered}
imagesMaxWidth={Dimensions.get('window').width * .9}
ignoredStyles={['width', 'height', 'video']}
/>
</ScrollView>
))}
</Modal>
))}
<FlatList
data={this.state.posts}
renderItem={this._renderItem}
keyExtractor={(item, index) => index}
/>
</View>
)
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
paddingTop: 0,
},
h1: {
color: 'black',
fontSize: 24,
paddingTop: 20,
fontWeight: 'bold',
},
h2: {
color: 'black',
fontSize: 24,
paddingTop: 20,
fontWeight: 'bold',
},
h3: {
fontSize: 13,
},
button: {
width: '45%',
margin: 5,
backgroundColor: '#492661',
padding: 8,
height: 36,
borderRadius: 18,
},
buttonGrey: {
width: '45%',
margin: 5,
backgroundColor: '#353535',
padding: 8,
height: 36,
borderRadius: 18,
},
buttonText: {
color: 'black',
alignSelf: 'center',
},
highlight: {
backgroundColor: '#f5f5f5',
borderRadius: 50,
width: 100,
height: 100,
marginRight: 20,
alignItems: 'center',
justifyContent: 'center',
borderColor: 'gold',
borderWidth: 0,
},
news: {
backgroundColor: '#f5f5f5',
borderRadius: 10,
width: '100%',
height: 200,
overflow: 'hidden',
},
hero: {
backgroundColor: '#492661',
width: '110%',
height: 260,
alignSelf: 'center',
marginTop: 0,
overflow: 'hidden'
},
itemTitle: {
backgroundColor: 'rgba(255,255,255,0.9)',
paddingVertical: 10,
position: 'absolute',
bottom: 0,
right: 0,
width: '100%',
paddingHorizontal: 10,
},
});
In FlatList, this is the issue it can't re-render again if dataModel is being there. For this You can use this :
in FlatList there is a propsTypes: ExtraData={} in this you should add a new boolean state, and wherever you again add the data in flatlist . set the state for that boolean key , that would help you :
<FlatList
data={this.state.posts}
renderItem={this._renderItem}
keyExtractor={(item, index) => index}
extraData={this.state.extraData}
/>
where you want add flatList data again add this line:
this.setState({extraData:!this.state.extraData})
by this line render method run again , and you will find a new update records.
Use this, this help me.