Skip to content

Commit dda2cee

Browse files
committed
fix: ios width
1 parent dca6b04 commit dda2cee

File tree

4 files changed

+25
-38
lines changed

4 files changed

+25
-38
lines changed

ios/RNDateTimePicker.m

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ - (instancetype)initWithFrame:(CGRect)frame
3232
#endif
3333

3434
_reactMinuteInterval = 1;
35-
36-
// Ensure the picker can expand to fill its container
37-
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
3835
}
3936
return self;
4037
}
@@ -83,11 +80,12 @@ - (CGSize)intrinsicContentSize {
8380
size.width = MAX(size.width, 280);
8481

8582
// For inline (calendar) display style, suggest larger dimensions
86-
// UICalendarView requires sufficient height to render its content
83+
// This helps the calendar expand to fill available width
8784
if (@available(iOS 14.0, *)) {
8885
if (self.preferredDatePickerStyle == UIDatePickerStyleInline) {
89-
// Suggest larger dimensions for proper calendar display
90-
size.width = MAX(size.width, 320);
86+
size.width = MAX(size.width, 375); // Standard iPhone width
87+
88+
// UICalendarView requires sufficient height to render its content
9189
size.height = MAX(size.height, 330);
9290
}
9391
}

ios/RNDateTimePickerShadowView.m

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,37 +70,36 @@ static YGSize RNDateTimePickerShadowViewMeasure(YGNodeConstRef node, float width
7070

7171
size = [shadowPickerView.picker sizeThatFits:UILayoutFittingCompressedSize];
7272

73-
// Check if we're using inline/calendar style
73+
// iOS DatePicker requires a minimum width of 280 points for proper display
74+
// See: https://github.com/react-native-datetimepicker/datetimepicker/issues/1014
75+
size.width = MAX(size.width, 280);
76+
77+
// Check if we're using inline/calendar style for height requirement
7478
BOOL isInlineStyle = NO;
7579
if (@available(iOS 14.0, *)) {
7680
isInlineStyle = shadowPickerView.picker.preferredDatePickerStyle == UIDatePickerStyleInline;
7781
}
7882

79-
// iOS DatePicker requires a minimum width of 280 points for proper display
8083
// 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);
8384
if (isInlineStyle) {
8485
size.height = MAX(size.height, 330);
8586
}
8687

87-
// Handle width constraints
88+
// Respect the provided width constraint to allow the picker to expand to full width
89+
// when a specific width is provided or when measuring at-most mode
8890
if (widthMode == YGMeasureModeExactly) {
8991
size.width = width;
9092
} else if (widthMode == YGMeasureModeAtMost) {
91-
// For inline/calendar style, use the full available width
93+
// For inline/calendar style, try to use the full available width
94+
// For other styles, use the minimum width needed
9295
if (isInlineStyle) {
93-
size.width = MAX(280, MIN(width, 500)); // Use available width, max 500pt
96+
size.width = width; // Use full available width for calendar
9497
} else {
9598
size.width = MIN(size.width + 10, width);
9699
}
97100
} else {
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-
}
101+
// For undefined mode, add small padding
102+
size.width += 10;
104103
}
105104

106105
// Handle height constraints for inline style

ios/fabric/RNDateTimePickerComponentView.mm

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,19 @@ - (void) updateMeasurements {
105105
CGSize size = [_dummyPicker sizeThatFits:UILayoutFittingCompressedSize];
106106

107107
// iOS DatePicker requires a minimum width of 280 points for proper display
108-
// UICalendarView (inline) requires a minimum height of 330 points
109108
// See: https://github.com/react-native-datetimepicker/datetimepicker/issues/1014
110109
size.width = MAX(size.width, 280);
111110

112-
// For inline (calendar) display style, use larger dimensions
113-
// The actual size will be constrained by the parent container's layout
111+
// For inline (calendar) display style, use a larger default width to fill the container
112+
// The actual width will be constrained by the parent container's layout
114113
if (@available(iOS 14.0, *)) {
115114
if (_dummyPicker.preferredDatePickerStyle == UIDatePickerStyleInline) {
116-
// Calendar needs larger dimensions for proper display
117-
size.width = MAX(size.width, 320);
115+
// Use a large width that will be constrained by the parent
116+
// This allows the calendar to expand to full width of its container
117+
size.width = 375; // Standard iPhone width, will be constrained by parent if smaller
118+
119+
// UICalendarView requires sufficient height to render its content
120+
// Without this, we get: "UICalendarView's height is smaller than it can render its content in"
118121
size.height = MAX(size.height, 330);
119122
} else {
120123
size.width += 10;

src/datetimepicker.ios.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
IOS_MODE,
1919
} from './constants';
2020
import * as React from 'react';
21-
import {Platform, StyleSheet} from 'react-native';
21+
import {Platform} from 'react-native';
2222

2323
import type {
2424
DateTimePickerEvent,
@@ -59,7 +59,6 @@ export default function Picker({
5959
display: providedDisplay = IOS_DISPLAY.default,
6060
// $FlowFixMe[incompatible-type]
6161
disabled = false,
62-
style,
6362
...other
6463
}: IOSNativeProps): React.Node {
6564
sharedPropsValidation({value, timeZoneOffsetInMinutes, timeZoneName, minimumDate, maximumDate});
@@ -93,21 +92,9 @@ export default function Picker({
9392
);
9493
};
9594

96-
// For inline/calendar display, ensure the component takes full width by default
97-
const computedStyle = React.useMemo(() => {
98-
if (display === IOS_DISPLAY.inline) {
99-
return StyleSheet.compose(
100-
{alignSelf: 'stretch'},
101-
style,
102-
);
103-
}
104-
return style;
105-
}, [display, style]);
106-
10795
return (
10896
<RNDateTimePicker
10997
{...other}
110-
style={computedStyle}
11198
date={dateToMilliseconds(value)}
11299
locale={locale !== null && locale !== '' ? locale : undefined}
113100
maximumDate={dateToMilliseconds(maximumDate)}

0 commit comments

Comments
 (0)