Skip to content

Commit 2ff2589

Browse files
authored
fix: iOS old architecture crash (#906)
Fix crash introduced for old arch on iOS in 5.0.10 [Exception thrown while executing UI block:-[_ _NSCFString timeIntervalSinceReferenceDate ]: unrecognized selector sent to instance Fixes #896
1 parent b6fa291 commit 2ff2589

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

ios/RNDatePickerManager.mm

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,49 @@ @implementation RNDatePickerManager
3030
// Keep: Required for RN built in Event Emitter Calls.
3131
}
3232

33+
- (NSDate *)convertToNSDate:(id)input {
34+
if (!input) return nil;
35+
std::string isoString = [input UTF8String];
36+
NSString *nsString = [NSString stringWithUTF8String:isoString.c_str()];
37+
NSISO8601DateFormatter *isoFormatter = [[NSISO8601DateFormatter alloc] init];
38+
isoFormatter.formatOptions = NSISO8601DateFormatWithInternetDateTime | NSISO8601DateFormatWithFractionalSeconds;
39+
NSDate *date = [isoFormatter dateFromString:nsString];
40+
return date;
41+
}
42+
3343
- (UIView *)view
3444
{
3545
return [RNDatePicker new];
3646
}
3747

3848
RCT_EXPORT_VIEW_PROPERTY(text, NSString)
39-
RCT_EXPORT_VIEW_PROPERTY(date, NSString)
49+
50+
RCT_CUSTOM_VIEW_PROPERTY(date, id, RNDatePicker)
51+
{
52+
NSDate *date = [self convertToNSDate:json];
53+
if (date) {
54+
[(RNDatePicker *)view setDate:date];
55+
}
56+
}
57+
4058
RCT_EXPORT_VIEW_PROPERTY(locale, NSLocale)
41-
RCT_EXPORT_VIEW_PROPERTY(minimumDate, NSString)
42-
RCT_EXPORT_VIEW_PROPERTY(maximumDate, NSString)
59+
60+
RCT_CUSTOM_VIEW_PROPERTY(minimumDate, id, RNDatePicker)
61+
{
62+
NSDate *date = [self convertToNSDate:json];
63+
if (date) {
64+
[(RNDatePicker *)view setMinimumDate:date];
65+
}
66+
}
67+
68+
RCT_CUSTOM_VIEW_PROPERTY(maximumDate, id, RNDatePicker)
69+
{
70+
NSDate *date = [self convertToNSDate:json];
71+
if (date) {
72+
[(RNDatePicker *)view setMaximumDate:date];
73+
}
74+
}
75+
4376
RCT_EXPORT_VIEW_PROPERTY(minuteInterval, NSInteger)
4477
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
4578
RCT_REMAP_VIEW_PROPERTY(mode, datePickerMode, UIDatePickerMode)

0 commit comments

Comments
 (0)