| Crates.io | compo-platform-loop |
| lib.rs | compo-platform-loop |
| version | 0.1.3 |
| created_at | 2025-10-17 04:12:46.968935+00 |
| updated_at | 2025-10-22 19:33:14.562663+00 |
| description | Cross-platform event loop implementation for the Compo declarative and reactive component framework |
| homepage | |
| repository | https://github.com/mzdk100/compo-platform-loop.git |
| max_upload_size | |
| id | 1887100 |
| size | 53,299 |
A cross-platform event loop implementation for the Compo declarative and reactive component framework. This library provides platform-specific event loop integration for Windows, macOS, iOS, and Android, enabling Compo applications to run natively on different operating systems.
| Platform | Status | Event Loop Implementation |
|---|---|---|
| Windows | ✅ | Win32 Message Loop |
| macOS | ✅ | NSRunLoop with NSTimer |
| iOS | ✅ | NSRunLoop with NSTimer |
| Android | ✅ | JNI with Java MainLoop |
Add this to your Cargo.toml:
cargo add compo compo-platform-loop
use compo::prelude::*;
use compo_platform_loop::prelude::run;
use tracing::info;
#[component]
async fn hello() {
println!("Hello, world!");
info!("Hello, world!");
}
#[cfg(not(target_os = "android"))]
fn main() {
run(hello);
}
#[cfg(target_os = "android")]
fn main(vm: jni::JavaVM) {
run(vm, hello);
}
The repository includes examples for different platforms:
cd examples/desktop
cargo run
cd examples/android
# See examples/android/README.md for detailed setup instructions
./run.sh # or run.bat on Windows
cd examples/ios
# See examples/ios/README.md for detailed setup instructions
# Open CompoPlatformLoopExample.xcodeproj in Xcode and run
PeekMessageW for non-blocking message pollingWM_QUIT message for graceful shutdownNSRunLoop with NSTimer for periodic runtime pollingNSApplication for native app lifecycleNSApplicationNSRunLoop with NSTimer for runtime pollingMainLoop class handles the Android event looprun FunctionThe main entry point for starting the platform-specific event loop:
// For most platforms
pub fn run<'a, C, F>(entry: F)
where
C: Component<'a> + 'a,
F: AsyncFn(Weak<C>) + 'a,
// For Android
pub fn run<C, F>(vm: JavaVM, entry: F)
where
C: Component<'static> + 'static,
F: AsyncFn(Weak<C>) + 'static,
cargo build --release
Requires Android NDK and appropriate toolchain setup:
cargo apk2 build --release
Requires Xcode and iOS toolchain:
cargo build --release --target aarch64-apple-ios
Contributions are welcome! Please feel free to submit issues and pull requests.
Apache-2.0