Tutorial: Building a Mobile App (iOS & Android)

Write your mobile user interface and business logic once in Nyx, and deploy to iOS and Android with 100% native platform performance.

1. Initializing the Mobile Project

nyx init nyx-mobile-app --template mobile
cd nyx-mobile-app

2. Building the Mobile Screen Layout

Nyx provides native mobile widgets that adapt to iOS Cupertino and Android Material Design 3 design languages:

import std.mobile
import std.ui
import std.gis.geo

pub fn main() {
    let mut app = mobile.create_app("Nyx Field Explorer")

    // Navigation Scaffold
    let mut scaffold = mobile.Scaffold::new()
        .with_top_app_bar(mobile.AppBar::title("Field Inspector"))
        .with_bottom_nav([
            mobile.NavItem::icon("map", "Map"),
            mobile.NavItem::icon("sensors", "Sensors"),
            mobile.NavItem::icon("settings", "Settings")
        ])

    // Touch & Location Sensor Interaction
    let location_card = ui.Card::elevated("Current Coordinates")
        .with_padding(12.0)
        .on_tap(|| {
            let coords = mobile.sensors.get_current_location()
            mobile.toast("Acquired GPS: " + coords.to_string())
        })

    scaffold.set_body(location_card)
    app.run(scaffold)
}

3. Accessing Mobile Hardware Sensors

Nyx provides direct bindings to mobile OS device APIs without bridging overhead:

import std.mobile.sensors

// Gyroscope & Accelerometer streaming
sensors.watch_accelerometer(|x, y, z| {
    if z < 0.0 {
        mobile.vibrate(50) // Haptic feedback on device flip
    }
})

4. Building and Deploying

Android Build (.apk & .aab):

# Build debug APK for connected Android phone
nyx build --target aarch64-linux-android --bundle-apk

# Generate release Android App Bundle for Google Play
nyx package --target android --release

iOS Build (.ipa & Xcode Project):

# Build iOS Framework and launch in iOS Simulator
nyx run --target aarch64-apple-ios-sim

# Generate signed release IPA for App Store submission
nyx package --target ios --release --sign "Apple Development: Team ID"