Skip to content

Use react-freeze to optimize TabController pages #1639

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 8 commits into from
Nov 22, 2021

Conversation

ethanshar
Copy link
Collaborator

@ethanshar ethanshar commented Nov 5, 2021

Description

Use react-freeze to optimize functionality of TabController.TabPage so pages that are not focused will not trigger renders

Changelog

Use react-freeze to optimize functionality of TabController.TabPage so pages that are not focused will not trigger renders

runOnJS(setFocused)(true);
}

if (wasActive && wasActive !== isActive) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not wasActive && !isActive or (to be sure we don't have a race condition):

if (isActive) {
  ...
} else if (wasActive) {
  runOnJS(setFocused)(false);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I change it.. now it's better.
Apparently we got to this part of code more than once, after adding currentPage to dependency array of useAnimatedReaction it fixed it.. so we can rely completely on wasActive

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@M-i-k-e-l
I changed the implementation again, I think it's even simpler now
It has a single useAnimatedReaction so I think it's more bug prune
Let me know if you find something 😬

@ethanshar ethanshar requested a review from M-i-k-e-l November 11, 2021 13:20
@ethanshar
Copy link
Collaborator Author

@M-i-k-e-l
I fix the logic a little bit..
I fixed how we handle pages that are near the active page - this is relevant when using PageCarousel

@ethanshar ethanshar added the Important for Next Release PR that must be included in the release version label Nov 14, 2021
Copy link
Collaborator

@M-i-k-e-l M-i-k-e-l left a comment

Choose a reason for hiding this comment

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

As we saw, adding the following log reveals problems in the logic of the frozen tabs:

console.log('Ethan', index, !shouldLoad || !focused);

Copy link
Collaborator

@M-i-k-e-l M-i-k-e-l left a comment

Choose a reason for hiding this comment

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

When on the Posts tab (index=1), do we want the Reviews (index=2) to load? It does not.

@ethanshar
Copy link
Collaborator Author

As we saw, adding the following log reveals problems in the logic of the frozen tabs:

console.log('Ethan', index, !shouldLoad || !focused);

The right thing to check is focused and not both IMO
Cause you want to check the focus logic (which seems like it's working)
The freeze also affected by shouldLoad which might give different results

@M-i-k-e-l
Copy link
Collaborator

As we saw, adding the following log reveals problems in the logic of the frozen tabs:

console.log('Ethan', index, !shouldLoad || !focused);

The right thing to check is focused and not both IMO Cause you want to check the focus logic (which seems like it's working) The freeze also affected by shouldLoad which might give different results

But if we freeze when !shouldLoad, then why have a different logic for the carousel? Assuming it has the same logic for shouldLoad, it'll be frozen or not at the same time, wouldn't it?

@M-i-k-e-l M-i-k-e-l merged commit 01007d1 into master Nov 22, 2021
@ethanshar ethanshar deleted the feat/TabController_pageFreeze branch April 18, 2022 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Important for Next Release PR that must be included in the release version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants