Pages - Menu

Sunday, March 26, 2017

UIDatePicker Countdown mode bug and solution in Xamarin.Forms

Problem

Show hh:mm:ss picker on iOS using Xamarin.Forms.

Goal

Extend Picker view in order to achieve the next result:

Solution

First I tried to keep it simple: to give up on seconds and use UIDatePicker in UIDatePickeCountDownMode. So the end result will look like this:
I achieved it by extending the DatePicker and it's DatePickerRenderer and changing the mode as described above. However, I discovered that 'datePickerValueChanged' is being called only on a second iteration with the values. The issue was successfully reproduced in Swift, so it's not a Xamarin bug. The Swift version can be found here.

After spending some time understanding the issue described above, I found an example on StackOverflow, thanks to Mathieu who shared his solution. His example was based on XLabs, so I removed the dependency and shared it with the community.
The code can be found on GitHub.


No comments:

Post a Comment