Your First App
This guide takes you from an empty directory to a native app running on your
phone, then changes it while it runs. It assumes you finished
Installation. Everything happens through the pam CLI; inside
a PAM Native project the short commands (pam dev, pam run, pam build) are
routed to the PAM Native toolchain that Composer installed in the project.
Create a project
Section titled “Create a project”Run pam init with the native template:
pam init acme --template nativeIn an interactive terminal PAM asks four questions. Press Enter to keep a default:
| Prompt | Default | Notes |
|---|---|---|
| Application name | the directory name | Shown under the launcher icon. |
| Application ID | app.pam.<directory> |
Reverse-DNS identifier, at least two lowercase segments. It becomes the Android package and the iOS bundle identifier. |
| Starter | 1 Blank |
Used by the native-ui template (see below). |
| Platforms | all |
android, ios, android-tv, a comma list, or all. |
For scripts and CI, pass the answers as options:
pam init acme --template native \ --name "Acme" \ --application-id com.example.acme \ --platform android,ios \ --no-interactionpam init writes the project, runs Composer to install pushinbr/pam-native and
prints the next command. Add --no-install to only write the files.
Start from the official UI kit
Section titled “Start from the official UI kit”The native-ui template also installs PAM Native UI, a
library of ready-made, themed components, and writes the first screen as a
single-file .pam component. With this template, --starter chooses the first
screen:
pam init acme --template native-ui --starter tabs| Starter | First screen |
|---|---|
blank |
A minimal screen. |
tabs |
Bottom-tab navigation. |
auth |
A sign-in form. |
ecommerce |
A product catalog. |
chat |
A conversation list. |
showcase |
A tour of the component library. |
Prepare the toolchain
Section titled “Prepare the toolchain”Enter the project and let PAM install anything that is missing:
cd acmepam doctor --fixpam doctorThe first run downloads the device PHP runtimes and the prebuilt renderer, and
installs the Android SDK components. It is a one-time step per machine and
pam-native version.
Run on Android
Section titled “Run on Android”Connect a phone with USB debugging enabled (Settings → Developer options), or start an emulator from Android Studio’s Device Manager. Then list the targets PAM can see:
pam devicespam devices prints the Android devices from adb devices -l and, on macOS, the
available iOS simulators. Now start a development session:
pam devpam dev builds a debug APK for the connected device’s ABI only (so the first
build stays fast), installs it, launches it, and keeps a sync server running for
hot reload. Leave it running.
To install and launch once without the sync server, use pam run:
pam runRun on the iOS Simulator
Section titled “Run on the iOS Simulator”On a Mac, boot a simulator (Xcode → Open Developer Tool → Simulator), then:
pam ios:devpam ios:dev prepares the Xcode host, builds, installs and launches the app on the
booted simulator, then keeps the hot reload server running. pam ios:run installs
and launches once.
Make your first change
Section titled “Make your first change”Open src/Hello.php. It is a plain PHP class that returns a tree of native
components:
<?php
declare(strict_types=1);
namespace App;
use Pam\Native\Attributes\State;use Pam\Native\Component;use Pam\Native\Element;use Pam\Native\Style;use Pam\Native\UI\Button;use Pam\Native\UI\Column;use Pam\Native\UI\SafeAreaView;use Pam\Native\UI\Screen;use Pam\Native\UI\Text;
final class Hello extends Component{ #[State] public int $count = 0;
public function render(): Element { return Screen::make( SafeAreaView::make( Column::make( Text::make('Hello, Alice') ->style(new Style(textColor: 0xFFF8FAFC, fontSize: 28, fontWeight: 700)), Button::make("Taps: {$this->count}") ->style(new Style( backgroundColor: 0xFF4ADE80, textColor: 0xFF052E16, minHeight: 48, paddingHorizontal: 16, borderRadius: 12, )) ->onPress($this->increment(...)), )->style(new Style(flexGrow: 1, padding: 24, gap: 16)), )->style(new Style(flexGrow: 1)), )->style(new Style(flexGrow: 1, backgroundColor: 0xFF0F172A)); }
public function increment(): void { $this->count++; }}Tap the button a few times, then change the greeting and save. Within about a
second the text changes on the device, and the tap count survives: properties
marked #[State] are carried across hot reloads. The terminal shows every step:
Android change e7a2501762af: 1 file changed (src/Hello.php), 2.1 KiB to send, indexed in 12 msAndroid reload e7a2501762af: screen updated in 240 ms, 1 file (2.1 KiB) applied; change to screen 410 msA few things to notice in this component:
- Assigning
$this->count++inside an event handler schedules a render. PAM compares the new tree with the previous one and updates only the button’s text on the native side. SafeAreaViewkeeps the content clear of the status bar, notch, navigation bar and home indicator. Every screen should have one; see Safe Areas.- Colors are ARGB integers (
0xFF0F172A). You can also write styles as scoped CSS in single-file components; see Styling.
If you save a syntax error, the app keeps running and opens the error overlay with the file and line. Fix the file and save again: the overlay clears by itself.
Write it as a single-file component
Section titled “Write it as a single-file component”The same screen can live in one .pam file with a template and scoped styles.
Generate one and compare:
pam make:screen Profile<?php
declare(strict_types=1);
namespace App\Screens;
use Pam\Native\Attributes\Action;use Pam\Native\Attributes\State;use Pam\Native\Component;
final class Profile extends Component{ #[State] public int $count = 0;
#[Action] public function increment(): void { $this->count++; }}?>
<template language="2"> <Screen> <SafeAreaView class="flex-1 surface"> <Column class="flex-1 p-6 gap-4"> <Text class="text-primary" height="48" fontSize="28" fontWeight="700">Profile</Text> <Button class="accent" height="52" @press="increment" accessibilityLabel="Profile counter"> Count: {{ $count }} </Button> </Column> </SafeAreaView> </Screen></template>To show it, change the entry point to run it:
<?php
declare(strict_types=1);
use App\Screens\Profile;use Pam\Native\App;
require __DIR__.'/vendor/autoload.php';
App::components(__DIR__.'/src', __DIR__.'/.pam-native/components');App::theme(\Pam\Native\Theme::pamLab());App::run(App::make(Profile::class));Keep the App::theme() line from the generated index.php: utility classes such
as text-primary and surface resolve against the active theme. See
Theming.
pam make:component and pam make:feature generate a reusable component and a
whole feature folder (screen, component, service, routes and a test) the same way.
The Components guide covers both authoring styles in depth.
Stop the session
Section titled “Stop the session”Press Ctrl+C in the terminal running pam dev. PAM stops the app first and then
removes only the port mapping it created, so other apps and devices are left
alone.
Next steps
Section titled “Next steps”- Project Structure: every file
pam initcreated. - Navigation: add screens and routes.
- Architecture: how PHP, Rust and the native views cooperate.
- Testing: test components without a device.