Compo Platform Loop
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.
Features
- Cross-Platform Support: Native event loop integration for Windows, macOS, iOS, and Android
- Compo Integration: Seamlessly integrates with the Compo component framework
- Platform-Specific Optimizations: Uses native APIs for optimal performance on each platform
- Async Runtime: Built on Compo's single-threaded async runtime for high performance
- Zero Dependencies: Minimal external dependencies, leveraging platform-native APIs
Platform Support
| Platform | Status | Event Loop Implementation |
|---|---|---|
| Windows | ✅ | Win32 Message Loop |
| macOS | ✅ | NSRunLoop with NSTimer |
| iOS | ✅ | NSRunLoop with NSTimer |
| Android | ✅ | JNI with Java MainLoop |
Quick Start
Installation
Add this to your Cargo.toml:
cargo add compo compo-platform-loop
Basic Usage
use *;
use run;
use info;
async
Examples
The repository includes examples for different platforms:
Desktop (Windows/macOS/Linux)
Android
# See examples/android/README.md for detailed setup instructions
iOS
# See examples/ios/README.md for detailed setup instructions
# Open CompoPlatformLoopExample.xcodeproj in Xcode and run
Platform-Specific Details
Windows
- Uses Win32
PeekMessageWfor non-blocking message polling - Integrates with Windows message pump for native window handling
- Supports
WM_QUITmessage for graceful shutdown
macOS
- Uses
NSRunLoopwithNSTimerfor periodic runtime polling - Integrates with
NSApplicationfor native app lifecycle - Runs on the main thread with 0.01s polling interval
iOS
- Similar to macOS but without
NSApplication - Uses
NSRunLoopwithNSTimerfor runtime polling - Designed for iOS app lifecycle integration
Android
- Uses JNI to bridge between Rust and Java
- Java
MainLoopclass handles the Android event loop - Native methods registered for runtime polling
API Reference
run Function
The main entry point for starting the platform-specific event loop:
// For most platforms
Building for Different Platforms
Desktop
Android
Requires Android NDK and appropriate toolchain setup:
iOS
Requires Xcode and iOS toolchain:
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
License
Apache-2.0
Related Projects
- Compo - The core declarative and reactive component framework
- cargo-apk2 - A command-line tool for easily building Android applications with Cargo