@onekeyfe/react-native-native-overlay 6.7.0-alpha.475 → 6.8.0-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +119 -21
  2. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayEntryRootView.kt +60 -0
  3. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayView.kt +12 -0
  4. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayViewManager.kt +8 -0
  5. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayMotionTest.kt +42 -0
  6. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlaySheetInsetTest.kt +78 -0
  7. package/docs/SPEC.md +189 -24
  8. package/ios/NativeOverlayContainerView.swift +6 -0
  9. package/ios/NativeOverlayWindowManager.swift +244 -7
  10. package/lib/module/NativeOverlayNativeComponent.ts +13 -0
  11. package/lib/module/OverlayView.js +7 -1
  12. package/lib/module/OverlayView.js.map +1 -1
  13. package/lib/module/animation/anchoredOrigin.js +26 -0
  14. package/lib/module/animation/anchoredOrigin.js.map +1 -0
  15. package/lib/module/animation/resolveAnimation.js +26 -4
  16. package/lib/module/animation/resolveAnimation.js.map +1 -1
  17. package/lib/module/index.js +1 -0
  18. package/lib/module/index.js.map +1 -1
  19. package/lib/module/web/animateTransition.js +38 -12
  20. package/lib/module/web/animateTransition.js.map +1 -1
  21. package/lib/typescript/src/NativeOverlayNativeComponent.d.ts +13 -0
  22. package/lib/typescript/src/NativeOverlayNativeComponent.d.ts.map +1 -1
  23. package/lib/typescript/src/OverlayView.d.ts.map +1 -1
  24. package/lib/typescript/src/animation/anchoredOrigin.d.ts +7 -0
  25. package/lib/typescript/src/animation/anchoredOrigin.d.ts.map +1 -0
  26. package/lib/typescript/src/animation/resolveAnimation.d.ts +9 -3
  27. package/lib/typescript/src/animation/resolveAnimation.d.ts.map +1 -1
  28. package/lib/typescript/src/animation/types.d.ts +5 -1
  29. package/lib/typescript/src/animation/types.d.ts.map +1 -1
  30. package/lib/typescript/src/index.d.ts +1 -0
  31. package/lib/typescript/src/index.d.ts.map +1 -1
  32. package/lib/typescript/src/web/animateTransition.d.ts +12 -0
  33. package/lib/typescript/src/web/animateTransition.d.ts.map +1 -1
  34. package/package.json +1 -1
  35. package/src/NativeOverlayNativeComponent.ts +13 -0
  36. package/src/OverlayView.tsx +7 -0
  37. package/src/animation/anchoredOrigin.ts +35 -0
  38. package/src/animation/resolveAnimation.ts +28 -7
  39. package/src/animation/types.ts +5 -1
  40. package/src/index.ts +1 -0
  41. package/src/web/animateTransition.ts +54 -14
package/docs/SPEC.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # react-native-native-overlay SPEC
2
2
 
3
3
  Status: Implemented through the P5 caller migration in app-monorepo. Android
4
- and Web runtime checks passed there; focused iOS 26.5 simulator and Android 16
5
- emulator checks are recorded below. Broader iOS runtime, physical-device and
6
- iPad acceptance remain unverified. Packaging in app-modules is validated
7
- separately.
4
+ and Web runtime checks passed there; focused iOS 26.5 and iOS 27.0 simulator
5
+ checks and Android 16 emulator checks are recorded below. The iOS 27.0 check
6
+ covers this window handoff with repeated More-sheet gestures, immediate and
7
+ delayed account-selector dismissal, and an interactive cancellation. Broader
8
+ iOS runtime, physical-device and iPad acceptance remain unverified. Packaging
9
+ in app-modules is validated separately.
8
10
 
9
11
  The implementation is migrated from app-monorepo commit
10
12
  `376633bd9f1c410dbccb01fb6a0492be9a5c3f38`, package
@@ -176,7 +178,10 @@ visible)`, `removePage(ownerKey)`.
176
178
 
177
179
  - `animation.enter` and `animation.exit` are each
178
180
  `{ type: none|fade|slide|scale, edge, distance, scale, offsetY, fade, origin: center|anchor, motion }`.
179
- - `exit` defaults to `enter`.
181
+ - `exit` resolution order: a caller-supplied `animation.exit`, otherwise a
182
+ mirror of a caller-supplied `animation.enter` (so custom enters keep their
183
+ old reverse exit), otherwise the presentation's own default exit (currently
184
+ only `center`, see below), otherwise the default `enter`.
180
185
  - `motion` is a preset name or a concrete `{ type: 'spring', spring: { mass, stiffness, damping, overshootClamping } }`
181
186
  or `{ type: 'timing', timing: { durationMs, easing: cubicBezier } }`.
182
187
  - Presets are resolved per platform:
@@ -199,14 +204,34 @@ visible)`, `removePage(ownerKey)`.
199
204
  it would slow web overlays down 4–9×.
200
205
  - Presentation defaults (`DEFAULT_OVERLAY_ANIMATIONS`):
201
206
 
