| Install | |
|---|---|
composer require nativemobile/laravel-mobile-ui |
|
| PHP: | ^8.2 |
<<<<<<< HEAD
A PHP-first mobile UI component library for Android WebView. Build reactive mobile interfaces with Laravel, Livewire 4, and Alpine.js.
✨ PHP-First Development - Write mobile UI entirely in PHP
⚡ Live Reactivity - Powered by Livewire 4 and Alpine.js
📱 Android WebView - Optimized for NativePHP and Android integration
🎨 Comprehensive Components - 20+ ready-to-use UI components
🔔 Push Notifications - Firebase FCM integration for Android
📐 Layout System - Flexible flex, grid, and stack layouts
⌨️ Form Components - Input, select, toggle, file upload with validation
🎯 Deep Linking - Navigate between app screens via notifications
composer require nativemobile/laravel-mobile-ui
php artisan vendor:publish --tag=mobile-ui-assets
php artisan vendor:publish --tag=mobile-ui-config
php artisan mobile-ui:install
php artisan mobile-ui:page home
<?php
use Livewire\Component;
use NativeMobile\LaravelMobileUI\MobileApp;
use NativeMobile\LaravelMobileUI\Components\{
AppBar, NavigationDrawer, BottomNavigation,
StackLayout, Button, TextView
};
class HomePage extends Component
{
public function render(): string
{
return MobileApp::make()
->appBar(
AppBar::make()
->title('Home')
->withDrawer()
)
->drawer(
NavigationDrawer::make()
->header('My App')
)
->content(
StackLayout::make()
->vertical()
->gap(16)
->children([
TextView::make('Welcome!')
->fontSize(24)
->fontWeight(600),
Button::make('Click Me')
->primary()
->onClick('handleClick'),
])
)
->render();
}
public function handleClick(): void
{
// Handle button click
}
}
| Component | Use Case |
|---|---|
| AppBar | Top navigation bar with title, drawer button, actions |
| NavigationDrawer | Side navigation menu |
| BottomNavigation | Bottom tab navigation |
| Modal | Dialog/popup overlays |
| StackLayout | Vertical/horizontal flex container |
| GridLayout | CSS Grid layout |
| FlexboxLayout | Low-level flexbox control |
| WrapLayout | Auto-wrapping container |
| Component | Description |
|---|---|
| TextInput | Text, email, password fields |
| SelectInput | Dropdown select |
| Toggle | Switch/checkbox input |
| FileUpload | Avatar, image, file upload modes |
| Form | Fluent form builder |
| Section | Field grouper with title/description |
| Component | Purpose |
|---|---|
| Button | 8 variants, 5 sizes, loading states |
| Link | Href navigation, external links |
| Card | 3 rendering modes (standard, stat, list) |
| TextView | Text display with styling |
| Image | Image display with lazy loading |
Use Livewire attributes for reactivity:
class SearchPage extends Component
{
public string $query = '';
public array $results = [];
#[Computed]
public function filteredResults()
{
return Post::where('title', 'like', "%{$this->query}%")->get();
}
public function updateQuery(string $query): void
{
$this->query = $query;
}
}
In your view:
TextInput::make('Search')
->wire:model('query')
->wire:debounce('500ms')
Send Firebase Cloud Messaging (FCM) notifications:
use NativeMobile\LaravelMobileUI\Services\PushNotification;
PushNotification::send(
$user,
title: 'Hello',
body: 'You have a new message',
url: '/messages'
);
See PUSH_NOTIFICATIONS.md for complete documentation.
Components dispatch Alpine.js events for custom handlers:
// Token received from Android
window.addEventListener('push-token-received', (event) => {
console.log('FCM Token:', event.detail);
});
// User tapped notification
window.addEventListener('push-notification-tapped', (event) => {
const { url } = JSON.parse(event.detail);
window.location = url;
});
All components use Tailwind CSS utilities. Customize via config/mobile-ui.php:
'primary_color' => env('MOBILE_UI_COLOR', '#6200EE'),
'app_name' => env('APP_NAME', 'My App'),
'alpine_cdn' => 'https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js',
Built-in Android WebView bridge with:
Register the bridge in your MainActivity.java:
PhpMobileBridge bridge = new PhpMobileBridge(this, webView);
webView.addJavascriptInterface(bridge, "AndroidBridge");
PushNotificationBridge pushBridge = new PushNotificationBridge(this, webView);
webView.addJavascriptInterface(pushBridge, "PushBridge");
Run the test suite:
php artisan test
Or with Pest:
php artisan test --compact
Clear caches:
php artisan config:clear
php artisan cache:clear
php artisan route:clear
Regenerate autoloader:
composer dump-autoload
Publish assets:
php artisan vendor:publish --tag=mobile-ui-assets --force
Rebuild frontend:
npm run build
Ensure Livewire trait is included in component:
use Livewire\Component;
use NativeMobile\LaravelMobileUI\Traits\WithPushNotifications;
class MyComponent extends Component
{
use WithPushNotifications;
}
This package is open-sourced software licensed under the MIT license.
Built with ❤️ by NativeMobile