Skip to content
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

make visibilityHooks animation work if element is visible initially #33

Closed
wants to merge 1 commit into from
Closed

Conversation

xstevenyung
Copy link

@xstevenyung xstevenyung commented Oct 7, 2021

Hello,

I finally got time to dig a bit and found a way to make visible hooks work even if the element is visible from the start. But I'm not sure this solution doesn't affect other part of the project, so this is mainly a WIP proposition.

The issue was mainly that useIntersectionObserver which all visibility hooks rely on doesn't detect intersection on first load when used in the created lifecycle (probably because the target element is not mounted in the app yet).

I changed the directive file to register on mounted instead, so useIntersectionObserver would work even on first load, as I'm not familiar with the rest of the codebase, I'm guessing this is actually wrong and created hook is used for a specific reason. I'm open to an alternative solution on this one.

Cheers

Related issue:
#29

@xstevenyung xstevenyung changed the title WIP make visibilityHooks animation if element is visible initially WIP make visibilityHooks animation work if element is visible initially Oct 7, 2021
@xstevenyung xstevenyung changed the title WIP make visibilityHooks animation work if element is visible initially make visibilityHooks animation work if element is visible initially Oct 12, 2021
@xstevenyung xstevenyung marked this pull request as ready for review October 14, 2021 23:36
@Qazzquimby
Copy link

I wish this wasn't closed. useIntersectionObserver not functioning on elements already in view makes it very troublesome to use.
Is there a workaround people are using for issues like #29?

@xstevenyung
Copy link
Author

Personally, the fix in the PR make it worked but as stated, I have no clue if this fix has any side effect, so use at your own risk.

Unfortunately, I have no more time to spend on this PR. Feel free to reopen one.

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