Summary:
Changelog: Fix possible sizing issue with DatePicker

Changing `preferredDatePickerStyle` changes size of the component without triggering re-layout of the react native screen. The fix is to make sure the size stays the same after changing the style.

Reviewed By: mdvacca

Differential Revision: D28035226

fbshipit-source-id: 2dcb50fd5ebaa0c0d01d3289c4ffa77a053cfc4a
This commit is contained in:
Samuel Susla 2021-04-28 13:47:11 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 2f62c2892d
Коммит 84d55868e8
1 изменённых файлов: 7 добавлений и 1 удалений

Просмотреть файл

@ -85,11 +85,17 @@ RCT_EXPORT_METHOD(setNativeDate : (nonnull NSNumber *)viewTag toDate : (NSDate *
RCT_CUSTOM_VIEW_PROPERTY(pickerStyle, UIDatePickerStyle, RCTDatePicker)
{
if (@available(iOS 14, *)) {
// If the style changed, then the date picker may need to be resized and will generate a layout pass to display
// correctly. We need to prevent that to get consistent layout. That's why we memorise the old frame and set it
// after style is changed.
CGRect oldFrame = view.frame;
if (json) {
view.preferredDatePickerStyle = [RCTConvert UIDatePickerStyle:json];
UIDatePickerStyle style = [RCTConvert UIDatePickerStyle:json];
view.preferredDatePickerStyle = style;
} else {
view.preferredDatePickerStyle = UIDatePickerStyleWheels;
}
view.frame = oldFrame;
}
}
#endif