Skip to main content

euv_ui/hook/use_intersection_observer/
struct.rs

1use super::*;
2
3/// Reactive state for an element's visibility.
4///
5/// The handle carries the element the hook watches — a [`NodeRef`] the
6/// caller attaches to its own markup — and the signals that report
7/// whether the element is intersecting the viewport and how much of it
8/// is visible.
9///
10/// This is the cheap way to defer the work of an off-screen element:
11/// the signal only changes when the element actually crosses the
12/// viewport, so a render closure that reads it stays quiet while the
13/// element scrolls past.
14#[derive(Clone, CustomDebug, Data)]
15pub struct UseIntersectionObserver {
16    /// The element the hook watches.
17    ///
18    /// Attach it to the caller's markup with the `ref:` attribute.
19    pub target: NodeRef<Element>,
20    /// Whether the element is currently intersecting the viewport.
21    #[get(type(copy))]
22    pub visible: Signal<bool>,
23    /// The fraction of the element that is visible, from 0 to 1.
24    #[get(type(copy))]
25    pub ratio: Signal<f64>,
26    /// The teardown that disconnects the observer.
27    #[get(pub(crate))]
28    #[debug(skip)]
29    pub(crate) teardown: Teardown,
30}