React native modal datetime picker not working - react-native

i am using react native modal datetime picker to user to pick date time.
i am checking if the time is a past time then now it will not be granted.
he have to select again. but when i select a previous time. then want to select again the modal not working. why ?
this is my main component
_showDateTimePicker = () => this.setState({ isDateTimePickerVisible: true });
_hideDateTimePicker = () => this.setState({ isDateTimePickerVisible: false });
_handleDatePicked = date => {
console.log("A date has been picked: ", date);
if (Date.now() > Date.parse(date)) {
console.log(" please select a future time");
} else {
this.setState({ orderDate: date });
this._hideDateTimePicker();
}
};
<SelectDate
orderDate={this.state.orderDate}
isDateTimePickerVisible={this.state.isDateTimePickerVisible}
_showDateTimePicker={this._showDateTimePicker}
_handleDatePicked={this._handleDatePicked}
_hideDateTimePicker={this._hideDateTimePicker}
/>
select date component
import React from "react";
import { View, Text } from "react-native";
import DateTimePicker from "react-native-modal-datetime-picker";
import {
Container,
Content,
Header,
Item,
Input,
Icon,
Button,
Body
} from "native-base";
class SelectDate extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
_showDateTimePicker = () => {
this.props._showDateTimePicker();
};
_handleDatePicked = date => {
this.props._handleDatePicked(date);
};
_hideDateTimePicker = () => {
this.props._hideDateTimePicker();
};
render() {
return (
<View>
<View>
<View
style={{
flex: 1,
backgroundColor: "#fff",
marginLeft: 15,
marginRight: 15
}}
>
<View style={{ alignSelf: "center", margin: 10, height: 20 }}>
{this.props.orderDate === "NO Date Time Selected" ? (
<Text style={{ color: "#000" }}>{this.props.orderDate}</Text>
) : (
<Text style={{ color: "#000" }}>
{this.props.orderDate.toLocaleString()}
</Text>
)}
</View>
<Button block onPress={this._showDateTimePicker}>
<Text style={{ color: "red", fontSize: 16 }}>
* Select Date and Time{" "}
</Text>
</Button>
<DateTimePicker
isVisible={this.props.isDateTimePickerVisible}
onConfirm={this._handleDatePicked}
onCancel={this._hideDateTimePicker}
mode="datetime"
is24Hour={false}
/>
</View>
</View>
</View>
);
}
}
export default SelectDate;

You need to send date to function onClick event, this is solution:
onConfirm={(date)=>this._handleDatePicked(date)}

Related

Fail to update parent component's state. Fail to reset form

