1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use dioxus::prelude::*;
use freya_core::prelude::EventMessage;
use freya_elements::{
    elements as dioxus_elements,
    events::{
        keyboard::{
            Key,
            Modifiers,
        },
        KeyboardEvent,
    },
};
use freya_hooks::{
    use_init_native_platform,
    use_platform,
};

#[allow(non_snake_case)]
#[component]
pub fn NativeContainer(children: Element) -> Element {
    let mut native_platform = use_init_native_platform();
    let platform = use_platform();

    let onglobalkeydown = move |e: KeyboardEvent| {
        let allowed_to_navigate = native_platform.navigation_mark.peek().allowed();
        if e.key == Key::Tab && allowed_to_navigate {
            if e.modifiers.contains(Modifiers::SHIFT) {
                platform
                    .send(EventMessage::FocusPrevAccessibilityNode)
                    .unwrap();
            } else {
                platform
                    .send(EventMessage::FocusNextAccessibilityNode)
                    .unwrap();
            }
        } else {
            native_platform.navigation_mark.write().set_allowed(true)
        }
    };

    rsx!(rect {
        width: "100%",
        height: "100%",
        onglobalkeydown,
        {children}
    })
}