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

Android - Undefined is not a function / NativeModule.closePicker() #751

Closed
Alissonfm opened this issue Jan 4, 2024 · 7 comments · Fixed by #782
Closed

Android - Undefined is not a function / NativeModule.closePicker() #751

Alissonfm opened this issue Jan 4, 2024 · 7 comments · Fixed by #782

Comments

@Alissonfm
Copy link

Alissonfm commented Jan 4, 2024

Describe the bug
On the RN old arch, but using Hermes, if you try to programatically dismiss the picker, in my EX below:

I have a hook watching the user interaction with the app, if he became idle for 5 min, we trigger logout due to sensitive data, so before the page/component unmount I tried to set the 'open' prop of the picker as false, in modal mode of course, and then I got this error, I checked the native code for android, the old arch one and its missing the closePicker function...

the path to the file where the closePicker is missing:
react-native-date-picker/android/src/oldarch/java/com/henninghall/date_picker/DatePickerModule.java

on iOS it work as expected.

Expected behavior
Dismiss the picker modal when passing a bool false to the 'open' modal prop

To Reproduce
tried to set the 'open' prop of the picker as false, in modal mode of course, and then I got this error, I checked the native code for android, the old arch one and its missing the closePicker function...

``
const [picker, setPicker] = useState(null);

const programaticallyDismissTimePicker = useCallback(() => {
setPicker(null);
}, [])

useEffect(() => {
const removeListener = navigation.addListener('beforeRemove', programaticallyDismissTimePicker)
return () => {
removeListener();
}
}, [programaticallyDismissTimePicker, navigation]);`

[...]

return (
<DatePicker
modal
title="Stel de gewenste tijd in"
open={!!picker}
date={new Date()}
mode="time"
cancelText="Annuleren"
confirmText="Selecteren"
onConfirm={(date) => {
addTimeslot(date, picker);
setPicker(null);
}}
onCancel={() => {
setPicker(null);
}}
/>
)
``

Smartphone (please complete the following information):

  • OS: Android
  • React Native version: 0.71.8
  • react-native-date-picker version: 4.3.5
Screenshot 2024-01-04 at 23 09 46
@nnabinh
Copy link

nnabinh commented Jan 26, 2024

@henninghall I got the same issue as described here. Can you take a look?

@nnabinh
Copy link

nnabinh commented Jan 26, 2024

@Alissonfm As a workaround, you can optionally render the component without using open prop.

shouldShowDatePicker && <DatePicker open ... />

@henninghall
Copy link
Owner

Hi, thanks for reporting this. Please provide a repo where this is reproducible and I can investigate this.

@devevecare
Copy link

Had the same issue, so steps to reproduce, Have a button on screen 1 which opens up the datepicker, open and set date and then go to inner screen and come back to first screen it throws error

Screen 1:

const [showDatepicker, setShowDatepicker] = useState(false);
const [selectedDate, setSelecteDate] = useState(new Date());
const showCalendar = useCallback(() => {
    setShowDatepicker(true);
  }, []);
  const hideCalendar = useCallback(() => {
    setShowDatepicker(false);
  }, []);
  const onChangeDate = useCallback((date: Date) => {
    setSelecteDate(date);
    setShowDatepicker(false);
  }, []);
  
  return (<DatePicker
            modal
            open={showDatepicker}
            date={selectedDate}
            mode="date"
            onConfirm={onChangeDate}
            onCancel={hideCalendar}
          />)

Go to some inner screen and try to come back and use the same button to open the datepicker again.

@MahmoudNafiseh
Copy link
Contributor

@devevecare I made a pr that should fix this issue. #782

@henninghall
Copy link
Owner

Thanks for the PR @MahmoudNafiseh, the fix is released in version 4.4.1

@devevecare
Copy link

Thanks for the PR @MahmoudNafiseh the fix works fine. 👍

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