@onekeyfe/react-native-native-overlay 6.7.0-60 → 6.7.0-62
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.
- package/docs/SPEC.md +126 -11
- package/ios/NativeOverlayWindowManager.swift +244 -7
- package/package.json +1 -1
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
|
|
5
|
-
emulator checks are recorded below.
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
@@ -345,6 +347,50 @@ not change React ownership. Public APIs, Android/Web, and page scope are unchang
|
|
|
345
347
|
first responder; passive toast/debug entries do not win solely by level.
|
|
346
348
|
Keyboard restoration may finish after dismissal completion; callers/tests
|
|
347
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.
|
|
348
394
|
- Every presentation lifetime has a generation. Asynchronous present, dismiss,
|
|
349
395
|
and animation completions must match the generation, controller/entry
|
|
350
396
|
identity and applicable phase before changing state or emitting callbacks.
|
|
@@ -634,11 +680,13 @@ of these UIKit resources. Native logger persistence is owned by the logger.
|
|
|
634
680
|
|
|
635
681
|
## 5.8 Performance and resource budget
|
|
636
682
|
|
|
637
|
-
- iOS entry windows are created lazily and released after their entry detaches
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
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.
|
|
642
690
|
- Android layers are views, not windows: no extra surfaces or WindowManager IPC.
|
|
643
691
|
- Store operations are O(n) in the number of live entries. Snapshots are
|
|
644
692
|
rebuilt once per mutation.
|
|
@@ -670,15 +718,82 @@ navigation remains a separate runtime acceptance item.
|
|
|
670
718
|
|
|
671
719
|
## 5.9 Conformance and acceptance
|
|
672
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
|
+
|
|
673
776
|
Automated (P0):
|
|
674
777
|
|
|
675
778
|
- `tests/ios/run.sh` compiles the production WindowManager, SheetController and
|
|
676
|
-
Animation into an isolated UIKit test app. Its
|
|
779
|
+
Animation into an isolated UIKit test app. Its original nineteen checks cover bounded/live
|
|
677
780
|
ordering, key restoration eligibility, owning-entry release, injected scene
|
|
678
781
|
disconnect/reuse with original-window identity and reentrant-registration
|
|
679
782
|
rejection, conditional original-input focus restoration (including
|
|
680
783
|
higher/foreign/new-input guards), and a native sheet surviving another
|
|
681
|
-
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.
|
|
682
797
|
Sheet checks use `animated: false`; they do not compile the React/Fabric
|
|
683
798
|
Container or replace Gallery coverage of animated reversal/generation races,
|
|
684
799
|
real multi-scene/disconnect, keyboard geometry or accessibility.
|
|
@@ -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
|
-
|
|
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 {
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
338
|
-
|
|
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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-native-overlay",
|
|
3
|
-
"version": "6.7.0-
|
|
3
|
+
"version": "6.7.0-62",
|
|
4
4
|
"description": "Native and Web overlay hosts with ordered levels, page scope and Fabric measurement",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|