202
- | Presentation | Enter / exit | Backdrop |
203
- | ------------ | -------------------------------------------------------------------------------- | ------------- |
204
- | sheet | slide from bottom, `quick` | fade, `quick` |
205
- | center | scale 0.85 + fade, `quick` | fade, `quick` |
206
- | toast | slide from top + fade, `toastSlide` (native 300 ms quad in-out, web 400 ms ease) | none |
207
- | fullscreen | fade, `quick` | none |
208
- | anchored | scale 0.95 + fade from the resolved anchor placement, `popoverQuick` | fade |
209
-
207
+ | Presentation | Enter | Exit | Backdrop |
208
+ | ------------ | ---------------------------------------------------------------------------------- | --------------------------------------------------------------- | ------------- |
209
+ | sheet | slide from bottom, `quick` | same as enter | fade, `quick` |
210
+ | center | scale 0.85 + fade, `quick` | scale 0.96 without fade, `quick` | fade, `quick` |
211
+ | toast | slide from top + fade, `toastSlide` (native 300 ms quad in-out, web 400 ms ease) | same as enter | none |
212
+ | fullscreen | fade, `quick` | same as enter | none |
213
+ | anchored | scale 0.95 + fade from the resolved anchor placement, `popoverQuick` | same as enter | fade |
214
+
215
+ - **Centered card keeps its surface opaque on exit (Implemented; consumer Web
216
+ runtime evidence pending):** a centered Dialog is a solid card over the page
217
+ or over another overlay. Fading the card out made any opaque content behind
218
+ it — a text-heavy page, the account list inside the account selector —
219
+ readable through the card for the whole transition, which consumers reported
220
+ as a doubled render right after closing a dialog (OK-66647, desktop, 120 fps
221
+ recording: the card reached ~20–30 % opacity while the list rows behind
222
+ stayed opaque). The default exit therefore shrinks the card from scale 1 to
223
+ 0.96 with `fade: false`; the host unmounts it when the exit completes.
224
+ `fade: false` is honoured by all three renderers (`hidesOpacity` on iOS and
225
+ Android, `hiddenKeyframe` on Web), and the backdrop still fades on the same
226
+ clock. A fade-free exit also starts from full opacity: when it interrupts a
227
+ still-running fade-in, the partly transparent surface is snapped back to
228
+ alpha 1 before the scale-out begins, so a rapid close cannot show the
229
+ content behind the card either. That interruption is covered by
230
+ `NativeOverlayMotionTest` on Android and by `buildTransitionKeyframes` on
231
+ Web; the iOS dismiss path lives in `NativeOverlayContainerView`, which the
232
+ iOS test app does not compile, so its snap is source-reviewed only. Reduce
233
+ Motion still degrades the exit to a fade on every platform, so this
234
+ protection does not apply there.
210
235
  - **Android sheet transform ownership (Implemented; Android 16 consumer-shell runtime verified):**
211
236
  the overlay's enter/exit transform belongs to the sheet's CoordinatorLayout
212
237
  parent. Material's IME insets callback owns the child sheet's `translationY`,
@@ -322,6 +347,50 @@ not change React ownership. Public APIs, Android/Web, and page scope are unchang
322
347
  first responder; passive toast/debug entries do not win solely by level.
323
348
  Keyboard restoration may finish after dismissal completion; callers/tests
324
349
  requiring keyboard geometry must observe the new keyboard readiness event.
350
+ - Delivered-touch retirement extension (Implemented; thirty native checks and
351
+ four focused local iOS 27.0 App cases passed):
352
+ before showing a global entry, install a passive touch observer on its real
353
+ app window and on the entry window. Active and retired entries of that real
354
+ host share a touch lifetime, including touches delivered to a lower entry or
355
+ the exiting window itself. Other real app windows remain independent, even
356
+ within the same scene. Each observer tracks delivered touch identities, never
357
+ retains UIEvent objects, never cancels or delays touches, and neither prevents
358
+ nor can be prevented by another recognizer. It stays possible until the last
359
+ tracked touch ends or cancels, then fails and resets without recognizing.
360
+ It accepts concurrent touch types with `requiresExclusiveTouchType = false`
361
+ and preserves UIKit's default allowed touch types.
362
+ - Removing an entry while its real app window or any active/retired entry owned
363
+ by that real host has delivered active touches or
364
+ an interactive UIKit presentation
365
+ removes that entry from active ordering and restores key ownership immediately,
366
+ but retains its exiting window/root/scene, without hiding it, until both the
367
+ delivered touch set is empty and the interaction finishes or cancels. Touch
368
+ completion/cancellation and UIKit interaction changes schedule cleanup on the
369
+ next main turn. Cleanup rechecks the complete current touch set and transition
370
+ coordinator before releasing
371
+ that exact window lifetime. A newly interactive transition keeps it retired
372
+ until its own completion; repeated or late callbacks cannot release a new
373
+ entry for the same owner. A new touch beginning after a previous touch ends but
374
+ before queued cleanup keeps the window retired. Overlapping multi-touch can
375
+ extend retirement without a timeout. When neither condition exists, removal
376
+ still releases synchronously. Remove an entry observer only when its window
377
+ is released; remove a real app window's observer only when that host has no
378
+ active or retired entries. Touch callbacks query current host ownership across
379
+ scenes, rather than binding to the scene of first installation. Moving the
380
+ same real host to another scene keeps its remaining users protected.
381
+ Reassigning an observed window to a different host does not change its
382
+ delivered touch context: retain weak prior-host associations until a next-turn
383
+ check finds its complete touch set empty and those hosts' retirements released.
384
+ A new touch during an idle gap still protects a prior host whose context remains
385
+ retired. Touch completion, observer removal and host reassignment wake current
386
+ and prior hosts; queued cleanup does not require the source observer to survive.
387
+ Scene disconnect removes that scene's records and unregisters only observers with
388
+ no remaining users before releasing active and retired windows
389
+ without notifying an already removed owner again. No fixed timeout controls
390
+ this handoff.
391
+ Key restoration MUST NOT activate a host that has moved to another scene.
392
+ Public UIKit observation cannot account for a DOWN not yet delivered to the
393
+ app window; acceptance must separately exercise that delivery/teardown boundary.
325
394
  - Every presentation lifetime has a generation. Asynchronous present, dismiss,
