Selaa lähdekoodia

fix focus events subscriptions

Evan Almloff 2 vuotta sitten
vanhempi
commit
9121d68d84
2 muutettua tiedostoa jossa 6 lisäystä ja 4 poistoa
  1. 1 0
      packages/tui/Cargo.toml
  2. 5 4
      packages/tui/src/focus.rs

+ 1 - 0
packages/tui/Cargo.toml

@@ -31,6 +31,7 @@ rustc-hash = "1.1.0"
 anymap = "1.0.0-beta.2"
 futures-channel = "0.3.25"
 shipyard = { version = "0.6.2", features = ["proc", "std"], default-features = false }
+once_cell = "1.17.1"
 
 [dev-dependencies]
 dioxus = { path = "../dioxus" }

+ 5 - 4
packages/tui/src/focus.rs

@@ -7,6 +7,8 @@ use dioxus_native_core::{
     Dependancy, NodeId, RealDom, SendAnyMap, State,
 };
 use dioxus_native_core_macro::partial_derive_state;
+use once_cell::sync::Lazy;
+use rustc_hash::FxHashSet;
 use shipyard::Component;
 use shipyard::{Get, ViewMut};
 
@@ -108,9 +110,7 @@ impl State for Focus {
             } else if node_view
                 .listeners()
                 .and_then(|mut listeners| {
-                    listeners
-                        .any(|l| FOCUS_EVENTS.binary_search(&l).is_ok())
-                        .then_some(())
+                    listeners.any(|l| FOCUS_EVENTS.contains(&l)).then_some(())
                 })
                 .is_some()
             {
@@ -140,7 +140,8 @@ impl State for Focus {
     }
 }
 
-const FOCUS_EVENTS: &[&str] = &["keydown", "keypress", "keyup"];
+static FOCUS_EVENTS: Lazy<FxHashSet<&str>> =
+    Lazy::new(|| ["keydown", "keypress", "keyup"].into_iter().collect());
 const FOCUS_ATTRIBUTES: &[&str] = &["tabindex"];
 
 pub(crate) struct FocusState {