ampproject / amp-react-prototype

A scratch pad to experiment with React rendered AMP Components
Apache License 2.0
36 stars 9 forks source link

Dependency on layout size and in-viewport #54

Open dvoytenko opened 4 years ago

dvoytenko commented 4 years ago

For some elements their layout size is important. For instance amp-fit-text picks the right font size given its content and available layout space. In AMP layout size is provided by the framework. However, in Bento, we do not want to depend on heavy framework features and instead need to enable the components themselves to react to size changes.

We can use a relatively new ResizeObserver to monitor size changes. See useResizeObserver as an example. There are some nuances however:

Very similar reasons should guide "in-viewport" approach with IntersectionObserver.