Skip to content

Fix/segmentedControl performance #1375

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 9 commits into from
Jul 27, 2021
Merged

Conversation

lidord-wix
Copy link
Contributor

Description

Fix segmentedControl performance
Jira WOAUILIB-1853

Changelog

Fix segmentedControl performance

[onChangeIndex, selectedSegment, updateSelectedSegment]);
[onChangeIndex, updateSelectedSegment]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure that's correct?
You are using selectedSegment in this callback, removing it can lead to bugs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, but actually, I think the condition is not required at all..
Fixed :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the condition is required (:
It meant to prevent calling the onChangeIndex callback in case the user press twice at the same segment.
Now when pressing twice on the same index I still get this callback 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, IMO the user should handle this (maybe the prop name is misleading and onSegmentPress is better).
Because the user might want a callback for any press and we should support it.
Let me know what you think, 'cause I'm not sure what is better :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can add a separate prop for onPress though I'm not sure it's needed.
If you think about it, product wise the user wants to be notified on index change, that's the purpose of the component, to change between different segments.
Our goal is to provide an API that is useful for the user

@lidord-wix
Copy link
Contributor Author

@ethanshar
I've added a setTimeout for the onChangeIndex and now the animation looks much better..
We should migrate it to reanimated 2 once we'll assure it improves performance :)

@lidord-wix lidord-wix requested a review from ethanshar July 13, 2021 13:12
updateSelectedSegment(index);
setTimeout(() => onChangeIndex?.(index), 400);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Other than delaying the callback, I'd consider also to throttle the calls.
For instance, if the user press quickly on multiple different segments, maybe we can throttles all of these calls and trigger only the last one.

Where are you checking the performance of this component? It's mostly noticeable in our SectionWheelPicker example screen.

Another thing worth checking (can be in another PR) is to move to reanimated2, other than simplifying the code it can also help with performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to wrap the callback with lodash throttle but couldn't see any change.. also, I couldn't see the throttle effect in other places we use it (PickerModal for example), let me know if it's only me

I'm checking it in the SectionWheelPickerScreen as well :)

I have a draft PR on moving this component to reanimated2, I'll publish it after this PR :)

@lidord-wix lidord-wix requested a review from ethanshar July 20, 2021 11:22
@ethanshar ethanshar merged commit b5068ab into master Jul 27, 2021
@lidord-wix lidord-wix deleted the fix/segmentedControl_performance branch August 9, 2021 08:03
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