326
395
  and animation completions must match the generation, controller/entry
327
396
  identity and applicable phase before changing state or emitting callbacks.
@@ -469,6 +538,11 @@ Max-width sheet (`sheet.maxWidth`, default 540):
469
538
  amount, so the fractional boundary between the two views cannot antialias
470
539
  into a hairline on scaled renders (Simulator windows, screenshots, screen
471
540
  recordings).
541
+ - Android hosts the sheet inside the activity content view and pads the sheet
542
+ by the navigation-bar inset, so the JS tail below the React content root is
543
+ not composited there. Native paints that inset strip with the drawn surface
544
+ color (`sheetBottomInsetColor`, limited by `sheetBottomInsetHorizontal`)
545
+ instead; the JS tail still covers the iOS home-indicator area.
472
546
 
473
547
  Width changes while open (rotation, folding, window resize):
474
548
 
@@ -562,7 +636,7 @@ Known divergences:
562
636
  | -------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
563
637
  | iOS global sheet (system physics) vs. iOS page sheet (custom physics) | Accepted (decision A). Revisit after on-device comparison. |
564
638
  | RN `Modal` and third-party dialogs on Android are windows above every layer | Accepted, mitigated by the lock policy (§5.7). |
565
- | Web anchored origin follows the resolved placement after flip; today's code uses the requested placement | Intentional fix. |
639
+ | Web anchored origin follows the resolved placement after flip; the Tamagui Popover used the requested placement | Intentional fix, implemented (`getAnchoredTransformOrigin`). |
566
640
 
567
641
  ## 5.7 Failure, fallback, and safety
568
642
 
@@ -606,11 +680,13 @@ of these UIKit resources. Native logger persistence is owned by the logger.
606
680
 
607
681
  ## 5.8 Performance and resource budget
608
682
 
609
- - iOS entry windows are created lazily and released after their entry detaches.
610
- Window count is O(active global entries) per scene, rather than a six-window
611
- level cache. No new public limit/configuration is introduced; page entries
612
- remain views. Re-ranking is O(n log n) for the affected scene and creates no
613
- per-frame bridge work.
683
+ - iOS entry windows are created lazily and released after their entry detaches,
684
+ or after an in-progress UIKit interaction finishes when release is deferred.
685
+ Window count is O(active global entries plus retired interactive windows) per
686
+ scene, rather than a six-window level cache. Scene disconnect drains both.
687
+ No new public limit/configuration is introduced; page entries remain views.
688
+ Re-ranking is O(n log n) for the affected scene and creates no per-frame
689
+ bridge work.
614
690
  - Android layers are views, not windows: no extra surfaces or WindowManager IPC.
615
691
  - Store operations are O(n) in the number of live entries. Snapshots are
616
692
  rebuilt once per mutation.
@@ -642,15 +718,82 @@ navigation remains a separate runtime acceptance item.
642
718
 
643
719
  ## 5.9 Conformance and acceptance
644
720
 
