Skip to content

Commit ca5cfef

Browse files
committed
🐛 fix: iOS inline dateTime picker height
1 parent b6f75a8 commit ca5cfef

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

ios/fabric/RNDateTimePickerComponentView.mm

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,22 @@ - (void) updateMeasurements {
103103
return;
104104
}
105105
CGSize size = [_dummyPicker sizeThatFits:UILayoutFittingCompressedSize];
106-
// iOS DatePicker requires a minimum width of 280 points for proper display
107-
// See: https://github.com/react-native-datetimepicker/datetimepicker/issues/1014
108-
size.width = MAX(size.width, 280);
109-
110-
// For inline (calendar) display style, use a larger default width to fill the container
111-
// The actual width will be constrained by the parent container's layout
106+
size.width += 10;
107+
108+
// Workaround: sizeThatFits: returns incorrect height for
109+
// UIDatePickerModeDateAndTime + UIDatePickerStyleInline (Apple bug).
110+
// The returned height only accounts for the calendar, missing the time row.
112111
if (@available(iOS 14.0, *)) {
113-
if (_dummyPicker.preferredDatePickerStyle == UIDatePickerStyleInline) {
114-
// Use a large width that will be constrained by the parent
115-
// This allows the calendar to expand to full width of its container
116-
size.width = 375; // Standard iPhone width, will be constrained by parent if smaller
117-
} else {
118-
size.width += 10;
112+
if (_dummyPicker.datePickerMode == UIDatePickerModeDateAndTime &&
113+
_dummyPicker.preferredDatePickerStyle == UIDatePickerStyleInline) {
114+
UIDatePicker *timePicker = [UIDatePicker new];
115+
timePicker.datePickerMode = UIDatePickerModeTime;
116+
timePicker.preferredDatePickerStyle = UIDatePickerStyleInline;
117+
CGSize timeSize = [timePicker sizeThatFits:UILayoutFittingCompressedSize];
118+
size.height += timeSize.height;
119119
}
120-
} else {
121-
size.width += 10;
122120
}
123-
121+
124122
auto newState = RNDateTimePickerState{RCTSizeFromCGSize(size)};
125123
_state->updateState(std::move(newState));
126124
}

0 commit comments

Comments
 (0)