Skip to main content

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;
30mod event;
31mod filter;
32mod host;
33mod keyboard;
34mod message;
35mod plugin;
36mod reconcile;
37mod registry;
38mod request;
39mod scroll;
40mod transition;
41mod ts_codegen;
42mod ui_map;
43
44// The native JS host (embedded V8 / deno_core on a dedicated thread). Exposed for
45// advanced use (custom integrations, headless tests). The web target has no such
46// thread — React runs in the browser's own engine — so this module is absent there.
47#[cfg(not(target_arch = "wasm32"))]
48pub mod js_thread;
49pub mod protocol;
50
51// The animation engine and the canvas/portal/surface host elements. Public
52// modules so consumers can reach their full APIs; the most-used items are also
53// re-exported at the crate root below.
54pub mod animations;
55pub mod canvas;
56pub mod portal;
57pub mod surface;
58
59pub use anchor::{Anchor, AnchorScaling, Anchored};
60pub use animations::ReactUiAnimationsPlugin;
61pub use bevy_react_macros::{react_event, react_message, react_request};
62pub use canvas::CanvasSurface;
63pub use event::{ReactEvent, ReactEvents};
64pub use message::{ReactAppExt, ReactMessage, ReactPayload};
65pub use plugin::{Fonts, PointerCapture, PointerCaptureSet, ReactUiPlugin};
66pub use portal::{
67    PortalCamera, RenderMode, RenderTarget, RenderTargetSpec, RenderTargets, Resolution,
68};
69pub use reconcile::OpApplyStats;
70pub use request::{RawRequest, ReactRequest, Request, RequestEvent, Responder};
71pub use surface::{SurfacePointer, SurfaceSpec, SurfaceVirtualPointer, Surfaces, UvChannel};