721
+ Focused iOS 27.0 simulator runtime check (2026-11-13): three repetitions of
722
+ the previously failing 0.25-second More-to-account-selector handoff and one
723
+ 1.25-second control dismissed to Home. A separate 0.25-second handoff with a
724
+ slow partial selector drag canceled and returned to its original position;
725
+ More reopened and a subsequent full drag dismissed normally. Home and Market
726
+ remained interactive. This checks the main-UI window handoff only; physical
727
+ devices and the broader runtime matrix remain unverified.
728
+
729
+ Historical app-touch acceptance for revision `404e87c` (2026-11-13,
730
+ local Debug build on an isolated
731
+ iOS 27.0 simulator): all eight first-pan-only cases passed, starting from the
732
+ Home header or list body at 250, 300, 350 and 400 ms after More close UP. The
733
+ 250/300 ms cases kept all twenty old-context events routed to the app window;
734
+ 350/400 ms started after teardown (observed 5–49 ms later) and routed all twenty
735
+ new-context events normally. No backing-event-only dispatch occurred. Native
736
+ pager logs recorded ended state 3 in every case. List-body accessibility samples
737
+ continued moving after UP without another input, confirming inertia. After
738
+ waiting for release, the first React control tap opened Home More (header) or
739
+ AccountSelectorStack (body), without another pan or tab switch. Per-case main
740
+ and background runtime markers remained unchanged. These measured teardown
741
+ boundaries do not guarantee observation of a DOWN UIKit has not delivered yet.
742
+
743
+ For the same historical revision, two additional selector handoffs exercised
744
+ multiple front-card drags and a partial rebound, then front dismissal followed
745
+ 250 ms later by either a complete
746
+ back-selector dismissal or a partial drag canceled into rebound. Both preserved
747
+ complete old-context delivery (36 and 16 events respectively), zero backing-only
748
+ events, stable main/background markers, and working direct React controls.
749
+ The entry was the watch-only account-row More inside AccountSelectorStack,
750
+ which uses the same global NativeOverlay UIWindow over a UIKit modal host.
751
+ It is an equivalent-host regression, not a replay of the original three-account
752
+ HD wallet-level menu. Release/TestFlight binaries, physical devices and other
753
+ OS versions remain unverified.
754
+
755
+ Review extension acceptance for `c59572b`: thirty focused native checks passed.
756
+ A rebuilt local Debug App passed first-only header/250 ms and body/300 ms Home
757
+ handoffs with native ended state 3, direct React control actions and stable
758
+ main/background runtime markers. Two further cases used an independently mounted
759
+ passive global entry over Home More. A lower-entry drag received all sixteen
760
+ events in its own context while the upper entry closed; its next React close
761
+ action worked. This does not establish use of the upper entry's context by the
762
+ lower drag. In the exiting-entry case, UIKit delivered DOWN to the upper window,
763
+ restored key ownership to the lower window on close, and delivered UP to the
764
+ same upper window/context 657 ms after native close; the next lower React close
765
+ action worked. Runtime markers stayed stable throughout these four post-recovery
766
+ cases. The earlier nineteen native checks, eight Home cases and two equivalent
767
+ selector handoffs above belong to `404e87c`, not a rerun of the review version.
768
+ The eleven added native groups cover lower/exiting-entry and cross-window touch
769
+ ownership, mixed delivered types, repeated host reassignment, UP/rehost/DOWN and
770
+ coordinator-held idle gaps, projected scene ownership/disconnect, and key scope.
771
+ Mixed-type tests directly deliver synthetic touches and assert observer flags;
772
+ they do not prove physical Pencil input. Scene tests project one real scene into
773
+ controlled manager identity buckets using an internal resolver; they do not prove
774
+ system multi-scene migration. The default resolver remains `ObjectIdentifier(scene)`.
775
+
645
776
  Automated (P0):
646
777
 
647
778
  - `tests/ios/run.sh` compiles the production WindowManager, SheetController and
648
- Animation into an isolated UIKit test app. Its seven checks cover bounded/live
779
+ Animation into an isolated UIKit test app. Its original nineteen checks cover bounded/live
649
780
  ordering, key restoration eligibility, owning-entry release, injected scene
650
781
  disconnect/reuse with original-window identity and reentrant-registration
651
782
  rejection, conditional original-input focus restoration (including
652
783
  higher/foreign/new-input guards), and a native sheet surviving another
653
- entry's dismissal.
784
+ entry's dismissal. Four focused checks cover interactive retirement after
785
+ finish and cancellation, reopening the same owner while the old window is
786
+ retired, and disconnecting a scene with only a retired window. They use a
787
+ controlled transition coordinator to test manager lifecycle; the real
788
+ gesture check is the iOS 27.0 simulator run above.
789
+ Eight app-touch checks directly drive the production observer's
790
+ `touchesBegan`/`touchesEnded`/`touchesCancelled` and reset with synthetic
791
+ touch objects. They assert passive gesture flags, touch-only retirement,
792
+ multi-touch and per-real-window isolation, next-turn touch-set rechecks,
793
+ reset cleanup, conjunction with coordinator ownership, owner/orphan reuse,
794
+ and scene-disconnect callback invalidation. They prove manager lifecycle,
795
+ not UIKit delivery or scroll inertia; those are covered separately by the
796
+ local App runtime checks above, with the stated selector-entry limitation.
654
797
  Sheet checks use `animated: false`; they do not compile the React/Fabric
655
798
  Container or replace Gallery coverage of animated reversal/generation races,
656
799
  real multi-scene/disconnect, keyboard geometry or accessibility.
@@ -669,11 +812,20 @@ Automated (P0):
669
812
  reparenting in both directions, including the exit-completion staging path,
670
813
  old-parent transition completion after the move, and reopen during exit.
671
814
  It also covers Fabric removal of staged content and replacement of presented
672
- content during a transition, including layout-listener cleanup.
815
+ content during a transition, including layout-listener cleanup, and the
816
+ fade-free centered exit snapping an interrupted fade-in to full opacity
817
+ before the scale-out.
673
818
  - `NativeOverlayPageHostLayoutTest` places the Android page host below an
674
819
  actual `ReactViewGroup` and checks a sheet at 200, 600 and 320 px after
675
820
  attachment. Height changes MUST relayout and bottom-pin the sheet without
676
821
  a Fabric host-size update, and leave no pending host layout flag.
822
+ - `NativeOverlaySheetInsetTest` exercises the production Android sheet inset
823
+ painter: the navigation-bar strip sits behind the content, follows the drawn
824
+ surface width, carries the surface color and is removed when the platform
825
+ sheet paints its own background. `src/__tests__/sheetSurface.test.ts` checks
826
+ that the drawn surface color and horizontal inset reach native only while
827
+ the JS surface is active. Source and Robolectric verified; physical-device
828
+ verification pending.
677
829
  - `src/__tests__/pageIsolation.web.test.ts` mounts a real React portal in a
