-
-
Notifications
You must be signed in to change notification settings - Fork 455
Expand file tree
/
Copy pathRNDateTimePickerShadowView.m
More file actions
104 lines (87 loc) · 3.48 KB
/
RNDateTimePickerShadowView.m
File metadata and controls
104 lines (87 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#import "RNDateTimePickerShadowView.h"
@implementation RNDateTimePickerShadowView
- (instancetype)init
{
if (self = [super init]) {
YGNodeSetMeasureFunc(self.yogaNode, RNDateTimePickerShadowViewMeasure);
}
return self;
}
- (void)setDate:(NSDate *)date {
_date = date;
YGNodeMarkDirty(self.yogaNode);
}
- (void)setLocale:(NSLocale *)locale {
_locale = locale;
YGNodeMarkDirty(self.yogaNode);
}
- (void)setMode:(UIDatePickerMode)mode {
_mode = mode;
YGNodeMarkDirty(self.yogaNode);
}
- (void)setDisplayIOS:(UIDatePickerStyle)displayIOS {
_displayIOS = displayIOS;
YGNodeMarkDirty(self.yogaNode);
}
- (void)setTimeZoneOffsetInMinutes:(NSInteger)timeZoneOffsetInMinutes {
_timeZoneOffsetInMinutes = timeZoneOffsetInMinutes;
YGNodeMarkDirty(self.yogaNode);
}
- (void)setTimeZoneName:(NSString *)timeZoneName {
_timeZoneName = timeZoneName;
YGNodeMarkDirty(self.yogaNode);
}
static YGSize RNDateTimePickerShadowViewMeasure(YGNodeConstRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode)
{
RNDateTimePickerShadowView *shadowPickerView = (__bridge RNDateTimePickerShadowView *)YGNodeGetContext(node);
__block CGSize size;
dispatch_sync(dispatch_get_main_queue(), ^{
[shadowPickerView.picker setDate:shadowPickerView.date];
[shadowPickerView.picker setDatePickerMode:shadowPickerView.mode];
[shadowPickerView.picker setLocale:shadowPickerView.locale];
[shadowPickerView.picker setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:shadowPickerView.timeZoneOffsetInMinutes * 60]];
if (shadowPickerView.timeZoneName) {
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:shadowPickerView.timeZoneName];
if (timeZone != nil) {
[shadowPickerView.picker setTimeZone:timeZone];
} else {
RCTLogWarn(@"'%@' does not exist in NSTimeZone.knownTimeZoneNames. Falling back to localTimeZone=%@", shadowPickerView.timeZoneName, NSTimeZone.localTimeZone.name);
[shadowPickerView.picker setTimeZone:NSTimeZone.localTimeZone];
}
} else {
[shadowPickerView.picker setTimeZone:NSTimeZone.localTimeZone];
}
if (@available(iOS 14.0, *)) {
[shadowPickerView.picker setPreferredDatePickerStyle:shadowPickerView.displayIOS];
}
size = [shadowPickerView.picker sizeThatFits:UILayoutFittingCompressedSize];
// iOS DatePicker requires a minimum width of 280 points for proper display
// See: https://github.com/react-native-datetimepicker/datetimepicker/issues/1014
size.width = MAX(size.width, 280);
// Respect the provided width constraint to allow the picker to expand to full width
// when a specific width is provided or when measuring at-most mode
if (widthMode == YGMeasureModeExactly) {
size.width = width;
} else if (widthMode == YGMeasureModeAtMost) {
// For inline/calendar style, try to use the full available width
// For other styles, use the minimum width needed
if (@available(iOS 14.0, *)) {
if (shadowPickerView.picker.preferredDatePickerStyle == UIDatePickerStyleInline) {
size.width = width; // Use full available width for calendar
} else {
size.width = MIN(size.width + 10, width);
}
} else {
size.width = MIN(size.width + 10, width);
}
} else {
// For undefined mode, add small padding
size.width += 10;
}
});
return (YGSize){
RCTYogaFloatFromCoreGraphicsFloat(size.width),
RCTYogaFloatFromCoreGraphicsFloat(size.height)
};
}
@end