Function use_swipe_with_options

Source
pub fn use_swipe_with_options<'hook>(
    node: NodeRef,
    options: UseSwipeOptions,
) -> impl 'hook + Hook<Output = UseSwipeHandle>
Expand description

A sensor hook that detects swipe based on TouchEvent with options. If you want to detect for window, pass NodeRef::default() to param node.

§Example

use yew_hooks::prelude::*;

#[function_component(UseSwipe)]
fn swipe() -> Html {
    let node =  use_node_ref();
    let state = use_swipe_with_options(node.clone(), UseSwipeOptions {
        onswipeend: Some(Box::new(move |_e, direction| {
            // Deal with TouchEvent.
            log::debug!("Swipe direction: {:?}", direction);
        })),
        ..Default::default()
    });
    
    html! {
        <div ref={node}>
            <b>{ " swiping: " }</b>
            { *state.swiping }
            <b>{ " direction: " }</b>
            { format!("{:?}", *state.direction) }
            <b>{ " coords_start: " }</b>
            { format!("{:?}", *state.coords_start) }
            <b>{ " coords_end: " }</b>
            { format!("{:?}", *state.coords_end) }
            <b>{ " length_x: " }</b>
            { *state.length_x }
            <b>{ " length_y: " }</b>
            { *state.length_y }
        </div>
    }
}

§Note

When used in function components and hooks, this hook is equivalent to:

pub fn use_swipe_with_options(
    node: NodeRef,
    options: UseSwipeOptions,
) -> UseSwipeHandle {
    /* implementation omitted */
}