Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing android whitespace error #873

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

henninghall
Copy link
Owner

@henninghall henninghall commented Dec 12, 2024

This is a start to solve issue #840
I have limited internet access until end of januari and wont be able to continue working on this until then.

I encourage anyone to pick it up from here, this is the general idea of the solution I am proposing.

(It is mostly pseudo coding, probably wont compile at this state but you can get the idea)

@johnf
Copy link

johnf commented Dec 24, 2024

I have made some changes to get this working. Here is a diff, let me know if you want a PR

Main change is that the argument is a std::string not an NSString

NOTE: I don't code in ObjC, got Chat GPT to help me make it compile :) So no doubt there is probably a more correct way to do this. But tested and works for me

# https://github.com/henninghall/react-native-date-picker/pull/873
diff --git a/src/fabric/RNDatePickerNativeComponent.ts b/src/fabric/RNDatePickerNativeComponent.ts
index 8f9d67e5fdcad8e83c75cdaa861bed777d676951..456439e573260a7c795cba7bcb6a2e4c4b9b4ad0 100644
--- a/src/fabric/RNDatePickerNativeComponent.ts
+++ b/src/fabric/RNDatePickerNativeComponent.ts
@@ -13,9 +13,9 @@ type DateEvent = {
 
 export interface NativeProps extends ViewProps {
   locale?: string
-  date: Double
-  maximumDate?: Double
-  minimumDate?: Double
+  date: string
+  maximumDate?: string
+  minimumDate?: string
   minuteInterval?: Int32
   mode?: WithDefault<'date' | 'time' | 'datetime', 'datetime'>
   onChange: BubblingEventHandler<DateEvent>
diff --git a/ios/RNDatePicker.mm b/ios/RNDatePicker.mm
--- a/ios/RNDatePicker.mm
+++ b/ios/RNDatePicker.mm
@@ -48,9 +48,11 @@
 }
 #endif
 
-NSDate* unixMillisToNSDate (double unixMillis) {
-    double time = unixMillis/1000.0;
-    return [NSDate dateWithTimeIntervalSince1970: time];
+NSDate *iso8601StringToNSDate(const std::string &iso8601String) {
+    NSString *nsString = [NSString stringWithUTF8String:iso8601String.c_str()];
+    NSISO8601DateFormatter *isoFormatter = [[NSISO8601DateFormatter alloc] init];
+    NSDate *date = [isoFormatter dateFromString:nsString];
+    return date;
 }
 
 #ifdef RCT_NEW_ARCH_ENABLED
@@ -101,7 +103,7 @@
     
     //  date
     if(oldViewProps.date != newViewProps.date) {
-        [_picker setDate: unixMillisToNSDate(newViewProps.date)];
+        [_picker setDate: iso8601StringToNSDate(newViewProps.date)];
     }
     
     //  locale
@@ -113,12 +115,12 @@
     
     // maximumDate
     if(oldViewProps.maximumDate != newViewProps.maximumDate) {
-        [_picker setMaximumDate: unixMillisToNSDate(newViewProps.maximumDate)];
+        [_picker setMaximumDate: iso8601StringToNSDate(newViewProps.maximumDate)];
     }
     
     //  minimumDate
     if(oldViewProps.minimumDate != newViewProps.minimumDate) {
-        [_picker setMinimumDate: unixMillisToNSDate(newViewProps.minimumDate)];
+        [_picker setMinimumDate: iso8601StringToNSDate(newViewProps.minimumDate)];
     }
     
     //  setMinuteInterval
diff --git a/ios/RNDatePickerManager.mm b/ios/RNDatePickerManager.mm
--- a/ios/RNDatePickerManager.mm
+++ b/ios/RNDatePickerManager.mm
@@ -36,10 +36,10 @@
 }
 
 RCT_EXPORT_VIEW_PROPERTY(text, NSString)
-RCT_EXPORT_VIEW_PROPERTY(date, NSDate)
+RCT_EXPORT_VIEW_PROPERTY(date, NSString)
 RCT_EXPORT_VIEW_PROPERTY(locale, NSLocale)
-RCT_EXPORT_VIEW_PROPERTY(minimumDate, NSDate)
-RCT_EXPORT_VIEW_PROPERTY(maximumDate, NSDate)
+RCT_EXPORT_VIEW_PROPERTY(minimumDate, NSString)
+RCT_EXPORT_VIEW_PROPERTY(maximumDate, NSString)
 RCT_EXPORT_VIEW_PROPERTY(minuteInterval, NSInteger)
 RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
 RCT_REMAP_VIEW_PROPERTY(mode, datePickerMode, UIDatePickerMode)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants