Closed alexanderwallin closed 5 years ago
Oh, and I didn't intend to address linting issues or indentations, but was enforced by lint-staged
. 😊
I don't really like doing this on every frame. This will trash the layout and will probably have a severe impact on performance. Did you consider using something like https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver?
The more I think about this, the lesser I think this should be a part of this library, especially if this might have a performance drawbacks. If this issue can't be solved in a performant manner, I'll probably decline this PR. What do you think of it?
I don't like this either. This solution fits better in a separate package. I'll have a look at MutationObserver
tho!
Okay, so neither MutationObserver
or any of the other newer *Observer
APIs work in this situation, since they watch DOM attributes or objects, whereas we are spying on the result of a function call.
We could do this in a couple of other ways:
scrollTargets
prop, where each target gets a scroll event listener that calls onResize()
.<ContainerDimensionsWithScrollUpdates>
, or perhaps something less verbose) that has the scrollTargets
functionality above, but renders <ContainerDimesions>
, stores a ref on it and calls this.storedRef.onResize()
.onResize()
whenever it changes.If none of these methods make sense here, I'm happy to just create a new lil lib and provide it through there. 😊
To be honest, I think the best option would be to have a separate HoC or HoF that is only concerned about scroll position. Based on that it's easy to calculate the realt top/left offsets. What do you think?
As discussed in #24, the
top
andleft
passed on to children components are not updated when they are changed, for instance when scrolling the page.This is a quite naive solution, where we basically check
getBoundingClientRect()
on every frame. I couldn't come up with a reasonable alternative, since there are a ton of ways an element's offset can be changed. If you have an idea, that'd be great!If we implement this, it should probably come with a friendly warning about the implementation.