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
Related
I am new with React Native and facing issue with Lodesh Filter. It is giving mid-string data. Ex if I want to search Mitsubishi and start typing "mi" it will not give me mitsubishi but if I start type "sub" then it is giving me mitsubishi.
Below is my code:
import React, { useEffect, useState } from 'react';
import {View, Text, Button, TextInput, FlatList, ActivityIndicator, StyleSheet, Image} from 'react-native';
import filter from 'lodash.filter';
const CarList = () => {
const [isLoading, setIsLoading] = useState(false);
const [data, setData] = useState([]);
const [error, setError] = useState(null);
const [query, setQuery] = useState('');
const [fullData, setFullData] = useState([]);
useEffect(() => {
setIsLoading(true);
fetch(`https://myfakeapi.com/api/cars/?seed=1&page=1&results=20`)
.then(response => response.json())
.then(response => {
setData(response.cars);
setFullData(response.cars);
setIsLoading(false);
})
.catch(err => {
setIsLoading(false);
setError(err);
});
}, []);
if (isLoading) {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<ActivityIndicator size="large" color="#5500dc" />
</View>
);
}
if (error) {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text style={{ fontSize: 18}}>
Error fetching data... Check your network connection!
</Text>
</View>
);
}
const handleSearch = text => {
const formattedQuery = text.toLowerCase();
const filteredData = filter(fullData, user => {
console.log(contains(user, formattedQuery));
return contains(user, formattedQuery);
});
setData(filteredData);
setQuery(text);
};
const contains = ({ car, car_model,car_color }, query) => {
if (car.includes(query) || car_model.includes(query) || car_color.includes(query)) {
return true;
}
return false;
};
function renderHeader() {
return (
<View
style={{
backgroundColor: '#fff',
padding: 10,
marginVertical: 10,
borderRadius: 20
}}
>
<TextInput
autoCapitalize="none"
autoCorrect={false}
clearButtonMode="always"
value={query}
onChangeText={queryText => handleSearch(queryText)}
placeholder="Search"
style={{ backgroundColor: '#fff', paddingHorizontal: 20 }}
/>
</View>
);
}
return (
<View style={styles.container}>
<Text style={styles.text}>Favorite Contacts</Text>
<FlatList
ListHeaderComponent={renderHeader}
data={data}
keyExtractor={({ id }) => id}
renderItem={({ item }) => (
<View style={styles.listItem}>
<Image
source={{
uri: 'https://picsum.photos/200',
}}
style={styles.coverImage}
/>
<View style={styles.metaInfo}>
<Text style={styles.title}>{`${item.car} ${
item.car_model
}`}</Text>
</View>
</View>
)}
/>
</View>
);
}
Each car record have following fields:
{
"id": 1,
"car": "Mitsubishi",
"car_model": "Montero",
"car_color": "Yellow",
"car_model_year": 2002,
"car_vin": "SAJWJ0FF3F8321657",
"price": "$2814.46",
"availability": false
}
When you write mit, in contain function you are checking if(car.includes(text)...) but car name starts with an uppercase letter. You need to convert the car name in lowerCase before checking the text like this:
const contains = ({ car, car_model, car_color }, query) => {
if (car.toLowerCase().includes(query) || car_model.toLowerCase().includes(query) || car_color.toLowerCase().includes(query)) {
return true;
}
return false;
};
In ReactNative, the bottomsheet is displayed overlaid on the fragment.
Is there a way to make the bottomsheet rise to the top of the screenenter image description here
The bottom sheet looks opaque as in the picture, so the bottom sheet cannot be touched Please help
The code below is a shortened version
enter image description here
enter image description here
import React, { FC , Component, useState, useEffect, Fragment,useCallback, useMemo, useRef } from "react"
import { FlatList, ViewStyle, StyleSheet, View, Platform, TextInput, TouchableOpacity} from "react-native"
import {
BottomSheetModal,
BottomSheetModalProvider,
BottomSheetBackdrop,
} from '#gorhom/bottom-sheet';
const ROOT: ViewStyle = {
backgroundColor: DefaultTheme.colors.background,
flex: 1,
}
export const ChecklookupScreen: FC<StackScreenProps<NavigatorParamList, "checklookup">> = observer(function ChecklookupScreen() {
const bottomSheetModalRef = useRef<BottomSheetModal>(null);
// variables
const snapPoints = useMemo(() => ['25%', '50%'], []);
// callbacks
const handlePresentModalPress = useCallback((index: string) => {
LOG.info('handlePresentModalPress', index);
bottomSheetModalRef.current?.present();
}, []);
const handleSheetChanges = useCallback((index: number) => {
LOG.info
console.log('handleSheetChanges', index);
}, []);
const renderItem = ({ item, index }) => (
<TouchableOpacity
key={index + item.inspNo + item.spvsNo}
//style={listContainer}
onPress={throttle(() => {
onClickItem(item.inspNo,item.spvsNo);
})}
>
<View>
<Fragment>
</View>
<Button icon="magnify-expand"
mode="elevated"
style={styles.detailButton}
onPress={throttle(() => {
onClickItem(item.inspNo,item.spvsNo);
})}
// onPress={() => navigation.navigate("checkdetail")}
>
</Button>
</View>
</Fragment>
</View>
</TouchableOpacity>
);
const fetchChecklookups = async (offset: number) => {
LOG.debug('fetchChecklookups:' + offset);
setRefreshing(true);
await checklookupStore.getChecklookups(offset)
setRefreshing(false);
};
const onEndReached = () => {
if (checklookupStore?.checklookupsTotalRecord <= checklookups?.length) {
LOG.debug('onEndReached555555555');
} else {
setPage(page + 1)
fetchChecklookups(page + 1);
}
};
const [searchQuery, setSearchQuery] = React.useState('');
const onChangeSearch = query => setSearchQuery(query);
return (
<Screen preset="fixed" style={{ backgroundColor: colors.background, flex: 1, padding: 10,}}>
<View style={{ flex: 1,}}>
<View style={{ flex: 1, }}>
<Searchbar
placeholder="조회조건을 입력해주세요"
onChangeText={onChangeSearch}
value={searchQuery}
onPressIn={() => handlePresentModalPress('touch on')}
/>
<BottomSheetModalProvider>
<BottomSheetModal
backgroundStyle={{ backgroundColor: "gray" }}
style={styles.bottomSheet}
ref={bottomSheetModalRef}
index={1}
snapPoints={snapPoints}
onChange={handleSheetChanges}
>
<View style={{ marginTop: 10, marginLeft: 50, marginRight: 50, flexDirection: "row"}}>
<View style={{ flex: 1, }}>
<Button
mode="outlined"
>소속을 입력하세요
</Button>
</View>
</View>
</BottomSheetModal>
</BottomSheetModalProvider>
</Screen>
)
})
You can try with portal, wrap you bottom sheet to from another package.
Screens and navigating is fine, but getting data from users has been a struggle. Not only are the UI elements different, the means to capture input and store in state effectively across various input types is troubling me. Here is an example of what I think is a simple UX yet I cannot get the text inputs to focus correctly.
In the below example, the desire is to have a list of items within a horizontal scroll view and when i click on the arrow of an item, the screen scrolls and a form to edit the item appears with one or more text boxes. Future enhancements were to have this second panel have more fields based on the type of field from the list, but i cant even get a simple text box to work properly
I've got some code to boot, copy and paste as app.js in an expo init project and it should run
main question: how to retain focus on inputs on the detail panel
import React from "react";
import {
Dimensions,
FlatList,
SafeAreaView,
Text,
TextInput,
TouchableOpacity,
View,
} from "react-native";
const init_items = [
{ name: "start", value: 12500, type: "num" },
{ name: "end", value: 12700, type: "num" },
{ name: "time", value: 123.45, type: "time" },
];
const main_color = "#dddddd";
const _base = 3;
const _width = Dimensions.get("window").width;
export default function App() {
const [index, setIndex] = React.useState(0);
const [items, setItems] = React.useState(init_items);
const [curItem, setCurItem] = React.useState("");
const ref = React.useRef(null);
const textRef = React.useRef(null);
React.useEffect(() => {
console.log("index chsnaged?", index);
//if (!index) return;
ref.current?.scrollToIndex({ index, animated: true });
}, [index]);
React.useEffect(() => {
setIndex(curItem === "" ? 0 : 1);
}, [curItem]);
const useCurItem = () => {
if (curItem == "") return;
return items.find((item) => item.name == curItem);
};
const setCurItemValue = (value) => {
console.log("update " + curItem + " to " + value);
const new_items = items.map((item) => {
if (item.name == curItem) return { ...item, value: value };
return item;
});
console.log("new_items: ", new_items);
setItems(new_items);
};
const Button = ({ type, press }) => {
return (
<TouchableOpacity onPress={() => press(type)}>
<Text style={{ fontSize: 20, fontWeight: "900", margin: _base }}>
{type == "arrow" ? ">" : "X"}
</Text>
</TouchableOpacity>
);
};
const ListPanel = () => {
return (
<View>
{items.map((item) => {
return (
<View
key={item.name}
style={{
margin: _base,
}}
>
<Text style={{ fontWeight: "600", margin: _base }}>
{item.name}
</Text>
<View
style={{
alignItems: "center",
backgroundColor: "white",
borderRadius: _base,
flexDirection: "row",
justifyContent: "space-between",
margin: _base,
padding: _base,
}}
>
<Text>{item.value}</Text>
<Button type="arrow" press={() => setCurItem(item.name)} />
{/* <EmojiButton
name={"fat_arrow"}
onPress={() => setCurItem(item.name)}
size={20}
/> */}
</View>
</View>
);
})}
</View>
);
};
const DetailPanel = () => {
let thisItem = useCurItem();
if (!thisItem) return null;
return (
<View style={{ width: "100%" }}>
{/* <EmojiButton name="arrow_left" onPress={() => setCurItem("")} /> */}
<Button type="cancel" press={() => setCurItem("")} />
<Text>{curItem}</Text>
<Text>{thisItem?.value}</Text>
<Text>{thisItem.type}</Text>
{thisItem.type == "num" && (
<TextInput
ref={textRef}
onChangeText={(text) => setCurItemValue(text)}
// onSubmitEditing={() => textRef.current.focus()}
style={{ backgroundColor: "white", margin: 2 }}
value={thisItem.value.toString()}
/>
)}
</View>
);
};
const screens = [
{ name: "listing", panel: <ListPanel /> },
{ name: "detail", panel: <DetailPanel /> },
];
return (
<View style={{ marginTop: 30 }}>
<Text>Sample sliding inputs</Text>
<FlatList
bounces={false}
horizontal
keyExtractor={(item) => item.name}
ref={ref}
showsHorizontalScrollIndicator={false}
data={screens}
renderItem={({ item, index: fIndex }) => {
console.log("rendering " + item);
return (
<View
style={{
backgroundColor: main_color,
height: 300,
width: _width,
padding: _base,
}}
>
<Text> {item.name}</Text>
{item.panel}
</View>
);
}}
/>
<Text>index: {index}</Text>
<Text>curItem: {curItem}</Text>
<TouchableOpacity onPress={() => setCurItem("")}>
<View>
<Text>reset</Text>
</View>
</TouchableOpacity>
</View>
);
}
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);
};
...
...
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)}