Skip to content

Commit 84d5586

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Fix DatePicker sizing issue
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
1 parent 2f62c28 commit 84d5586

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

React/Views/RCTDatePickerManager.m

+7-1
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,17 @@ - (UIView *)view
8585
RCT_CUSTOM_VIEW_PROPERTY(pickerStyle, UIDatePickerStyle, RCTDatePicker)
8686
{
8787
if (@available(iOS 14, *)) {
88+
// If the style changed, then the date picker may need to be resized and will generate a layout pass to display
89+
// correctly. We need to prevent that to get consistent layout. That's why we memorise the old frame and set it
90+
// after style is changed.
91+
CGRect oldFrame = view.frame;
8892
if (json) {
89-
view.preferredDatePickerStyle = [RCTConvert UIDatePickerStyle:json];
93+
UIDatePickerStyle style = [RCTConvert UIDatePickerStyle:json];
94+
view.preferredDatePickerStyle = style;
9095
} else {
9196
view.preferredDatePickerStyle = UIDatePickerStyleWheels;
9297
}
98+
view.frame = oldFrame;
9399
}
94100
}
95101
#endif

0 commit comments

Comments
 (0)