678
830
  DOM host and verifies late suspension, level ordering and restoration after
679
831
  the blocking entry is removed.
@@ -698,7 +850,11 @@ Automated (P0):
698
850
  - the spring response in all damping regimes, overshoot clamping and settle
699
851
  time;
700
852
  - Android `SpringForce` conversion and CSS `linear()` sampling;
701
- - presentation defaults and per-platform preset resolution.
853
+ - presentation defaults and per-platform preset resolution, including the
854
+ centered fade-free exit and a caller-supplied exit override;
855
+ - Web enter/exit keyframes: a fade-free exit keeps opacity 1 when it
856
+ interrupts a partial fade-in, a fading exit starts from the interrupted
857
+ opacity, and the interrupted enter transform is retargeted.
702
858
 
703
859
  Runtime matrix, required per platform before migrating callers (P1–P3):
704
860
 
@@ -815,7 +971,9 @@ P4b dialog loading notes:
815
971
  it. Its 50 ms delays and the iOS remount key are gone; text updates in
816
972
  place.
817
973
  - Android sheets pad their content by the navigation-bar inset, matching the
818
- UIKit sheet's home-indicator inset.
974
+ UIKit sheet's home-indicator inset, and paint that inset strip natively with
975
+ the drawn surface color (the JS tail is not composited below the React
976
+ content root on Android).
819
977
 
820
978
  P1 implementation map:
821
979
 
@@ -921,6 +1079,13 @@ P5b web popover notes:
921
1079
  untransformed, so Floating UI uses the same coordinate space during and after
922
1080
  the animation. Completion positioning must not correct coordinates distorted
923
1081
  by the enter scale. Multi-child roots retain their shared full-window motion.
1082
+ - The anchored content's transform origin is the side and corner facing the
1083
+ anchor, read from its `data-placement` (Floating UI notation, after flip):
1084
+ `bottom-end` scales from `right top`, `top-start` from `left bottom`, and so
1085
+ on. Without a placement it falls back to the content center. The caller
1086
+ sets `data-placement` once Floating UI resolves; because the enter run can
1087
+ start before that, the caller also writes the same origin
1088
+ (`getAnchoredTransformOrigin`) onto the running content.
924
1089
  - Press-triggered anchored panels close on a backdrop press without activating
925
1090
  the page underneath. Presses on the panel or inside an overlay ranked above
926
1091
  it do not close it, so a nested Select or a Dialog opened from the panel
@@ -470,6 +470,12 @@ final class NativeOverlayEntryView: UIView {
470
470
  contentExtent: entry.contentExtent(),
471
471
  bounds: entry.bounds
472
472
  )
473
+ // A fade-free exit does not animate alpha. If the fade-in was interrupted,
474
+ // the card would otherwise stay partly transparent and show the content
475
+ // behind it for the whole scale-out (OK-66647).
476
+ if !transition.hidesOpacity {
477
+ entry.contentView.alpha = 1
478
+ }
473
479
  let contentAnimator = transition.motion.makeAnimator()
474
480
  contentAnimator.addAnimations {
475
481
  if transition.hidesOpacity {
@@ -147,6 +147,57 @@ protocol NativeOverlayWindowOwner: AnyObject {
147
147
  func overlaySceneDidDisconnect(window: UIWindow)
148
148
  }
149
149
 
150
+ /// Observes delivered window touches without participating in gesture arbitration.
151
+ final class NativeOverlayAppTouchObserver: UIGestureRecognizer {
152
+ var onTouchesFinished: (() -> Void)?
153
+ private var activeTouches = Set<ObjectIdentifier>()
154
+ var hasActiveTouches: Bool { !activeTouches.isEmpty }
155
+
156
+ override init(target: Any?, action: Selector?) {
157
+ super.init(target: target, action: action)
158
+ configure()
159
+ }
160
+
161
+ private func configure() {
162
+ cancelsTouchesInView = false
163
+ delaysTouchesBegan = false
164
+ delaysTouchesEnded = false
165
+ requiresExclusiveTouchType = false
166
+ }
167
+
168
+ override func canPrevent(_ preventedGestureRecognizer: UIGestureRecognizer) -> Bool { false }
169
+ override func canBePrevented(by preventingGestureRecognizer: UIGestureRecognizer) -> Bool { false }
170
+
171
+ override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
172
+ activeTouches.formUnion(touches.map(ObjectIdentifier.init))
173
+ }
174
+
175
+ override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {}
176
+
177
+ override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) {
178
+ finish(touches)
179
+ }
180
+
181
+ override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent) {
182
+ finish(touches)
183
+ }
184
+
185
+ private func finish(_ touches: Set<UITouch>) {
186
+ let hadTouches = hasActiveTouches
187
+ activeTouches.subtract(touches.map(ObjectIdentifier.init))
188
+ guard hadTouches, !hasActiveTouches else { return }
189
+ state = .failed
190
+ onTouchesFinished?()
191
+ }
192
+
193
+ override func reset() {
194
+ super.reset()
195
+ let hadTouches = hasActiveTouches
196
+ activeTouches.removeAll()
197
+ if hadTouches { onTouchesFinished?() }
198
+ }
199
+ }
200
+
150
201
  final class NativeOverlayWindowManager: NSObject {
151
202
  static let shared = NativeOverlayWindowManager()
152
203
 
@@ -174,11 +225,53 @@ final class NativeOverlayWindowManager: NSObject {
174
225
  }
175
226
  }
