Current section

Files

Jump to
dala android jni dala_beam.h
Raw

android/jni/dala_beam.h

// dala_beam.h — Public API for dala's BEAM launcher and UI initialisation.
// Include this in your app's beam_jni.c stub.
#ifndef DALA_BEAM_H
#define DALA_BEAM_H
#include <jni.h>
// Call from JNI_OnLoad (main thread).
// bridge_class: e.g. "com/myapp/DalaBridge"
void dala_ui_cache_class(JNIEnv* env, const char* bridge_class);
// Send a tap event to the BEAM process registered for handle.
// Called from the app's Java_..._DalaBridge_nativeSendTap JNI stub.
void dala_send_tap(int handle);
// Send a {:change, tag, value} event. Called from the app's
// Java_..._DalaBridge_nativeSendChange* JNI stubs.
void dala_send_change_str(int handle, const char* utf8);
void dala_send_change_bool(int handle, int bool_val); // 0 = false, 1 = true
void dala_send_change_float(int handle, double value);
// Send {:focus, tag}, {:blur, tag}, {:submit, tag} events.
void dala_send_focus(int handle);
void dala_send_blur(int handle);
void dala_send_submit(int handle);
// Send {:select, tag} for pickers, menus, segmented controls.
void dala_send_select(int handle);
// Send {:compose, tag, %{text, phase}} for IME composition events on text
// fields. phase is "began" | "updating" | "committed" | "cancelled". Apps
// that observe this can implement commit-only behaviour for CJK input
// (ignore on_change while composing, replace text on :committed).
void dala_send_compose(int handle, const char* text, const char* phase);
// ── Gesture senders (Batch 4) ────────────────────────────────────────────
// Called from beam_jni.c JNI stubs when Compose's gesture detector fires.
// Per-widget opt-in — only nodes with the corresponding registered handle emit.
void dala_send_long_press(int handle);
void dala_send_double_tap(int handle);
void dala_send_swipe_left(int handle);
void dala_send_swipe_right(int handle);
void dala_send_swipe_up(int handle);
void dala_send_swipe_down(int handle);
// Direction-aware: emits {:swipe, tag, direction_atom} where direction is
// "left" | "right" | "up" | "down".
void dala_send_swipe_with_direction(int handle, const char* direction);
// ── Batch 5 Tier 1: high-frequency scroll/drag/pinch/rotate/pointer ─────
// Throttling and delta-thresholding are applied native-side BEFORE these
// fire — by the time they're called, the BEAM crossing is justified.
// Defaults (when no explicit config): scroll 33ms/1px, drag 16ms/1px,
// pinch 16ms/0.01, rotate 16ms/1°, pointer_move 33ms/4px.
void dala_set_throttle_config(int handle,
int throttle_ms, int debounce_ms,
double delta_threshold,
int leading, int trailing);
// Phase is "began" | "dragging" | "decelerating" | "ended"
void dala_send_scroll(int handle,
double x, double y,
double dx, double dy,
double vx, double vy,
const char* phase);
void dala_send_drag(int handle,
double x, double y,
double dx, double dy,
const char* phase);
void dala_send_pinch(int handle, double scale, double velocity, const char* phase);
void dala_send_rotate(int handle, double degrees, double velocity, const char* phase);
void dala_send_pointer_move(int handle, double x, double y);
// ── Batch 5 Tier 2: semantic single-fire scroll events ──
void dala_send_scroll_began(int handle);
void dala_send_scroll_ended(int handle);
void dala_send_scroll_settled(int handle);
void dala_send_top_reached(int handle);
void dala_send_scrolled_past(int handle);
// Signal a system back gesture to the BEAM screen process.
// The BEAM pops the nav stack or calls exit_app if at root.
void dala_handle_back(void);
// Call from nativeSetActivity.
void dala_init_bridge(JNIEnv* env, jobject activity);
// Call from nativeStartBeam.
// app_module: Erlang module name, e.g. "dala_demo"
void dala_start_beam(const char* app_module);
// Update the startup status shown on screen while BEAM is initialising.
// dala_set_startup_error stalls the screen with an error message (does not crash).
// Both are safe to call from any thread; no-op if DalaBridge lacks the method.
void dala_set_startup_phase(const char* phase);
void dala_set_startup_error(const char* error);
// Global JVM pointer — defined in dala_beam.c, extern'd for dala_nif.c.
extern JavaVM* g_jvm;
extern jobject g_activity;
// ── Device capability delivery functions ─────────────────────────────────
// Called from beam_jni.c JNI stubs when Kotlin delivers async results.
// pid is an ErlNifPid passed as jlong through Kotlin.
void dala_deliver_atom2(jlong pid, const char* a1, const char* a2);
void dala_deliver_atom3(jlong pid, const char* a1, const char* a2, const char* a3);
void dala_deliver_location(jlong pid, double lat, double lon, double acc, double alt);
void dala_deliver_motion(jlong pid, double ax, double ay, double az,
double gx, double gy, double gz, long long ts);
void dala_deliver_file_result(jlong pid, const char* event, const char* sub,
const char* json_items);
void dala_deliver_push_token(jlong pid, const char* token);
void dala_deliver_notification(jlong pid, const char* json);
void dala_set_launch_notification(const char* json);
// Deliver {:alert, action_atom} to the registered :dala_screen process.
// Called from beam_jni.c when a dialog button is tapped.
void dala_deliver_alert_action(const char* action);
// Deliver {:component_event, event, payload_json} to a native view component process.
// Called from beam_jni.c when Kotlin fires a component event via the send callback.
void dala_send_component_event(int handle, const char* event, const char* payload_json);
// Deliver {:dala_device, :color_scheme_changed, :light | :dark} to the
// dispatcher pid registered via Dala.Device. Called from beam_jni.c's
// nativeNotifyColorScheme when MainActivity sees a uiMode flip.
// `scheme` must be "light" or "dark".
void dala_send_color_scheme_changed(const char* scheme);
#endif // DALA_BEAM_H