Skip to content

Commit d85b8a3

Browse files
committed
fix: ios width
1 parent b6f75a8 commit d85b8a3

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

ios/RNDateTimePicker.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,14 @@ - (CGSize)intrinsicContentSize {
7878
// See: https://github.com/react-native-datetimepicker/datetimepicker/issues/1014
7979
size.width = MAX(size.width, 280);
8080

81-
// For inline (calendar) display style, suggest a larger width
82-
// This helps the calendar expand to fill available width
81+
// For inline (calendar) display style, suggest larger dimensions
82+
// UICalendarView requires sufficient height to render its content
8383
if (@available(iOS 14.0, *)) {
8484
if (self.preferredDatePickerStyle == UIDatePickerStyleInline) {
8585
size.width = MAX(size.width, 375); // Standard iPhone width
86+
// UICalendarView needs minimum height to avoid content rendering warning
87+
// Typical calendar height is around 320-360 points
88+
size.height = MAX(size.height, 330);
8689
}
8790
}
8891

ios/RNDateTimePickerShadowView.m

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,41 @@ static YGSize RNDateTimePickerShadowViewMeasure(YGNodeConstRef node, float width
7373
// See: https://github.com/react-native-datetimepicker/datetimepicker/issues/1014
7474
size.width = MAX(size.width, 280);
7575

76+
// Check if we're using inline/calendar style
77+
BOOL isInlineStyle = NO;
78+
if (@available(iOS 14.0, *)) {
79+
isInlineStyle = shadowPickerView.picker.preferredDatePickerStyle == UIDatePickerStyleInline;
80+
}
81+
7682
// Respect the provided width constraint to allow the picker to expand to full width
7783
// when a specific width is provided or when measuring at-most mode
7884
if (widthMode == YGMeasureModeExactly) {
7985
size.width = width;
8086
} else if (widthMode == YGMeasureModeAtMost) {
8187
// For inline/calendar style, try to use the full available width
8288
// For other styles, use the minimum width needed
83-
if (@available(iOS 14.0, *)) {
84-
if (shadowPickerView.picker.preferredDatePickerStyle == UIDatePickerStyleInline) {
85-
size.width = width; // Use full available width for calendar
86-
} else {
87-
size.width = MIN(size.width + 10, width);
88-
}
89+
if (isInlineStyle) {
90+
size.width = width; // Use full available width for calendar
8991
} else {
9092
size.width = MIN(size.width + 10, width);
9193
}
9294
} else {
9395
// For undefined mode, add small padding
9496
size.width += 10;
9597
}
98+
99+
// UICalendarView (inline style) requires sufficient height to render content
100+
// Without this, we get: "UICalendarView's height is smaller than it can render its content in"
101+
if (isInlineStyle) {
102+
size.height = MAX(size.height, 330);
103+
104+
// Respect height constraints if provided
105+
if (heightMode == YGMeasureModeExactly) {
106+
size.height = height;
107+
} else if (heightMode == YGMeasureModeAtMost) {
108+
size.height = MIN(size.height, height);
109+
}
110+
}
96111
});
97112

98113
return (YGSize){

ios/fabric/RNDateTimePickerComponentView.mm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,17 @@ - (void) updateMeasurements {
107107
// See: https://github.com/react-native-datetimepicker/datetimepicker/issues/1014
108108
size.width = MAX(size.width, 280);
109109

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
110+
// For inline (calendar) display style, use larger dimensions to fill the container
111+
// The actual size will be constrained by the parent container's layout
112112
if (@available(iOS 14.0, *)) {
113113
if (_dummyPicker.preferredDatePickerStyle == UIDatePickerStyleInline) {
114114
// Use a large width that will be constrained by the parent
115115
// This allows the calendar to expand to full width of its container
116116
size.width = 375; // Standard iPhone width, will be constrained by parent if smaller
117+
118+
// UICalendarView requires sufficient height to render its content
119+
// Without this, we get: "UICalendarView's height is smaller than it can render its content in"
120+
size.height = MAX(size.height, 330);
117121
} else {
118122
size.width += 10;
119123
}

0 commit comments

Comments
 (0)