176
227
 
228
+ private final class RetiredWindow {
229
+ let window: NativeOverlayPassthroughWindow
230
+ weak var appWindow: UIWindow?
231
+ weak var observedCoordinator: AnyObject?
232
+
233
+ init(window: NativeOverlayPassthroughWindow, appWindow: UIWindow?) {
234
+ self.window = window
235
+ self.appWindow = appWindow
236
+ }
237
+ }
238
+
239
+ private final class WeakAppWindow {
240
+ weak var window: UIWindow?
241
+ init(_ window: UIWindow) { self.window = window }
242
+ }
243
+
244
+ private final class AppTouchObservation {
245
+ weak var window: UIWindow?
246
+ weak var appWindow: UIWindow?
247
+ let observer: NativeOverlayAppTouchObserver
248
+ var previousAppWindows: [ObjectIdentifier: WeakAppWindow] = [:]
249
+
250
+ var appWindows: [UIWindow] {
251
+ (appWindow.map { [$0] } ?? []) + previousAppWindows.values.compactMap(\.window)
252
+ }
253
+
254
+ init(window: UIWindow, appWindow: UIWindow, observer: NativeOverlayAppTouchObserver) {
255
+ self.window = window
256
+ self.appWindow = appWindow
257
+ self.observer = observer
258
+ }
259
+ }
260
+
177
261
  private var scenes: [ObjectIdentifier: [ObjectIdentifier: Entry]] = [:]
262
+ private var retiredWindows: [ObjectIdentifier: [ObjectIdentifier: RetiredWindow]] = [:]
263
+ private var appTouchObservations: [ObjectIdentifier: AppTouchObservation] = [:]
178
264
  private var disconnectingScenes = Set<ObjectIdentifier>()
179
265
  private var sequence = 0
266
+ private let sceneIdentity: (UIWindowScene) -> ObjectIdentifier
267
+
268
+ override convenience init() {
269
+ self.init(sceneIdentity: { ObjectIdentifier($0) })
270
+ }
180
271
 
