Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"appDelegateSubscribers": [
"T3WorkspaceOrientationSubscriber",
"T3MenuDismissTouchGateSubscriber",
"T3BackgroundGraceSubscriber"
"T3BackgroundGraceSubscriber",
"T3RailPocketBlurSubscriber"
]
},
"android": {
Expand Down
90 changes: 90 additions & 0 deletions apps/mobile/modules/t3-native-controls/ios/T3RailPocketBlur.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import ExpoModulesCore
import QuartzCore
import UIKit

// Folded iPhone Duo rail (iOS 27.2): each of T3's navigation controllers shows its own private
// VerticalBarPocketView. After a return from the background the tab bar's pocket lands above that
// one and its CABackdropLayer blurs the header buttons. A plain UIKit app only has the tab bar's
// pocket, so this is a stopgap. A UIKit rename of these private classes makes this a no-op.
public final class T3RailPocketBlurSubscriber: ExpoAppDelegateSubscriber {
public func applicationDidBecomeActive(_ application: UIApplication) {
// UIKit can add the second pocket a moment after activation, so look again shortly after.
DispatchQueue.main.async { T3RailPocketBlur.update() }
for delay in [0.3, 1.5] {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) { T3RailPocketBlur.update() }
}
}
}

@MainActor
enum T3RailPocketBlur {
private static let pocketClassName = "VerticalBar".appending("PocketView")
private static let backdropClassName = "CABackdrop".appending("Layer")
/// Backdrop layers this hid, so they can be shown again once their pocket is alone.
private static let hiddenLayers = NSHashTable<CALayer>.weakObjects()

private struct Pocket {
let view: UIView
/// Subview indexes from the window, which give the drawing order.
let path: [Int]
let frame: CGRect
}

static func update() {
var stacked: [CALayer] = []
let windows = UIApplication.shared.connectedScenes
.compactMap { $0 as? UIWindowScene }
.flatMap(\.windows)
for window in windows {
var pockets: [Pocket] = []
var path: [Int] = []
collectPockets(in: window, window: window, path: &path, into: &pockets)
let overlapping = pockets.filter { pocket in
pockets.contains { $0.view !== pocket.view && $0.frame.intersects(pocket.frame) }
}
if let top = overlapping.max(by: { drawsBelow($0.path, $1.path) }) {
stacked += backdropLayers(of: top.view)
}
}
for layer in hiddenLayers.allObjects where !stacked.contains(where: { $0 === layer }) {
layer.isHidden = false
hiddenLayers.remove(layer)
}
// A backdrop UIKit hid itself stays UIKit's to show again.
for layer in stacked where !layer.isHidden {
layer.isHidden = true
hiddenLayers.add(layer)
}
}

private static func collectPockets(
in view: UIView, window: UIWindow, path: inout [Int], into pockets: inout [Pocket]
) {
guard !view.isHidden, view.alpha > 0.01 else { return }
if NSStringFromClass(type(of: view)).contains(pocketClassName) {
let frame = view.convert(view.bounds, to: window)
if !frame.isEmpty { pockets.append(Pocket(view: view, path: path, frame: frame)) }
}
for (index, subview) in view.subviews.enumerated() {
path.append(index)
collectPockets(in: subview, window: window, path: &path, into: &pockets)
path.removeLast()
}
}

/// A later sibling, or a descendant, draws above.
private static func drawsBelow(_ a: [Int], _ b: [Int]) -> Bool {
for (x, y) in zip(a, b) where x != y { return x < y }
return a.count < b.count
}

/// The pocket's frost is a layer no view owns, holding the backdrop layer that blurs.
private static func backdropLayers(of pocket: UIView) -> [CALayer] {
(pocket.layer.sublayers ?? []).filter { layer in
!(layer.delegate is UIView)
&& ([layer] + (layer.sublayers ?? [])).contains {
NSStringFromClass(type(of: $0)) == backdropClassName
}
}
}
}
Loading