Expand description
Drive bevy_ui from a React app running on an embedded V8 (deno_core)
runtime. The bridge is deliberately tiny: two channels and two ops connect a
dedicated JS thread to Bevy.
The public entry point is ReactUiPlugin: add it to your Bevy App,
pointing it at a built JS bundle, and the library owns the JS thread, the
op/event channels, the UI root, and (optionally) hot reload.
use bevy::prelude::*;
use bevy_react::ReactUiPlugin;
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(ReactUiPlugin::new("path/to/dist/app.js"))
.run();The protocol and js_thread modules are exposed for advanced use (custom
integrations, headless tests); most users only need ReactUiPlugin.
Re-exports§
pub use animations::ReactUiAnimationsPlugin;pub use canvas::CanvasSurface;pub use portal::PortalCamera;pub use portal::RenderMode;pub use portal::RenderTarget;pub use portal::RenderTargetSpec;pub use portal::RenderTargets;pub use portal::Resolution;pub use surface::SurfacePointer;pub use surface::SurfaceSpec;pub use surface::SurfaceVirtualPointer;pub use surface::Surfaces;
Modules§
- animations
ReactUiAnimationsPlugin— a Reanimated-style animation engine forbevy-react.- canvas
- The
canvashost element: an arbitrary anti-aliased vector drawing surface. - js_
thread Non-WebAssembly - The dedicated JS thread: owns the V8 isolate, runs the React bundle, and exposes the ops that form the whole Rust<->JS boundary.
- portal
- The
portalhost element: a UI rectangle that displays an offscreen render target — the live (or snapshot) output of a Bevy camera drawing into a GPU texture. - protocol
- The wire protocol shared between the JS reconciler and the Bevy side.
- surface
- The
surfacehost element: the inverse ofcrate::portal. Where a portal draws an offscreen Bevy camera into the React UI, a surface renders a React UI subtree out into an offscreenImagethe app can drape over any 3D mesh/material (a diegetic monitor, a control panel, a curved hologram — with the app’s own shader on top).
Structs§
- Anchor
- The wire form of an
Anchored.node’sanchorprop: the Bevy entity to follow (asEntity::to_bits()), an optional world-space offset, and optional distance-based scaling. Pure-serde, like the rest ofcrate::protocol. - Anchor
Scaling - Distance-based scaling config for an anchored overlay. The applied scale is
clamp(1 + factor * (base_distance / distance - 1), min, max), so the overlay renders at scale 1 when the camera is exactlybase_distanceaway, grows as it gets closer, and shrinks farther out — bounded bymin/max. - Anchored
- Component stamped (by the main reconciler) on any
Anchored.node. Carries the followed entity, world-space offset, and optional distance scaling. RequiresVisibilityso the system can hide the overlay when its anchor is behind the camera, andUiTransformso it can apply the distance scale. - Fonts
- Fonts loaded from the plugin config, resolved to handles at startup. The
default backs every
<text>run; named entries are selected per element via thefontFamilystyle prop. Empty (unconfigured) → Bevy’s built-in font. - OpApply
Stats - Live instrumentation of the [
apply_js_ops] hot path. Updated once per frame that applies at least one reconciler op (empty frames leave it untouched), so a benchmark driver — or any consumer — can pollapplied_countto detect “my flushed batch has landed” and read the timing of the most recent batch. - Pointer
Capture - Whether the React UI currently owns the mouse pointer. Refreshed every frame
in
PointerCaptureSet; world-input systems (a 3D camera controller, picking, …) should consult it and ignore the mouse when it reports captured, so a UI drag or click doesn’t also drive the scene. - Pointer
Capture Set - System set in which
PointerCaptureis refreshed each frame. Order your world-input systems.after(PointerCaptureSet)so they see this frame’s state. - RawRequest
- The raw wire form of a request crossing JS → Bevy: a correlation
id, the requestname, and the JSON payload. Routed by [ReactRequestRegistry]. - React
Events - System param for sending
ReactEvents to the React app. - React
Message - A named, JSON-valued signal sent from the React app to Bevy.
- React
UiPlugin - Adds a React-driven
bevy_uilayer to a BevyApp. - Request
- What a request handler observes: the deserialized
payloadplus aResponderto reply with. Observe it withOn<Request<T>>. - Responder
- Replies to a single React request, correlated by id.
Enums§
- UvChannel
- Which of a mesh’s UV sets a surface texture is mapped to. Re-exported from
bevy_meshso apps pass the same value to the material’s*_channelfields and toSurfacePointer. An enum to define which UV attribute to use for a texture.
Traits§
- React
AppExt - Registers typed React message payloads on a Bevy
App. - React
Event - A typed payload Bevy sends to React as a named event. Out-only — it is never
deserialized on the Rust side, so it derives
Serialize(notDeserialize). - React
Payload - A typed payload a React
emit(NAME, value)call deserializes into. - React
Request - A typed request payload a React
request(NAME, value)call deserializes into, paired with the typed reply it resolves to. - Request
Event - Lets
ReactAppExt::add_react_request_handlerrecover the request typeTfrom anOn<Request<T>>observer, whose event type isRequest<T>.
Attribute Macros§
- react_
event - Turn a struct into a typed React event payload (a Bevy → React broadcast).
- react_
message - Turn a struct into a typed React message payload.
- react_
request - Turn a struct into a typed React request payload (a React → Bevy call that awaits a typed reply).