gusparis / react-native-month-year-picker

React Native Month Picker component for iOS & Android
MIT License
106 stars 74 forks source link

Incorrect work on android #3

Closed nightdaydream closed 4 years ago

nightdaydream commented 4 years ago

when I clicked Ok at dialog, then picker opens multiple times and doesn't close, i can do it only by clicking on Ok button and I can't see action for Cancel button, and can't setVisible for modal like "false" value and modal always visible. please help

gusparis commented 4 years ago

I’ll check it

gusparis commented 4 years ago

@vivaLaChoco can you share the piece of code where you are using the component? I'm not able to reproduce that behavior in the example. Also, for the cancel button action, I didn't want to add a lot of different props for iOS and Android, so the actions can be caught through the event. eg. in Android you have these two events:

ACTION_DATE_SET = 'dateSetAction'
ACTION_DISMISSED = 'dismissedAction'

Please let me know if that works for you.

Zonfer commented 4 years ago

UP ip. This problem was fixed? I have the same issue.

this is my components version.

"react": "16.9.0", "react-native": "0.61.5", "react-native-month-year-picker": "^1.0.5"

Code:

 const [date, setDate] = useState(new Date());
 const onValueChange = (event, newDate) => {
    setDate(newDate);
  };
<MonthPicker
                      onChange={onValueChange}
                      value={date}
                      minimumDate={new Date(2018, 1)}
                      maximumDate={new Date(2021, 5)}/>
gusparis commented 4 years ago

Just did an update to the readme's usage section with a working example. Can you guys try it?

nightdaydream commented 4 years ago

after click on "Ok" button it works fine, thank you as I understand, onChange doesn't call, when event is "dismissedAction", that's why flag "show" is true, and when you clicked on button "Open picker", picker wouldn't open and I can't understand, why. Can you help me please?

gusparis commented 4 years ago

The onChange method returns an event and the selected date. If the dialog was canceled, the event will be “dismissedAction”. You can perform a check (with a switch if you like) to trigger needed actions. eg

const onDateChange = (event, newDate) => {
     switch (event) {
          case ACTION_DATE_SET:
               setDate(newDate);
          case ACTION_DISMISSED:
          default:
                doSomeErrorHandlingHere();
     }
} 

Notice that when event is other than ACTION_DATE_SET, newDate will be undefined.

Zonfer commented 4 years ago

I'm testing and the example at the README's section work's fine with function setShow. But still have a litle bug with close and open modal events. ACTION_DATE_SET, and ACTION_DISMISSED, doesn't exist theses events.