function DateTimePick is a child function to render picked date and picked time in parent component Reservation. Currently there are two issues with the codes: 1. the form in Reservation does not reset after submit data. 2. child DateTimePick fails to update the state for 'date' and 'time' in parent Reservation. Please have a look and lemme know how to fix these. Thanks.
child function DateTimePick is below:
import React, {useState} from 'react';
import {View, Button, Platform, Text, TextInput, StyleSheet} from 'react-native';
import DateTimePicker from '#react-native-community/datetimepicker';
import { Icon } from 'react-native-elements';
import Moment from "moment";
export const DateTimePick = () => {
const [date, setDate] = useState(new Date());
const [mode, setMode] = useState('date');
const [show, setShow] = useState(false);
const onChange = (event, selectedDate) => {
const currentDate = selectedDate || date;
setShow(Platform.OS === 'ios');
setDate(currentDate);
};
const showMode = (currentMode) => {
setShow(true);
setMode(currentMode);
};
const showDatepicker = () => {
showMode('date');
};
const showTimepicker = () => {
showMode('time');
};
return (
<View>
<View style={styles.formRow}>
<Text style={styles.formLabel}> Date</Text>
<Text onPress={showDatepicker} style={styles.formItem} value_date={date.toDateString()} onChange = {(value_date) => this.props.setState({date: value_date})}><Icon type='font-awesome-5' name='calendar' color='#512DA8' />{' ' + Moment(date).format('DD-MMM-YYYY') }</Text>
</View>
<View style={styles.formRow}>
<Text style={styles.formLabel}> Time</Text>
<Text onPress={showTimepicker} style={styles.formItem} value_time={date.toTimeString()} onChange = {(value_time) => this.props.setState({time: value_time})}><Icon type='font-awesome-5' name='clock' color='#512DA8' /> {' ' + Moment(date).format('h:mm A') }</Text>
</View>
{show && (
<DateTimePicker
testID="dateTimePicker"
value={date}
mode={mode}
is24Hour={true}
display="default"
onChange={onChange}
/>
)}
</View>
);
};
//export default DateTimePick;
const styles = StyleSheet.create({
formRow: {
alignItems: 'center',
justifyContent: 'center',
flex: 1,
flexDirection: 'row',
margin: 20
},
formLabel: {
fontSize: 18,
flex: 1
},
formItem: {
flex: 1
},
modal: {
justifyContent: 'center',
margin: 20
},
modalTitle: {
fontSize: 24,
fontWeight: 'bold',
backgroundColor: '#512DA8',
textAlign: 'center',
color: 'white',
marginBottom: 20
},
modalText: {
fontSize: 18,
margin: 10
},
})
parent Reservation which produces a reservation form and a reservation input confirmed modal
import React, {Component} from 'react';
import { Text, View, ScrollView, StyleSheet, Switch, Button, TextInput, Modal} from 'react-native';
import {DateTimePick} from './DateTimePickComponent';
class Reservation extends Component {
constructor(props) {
super(props);
this.state = {
guests: 1,
smoking: false,
notes:'',
date: new Date().toDateString(),
time: new Date().toTimeString(),
showModal: false
}
}
toggleModal() {
this.setState({showModal: !this.state.showModal})
}
handleReservation() {
console.log(JSON.stringify(this.state)); //log current state
//this.setState({ // reset the form
//})
this.toggleModal();
}
resetForm() {
this.setState({
guests: 1,
smoking: false,
notes:'',
date: new Date().toDateString(),
time: new Date().toTimeString(),
showModal: false
});
}
render() {
//, transform: [{ scaleX: 3 }, { scaleY: 1.5 }] => for switch
return(
<ScrollView>
<View style={styles.formRow}>
<Text style={styles.formLabel}> Guests </Text>
<TextInput style={styles.formItem} keyboardType="numeric" placeholder="Number"
value_guests={this.state.guests}
onChangeText = {(value_guests) => this.setState({guests: value_guests})} >
</TextInput>
</View>
<View style={styles.formRow}>
<Text style={styles.formLabel}> Notes </Text>
<TextInput style={styles.formItem} keyboardType="default" placeholder="Allergy,..etc"
value_notes={this.state.notes}
onChangeText = {(value_notes) => this.setState({notes: value_notes})} >
</TextInput>
</View>
<View style={styles.formRow}>
<Text style={styles.formLabel}> Non-Smoking </Text>
<Switch style={{ flex: 1, backgroundColor: "orange", paddingLeft:0, marginLeft:0 }} trackColor={{true: 'red', false: 'grey'}}
value={this.state.smoking}
onValueChange = {(value) => this.setState({smoking: value})} />
<Text style={styles.formLabel}> Smoking </Text>
</View>
<DateTimePick />
<View style={styles.formRow}>
<Button
onPress={() => this.handleReservation()}
title="Reserve"
color="#512DA8"
accessibilityLabel="Learn more about this purple button"
/>
</View>
<Modal animationType={'slide'} transparent={false} visible={this.state.showModal}
onDismiss={() => {this.toggleModal()}}
onRequestClose={() => {this.toggleModal()}}>
<View style={styles.modal}>
<Text style={styles.modalTitle}>Your Reservation</Text>
<Text style={styles.modalText}>Number of Guests: {this.state.guests}</Text>
<Text style={styles.modalText}>Notes: {this.state.notes}</Text>
<Text style = {styles.modalText}>Smoking?: {this.state.smoking ? 'Yes' : 'No'}</Text>
<Text style = {styles.modalText}>Date and Time: {this.state.date} {this.state.time}</Text>
<Button
onPress = {() =>{this.toggleModal(); this.resetForm();}}
color="#512DA8"
title="Close"
/>
</View>
</Modal>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
formRow: {
alignItems: 'center',
justifyContent: 'center',
flex: 1,
flexDirection: 'row',
margin: 20
},
formLabel: {
fontSize: 18,
flex: 1
},
formItem: {
flex: 1
},
modal: {
justifyContent: 'center',
margin: 20
},
modalTitle: {
fontSize: 24,
fontWeight: 'bold',
backgroundColor: '#512DA8',
textAlign: 'center',
color: 'white',
marginBottom: 20
},
modalText: {
fontSize: 18,
margin: 10
},
})
export default Reservation;
you could fix it by transfering state consts date, show, mode to parent Reservation
then pass state change functions to the DateTimePick component in props like below
<DateTimePick onDateChange={(date) => this.setState({date: date}) } />
and in DateTimePick component:
const onChange = (event, selectedDate) => {
const currentDate = selectedDate || date;
setShow(Platform.OS === 'ios');
props.onDateChange(currentDate);
};
also dont forget to pass props in the component like
export const DateTimePick = (props) => {
Solved it. For using child data to update parents' state need to pass a handler for setting the state of parent to child, refer How to update parent's state in React?
class Parent extends React.Component {
constructor(props) {
super(props)
this.handler = this.handler.bind(this)
}
handler() {
this.setState({
someVar: 'some value'
})
}
render() {
return <Child handler = {this.handler} />
}
}
class Child extends React.Component {
render() {
return <Button onClick = {this.props.handler}/ >
}
}
In implementation, a handler is inserted into parent class Reservation as below
...
class Reservation extends Component {
constructor(props) {
...
this.handler = this.handler.bind(this)
}
handler(selectedDate) {
this.setState({
date: Moment(selectedDate).format('DD-MMM-YYYY'),
time: Moment(selectedDate).format('h:mm A'),
})
}
...
In child DateTimePick, embed the handler in onChange to pass child update from onChange to state update in parent Reservation like this
...
export const DateTimePick = (props) => {
const handler = props.handler;
...
const onChange = (event, selectedDate) => {
...
handler(currentDate);
};
...
...

react-native-community/datetimepicker is not setting all its values

I am doing a datatimepicker with #react-native-community/datetimepicker but I am facing a problem in which the default value does not change its year and day but It changes its hour.
I did a logic to open the set day and year, and after closing/setting that it opens the set hour, it is weird because when I set the year and day It changes its value in the screen but when I finished changing the hour, they set its value to default
const [date, setDate] = useState(new Date());
const [show, setShow] = useState(false);
const [mode, setMode] = useState('date');
[enter image description here][1]
const initialState = {
guests,
smoking,
date,
show,
mode
};
const changeShowMode = () => {
setShow(true)
setMode('date')
}
const handleReservation = () => {
console.log(JSON.stringify(initialState));
setGuests(1)
setSmoking(false)
setDate(date)
}
<View style={styles.formRow}>
<Text style={styles.formLabel}>Date and Time</Text>
<TouchableOpacity style={styles.formItem}
style={{
padding: 7,
borderColor: '#512DA8',
borderWidth: 2,
flexDirection: 'row'
}}
onPress={() => changeShowMode()}
>
<Icon type='font-awesome' name='calendar' color='#512DA8' />
<Text>
{' ' + Moment(date).format('DD-MMM-YYYY h:mm A') }
</Text>
</TouchableOpacity>
{show && (
<DateTimePicker
value={date}
display='default'
mode={mode}
minimumDate={new Date()}
minuteInterval={30}
onChange={(event, date) => {
if (date === undefined) {
setShow(false)
}
else {
setShow(mode === 'time' ? false : true),
setMode('time'),
setDate(date)
}
}}
/>
)}
</View>
<View style={styles.formRow}>
<Button
title='reserver'
color='#512DA8'
onPress={() => handleReservation()}
accessibilityLabel='Learn more about this purple button'
/>
</View>
You will see how the hour is changing, but the year and day are not.
https://i.stack.imgur.com/2FfuI.jpg
Your logic seems OK but there is something happening under the hood when you update the state. I have been playing with this and set up a snack for you. Here is the link.
Full code here
import * as React from 'react';
import {
Text,
View,
StyleSheet,
Button,
TouchableOpacity,
Alert,
} from 'react-native';
import Constants from 'expo-constants';
import Moment from 'moment';
import DateTimePicker from '#react-native-community/datetimepicker';
export default function App() {
const [dateInfo, updateDateInfo] = React.useState({
date: new Date(),
show: false,
mode: 'date',
});
const changeShowMode = () => {
updateInfo({ show: true, mode: 'date' });
};
const updateInfo = (info) => {
updateDateInfo({ ...dateInfo, ...info });
};
const handleReservation = () => {};
return (
<>
<View style={styles.formRow}>
<Text style={styles.formLabel}>Date and Time</Text>
<TouchableOpacity
style={styles.formItem}
onPress={() => changeShowMode()}>
<Text>
{' ' + Moment(dateInfo.date).format('DD-MMM-YYYY h:mm A')}
</Text>
</TouchableOpacity>
{dateInfo.show && (
<DateTimePicker
value={dateInfo.date}
display="default"
mode={dateInfo.mode}
minimumDate={new Date()}
minuteInterval={30}
onChange={(event, dateTime) => {
if (dateTime === undefined) {
updateInfo({ show: false });
} else if (dateInfo.mode === 'time') {
let timeDate = Moment(dateTime);
updateInfo({
show: false,
mode: 'date',
date: Moment(dateInfo.date)
.set('hour', timeDate.get('hour'))
.set('minute', timeDate.get('minute'))
.set('minute', timeDate.get('second'))
.toDate(),
});
} else {
updateInfo({ mode: 'time', date: dateTime });
}
}}
/>
)}
</View>
<View style={styles.formRow}>
<Button
title="reserver"
color="#512DA8"
onPress={() => handleReservation()}
accessibilityLabel="Learn more about this purple button"
/>
</View>
</>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
});
Basically instead of updating states multiple time, which were causing an issue, I used an object which updates the date object fine. Please take a look and try if this works fine.
Good Luck

What am I doing wrong with my code here I'm so lost

I'm trying to input my firestore into the form and put all my user data so I can pass information as
profile.name
profile.email
profile.location
profile.avatar
so what am I doing wrong here to keep on receiving this error?
Error
This is my mock screen
import Fire from '../utilities/Fire';
super(props);
this.state = {
user: {}
}
const user = this.props.uid || Fire.shared.uid
this.unsubscribe = Fire.shared.firestore
.collection("users")
.doc(user)
.onSnapshot(doc => {
this.setState({ user: doc.data() });
});
this.unsubscribe();
unsubscribe = null;
const profile = {
username: this.state.user.name,
location: this.state.user.location,
email: this.state.user.email,
avatar: this.state.user.avatar ? { uri: this.state.user.avatar } : require("../assets/avatar.png"),
notifications: true,
};
export { profile };
This is my Settings Page
import React, { Component } from "react";
import { Image, StyleSheet, ScrollView, TextInput } from "react-native";
import { Divider, Button, Block, Text, Switch } from "../components";
import { theme, mock } from "../constants";
class Settings extends Component {
state = {
notifications: true,
editing: null,
profile: {}
};
componentDidMount() {
this.setState({ profile: this.props.profile });
}
handleEdit(name, text) {
const { profile } = this.state;
profile[name] = text;
this.setState({ profile });
}
toggleEdit(name) {
const { editing } = this.state;
this.setState({ editing: !editing ? name : null });
}
renderEdit(name) {
const { profile, editing } = this.state;
if (editing === name) {
return (
<TextInput
defaultValue={profile[name]}
onChangeText={text => this.handleEdit([name], text)}
/>
);
}
return <Text bold>{profile[name]}</Text>;
}
render() {
const { profile, editing } = this.state;
return (
<Block>
<Block flex={false} row center space="between" style={styles.header}>
<Text h1 bold>
Settings
</Text>
<Button>
<Image source={profile.avatar} style={styles.avatar} />
</Button>
</Block>
<ScrollView showsVerticalScrollIndicator={false}>
<Block style={styles.inputs}>
<Block row space="between" margin={[10, 0]} style={styles.inputRow}>
<Block>
<Text gray2 style={{ marginBottom: 10 }}>
Username
</Text>
{this.renderEdit("username")}
</Block>
<Text
medium
secondary
onPress={() => this.toggleEdit("username")}
>
{editing === "username" ? "Save" : "Edit"}
</Text>
</Block>
<Block row space="between" margin={[10, 0]} style={styles.inputRow}>
<Block>
<Text gray2 style={{ marginBottom: 10 }}>
Location
</Text>
{this.renderEdit("location")}
</Block>
<Text
medium
secondary
onPress={() => this.toggleEdit("location")}
>
{editing === "location" ? "Save" : "Edit"}
</Text>
</Block>
<Block row space="between" margin={[10, 0]} style={styles.inputRow}>
<Block>
<Text gray2 style={{ marginBottom: 10 }}>
E-mail
</Text>
<Text bold>{profile.email}</Text>
</Block>
</Block>
</Block>
<Divider margin={[theme.sizes.base, theme.sizes.base * 2]} />
<Divider />
<Block style={styles.toggles}>
<Block
row
center
space="between"
style={{ marginBottom: theme.sizes.base * 2 }}
>
<Text gray2>Notifications</Text>
<Switch
value={this.state.notifications}
onValueChange={value => this.setState({ notifications: value })}
/>
</Block>
</Block>
</ScrollView>
</Block>
);
}
}
Settings.defaultProps = {
profile: mock.profile
};
export default Settings;
const styles = StyleSheet.create({
header: {
paddingHorizontal: theme.sizes.base * 2
},
avatar: {
height: theme.sizes.base * 2.2,
width: theme.sizes.base * 2.2
},
inputs: {
marginTop: theme.sizes.base * 0.7,
paddingHorizontal: theme.sizes.base * 2
},
inputRow: {
alignItems: "flex-end"
},
sliders: {
marginTop: theme.sizes.base * 0.7,
paddingHorizontal: theme.sizes.base * 2
},
thumb: {
width: theme.sizes.base,
height: theme.sizes.base,
borderRadius: theme.sizes.base,
borderColor: "white",
borderWidth: 3,
backgroundColor: theme.colors.secondary
},
toggles: {
paddingHorizontal: theme.sizes.base * 2
}
});
Tried to add a class function to fix it but now it's not recognized my profile on my const, tried to change the class name to mock and export both mock and profile but not working any tips?
fixed the first error but now I am getting a second error with my setState
The error is pretty informative.
You can not have super() sitting outside of a class constructor.
Here would be a working example of that:
class YourComponentName extends Component {
constructor( props ) {
super( props )
this.state = {
user: {}
}
}
...
}
export default YourComponentName
More info on super: https://overreacted.io/why-do-we-write-super-props/
While this should resolve the error you're getting, it probably will not resolve your underlying issue. I recommend researching React state machines.
super(props); should be used inside constructor on the class. So just wrap your super and state in the constructor or remove super completely.

How to get value of text in state.when i clicked on TouchableOpacity in react-native?

How to get value of text in state.when i clicked on TouchableOpacity in react-native ?
I have gender value in text of TouchableOpacity . so I want to get value of selected gender in state when i clicked on TouchableOpacity.
So please help me how i can achieve this functionality.Thank you in advanced.
This is some part of my screen you can see below.
Create function like this
setGender=(props)={
this.setState({gender:props})
}
call this function from button onPress like this
onPress={()=>this.setGender("Male")}
onPress={()=>this.setGender("Female")
and show state value in Text
Example Codebase :
import React, { Component } from "react";
import {
View,
Text,
StyleSheet,
TextInput,
TouchableOpacity
} from "react-native";
export default class Home extends Component {
constructor(props) {
super(props);
this.state = {
gender: "",
textGender:"Male"
};
}
//Get text value
getTextValue = () => {
alert(this.state.gender);
console.log("Selected Gender is ", this.state.gender);
console.log("Selected Gender From Text ", this.state.textGender);
};
render() {
return (
<View style={styles.container}>
<TextInput
value={this.state.gender}
keyboardType="default"
onChangeText={gender => this.setState({ gender })}
/>
<Text>{this.state.textGender}</Text>
<TouchableOpacity
onPress={() => this.getTextValue()}
></TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1
}
});
hope this will help you
onPress = (Male) => {
this.setState({ gender: 'Male'})
}
onPress1 = (Female) => {
this.setState({ gender: 'Female'})
}
<TouchableOpacity
style={styles.button}
onPress={this.onPress(Male)}
>
<Text> Male </Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={this.onPress1(Female)}
>
<Text> Female </Text>
</TouchableOpacity>*
Hope this will help you
import React, { Component } from 'react';
import { View, Text, StyleSheet, Button } from 'react-native';
export default class Home extends Component {
state = {
value: '',
};
onChangeValue = value => {
if (value !== this.state.value) {
this.setState({
value: value,
});
}
};
render() {
return (
<View style={styles.container}>
{this.state.value.length > 0 ? (
<Text
style={{
fontSize: 40,
alignSelf: 'center',
justifyContent: 'center',
}}>
{this.state.value}
</Text>
) : (
<Text
style={{
fontSize: 40,
alignSelf: 'center',
justifyContent: 'center',
}}>
I identify as you
</Text>
)}
<Button
color="#000"
title="Male"
onPress={() => this.onChangeValue('male')}
/>
<Button title="Female" onPress={() => this.onChangeValue('female')} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignContent: 'center',
justifyContent: 'center',
},
});
Feel free for doudts.

Results do not update after a change of state

I have a problem, when I do a search, I get the data from my API, the first time I do a search, everything is fine, all the data is displayed. However, when I do a second search immediately, nothing is updated.
I put in console.log, and I see that I'm getting this data back, yet the display is not updated.
import React, { Component } from "react";
import { SafeAreaView, StyleSheet } from "react-native";
import Search from "./Component/Search";
export default class App extends Component {
render() {
return (
<SafeAreaView style={styles.container}>
<Search />
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1
}
});
import React from "react";
import { View, TextInput, Button, FlatList, StyleSheet } from "react-native";
import LivreItem from "../Component/LivreItem";
class Search extends React.Component {
constructor(props) {
super(props);
this.inputValue = "";
this.state = { livres: [] };
}
searchBooks = async () => {
const key = "&key=XXXXXXXXXXXXXXXXXXXXXXX";
const url = "https://www.googleapis.com/books/v1/volumes?q=" + this.inputValue + key;
return fetch(url)
.then(response => response.json())
.catch(e => {
console.log("Une erreur s'est produite");
console.log(e);
});
};
getBooks = () => {
if (this.inputValue.length > 0) {
this.searchBooks()
.then(data => this.setState({ livres: data.items }))
.catch(reject => console.log(reject));
}
};
changeText = text => {
this.inputValue = text;
};
render() {
return (
<View style={styles.header_container}>
<View style={styles.sub_container}>
<TextInput
onChangeText={text => this.changeText(text)}
style={styles.input}
placeholder="Ex: Harry Potter"
/>
<Button
style={styles.button}
title="Rechercher"
onPress={() => this.getBooks()}
/>
</View>
<FlatList
style={styles.list}
data={this.state.livres}
keyExtractor={(item, index) => item + index}
renderItem={({ item }) => <LivreItem livre={item.volumeInfo} />}
/>
</View>
);
}
}
const styles = StyleSheet.create({
sub_container: {
justifyContent: "space-between",
flexDirection: "row",
marginTop: 30,
paddingRight: 10,
paddingLeft: 10
},
header_container: {
flex: 1,
flexDirection: "column",
padding: 10
},
input: {
borderRadius: 4,
borderWidth: 0.5,
borderColor: "#d6d7da",
width: 150,
paddingLeft: 5
},
button: {
borderRadius: 4
},
list: {
paddingLeft: 15,
paddingRight: 15
}
});
export default Search;
import React from "react";
import { View, StyleSheet, Image, Text } from "react-native";
class LivreItem extends React.Component {
constructor(props) {
super(props);
this.state = { livre: this.props.livre};
this.description =
this.state.livre.description === null || this.state.livre.description === undefined
? "Pas de description disponible"
: this.state.livre.description;
this.img = this.state.livre.imageLinks;
this.image =
this.img === undefined ||
this.img.smallThumbnail === undefined ||
this.img.smallThumbnail === null
? null
: this.state.livre.imageLinks.smallThumbnail;
}
render() {
return (
<View style={styles.content}>
<View>
<Image style={styles.image} source={{ uri: this.image }} />
<Image style={styles.image} source={this.image} />
</View>
<View style={styles.content_container}>
<Text style={styles.titre}>{this.state.livre.title}</Text>
<Text style={styles.description} numberOfLines={4}>
{this.description}
</Text>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
content: {
height: 125,
flexDirection: "row",
marginTop: 15
},
content_container: {
flexDirection: "column",
flexShrink: 1,
marginLeft: 10
},
image: {
width: 100,
height: 100
},
titre: {
fontWeight: "bold",
flexWrap: "wrap"
},
description: {
flexWrap: "wrap"
}
});
export default LivreItem;
Thanks.
Configure the prop extraData in Flatlist component ala:
<FlatList
extraData={this.state.livres}
/>
Pass a boolean value to the FlatList extraData.
<FlatList
extraData={this.state.refresh}
/>