use crate::event::{
AccessibilityActionData, AreaData, ArkEventKind, AxisData, ChangeData, ClickData, FocusData,
HoverData, KeyData, MouseData, PointerData, ReachEndData, RefreshData, ScrollData, SubmitData,
SwiperChangeData,
};
macro_rules! impl_events {
($(
$data:ty;
$($name:ident => $kind:ident),* $(,)?;
)*) => {
$($(
#[inline]
pub fn $name<__Marker>(mut _f: impl ::dioxus_core::SuperInto<::dioxus_core::ListenerCallback<$data>, __Marker>) -> ::dioxus_core::Attribute {
let event_handler = _f.super_into();
::dioxus_core::Attribute::new(
stringify!($name),
::dioxus_core::AttributeValue::listener(move |e: ::dioxus_core::Event<$crate::event::ArkEventData>| {
let event: ::dioxus_core::Event<$data> = e.map(|d| d.into());
event_handler.call(event.into_any());
}),
None,
false,
)
}
#[doc(hidden)]
pub mod $name {
use super::*;
#[allow(deprecated)]
pub fn call_with_explicit_closure<__Marker, Return: ::dioxus_core::SpawnIfAsync<__Marker> + 'static>(
event_handler: impl FnMut(::dioxus_core::Event<$data>) -> Return + 'static,
) -> ::dioxus_core::Attribute {
super::$name(event_handler)
}
}
)*)*
pub(crate) const EVENT_KINDS: &[(&str, ArkEventKind)] = &[
$($(
(stringify!($name), ArkEventKind::$kind),
)*)*
];
};
}
impl_events! {
AccessibilityActionData;
onaccessibilityaction => AccessibilityAction;
ClickData;
onclick => Click, onlongpress => LongPress;
ChangeData;
onchange => Change, oninput => Change, ontoggle => Change;
SubmitData;
onsubmit => Submit;
ScrollData;
onscroll => Scroll;
ReachEndData;
onreachend => ReachEnd;
SwiperChangeData;
onswiperchange => SwiperChange;
RefreshData;
onrefresh => Refresh;
AreaData;
onarea => AreaChange;
HoverData;
onhover => Hover;
FocusData;
onfocus => Focus, onblur => Blur, onfocusin => FocusIn, onfocusout => FocusOut;
PointerData;
onhovermove => HoverMove, ondragstart => DragStart, ondragmove => DragMove,
ondragend => DragEnd, ondragleave => DragLeave, ondragenter => DragEnter, ontouch => Touch;
KeyData;
onkey => Key, onkeypreime => KeyPreIme;
MouseData;
onmouse => Mouse;
AxisData;
onaxis => Axis;
}