gusparis / react-native-month-year-picker

React Native Month Picker component for iOS & Android
MIT License
105 stars 72 forks source link

Month Automatically jumping back to where it is being moved #135

Closed taatiq882 closed 1 year ago

taatiq882 commented 1 year ago

Hello, I have this weird behavior, Can anyone here help me out with why is this happening? I have attached a vide.

        <RnMonthPicker
          onChange={onValueChangeEndingDate}
          autoTheme={false}
          value={new Date()}
          minimumDate={new Date()}
          maximumDate={new Date(2025, 5)}
          locale="en"
        />

https://user-images.githubusercontent.com/30371302/198722446-2ac9ccaf-537c-4fbf-b652-e251c762a5da.mov

shahanshah87 commented 1 year ago

Hey did you find any solution?

taatiq882 commented 1 year ago

Nop I couldn't find any solution for that.

bkcan commented 1 year ago

@taatiq882 You need to update the value prop. Refer to the Usage section

Pseudocode:

let currentDate = new Date() // use the useState hook so that the component re-renders

const onValueChangeEndingDate = (newDate) => {
  currentDate = newDate
}

........

<RnMonthPicker
  onChange={onValueChangeEndingDate}
  autoTheme={false}
  value={currentDate} // update this prop to the new chosen value
  minimumDate={new Date()}
  maximumDate={new Date(2025, 5)}
  locale="en"
/>
gusparis commented 1 year ago

@taatiq882 not a bug. you set the maximum date to June 2025, if you go pass that date, it will scroll back to the maximum. Remove maximumDate if it was not intended, or increase the limit date.