Skip to content

Commit b6f75a8

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

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

ios/RNDateTimePicker.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ - (CGSize)intrinsicContentSize {
7777
// iOS DatePicker requires a minimum width of 280 points for proper display
7878
// See: https://github.com/react-native-datetimepicker/datetimepicker/issues/1014
7979
size.width = MAX(size.width, 280);
80+
81+
// For inline (calendar) display style, suggest a larger width
82+
// This helps the calendar expand to fill available width
83+
if (@available(iOS 14.0, *)) {
84+
if (self.preferredDatePickerStyle == UIDatePickerStyleInline) {
85+
size.width = MAX(size.width, 375); // Standard iPhone width
86+
}
87+
}
88+
8089
return size;
8190
}
8291

ios/RNDateTimePickerShadowView.m

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,27 @@ static YGSize RNDateTimePickerShadowViewMeasure(YGNodeConstRef node, float width
7272
// iOS DatePicker requires a minimum width of 280 points for proper display
7373
// See: https://github.com/react-native-datetimepicker/datetimepicker/issues/1014
7474
size.width = MAX(size.width, 280);
75-
size.width += 10;
75+
76+
// Respect the provided width constraint to allow the picker to expand to full width
77+
// when a specific width is provided or when measuring at-most mode
78+
if (widthMode == YGMeasureModeExactly) {
79+
size.width = width;
80+
} else if (widthMode == YGMeasureModeAtMost) {
81+
// For inline/calendar style, try to use the full available width
82+
// 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+
} else {
90+
size.width = MIN(size.width + 10, width);
91+
}
92+
} else {
93+
// For undefined mode, add small padding
94+
size.width += 10;
95+
}
7696
});
7797

7898
return (YGSize){

ios/fabric/RNDateTimePickerComponentView.mm

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,21 @@ - (void) updateMeasurements {
106106
// iOS DatePicker requires a minimum width of 280 points for proper display
107107
// See: https://github.com/react-native-datetimepicker/datetimepicker/issues/1014
108108
size.width = MAX(size.width, 280);
109-
size.width += 10;
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
112+
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;
119+
}
120+
} else {
121+
size.width += 10;
122+
}
123+
110124
auto newState = RNDateTimePickerState{RCTSizeFromCGSize(size)};
111125
_state->updateState(std::move(newState));
112126
}

0 commit comments

Comments
 (0)