diff --git a/examples/accessibility.rs b/examples/accessibility.rs new file mode 100644 index 00000000..44b894f2 --- /dev/null +++ b/examples/accessibility.rs @@ -0,0 +1,13 @@ +use dioxus::prelude::*; + +fn main() { + dioxus_blitz::launch(app); +} + +fn app() -> Element { + rsx! { + body { + "Dioxus 4 all" + } + } +} diff --git a/packages/dioxus-blitz/src/lib.rs b/packages/dioxus-blitz/src/lib.rs index 2b90cec7..e2ccd0f0 100644 --- a/packages/dioxus-blitz/src/lib.rs +++ b/packages/dioxus-blitz/src/lib.rs @@ -106,7 +106,6 @@ fn launch_with_window(window: View<'static, Doc>) { #[cfg(not(any(target_os = "android", target_os = "ios")))] let mut initial = true; - // Setup hot-reloading if enabled. #[cfg(all( feature = "hot-reload", @@ -127,8 +126,6 @@ fn launch_with_window(window: View<'static, Doc>) { }); } - - // the move to winit wants us to use a struct with a run method instead of the callback approach // we want to just keep the callback approach for now #[allow(deprecated)] @@ -194,7 +191,7 @@ fn launch_with_window(window: View<'static, Doc>) { #[cfg(feature = "accesskit")] UserEvent::Accessibility(accessibility_event) => { if let Some(window) = windows.get_mut(&accessibility_event.window_id) { - window.handle_accessibility_event(&accessibility_event); + window.handle_accessibility_event(&accessibility_event.window_event); } } #[cfg(all( diff --git a/packages/dioxus-blitz/src/waker.rs b/packages/dioxus-blitz/src/waker.rs index 1fd5faf2..9398dd67 100644 --- a/packages/dioxus-blitz/src/waker.rs +++ b/packages/dioxus-blitz/src/waker.rs @@ -15,7 +15,7 @@ pub enum UserEvent { /// An accessibility event from `accesskit`. #[cfg(feature = "accesskit")] Accessibility(Arc), - + /// A hotreload event, basically telling us to update our templates. #[cfg(all( feature = "hot-reload", @@ -33,7 +33,6 @@ impl From for UserEvent { } } - #[derive(Debug, Clone)] pub enum EventData { Poll, diff --git a/packages/dioxus-blitz/src/window.rs b/packages/dioxus-blitz/src/window.rs index 9e07cc08..e285c44d 100644 --- a/packages/dioxus-blitz/src/window.rs +++ b/packages/dioxus-blitz/src/window.rs @@ -278,8 +278,42 @@ impl<'a, Doc: DocumentLike> View<'a, Doc> { } #[cfg(feature = "accesskit")] - pub fn handle_accessibility_event(&mut self, event: &accesskit_winit::Event) { - todo!() + pub fn handle_accessibility_event(&mut self, event: &accesskit_winit::WindowEvent) { + let Some(ref mut state) = self.state else { + return; + }; + + match event { + accesskit_winit::WindowEvent::InitialTreeRequested => { + let doc = self.renderer.dom.as_ref(); + let root = doc.root_node(); + + let mut window = accesskit::NodeBuilder::new(accesskit::Role::Window); + + let mut text = accesskit::NodeBuilder::new(accesskit::Role::StaticText); + + text.set_name(dbg!(doc.get_node(root.children[0]).unwrap().text_content())); + window.push_child(accesskit::NodeId(1)); + + let tree = accesskit::Tree::new(accesskit::NodeId(0)); + let tree_update = accesskit::TreeUpdate { + nodes: vec![ + (accesskit::NodeId(0), window.build()), + (accesskit::NodeId(1), text.build()), + ], + tree: Some(tree), + focus: accesskit::NodeId(1), + }; + + state.adapter.update_if_active(|| tree_update) + } + accesskit_winit::WindowEvent::AccessibilityDeactivated => { + // TODO + } + accesskit_winit::WindowEvent::ActionRequested(_action) => { + // TODO + } + } } pub fn resume(