Skip to content

Commit

Permalink
Fix DatePicker sizing issue
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Apr 28, 2021
1 parent 2f62c28 commit 84d5586
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion React/Views/RCTDatePickerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,17 @@ - (UIView *)view
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
Expand Down

0 comments on commit 84d5586

Please sign in to comment.