mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-26 22:20:19 +00:00
fix the onload event
This commit is contained in:
parent
b6463e4b27
commit
043aae1689
5 changed files with 14 additions and 9 deletions
|
@ -127,6 +127,7 @@ pub fn event_bubbles(evt: &str) -> bool {
|
|||
"loadeddata" => false,
|
||||
"loadedmetadata" => false,
|
||||
"loadstart" => false,
|
||||
"load" => false,
|
||||
"pause" => false,
|
||||
"play" => false,
|
||||
"playing" => false,
|
||||
|
|
|
@ -4,6 +4,7 @@ pub type ImageEvent = Event<ImageData>;
|
|||
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ImageData {
|
||||
#[cfg_attr(feature = "serialize", serde(default))]
|
||||
pub load_error: bool,
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ fn fun_name(
|
|||
// Touch
|
||||
"touchcancel" | "touchend" | "touchmove" | "touchstart" => Touch(de(data)?),
|
||||
|
||||
// Srcoll
|
||||
// Scroll
|
||||
"scroll" => Scroll(de(data)?),
|
||||
|
||||
// Wheel
|
||||
|
@ -102,7 +102,7 @@ fn fun_name(
|
|||
| "ended" | "interruptbegin" | "interruptend" | "loadeddata" | "loadedmetadata"
|
||||
| "loadstart" | "pause" | "play" | "playing" | "progress" | "ratechange" | "seeked"
|
||||
| "seeking" | "stalled" | "suspend" | "timeupdate" | "volumechange" | "waiting"
|
||||
| "error" | "load" | "loadend" | "timeout" => Media(de(data)?),
|
||||
| "loadend" | "timeout" => Media(de(data)?),
|
||||
|
||||
// Animation
|
||||
"animationstart" | "animationend" | "animationiteration" => Animation(de(data)?),
|
||||
|
@ -113,7 +113,8 @@ fn fun_name(
|
|||
// Toggle
|
||||
"toggle" => Toggle(de(data)?),
|
||||
|
||||
// ImageData => "load" | "error";
|
||||
"load" | "error" => Image(de(data)?),
|
||||
|
||||
// OtherData => "abort" | "afterprint" | "beforeprint" | "beforeunload" | "hashchange" | "languagechange" | "message" | "offline" | "online" | "pagehide" | "pageshow" | "popstate" | "rejectionhandled" | "storage" | "unhandledrejection" | "unload" | "userproximity" | "vrdisplayactivate" | "vrdisplayblur" | "vrdisplayconnect" | "vrdisplaydeactivate" | "vrdisplaydisconnect" | "vrdisplayfocus" | "vrdisplaypointerrestricted" | "vrdisplaypointerunrestricted" | "vrdisplaypresentchange";
|
||||
other => {
|
||||
return Err(serde_value::DeserializerError::UnknownVariant(
|
||||
|
@ -134,6 +135,7 @@ impl HtmlEvent {
|
|||
|
||||
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
|
||||
#[serde(untagged)]
|
||||
#[non_exhaustive]
|
||||
pub enum EventData {
|
||||
Mouse(MouseData),
|
||||
Clipboard(ClipboardData),
|
||||
|
@ -151,6 +153,7 @@ pub enum EventData {
|
|||
Animation(AnimationData),
|
||||
Transition(TransitionData),
|
||||
Toggle(ToggleData),
|
||||
Image(ImageData),
|
||||
}
|
||||
|
||||
impl EventData {
|
||||
|
@ -172,6 +175,7 @@ impl EventData {
|
|||
EventData::Animation(data) => Rc::new(data) as Rc<dyn Any>,
|
||||
EventData::Transition(data) => Rc::new(data) as Rc<dyn Any>,
|
||||
EventData::Toggle(data) => Rc::new(data) as Rc<dyn Any>,
|
||||
EventData::Image(data) => Rc::new(data) as Rc<dyn Any>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -894,10 +894,9 @@ function event_bubbles(event) {
|
|||
case "error":
|
||||
return false;
|
||||
case "loadeddata":
|
||||
return false;
|
||||
case "loadedmetadata":
|
||||
return false;
|
||||
case "loadstart":
|
||||
case "load":
|
||||
return false;
|
||||
case "pause":
|
||||
return false;
|
||||
|
|
|
@ -17,7 +17,7 @@ use js_sys::Array;
|
|||
use rustc_hash::FxHashMap;
|
||||
use std::{any::Any, rc::Rc, sync::Arc};
|
||||
use wasm_bindgen::{closure::Closure, prelude::wasm_bindgen, JsCast};
|
||||
use web_sys::{console, Document, Element, Event, HtmlElement};
|
||||
use web_sys::{Document, Element, Event, HtmlElement};
|
||||
|
||||
use crate::{file_engine::WebFileEngine, Config};
|
||||
|
||||
|
@ -211,7 +211,6 @@ impl WebsysDom {
|
|||
},
|
||||
SetText { value, id } => i.set_text(id.0 as u32, value),
|
||||
NewEventListener { name, id, .. } => {
|
||||
console::log_1(&format!("new event listener: {}", name).into());
|
||||
i.new_event_listener(name, id.0 as u32, event_bubbles(name) as u8);
|
||||
}
|
||||
RemoveEventListener { name, id } => {
|
||||
|
@ -230,7 +229,6 @@ impl WebsysDom {
|
|||
// We need tests that simulate clicks/etc and make sure every event type works.
|
||||
pub fn virtual_event_from_websys_event(event: web_sys::Event, target: Element) -> Rc<dyn Any> {
|
||||
use dioxus_html::events::*;
|
||||
console::log_1(&event.clone().into());
|
||||
|
||||
match event.type_().as_str() {
|
||||
"copy" | "cut" | "paste" => Rc::new(ClipboardData {}),
|
||||
|
@ -266,9 +264,11 @@ pub fn virtual_event_from_websys_event(event: web_sys::Event, target: Element) -
|
|||
}
|
||||
"transitionend" => Rc::new(TransitionData::from(event)),
|
||||
"abort" | "canplay" | "canplaythrough" | "durationchange" | "emptied" | "encrypted"
|
||||
| "ended" | "error" | "loadeddata" | "loadedmetadata" | "loadstart" | "pause" | "play"
|
||||
| "ended" | "loadeddata" | "loadedmetadata" | "loadstart" | "pause" | "play"
|
||||
| "playing" | "progress" | "ratechange" | "seeked" | "seeking" | "stalled" | "suspend"
|
||||
| "timeupdate" | "volumechange" | "waiting" => Rc::new(MediaData {}),
|
||||
"error" => Rc::new(ImageData { load_error: true }),
|
||||
"load" => Rc::new(ImageData { load_error: false }),
|
||||
"toggle" => Rc::new(ToggleData {}),
|
||||
|
||||
_ => Rc::new(()),
|
||||
|
|
Loading…
Reference in a new issue