Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,29 @@ public class DatePickerModuleImpl {
ApplicationStarter.initialize(context, false); // false = no need to prefetch on time data background tread
}

public void openPicker(ReadableMap props){
public void openPicker(ReadableMap props, Callback onConfirm, Callback onCancel){
final PickerView picker = createPicker(props);
Callback onConfirm = new Callback() {
Callback onConfirmCallback = new Callback() {
@Override
public void invoke(Object... objects) {
Emitter.onConfirm(picker.getDate(), picker.getPickerId());
if (onConfirm != null) {
onConfirm.invoke(picker.getDate());
}
}
};

Callback onCancel = new Callback() {
Callback onCancelCallback = new Callback() {
@Override
public void invoke(Object... objects) {
Emitter.onCancel(picker.getPickerId());
if (onCancel != null) {
onCancel.invoke();
}
}
};

dialog = createDialog(props, picker, onConfirm, onCancel);
dialog = createDialog(props, picker, onConfirmCallback, onCancelCallback);
dialog.show();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import androidx.annotation.NonNull;

import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReadableMap;

Expand All @@ -28,8 +29,8 @@ public void removeListeners(double type) {
}

@Override
public void openPicker(ReadableMap props){
module.openPicker(props);
public void openPicker(ReadableMap props, Callback onConfirm, Callback onCancel){
module.openPicker(props, onConfirm, onCancel);
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions ios/RNDatePickerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
#import <React/RCTConvert.h>
#import <React/RCTViewManager.h>

#ifdef RCT_NEW_ARCH_ENABLED
#import <RNDatePickerSpecs/RNDatePickerSpecs.h>
#endif

@interface RNDatePickerManager : RCTViewManager
#ifdef RCT_NEW_ARCH_ENABLED
<NativeRNDatePickerSpec>
#endif

@property (strong, nonatomic) UIViewController *topViewController;

Expand Down
16 changes: 16 additions & 0 deletions ios/RNDatePickerManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,22 @@ - (double) getPickerHeight :(UIView *) alertView
return 216;
}

// New Architecture support - provide module instance to TurboModule system
(BOOL)requiresMainQueueSetup {
return NO;
}

#ifdef RCT_NEW_ARCH_ENABLED
// Implement the Spec protocol methods required by TurboModule
- (void)getConstants:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
resolve(@{});
}

- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
return std::make_shared<facebook::react::NativeRNDatePickerSpecJSI>(params);
}
#endif

@end


7 changes: 4 additions & 3 deletions src/DatePickerAndroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ export const DatePickerAndroid = React.memo((props) => {
onStateChange: onSpinnerStateChanged,
}

useModal({ props: modifiedProps, id: thisId })

if (props.modal) return null
if (props.modal){
useModal({ props: modifiedProps, id: thisId })
return null
}

return <NativeComponent {...modifiedProps} />
})
Expand Down
7 changes: 4 additions & 3 deletions src/DatePickerIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
style: [styles.datePickerIOS, props.style],
date: props.date ? props.date.toISOString() : undefined,
locale: props.locale ? props.locale : undefined,
maximumDate: props.maximumDate ? props.maximumDate.toISOString() : undefined,

Check failure on line 26 in src/DatePickerIOS.js

View workflow job for this annotation

GitHub Actions / Check / Lint

Replace `·?·props.maximumDate.toISOString()` with `⏎······?·props.maximumDate.toISOString()⏎·····`
minimumDate: props.minimumDate ? props.minimumDate.toISOString() : undefined,

Check failure on line 27 in src/DatePickerIOS.js

View workflow job for this annotation

GitHub Actions / Check / Lint

Replace `·?·props.minimumDate.toISOString()` with `⏎······?·props.minimumDate.toISOString()⏎·····`
theme: props.theme ? props.theme : 'auto',
}

useModal({ props: modifiedProps, id: undefined })

if (props.modal) return null
if (props.modal){
useModal({ props: modifiedProps, id: undefined })
return null
}

return (
<NativeComponent
Expand Down
2 changes: 1 addition & 1 deletion src/fabric/NativeRNDatePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Double, UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes'
export interface Spec extends TurboModule {
readonly getConstants: () => {}
closePicker(): void
openPicker(props: UnsafeObject): void
openPicker(props: UnsafeObject, onConfirm: (result: UnsafeObject) => void, onCancel: () => void): void
removeListeners(type: Double): void
addListener(eventName: string): void
}
Expand Down
7 changes: 1 addition & 6 deletions src/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,7 @@ export const useModal = ({ props, id }) => {
useEffect(() => {
if (shouldOpenModal(props, previousProps)) {
closing.current = false
const params = Platform.select({
android: [props],
ios: [props, onConfirm, onCancel],
})
if (!params) throw Error('Unsupported platform')
NativeModule.openPicker(...params)
NativeModule.openPicker(props, onConfirm, onCancel)
}
}, [onCancel, onConfirm, previousProps, props])

Expand Down
Loading