Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/native-ui-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion docs/experimental/glass-capture.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion docs/maintenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
13 changes: 10 additions & 3 deletions ios/Sources/NativeUIGlassCapture/NativeUIGlassCapture.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSArray *> *states = [NSMutableArray array];
@try { prepare(root, states); }
@catch (NSException *exception) {
Expand All @@ -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<UIView *> *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) {
Expand Down
32 changes: 32 additions & 0 deletions ios/Tests/NativeUIGlassCaptureTests/NativeUIGlassCaptureTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
Loading