O'Reilly logo

React Native By Example by Richard Kho

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

DatePickerAndroid and TimePickerAndroid

Setting a time and date on Android is much different from iOS. With iOS, you have a DatePickerIOS component that includes both the date and time. On Android, this is split into two native modals, DatePickerAndroid for the date and TimePickerAndroid for the time. It's not a component to render either, it's an asynchronous function that opens the modal and waits for a natural conclusion before applying logic to it.

To open one of these, wrap an asynchronous function around it:

async renderDatePicker () {   const { action, year, month, day } = await DatePickerAndroid.open({     date: new Date()   });   if (action === DatePickerAndroid.dismissedAction) {     return;   }  // do something with the year, month, and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required