From 67605074968d6e2024d2a21cfebd58e93f21d85f Mon Sep 17 00:00:00 2001 From: rdlabo Date: Tue, 17 Nov 2026 11:44:17 +0900 Subject: [PATCH 1/2] fix(ios): preserve transparent modal Glass snapshots --- docs/experimental/glass-capture.md | 4 ++- .../NativeUIGlassCapture.mm | 13 ++++++-- .../NativeUIGlassCaptureTests.m | 32 +++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/docs/experimental/glass-capture.md b/docs/experimental/glass-capture.md index 5883191..9fe60c7 100644 --- a/docs/experimental/glass-capture.md +++ b/docs/experimental/glass-capture.md @@ -10,7 +10,9 @@ NativeUICoveredSnapshots.experimentalInPlaceFilteringEnabled = false The option is process-wide. Configure it at startup; changing it while retaining cached captures does not invalidate those images. Disabling it restores the original drawing path and timing. The helper remains compiled into the dependency when disabled, so disabling execution is not an App Store acceptance guarantee. Before iOS 26, the workaround is not invoked. -The enabled path temporarily sets `allowsInPlaceFiltering` on backdrop layers with a `glassBackground` filter and uses `afterScreenUpdates: true`, including pre-interaction acquisition. Both are needed for the tested cold-launch issue. Each original value is recorded before mutation and restored in `@finally`; originally enabled values remain unchanged. No lifecycle hook or additional swizzling is installed by this workaround. +The workaround applies only to composited window captures. Explicit view-root captures, including transparent modal rail images, retain their original filtering: enabling in-place filtering there can turn the glass surface opaque gray. Both paths keep the same exception handling and reentry protection. + +The enabled window path temporarily sets `allowsInPlaceFiltering` on backdrop layers with a `glassBackground` filter and uses `afterScreenUpdates: true`, including pre-interaction acquisition. Both are needed for the tested cold-launch issue. Each original value is recorded before mutation and restored in `@finally`; originally enabled values remain unchanged. No lifecycle hook or additional swizzling is installed by this workaround. Setting and drawing run synchronously on main inside Objective-C++. Unsupported layers draw normally; getter/setter exceptions restore partial changes before falling back to normal drawing. Drawing exceptions return failure after restoration without unwinding a Swift callback. Background and reentrant calls are rejected, and option access is protected by a lock. If a restoration setter throws, remaining restorations are attempted, the capture is rejected, and future mutation is disabled for that process. This cannot guarantee recovery from a setter that refuses restoration, or catch `EXC_BAD_ACCESS`, failed symbol resolution, or process termination. diff --git a/ios/Sources/NativeUIGlassCapture/NativeUIGlassCapture.mm b/ios/Sources/NativeUIGlassCapture/NativeUIGlassCapture.mm index 59de4f7..7d37919 100644 --- a/ios/Sources/NativeUIGlassCapture/NativeUIGlassCapture.mm +++ b/ios/Sources/NativeUIGlassCapture/NativeUIGlassCapture.mm @@ -32,14 +32,14 @@ static BOOL drawSafely(BOOL (^draw)(void)) { @catch (NSException *exception) { return NO; } } -BOOL NUICaptureWithInPlaceFiltering(CALayer *root, BOOL (^draw)(void)) { +static BOOL capture(CALayer *root, BOOL inPlaceFiltering, BOOL (^draw)(void)) { // All mutation is synchronous on main. Reject reentry even on the same thread. static BOOL capturing = NO; static BOOL disabledAfterRestoreFailure = NO; if (!NSThread.isMainThread || capturing) return NO; capturing = YES; @try { - if (disabledAfterRestoreFailure) return drawSafely(draw); + if (!inPlaceFiltering || disabledAfterRestoreFailure) return drawSafely(draw); NSMutableArray *states = [NSMutableArray array]; @try { prepare(root, states); } @catch (NSException *exception) { @@ -59,10 +59,17 @@ BOOL NUICaptureWithInPlaceFiltering(CALayer *root, BOOL (^draw)(void)) { @finally { capturing = NO; } } +BOOL NUICaptureWithInPlaceFiltering(CALayer *root, BOOL (^draw)(void)) { + return capture(root, YES, draw); +} + BOOL NUICaptureHierarchyWithInPlaceFiltering(UIWindow *window, NSArray *roots, BOOL afterScreenUpdates) { if (!NSThread.isMainThread) return NO; // Do not pass a Swift closure through an NSException unwind. Drawing stays here. - return NUICaptureWithInPlaceFiltering(window.layer, ^BOOL { + // Only composited window capture needs the cold-launch backdrop workaround. + // Applying it to isolated transparent roots makes Liquid Glass opaque gray. + // Keep exception and reentry protection for both drawing paths. + return capture(window.layer, roots == nil, ^BOOL { if (!roots) return [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:afterScreenUpdates]; BOOL drawn = YES; for (UIView *root in roots) { diff --git a/ios/Tests/NativeUIGlassCaptureTests/NativeUIGlassCaptureTests.m b/ios/Tests/NativeUIGlassCaptureTests/NativeUIGlassCaptureTests.m index e15c00e..aa16815 100644 --- a/ios/Tests/NativeUIGlassCaptureTests/NativeUIGlassCaptureTests.m +++ b/ios/Tests/NativeUIGlassCaptureTests/NativeUIGlassCaptureTests.m @@ -38,6 +38,15 @@ - (BOOL)drawViewHierarchyInRect:(CGRect)rect afterScreenUpdates:(BOOL)updates { } @end +@interface ObservingCaptureWindow : UIWindow +@property (nonatomic, copy) BOOL (^onDraw)(void); +@end +@implementation ObservingCaptureWindow +- (BOOL)drawViewHierarchyInRect:(CGRect)rect afterScreenUpdates:(BOOL)updates { + return self.onDraw(); +} +@end + @interface NativeUIGlassCaptureTests : XCTestCase @end @implementation NativeUIGlassCaptureTests @@ -129,6 +138,29 @@ - (void)testOffMainCallIsRejectedWithoutDrawing { [self waitForExpectationsWithTimeout:3 handler:nil]; XCTAssertFalse(root.allowsInPlaceFiltering); } +- (void)testTransparentRootsKeepOriginalGlassFilteringAndRejectReentry { + ObservingCaptureWindow *window = [[ObservingCaptureWindow alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + TestGlassLayer *glass = [self glass]; [window.layer addSublayer:glass]; + __block int draws = 0; + window.onDraw = ^BOOL { + draws++; + XCTAssertFalse(glass.allowsInPlaceFiltering); + XCTAssertFalse(NUICaptureHierarchyWithInPlaceFiltering(window, @[window], YES)); + return YES; + }; + XCTAssertTrue(NUICaptureHierarchyWithInPlaceFiltering(window, @[window], YES)); + XCTAssertEqual(draws, 1); + XCTAssertFalse(glass.allowsInPlaceFiltering); + window.onDraw = nil; +} +- (void)testWindowCaptureStillAppliesAndRestoresGlassFiltering { + ObservingCaptureWindow *window = [[ObservingCaptureWindow alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + TestGlassLayer *glass = [self glass]; [window.layer addSublayer:glass]; + window.onDraw = ^BOOL { XCTAssertTrue(glass.allowsInPlaceFiltering); return YES; }; + XCTAssertTrue(NUICaptureHierarchyWithInPlaceFiltering(window, nil, YES)); + XCTAssertFalse(glass.allowsInPlaceFiltering); + window.onDraw = nil; +} - (void)testUIKitDrawingExceptionReturnsFailureWithoutEscaping { ThrowingCaptureWindow *window = [[ThrowingCaptureWindow alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; XCTAssertFalse(NUICaptureHierarchyWithInPlaceFiltering(window, nil, YES)); From 4fd9e53e22e053922d117d27c8a940ab5ac13e75 Mon Sep 17 00:00:00 2001 From: rdlabo Date: Tue, 17 Nov 2026 12:01:04 +0900 Subject: [PATCH 2/2] ci: allow cold iOS consumer builds to finish validation --- .github/workflows/native-ui-engine.yml | 4 ++-- docs/maintenance.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/native-ui-engine.yml b/.github/workflows/native-ui-engine.yml index a686411..1db39b8 100644 --- a/.github/workflows/native-ui-engine.yml +++ b/.github/workflows/native-ui-engine.yml @@ -91,7 +91,7 @@ jobs: retention-days: 7 ios-integration: runs-on: macos-26 - timeout-minutes: 12 + timeout-minutes: 20 steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 @@ -128,7 +128,7 @@ jobs: retention-days: 7 ios-consumers: runs-on: macos-26 - timeout-minutes: 12 + timeout-minutes: 20 strategy: fail-fast: false matrix: diff --git a/docs/maintenance.md b/docs/maintenance.md index addabc3..4c8d073 100644 --- a/docs/maintenance.md +++ b/docs/maintenance.md @@ -47,7 +47,7 @@ Lint combines strict TypeScript checking, the standard ESLint/TypeScript recomme Native checks run in their platform CI jobs: `npm run lint:swift` uses node-swiftlint with the Capacitor configuration on macOS (`brew install swiftlint`); `npm run lint:android` runs Kotlin formatting checks and Android Lint with warnings treated as errors (JDK 21 and Android SDK 36). Use `npm run format:swift` and `npm run format:kotlin` to apply native formatting. Kotlin uses ktfmt because the Prettier Kotlin plugin cannot parse the existing native test fixture. -Swift CI splits independent work between `swift-package`, `ios-integration` and `ios-consumers`; the existing `swift` check requires all three to succeed. Package tests cover deterministic native views, capture ownership and encoding contracts. Actual WKWebView navigation/scroll tracking and active UIKit presentations run in `NativeUIHostedTests` with a UIApplication, alongside the real-screen image pipeline. CocoaPod and Cordova consumer checks run in parallel matrix jobs under `ios-consumers`; the `swift` gate requires both. Both native test selections execute their assigned suites, including the application-only cases. Simulator boot starts after Node.js setup and runtime generation to avoid competing with dependency setup, and each job tests serially on its selected device. Simulator readiness is bounded to two minutes for the package and hosted suites, test execution to five minutes per suite, and each macOS job to twelve minutes. Failed test runs retain their `.xcresult` bundles. `-collect-test-diagnostics never` avoids the slow post-failure system diagnostic collection, as [documented by Apple](https://developer.apple.com/forums/thread/698054); test failures, captured assertions and fixture state still appear in the result bundle. No automatic retry hides a failure. +Swift CI splits independent work between `swift-package`, `ios-integration` and `ios-consumers`; the existing `swift` check requires all three to succeed. Package tests cover deterministic native views, capture ownership and encoding contracts. Actual WKWebView navigation/scroll tracking and active UIKit presentations run in `NativeUIHostedTests` with a UIApplication, alongside the real-screen image pipeline. CocoaPod and Cordova consumer checks run in parallel matrix jobs under `ios-consumers`; the `swift` gate requires both. Both native test selections execute their assigned suites, including the application-only cases. Simulator boot starts after Node.js setup and runtime generation to avoid competing with dependency setup, and each job tests serially on its selected device. Simulator readiness is bounded to two minutes for the package and hosted suites, test execution to five minutes per suite, the package job to twelve minutes, and the hosted integration and consumer jobs to twenty minutes. The latter jobs include cold Xcode builds and simulator installation; their previous twelve-minute limit could cancel successful builds before validation completed. Failed test runs retain their `.xcresult` bundles. `-collect-test-diagnostics never` avoids the slow post-failure system diagnostic collection, as [documented by Apple](https://developer.apple.com/forums/thread/698054); test failures, captured assertions and fixture state still appear in the result bundle. No automatic retry hides a failure. The exact Package exclusions live in `.github/workflows/native-ui-engine.yml`; the hosted selection lives in `ios/Tests/project.yml` using [XcodeGen's test selection](https://github.com/yonaskolb/XcodeGen/blob/master/Docs/ProjectSpec.md#test-target). When moving a test between environments, verify that their executed test sets remain disjoint and their union retains the complete suite. Run the hosted selection locally with: