Skip to content

Commit

Permalink
fix: Out of sync element ids on events (#609)
Browse files Browse the repository at this point in the history
* fix: Out of sync element ids on events

* fix

* fmt
  • Loading branch information
marc2332 authored May 17, 2024
1 parent 36f1dac commit 0bc8d3e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
8 changes: 0 additions & 8 deletions crates/core/src/events/dom_event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{any::Any, rc::Rc};

use dioxus_core::ElementId;
use freya_elements::{
elements::PlatformEventData,
events::{
Expand All @@ -19,7 +18,6 @@ use super::event_name::EventName;
pub struct DomEvent {
pub name: EventName,
pub node_id: NodeId,
pub element_id: ElementId,
pub data: DomEventData,
pub bubbles: bool,
pub layer: Option<i16>,
Expand All @@ -46,7 +44,6 @@ impl DomEvent {
layer,
event,
}: PotentialEvent,
element_id: ElementId,
node_area: Option<Area>,
scale_factor: f64,
) -> Self {
Expand Down Expand Up @@ -80,7 +77,6 @@ impl DomEvent {

Self {
node_id,
element_id,
name,
data: event_data,
bubbles,
Expand All @@ -89,7 +85,6 @@ impl DomEvent {
}
PlatformEvent::Wheel { scroll, .. } => Self {
node_id,
element_id,
name,
data: DomEventData::Wheel(WheelData::new(scroll.x, scroll.y)),
bubbles,
Expand All @@ -102,7 +97,6 @@ impl DomEvent {
..
} => Self {
node_id,
element_id,
name,
data: DomEventData::Keyboard(KeyboardData::new(key.clone(), code, modifiers)),
bubbles,
Expand Down Expand Up @@ -140,7 +134,6 @@ impl DomEvent {

Self {
node_id,
element_id,
name,
data: event_data,
bubbles,
Expand All @@ -154,7 +147,6 @@ impl DomEvent {

Self {
node_id,
element_id,
name,
data: event_data,
bubbles,
Expand Down
8 changes: 1 addition & 7 deletions crates/core/src/events/events_measurer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use freya_native_core::real_dom::NodeImmutable;
use freya_native_core::NodeId;
use freya_native_core::{prelude::NodeImmutableDioxusExt, tree::TreeRef};
use freya_native_core::{real_dom::NodeImmutable, tree::TreeRef};

use freya_engine::prelude::*;
use freya_node_state::{Fill, Style, ViewportState};
Expand Down Expand Up @@ -243,11 +242,8 @@ fn measure_dom_events(
let layout = fdom.layout();
let layout_node = layout.get(potential_event.node_id);
if let Some(layout_node) = layout_node {
let node_ref = fdom.rdom().get(potential_event.node_id).unwrap();
let element_id = node_ref.mounted_id().unwrap();
let event = DomEvent::new(
potential_event,
element_id,
Some(layout_node.visible_area()),
scale_factor,
);
Expand All @@ -272,14 +268,12 @@ fn emit_global_events_listeners(
let listeners = fdom.rdom().get_listeners(&event_name);

for listener in listeners {
let element_id = listener.mounted_id().unwrap();
let event = DomEvent::new(
PotentialEvent {
node_id: listener.id(),
layer: None,
event: global_event.clone(),
},
element_id,
None,
scale_factor,
);
Expand Down
14 changes: 11 additions & 3 deletions crates/renderer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use freya_common::EventMessage;
use freya_core::prelude::*;
use freya_engine::prelude::*;
use freya_hooks::PlatformInformation;
use freya_native_core::prelude::NodeImmutableDioxusExt;
use freya_native_core::NodeId;
use futures_task::Waker;
use futures_util::FutureExt;
Expand Down Expand Up @@ -173,9 +174,16 @@ impl<State: 'static + Clone> App<State> {
ev = self.event_receiver.recv() => {
if let Some(ev) = ev {
let data = ev.data.any();
self.vdom.handle_event(ev.name.into(), data, ev.element_id, ev.bubbles);

self.vdom.process_events();
let fdom = self.sdom.get();
let rdom = fdom.rdom();
let node = rdom.get(ev.node_id);
if let Some(node) = node {
let element_id = node.mounted_id();
if let Some(element_id) = element_id {
self.vdom.handle_event(ev.name.into(), data, element_id, ev.bubbles);
self.vdom.process_events();
}
}
}
},
_ = self.vdom.wait_for_work() => {},
Expand Down
18 changes: 15 additions & 3 deletions crates/testing/src/test_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use freya_common::EventMessage;
use freya_core::prelude::*;
use freya_engine::prelude::FontCollection;
use freya_hooks::PlatformInformation;
use freya_native_core::dioxus::NodeImmutableDioxusExt;
use tokio::sync::broadcast;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use tokio::time::{interval, timeout};
Expand Down Expand Up @@ -137,9 +138,20 @@ impl TestingHandler {
}

if let Ok(ev) = vdom_ev {
self.vdom
.handle_event(ev.name.into(), ev.data.any(), ev.element_id, ev.bubbles);
self.vdom.process_events();
let data = ev.data.any();
let fdom = self.utils.sdom().get();
let rdom = fdom.rdom();
let node = rdom.get(ev.node_id);
if let Some(node) = node {
let element_id = node.mounted_id();
if let Some(element_id) = element_id {
println!("{:?} / {:?} / {:?}", ev.name, element_id, ev.bubbles);
self.vdom
.handle_event(ev.name.into(), data, element_id, ev.bubbles);

self.vdom.process_events();
}
}
}
}

Expand Down

0 comments on commit 0bc8d3e

Please sign in to comment.