181
- override init() {
272
+ // Internal identity projection lets native tests exercise scene ownership with real windows.
273
+ init(sceneIdentity: @escaping (UIWindowScene) -> ObjectIdentifier) {
274
+ self.sceneIdentity = sceneIdentity
182
275
  super.init()
183
276
  NotificationCenter.default.addObserver(
184
277
  self, selector: #selector(sceneDidDisconnect(_:)),
@@ -186,7 +279,13 @@ final class NativeOverlayWindowManager: NSObject {
186
279
  )
187
280
  }
188
281
 
189
- deinit { NotificationCenter.default.removeObserver(self) }
282
+ deinit {
283
+ NotificationCenter.default.removeObserver(self)
284
+ for observation in appTouchObservations.values {
285
+ observation.observer.onTouchesFinished = nil
286
+ observation.window?.removeGestureRecognizer(observation.observer)
287
+ }
288
+ }
190
289
 
191
290
  /// Every owner has an independent root presenter, shared by no other entry.
192
291
  func window(for owner: NativeOverlayWindowOwner, level: NativeOverlayLevel,
@@ -196,10 +295,11 @@ final class NativeOverlayWindowManager: NSObject {
196
295
  ((hostWindow as? NativeOverlayPassthroughWindow)?.rootViewController
197
296
  as? NativeOverlayRootViewController)?.appWindow ?? hostWindow
198
297
  guard let scene = appWindow.windowScene, scene.activationState != .unattached else { return nil }
199
- let sceneKey = ObjectIdentifier(scene)
298
+ let sceneKey = sceneIdentity(scene)
200
299
  guard !disconnectingScenes.contains(sceneKey) else { return nil }
201
300
  let orphanWindows = (scenes[sceneKey] ?? [:]).values.filter { $0.owner == nil }.map(\.window)
202
301
  orphanWindows.forEach { entryRemoved(from: $0) }
302
+ observeTouches(in: appWindow, appWindow: appWindow)
203
303
  let ownerKey = ObjectIdentifier(owner)
204
304
  var entries = scenes[sceneKey] ?? [:]
205
305
  let entry: Entry
@@ -222,9 +322,11 @@ final class NativeOverlayWindowManager: NSObject {
222
322
  }
223
323
  entry.appWindow = appWindow
224
324
  (entry.window.rootViewController as? NativeOverlayRootViewController)?.appWindow = appWindow
325
+ observeTouches(in: entry.window, appWindow: appWindow)
225
326
  reorder(entries)
226
327
  entry.window.isHidden = false
227
328
  entry.window.rootViewController?.setNeedsStatusBarAppearanceUpdate()
329
+ removeUnusedTouchObservers()
228
330
  return entry.window
229
331
  }
230
332
 
@@ -256,13 +358,23 @@ final class NativeOverlayWindowManager: NSObject {
256
358
  scenes[sceneKey]?[ownerKey] = nil
257
359
  let remaining = scenes[sceneKey] ?? [:]
258
360
  if remaining.isEmpty { scenes[sceneKey] = nil }
259
- release(entry.window)
361
+ if hasActiveTouches(in: entry.appWindow) || Self.interactiveCoordinator(in: entry.appWindow) != nil {
362
+ // Keep the routing context until this host's delivered touches and UIKit interactions finish.
363
+ let retirement = RetiredWindow(window: entry.window, appWindow: entry.appWindow)
364
+ let windowKey = ObjectIdentifier(entry.window)
365
+ retiredWindows[sceneKey, default: [:]][windowKey] = retirement
366
+ finishRetirement(retirement, sceneKey: sceneKey, windowKey: windowKey)
367
+ } else {
368
+ release(entry.window)
369
+ }
370
+ removeUnusedTouchObservers()
260
371
  reorder(remaining)
261
372
  guard wasKey, let scene,
262
373
  scene.activationState == .foregroundActive || scene.activationState == .foregroundInactive else { return }
263
374
  let next = remaining.values.filter { Self.eligible($0, in: scene) }
264
375
  .max { Self.ordered($0, before: $1) }
265
- (next?.window ?? entry.appWindow)?.makeKey()
376
+ let appWindow = entry.appWindow?.windowScene === scene ? entry.appWindow : nil
377
+ (next?.window ?? appWindow)?.makeKey()
266
378
  }
267
379
 
268
380
  func restoreFocus(_ responder: UIView, in window: UIWindow) -> Bool {
@@ -331,17 +443,142 @@ final class NativeOverlayWindowManager: NSObject {
331
443
  window.windowScene = nil
332
444
  }
333
445
 
446
+ private func observeTouches(in window: UIWindow, appWindow: UIWindow) {
447
+ let windowKey = ObjectIdentifier(window)
448
+ if let observation = appTouchObservations[windowKey] {
449
+ if observation.appWindow !== appWindow, let previous = observation.appWindow {
450
+ // Reparenting does not change the context of an already delivered or queued touch stream.
451
+ if observation.observer.hasActiveTouches || hasRetirements(for: previous) {
452
+ observation.previousAppWindows[ObjectIdentifier(previous)] = WeakAppWindow(previous)
453
+ }
454
+ observation.appWindow = appWindow
455
+ scheduleObservationCleanup(observation, windowKey: windowKey)
456
+ scheduleRetirementCheck(for: previous)
457
+ } else {
458
+ observation.appWindow = appWindow
459
+ }
460
+ return
461
+ }
462
+ let observer = NativeOverlayAppTouchObserver(target: nil, action: nil)
463
+ appTouchObservations[windowKey] = AppTouchObservation(
464
+ window: window, appWindow: appWindow, observer: observer)
465
+ observer.onTouchesFinished = { [weak self, weak window, weak observer] in
466
+ guard let self, let window, let observer,
467
+ let observation = self.appTouchObservations[ObjectIdentifier(window)],
468
+ observation.observer === observer else { return }
469
+ self.scheduleObservationCleanup(observation, windowKey: ObjectIdentifier(window))
470
+ for appWindow in observation.appWindows { self.scheduleRetirementCheck(for: appWindow) }
471
+ }
472
+ window.addGestureRecognizer(observer)
473
+ }
474
+
475
+ private func scheduleObservationCleanup(_ observation: AppTouchObservation, windowKey: ObjectIdentifier) {
476
+ guard !observation.previousAppWindows.isEmpty else { return }
477
+ DispatchQueue.main.async { [weak self, weak observation] in
478
+ guard let self, let observation, self.appTouchObservations[windowKey] === observation,
479
+ !observation.observer.hasActiveTouches else { return }
480
+ self.prunePreviousAppWindows(in: observation)
481
+ }
482
+ }
483
+
484
+ private func prunePreviousAppWindows(in observation: AppTouchObservation) {
485
+ guard !observation.observer.hasActiveTouches else { return }
486
+ // An idle gap does not retire the old context if another touch or transition still owns it.
487
+ observation.previousAppWindows = observation.previousAppWindows.filter {
488
+ $0.value.window.map { hasRetirements(for: $0) } ?? false
489
+ }
490
+ }
491
+
492
+ private func hasRetirements(for appWindow: UIWindow) -> Bool {
493
+ retiredWindows.values.contains { $0.values.contains { $0.appWindow === appWindow } }
494
+ }
495
+
496
+ private func scheduleRetirementCheck(for appWindow: UIWindow?) {
497
+ guard let appWindow, hasRetirements(for: appWindow) else { return }
498
+ DispatchQueue.main.async { [weak self, weak appWindow] in
499
+ guard let self, let appWindow else { return }
500
+ // The source observer may be gone; query current host ownership and all delivered touches.
501
+ for (sceneKey, windows) in self.retiredWindows {
502
+ for (windowKey, retirement) in windows where retirement.appWindow === appWindow {
503
+ self.finishRetirement(retirement, sceneKey: sceneKey, windowKey: windowKey)
504
+ }
505
+ }
506
+ }
507
+ }
508
+
509
+ private func hasActiveTouches(in appWindow: UIWindow?) -> Bool {
510
+ guard let appWindow else { return false }
511
+ return appTouchObservations.values.contains {
512
+ $0.observer.hasActiveTouches && ($0.appWindow === appWindow ||
513
+ $0.previousAppWindows[ObjectIdentifier(appWindow)]?.window === appWindow)
514
+ }
515
+ }
516
+
517
+ private func removeUnusedTouchObservers() {
518
+ for (key, observation) in appTouchObservations {
519
+ prunePreviousAppWindows(in: observation)
520
+ let active = observation.window.map { window in
521
+ scenes.values.contains { $0.values.contains { $0.window === window || $0.appWindow === window } } ||
522
+ retiredWindows.values.contains { $0.values.contains { $0.window === window || $0.appWindow === window } }
523
+ } ?? false
524
+ guard !active else { continue }
525
+ observation.observer.onTouchesFinished = nil
526
+ observation.window?.removeGestureRecognizer(observation.observer)
527
+ appTouchObservations[key] = nil
528
+ for appWindow in observation.appWindows { scheduleRetirementCheck(for: appWindow) }
529
+ }
530
+ }
531
+
532
+ private static func interactiveCoordinator(in appWindow: UIWindow?) -> UIViewControllerTransitionCoordinator? {
533
+ var controller = appWindow?.rootViewController
534
+ while let current = controller {
535
+ if let coordinator = current.transitionCoordinator, coordinator.isInteractive {
536
+ return coordinator
537
+ }
538
+ controller = current.presentedViewController
539
+ }
540
+ return nil
541
+ }
542
+
543
+ private func finishRetirement(_ retirement: RetiredWindow, sceneKey: ObjectIdentifier,
544
+ windowKey: ObjectIdentifier) {
545
+ guard retiredWindows[sceneKey]?[windowKey] === retirement else { return }
546
+ let coordinator = Self.interactiveCoordinator(in: retirement.appWindow)
547
+ if coordinator == nil && !hasActiveTouches(in: retirement.appWindow) {
548
+ retiredWindows[sceneKey]?[windowKey] = nil
549
+ if retiredWindows[sceneKey]?.isEmpty == true { retiredWindows[sceneKey] = nil }
550
+ release(retirement.window)
551
+ removeUnusedTouchObservers()
552
+ return
553
+ }
554
+ guard let coordinator else { return }
555
+ guard retirement.observedCoordinator !== coordinator else { return }
556
+ retirement.observedCoordinator = coordinator
557
+ coordinator.notifyWhenInteractionChanges { [weak self, weak retirement] context in
558
+ guard !context.isInteractive else { return }
559
+ DispatchQueue.main.async { [weak self, weak retirement] in
560
+ guard let self, let retirement,
561
+ self.retiredWindows[sceneKey]?[windowKey] === retirement else { return }
562
+ self.finishRetirement(retirement, sceneKey: sceneKey, windowKey: windowKey)
563
+ }
564
+ }
565
+ }
566
+
334
567
  @objc private func sceneDidDisconnect(_ notification: Notification) {
335
568
  precondition(Thread.isMainThread)
336
569
  guard let scene = notification.object as? UIWindowScene else { return }
337
- let sceneKey = ObjectIdentifier(scene)
338
- guard let entries = scenes.removeValue(forKey: sceneKey) else { return }
570
+ let sceneKey = sceneIdentity(scene)
571
+ let entries = scenes.removeValue(forKey: sceneKey) ?? [:]
572
+ let retired = retiredWindows.removeValue(forKey: sceneKey) ?? [:]
573
+ guard !entries.isEmpty || !retired.isEmpty else { return }
339
574
  disconnectingScenes.insert(sceneKey)
340
575
  defer { disconnectingScenes.remove(sceneKey) }
576
+ removeUnusedTouchObservers()
341
577
  // Unregister first: owner callbacks must not restore a disconnected scene's key.
342
578
  for entry in entries.values {
343
579
  entry.owner?.overlaySceneDidDisconnect(window: entry.window)
344
580
  release(entry.window)
345
581
  }
582
+ for retirement in retired.values { release(retirement.window) }
346
583
  }
347
584
  }
@@ -54,6 +54,19 @@ export interface INativeOverlayNativeProps extends ViewProps {
54
54
  sheetCornerRadius?: CodegenTypes.WithDefault<CodegenTypes.Double, 24>;
55
55
  showHandle?: CodegenTypes.WithDefault<boolean, false>;
56
56
  sheetBackgroundColor?: ColorValue;
57
+ /**
58
+ * `sheet` presentation: paints the platform sheet's bottom inset (the
59
+ * navigation-bar strip padded below the fitted content) with the drawn
60
+ * surface color. Android hosts the sheet inside the activity content view,
61
+ * so a JS view below the content root is not composited there; iOS uses the
62
+ * JS safe-area tail instead.
63
+ */
64
+ sheetBottomInsetColor?: ColorValue;
65
+ /**
66
+ * `sheet` presentation: horizontal inset of the drawn surface inside the
67
+ * platform sheet, in points, so the bottom inset paint stops with it.
68
+ */
69
+ sheetBottomInsetHorizontal?: CodegenTypes.WithDefault<CodegenTypes.Double, 0>;
57
70
  dismissOnPanDown?: CodegenTypes.WithDefault<boolean, true>;
58
71
  /** JSON of the resolved animation (`IResolvedOverlayAnimation`). */
59
72
  animationConfig?: CodegenTypes.WithDefault<string, ''>;