-
Notifications
You must be signed in to change notification settings - Fork 754
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(use-viewport-scroll): support passing element ref #195
feat(use-viewport-scroll): support passing element ref #195
Conversation
Hey man, thanks for taking a look at this! To answer your questions:
I don't think this is necessary tbh. If the element doesn't scroll there probably won't be a broken expectation when scroll values don't update.
I don't think we should be too permissive in this instance.
Yeah so I definitely would like
I'd prefer not to involve |
Thanks for taking a look! Sounds good! I'll set up the WeakMap today :) |
I looked into adding This is my simple implementation for the const motionValues = new WeakMap()
function getViewportMotionValues(element) {
if (!motionValues.has(element)) {
motionValues.set(element, {
scrollX: motionValue(0),
scrollY: motionValue(0),
scrollXProgress: motionValue(0),
scrollYProgress: motionValue(0),
})
}
return motionValues.get(element)
} |
Ah yeah I hadn't considered that. Maybe they are treated slightly differently then, with an event handler created for each element but window only getting a single set/motion values |
Closed this by accident -_- |
@InventingWithMonster been a little busy, apologies for the delay! Added support for reusing window scroll values. Not sure how to go about typing the event callback and |
馃憢 just checking in on this PR. Any interest in this still? |
How can you achieve this without this PR? |
Would it be possible to get an idea if this is something coming to Framer. PR seems stalled, just looking to understand if worth waiting for it. |
I could also do with this feature on a project, can I be of any assistance in getting things moving again? 馃槆 |
Sorry for the delay on this! |
* feat(use-viewport-scroll): support passing element ref (#195) * feat(use-viewport-scroll): support passing element ref * reuse window scroll values * Adding useScroll hook * Removing useScroll in lieu of useElementScroll * Updating changelog * Fixing generated type import * Updating API Co-authored-by: Travis Arnold <ftntravis@gmail.com>
This change introduces
A common fix is to create a const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : useEffect
function Comp() {
useIsomorphicLayoutEffect(() => {
// ...
})
} |
This was a quick take on adding
ref
support touseViewportScroll
, curious your thoughts on everything. Still new to Typescript, so I'm sure I'm missing some things 馃槆. Please comment on any concerns and I can address them. I can also update documentation once there's some finalization and take a stab at adding tests.Some questions I had while implementing this:
ref.current
is available but is notoverflow: scroll
?useResize
hook and implementResizeObserver
inside that?I understand if you don't want to add
ResizeObserver
support. Although, I think it could be ok since most modern browsers will support this in their next release. We could also add docs and point to the polyfill since older browser support is probably needed.Closes #182