score:3
According to the documentation, for the react-native-datepicker, minDate is not supported for the Android. It works fine for ios.
Note : Use the "datetime" value for the prop-mode.
I followed the method below to overcome the issue in android.
<DatePicker
style={{width: 200}}
date={this.state.valueDate}
mode="datetime"
format="YYYY/MM/DD HH:mm"
minDate={new Date(Date.now()+(10 * 60 * 1000))} //To book after 10 minutes
confirmBtnText="Confirm"
cancelBtnText="Cancel"
customStyles={{
dateIcon: {
position: 'absolute',
left: 5,
top: 4,
marginLeft: 10
},
dateInput: {
marginLeft: 46
}
// ... You can check the source to find the other keys.
}}
onDateChange={(date) => { // returns 2019-10-15T23:23 - set in format prop
var selectedDate = new Date(date);
var dateNow = new Date();
var YYYY = dateNow.getFullYear();
var MM = dateNow.getMonth()+1;
var DD = dateNow.getDate();
var HH = dateNow.getHours();
var mm = dateNow.getMinutes()+10; //To book after 10 minutes
var minDate = new Date(YYYY+'/'+MM+'/'+DD+' '+HH+':'+mm)
var selectedYYYY = selectedDate.getFullYear();
var selectedMM = selectedDate.getMonth()+1;
var selectedDD = selectedDate.getDate();
var selectedHH = selectedDate. getHours();
var selectedmm = selectedDate.getMinutes();
if(Platform.OS == 'ios'){
this.setState({
valueDate:date,
date: selectedYYYY+'-'+selectedMM+'-'+selectedDD,
time: selectedHH+':'+selectedmm
})
}else{
if(selectedDate.getTime()<minDate.getTime()){ //getTime() - Get the time (milliseconds since January 1, 1970)
alert("You can book after 10 minutes from now!");
}else{
this.setState({
valueDate:date,
date: selectedYYYY+'-'+selectedMM+'-'+selectedDD,
time: selectedHH+':'+selectedmm
})
}
}
}
}
/>
Hope it will help!!
Source: stackoverflow.com
Related Query
- How to set min date in TimePickerAndroid for react-native
- How to set up analytics on React Native for iOS
- how to set font size for different IOS devices in react native
- How to set max and min value for increment and decrement methods inside React
- how do I set the min and max date for date fields?
- How to add sourcemap in React Native for Production?
- How to adjust font size to fit view in React Native for Android?
- How to set NODE_ENV from package.json for react
- How do I set a marker in MapView of React Native
- How to set the height of button in React Native Android
- React.js - How to set a default value for input date type
- How to set headers for a React app created using 'create-react-app'
- How to set React default props for object type
- How to set placeholder for dropdown in react js?
- How to restrict date selection in React native ios/android datepicker
- How do you set the Typescript type for useRef hook in React Native?
- How to enable the Android monitor in React Native for checking logs?
- How to make React input onChange set state only after onChange stops firing for set time?
- React Native start failed with error code -4094 how to solve this ONCE for ALL?
- how do I set logging levels on Android, for react native?
- How to set Two inputs on same row in react native ?
- How to integrate twilio in react native for android?
- How can I replace screen with React Navigation for React Native
- How to use React Native launch options parameter for RCTRootView
- How to set cookie in React Native with Expo?
- How to set display name for a React class (ES6)?
- How to center text in Facebook Login Button for React Native (Android)?
- React Cookie + ReactJS: How to set expiration time for a cookie?
- how to set react native button to full width
- How can I programmatically set the user details for Launch Darkly in my react app
More Query from same tag
- How to detect if React Material UI Select Field is expanded?
- auth0 - invalid user_metadata type
- Is this.state current when the setState updater is called?
- How to give border to this react tooltip and remove the arrow?
- How can you programmatically resize a column using react-table
- Is it possible to handle Multiple useState hooks with one simple function?
- How can I send Firebase User Email to MongoDB using React Hook Forms?
- Pass typescript's interface to react state
- Hook Re-render update array items from child component
- React Hooks: useCallback return value not being recognized for hamburger menu onClick
- React Relay project directory structure organization
- React component isn't re rendering the fetch data in unit test
- getting return value from confirm alert function so that i can setEditclicked to false
- React Native Extending Multiple Components vs createClass
- Declaring variables outside of functional React component
- Not able to go back to Loginform when i click on cancel
- Load (external) components dynamically into React.js
- (Isomorphic) Back-end rendering of routes and ajax-based react components
- Default Props in stateful (using hooks) functional components
- React Native - How to Build an Image Grid like FaceBook
- How to automatically add hyphen on the state textbox when onchange handler detect on length 4 using javascript
- React.js URL ID Changes but not showing the component
- How to link an image to a page dynamically with React Router Dom?
- Having trouble rendering items in React.js
- ReactJS - sharing an array of data among components without props
- Validate PropType without a value in React
- TypeError: setOpenModal is not a function
- Style disappears in secondary pages
- Rendering Component with custom styles with Material UI V1
- Type 'string' is not assignable to type 'WebkitAppearance | undefined' in React + TypeScript?