Static
createCreates a new instance of LayoutWatcher with the given LayoutWatcherConfig. It does not save it for future reuse.
Static
reuseReturns an existing instance of LayoutWatcher with the given LayoutWatcherConfig, or creates a new one.
NOTE: It saves it for future reuse, so don't use this for temporary short-lived watchers.
Readonly
fetchGet the current screen layout.
Readonly
offRemoves a previously added handler.
Readonly
onCall the given handler whenever the layout changes.
Unless OnLayoutOptions.skipInitial is true, the handler is also called (almost) immediately with the current layout.
IMPORTANT: The same handler can not be added multiple times, even if the options differ. If the handler has already been added, it is removed and re-added with the current options.
LisnUsageError If the options are invalid.
LayoutWatcher listens for changes in either the width or aspect ratio of the viewport or the given root.
It does not track resize events; rather it's built on top of IntersectionObserver.
It manages registered callbacks globally and reuses IntersectionObservers for more efficient performance.