Skip to content

Fix/wheel picker initial value on change #3029

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

Merged
merged 7 commits into from
Apr 16, 2024

Conversation

nitzanyiz
Copy link
Collaborator

Description

The WheelPicker was not invoking onChange if the initialValue was changed right after onChange was called. I added a handling for wether the drag is a user or a programatic scroll.

Changelog

WheelPicker - Fix onChange not called when initial value is changed.

Additional info

MADS-4145

@nitzanyiz nitzanyiz requested a review from ethanshar April 16, 2024 08:48
@nitzanyiz nitzanyiz marked this pull request as ready for review April 16, 2024 08:48
Copy link
Collaborator

@ethanshar ethanshar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, wrote small comment on the flag

@@ -148,7 +148,7 @@ const WheelPicker = <T extends WheelPickerItemValue>(props: WheelPickerProps<T>)
preferredNumVisibleRows: numberOfVisibleRows
});

const prevInitialValue = useRef(initialValue);
const shouldInvokeOnChange = useRef(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better that the flag will represent the edge case and not the common case.
Meaning that false will be the usual value, so it's better to name it something like shouldSkipNextOnChange or something similar.
This way its value will be usually false and only when turning it on set it to true.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@nitzanyiz nitzanyiz requested a review from ethanshar April 16, 2024 12:19
@ethanshar ethanshar merged commit e9772b5 into master Apr 16, 2024
@ethanshar ethanshar deleted the fix/WheelPickerInitialValueOnChange branch April 16, 2024 14:15
nitzanyiz added a commit that referenced this pull request Apr 16, 2024
* WheelPicker prevInitailValue setter changed

* Revert "WheelPicker prevInitailValue setter changed"

This reverts commit 2727fa1.

* added handling for when a scroll is invoked by the user and not programatically

* change WheelPicker Driver to invoke onScrollBeginDrag on moveToItem

* changed naming

* changed naming to be more explanatory

* changed default skip value
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