uzor-mobile
Mobile platform backend for uzor supporting iOS and Android.
Overview
This crate provides the mobile platform implementation for uzor, enabling touch-first applications on iOS and Android devices. It implements all platform traits with mobile-specific features like:
- Touch Input: Multi-touch support with gesture recognition
- Virtual Keyboard: IME integration for text input
- Haptic Feedback: Tactile feedback for UI interactions
- Safe Areas: Proper handling of notches, home indicators, and system bars
- Screen Orientation: Detect and respond to orientation changes
- Native Integration: Clipboard, URL opening, theme detection
Architecture
uzor-mobile/
├── lib.rs # Main MobilePlatform struct + trait implementations
├── android.rs # Android-specific backend (NDK + JNI)
├── ios.rs # iOS-specific backend (UIKit + Objective-C)
└── common.rs # Shared gesture recognition utilities
Platform Abstraction
The crate uses conditional compilation to provide a unified API across platforms:
use AndroidBackend;
use IosBackend;
When compiled for non-mobile platforms (e.g., during desktop development), a stub backend is used that compiles but returns placeholder values.
Usage
Basic Setup
use MobilePlatform;
use ;
Touch Event Handling
use PlatformEvent;
Mobile-Specific Features
Safe Area Insets
let = platform.safe_area_insets;
println!;
println!;
Haptic Feedback
use HapticStyle;
// Light tap feedback
platform.haptic_feedback;
// Success feedback
platform.haptic_feedback;
// Error feedback
platform.haptic_feedback;
Screen Orientation
use ScreenOrientation;
match platform.orientation
Virtual Keyboard (IME)
use ImeSupport;
// Show keyboard when text field is focused
platform.set_ime_allowed;
platform.set_ime_position;
// Hide keyboard when done
platform.set_ime_allowed;
Implemented Traits
PlatformBackend
Core window and event management:
capabilities()- Returns mobile capabilitiescreate_window()- Creates the app window (single window on mobile)poll_event()- Gets platform eventsrequest_redraw()- Requests screen redrawwindow_size()- Gets screen dimensionsscale_factor()- Gets device pixel ratio
Clipboard
Native clipboard integration:
get_text()- Read clipboard textset_text()- Write clipboard text
SystemIntegration
System-level operations:
open_url()- Opens URL in browserget_system_theme()- Gets light/dark modeget_scale_factor()- Gets display scaling
CursorManagement
Stub implementation (mobile devices don't have cursors):
set_cursor()- No-op (tracks state for compatibility)set_cursor_visible()- No-opset_cursor_locked()- Returns NotSupported error
ImeSupport
Virtual keyboard integration:
set_ime_position()- Sets keyboard position hintset_ime_allowed()- Shows/hides virtual keyboardset_ime_cursor_area()- Sets text field cursor area
RenderSurface
Surface for rendering:
raw_window_handle()- Returns None (platform-specific access needed)surface_size()- Gets render surface dimensionssurface_scale_factor()- Gets surface scaling
Platform Capabilities
Mobile platforms have these characteristics:
PlatformCapabilities
Feature Flags
android
Enables Android-specific functionality:
[]
= { = "0.1.0", = ["android"] }
Provides:
- Android NDK integration
- JNI bindings for Java APIs
- Android-specific clipboard, theme detection, etc.
ios
Enables iOS-specific functionality:
[]
= { = "0.1.0", = ["ios"] }
Provides:
- UIKit integration
- Objective-C bindings
- iOS-specific clipboard, theme detection, etc.
Current Implementation Status
✅ Complete
- Platform trait implementations
- Gesture recognition framework
- Feature flag structure
- Stub backend (compiles on desktop)
- Comprehensive tests
🚧 Stub Implementations
The following require native integration:
Android (via NDK + JNI)
- Get screen size from Display API
- Get density from DisplayMetrics
- Window insets from WindowInsets API
- Haptic feedback via Vibrator
- Touch event processing from native activity
- Clipboard via ClipboardManager
- URL opening via Intent.ACTION_VIEW
- Theme detection via Configuration
- Virtual keyboard via InputMethodManager
iOS (via UIKit + Objective-C)
- Get screen size from UIScreen
- Get scale from UIScreen.scale
- Safe area insets from UIWindow
- Haptic feedback via UIImpactFeedbackGenerator
- Touch event processing from UIApplication
- Clipboard via UIPasteboard
- URL opening via UIApplication.openURL
- Theme detection via UITraitCollection
- Virtual keyboard via UITextField
Next Steps
-
Android Native Integration
- Setup NDK activity lifecycle
- Implement JNI wrappers for Java APIs
- Handle touch events from native activity
-
iOS Native Integration
- Setup UIKit integration
- Implement Objective-C bindings
- Handle touch events from UIApplication
-
Rendering Integration
- Provide CAMetalLayer access (iOS)
- Provide ANativeWindow access (Android)
- Integrate with wgpu/Vello rendering
Gesture Recognition
The common module provides a gesture recognizer for high-level touch gestures:
use ;
let mut recognizer = new;
// Feed touch events
recognizer.touch_start;
recognizer.touch_move;
if let Some = recognizer.touch_end
Supported gestures:
- Tap: Quick touch and release
- Long Press: Touch held for duration
- Swipe: Fast directional movement
- Pinch: Two-finger zoom in/out
- Rotation: Two-finger rotation (TODO)
Development Notes
Compiling for Desktop
During development, you can compile on desktop platforms. The stub backend will be used:
Compiling for Android
Requires Android NDK and cargo-mobile2:
# Install cargo-mobile2
# Build for Android
Compiling for iOS
Requires Xcode and cargo-mobile2:
# Build for iOS
Testing
Run tests:
Test with feature flags:
Related Crates
uzor-core- Platform-agnostic uzor coreuzor-desktop- Desktop platform backend (winit)uzor-web- Web platform backend (WASM)