Skip to content

Commit ccbc33d

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

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

ios/RNDateTimePicker.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ - (void)setDate:(NSDate *)date {
7474

7575
- (CGSize)intrinsicContentSize {
7676
CGSize size = [super intrinsicContentSize];
77+
7778
// iOS DatePicker requires a minimum width of 280 points for proper display
7879
// See: https://github.com/react-native-datetimepicker/datetimepicker/issues/1014
7980
size.width = MAX(size.width, 280);
@@ -82,9 +83,8 @@ - (CGSize)intrinsicContentSize {
8283
// UICalendarView requires sufficient height to render its content
8384
if (@available(iOS 14.0, *)) {
8485
if (self.preferredDatePickerStyle == UIDatePickerStyleInline) {
85-
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
86+
// Suggest larger dimensions for proper calendar display
87+
size.width = MAX(size.width, 320);
8888
size.height = MAX(size.height, 330);
8989
}
9090
}

ios/RNDateTimePickerShadowView.m

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,41 +69,44 @@ static YGSize RNDateTimePickerShadowViewMeasure(YGNodeConstRef node, float width
6969
}
7070

7171
size = [shadowPickerView.picker sizeThatFits:UILayoutFittingCompressedSize];
72-
// iOS DatePicker requires a minimum width of 280 points for proper display
73-
// See: https://github.com/react-native-datetimepicker/datetimepicker/issues/1014
74-
size.width = MAX(size.width, 280);
7572

7673
// Check if we're using inline/calendar style
7774
BOOL isInlineStyle = NO;
7875
if (@available(iOS 14.0, *)) {
7976
isInlineStyle = shadowPickerView.picker.preferredDatePickerStyle == UIDatePickerStyleInline;
8077
}
8178

82-
// Respect the provided width constraint to allow the picker to expand to full width
83-
// when a specific width is provided or when measuring at-most mode
79+
// iOS DatePicker requires a minimum width of 280 points for proper display
80+
// UICalendarView (inline) requires a minimum height of 330 points
81+
// See: https://github.com/react-native-datetimepicker/datetimepicker/issues/1014
82+
size.width = MAX(size.width, 280);
83+
if (isInlineStyle) {
84+
size.height = MAX(size.height, 330);
85+
}
86+
87+
// Handle width constraints
8488
if (widthMode == YGMeasureModeExactly) {
8589
size.width = width;
8690
} else if (widthMode == YGMeasureModeAtMost) {
87-
// For inline/calendar style, try to use the full available width
88-
// For other styles, use the minimum width needed
91+
// For inline/calendar style, use the full available width
8992
if (isInlineStyle) {
90-
size.width = width; // Use full available width for calendar
93+
size.width = MAX(280, MIN(width, 500)); // Use available width, max 500pt
9194
} else {
9295
size.width = MIN(size.width + 10, width);
9396
}
9497
} else {
95-
// For undefined mode, add small padding
96-
size.width += 10;
98+
// For undefined mode with inline style, suggest a larger width
99+
if (isInlineStyle) {
100+
size.width = MAX(size.width, 375);
101+
} else {
102+
size.width += 10;
103+
}
97104
}
98105

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"
106+
// Handle height constraints for inline style
101107
if (isInlineStyle) {
102-
size.height = MAX(size.height, 330);
103-
104-
// Respect height constraints if provided
105108
if (heightMode == YGMeasureModeExactly) {
106-
size.height = height;
109+
size.height = MAX(height, 280); // Enforce reasonable minimum even for exact mode
107110
} else if (heightMode == YGMeasureModeAtMost) {
108111
size.height = MIN(size.height, height);
109112
}

ios/fabric/RNDateTimePickerComponentView.mm

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,18 @@ - (void) updateMeasurements {
103103
return;
104104
}
105105
CGSize size = [_dummyPicker sizeThatFits:UILayoutFittingCompressedSize];
106+
106107
// iOS DatePicker requires a minimum width of 280 points for proper display
108+
// UICalendarView (inline) requires a minimum height of 330 points
107109
// See: https://github.com/react-native-datetimepicker/datetimepicker/issues/1014
108110
size.width = MAX(size.width, 280);
109111

110-
// For inline (calendar) display style, use larger dimensions to fill the container
112+
// For inline (calendar) display style, use larger dimensions
111113
// The actual size will be constrained by the parent container's layout
112114
if (@available(iOS 14.0, *)) {
113115
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-
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"
116+
// Calendar needs larger dimensions for proper display
117+
size.width = MAX(size.width, 320);
120118
size.height = MAX(size.height, 330);
121119
} else {
122120
size.width += 10;

0 commit comments

Comments
 (0)