DEV Community

Cover image for A native sheet that stayed open after navigation in PAM Native, and the 1.54.15 fix
David William Balbino
David William Balbino

Posted on

A native sheet that stayed open after navigation in PAM Native, and the 1.54.15 fix

I maintain PAM Native, a framework for building Android and iOS apps in typed PHP. PHP describes the UI. Rust reconciles the tree and runs layout. Kotlin and Swift apply the changes to real Android Views and UIKit controls. There is no JavaScript runtime or WebView. This post covers one navigation bug that I fixed in 1.54.15.

The bug

A screen could close a sheet and navigate in the same event. A "close and go to the product" button is a common example. When that happened, the native modal could stay open.

The cause was the order of operations. The departing screen's state was frozen before the sheet's closed state had been committed. As a result, closing a sheet and navigating in the same event could retain an open native modal.

Navigation in PAM Native is declared with named routes:

<?php

use App\Screens\HomeScreen;
use App\Screens\ProductScreen;
use Pam\Native\App;
use Pam\Native\Routing\Route;

App::run(
    Route::stack('main', initial: 'home', routes: function (): void {
        Route::screen('home', HomeScreen::class);
        Route::screen('product', ProductScreen::class);
    }),
);
Enter fullscreen mode Exit fullscreen mode

Picture a sheet open on home and an action that closes it and pushes product. That is the case that failed.

The fix

The changelog entry for 1.54.15 says it directly: commit the departing screen state before freezing it. With that order, closing a sheet and navigating in the same event can no longer retain an open native modal.

While working on this I also fixed related problems with input on each platform:

  • Android: a modal covered by another screen no longer consumes Back. Before, the code suppressed duplicate Back deliveries, but it could also suppress a real second press. Now it tells a new Back key interaction apart from a duplicate delivery of the same one.
  • iOS: a covered sheet can no longer claim Escape or act on an earlier keyboard command.

The regression tests cover retained sheets, pending presentation, repeated Back keys, canceled input, programmatic dismissal and covered autofocus. Repeated Back keys and programmatic dismissal were the cases I most wanted locked down. A Back handler that is too strict and one that is too loose both break in ways users notice right away.

Upgrading

The public API, the protocol and the dependencies are unchanged. The changelog asks you to rebuild your native apps to get the fix. If you are starting fresh:

pam init my-app --template native
cd my-app
pam doctor --fix
pam dev
Enter fullscreen mode Exit fullscreen mode

A limit worth knowing

Updating the Composer package is not enough. The fix only reaches users after you rebuild and ship a new APK, AAB or IPA. The same rebuild requirement applies to the 1.54.13 Android ActivityIndicator stroke fix. It also applies to 1.54.16, which adds a new feature rather than a fix: an Android native plugin event for Firebase token creation and rotation. Plugins that consume that event also require SDK 1.54.16. If your app is on an older build, the old behavior stays on devices until you release a new build.

The code is at https://github.com/push-in/pam-native. If you still see a sheet or Back key behaving oddly after rebuilding, please open an issue with the steps to reproduce it.

Top comments (0)