bevy_react/lib.rs
1#![cfg_attr(docsrs, feature(doc_cfg))]
2//! Drive `bevy_ui` from a React app running on an embedded V8 (deno_core)
3//! runtime. The bridge is deliberately tiny: two channels and two ops connect a
4//! dedicated JS thread to Bevy.
5//!
6//! The public entry point is [`ReactUiPlugin`]: add it to your Bevy `App`,
7//! pointing it at a built JS bundle, and the library owns the JS thread, the
8//! op/event channels, the UI root, and (optionally) hot reload.
9//!
10//! ```no_run
11//! use bevy::prelude::*;
12//! use bevy_react::ReactUiPlugin;
13//!
14//! App::new()
15//! .add_plugins(DefaultPlugins)
16//! .add_plugins(ReactUiPlugin::new("path/to/dist/app.js"))
17//! .run();
18//! ```
19//!
20//! The `protocol` and `js_thread` modules are exposed for advanced use (custom
21//! integrations, headless tests); most users only need [`ReactUiPlugin`].
22
23// Let the `#[react_message]` macro's generated `::bevy_react::…` paths resolve
24// inside this crate too (e.g. in our own tests and examples).
25extern crate self as bevy_react;
26
27mod anchor;
28mod bridge;
29mod cursor;
30// Devtools diagnostics sinks (invalid style/prop values). Always declared —
31// the protocol/apply call sites are unconditional — but its real implementation
32// only exists with the `devtools` feature on a debug build; otherwise every fn
33// is an inline no-op stub.
34mod diag;
35// The devtools inspector. A feature-gated module (not a separate
36// crate — it needs `JsBridge` and friends, which stay private) that is fully
37// compiled out unless the `devtools` cargo feature (a default feature) is on.
38// Crate-internal: `ReactUiPlugin` auto-registers `DevtoolsPlugin` and exposes
39// the only knob (`ReactUiPlugin::devtools`).
40#[cfg(feature = "devtools")]
41mod devtools;
42mod event;
43mod filter;
44mod host;
45mod keyboard;
46mod message;
47mod pick_clip;
48mod plugin;
49mod reconcile;
50mod registry;
51mod request;
52mod scroll;
53mod scrollbar;
54mod transition;
55mod ts_codegen;
56mod ui_map;
57mod window;
58
59// The native JS host (embedded V8 / deno_core on a dedicated thread). Exposed for
60// advanced use (custom integrations, headless tests). The web target has no such
61// thread — React runs in the browser's own engine — so this module is absent there.
62#[cfg(not(target_arch = "wasm32"))]
63pub mod js_thread;
64pub mod protocol;
65
66// The animation engine and the canvas/portal/surface host elements. Public
67// modules so consumers can reach their full APIs; the most-used items are also
68// re-exported at the crate root below.
69pub mod animations;
70pub mod canvas;
71pub mod portal;
72pub mod surface;
73
74pub use anchor::{Anchor, AnchorScaling, Anchored};
75pub use animations::ReactUiAnimationsPlugin;
76pub use bevy_react_macros::{react_event, react_message, react_request};
77pub use canvas::CanvasSurface;
78#[cfg(feature = "devtools")]
79#[cfg_attr(docsrs, doc(cfg(feature = "devtools")))]
80pub use devtools::DevtoolsConfig;
81pub use event::{ReactEvent, ReactEvents};
82pub use message::{ReactAppExt, ReactMessage, ReactPayload};
83pub use plugin::{Fonts, PointerCapture, PointerCaptureSet, ReactUiPlugin};
84pub use portal::{
85 PortalCamera, RenderMode, RenderTarget, RenderTargetSpec, RenderTargets, Resolution,
86};
87pub use reconcile::OpApplyStats;
88pub use request::{RawRequest, ReactRequest, Request, RequestEvent, Responder};
89pub use scrollbar::{
90 HorizontalEdge, ScrollbarConfig, ScrollbarPartStyle, ScrollbarPosition, ScrollbarSpec,
91 VerticalEdge,
92};
93pub use surface::{SurfacePointer, SurfaceSpec, SurfaceVirtualPointer, Surfaces, UvChannel};