@ajuarezso/capacitor-liquid-glass 0.3.3 → 0.3.5

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.
@@ -152,7 +152,12 @@ public class LiquidGlassPlugin: CAPPlugin, CAPBridgedPlugin {
152
152
  }
153
153
 
154
154
  private func presentTabBar(items: [LiquidGlassTabItem], selectedIndex: Int, tintHex: String?, styleRaw: String) {
155
- guard let window = UIApplication.shared.capacitorWindow else { return }
155
+ // CRÍTICO: usar `bridge?.viewController` (el VC que contiene el
156
+ // WKWebView de Capacitor) en lugar del `rootViewController` del
157
+ // window. iOS 26 aplica Liquid Glass automáticamente al UITabBar
158
+ // solo cuando está en la jerarquía del VC del webview. El rootVC
159
+ // del window puede ser un container distinto y romper el adopt.
160
+ guard let hostVC = bridge?.viewController else { return }
156
161
 
157
162
  if tabBarOverlay == nil {
158
163
  let overlay = LiquidGlassTabBarOverlay()
@@ -169,7 +174,7 @@ public class LiquidGlassPlugin: CAPPlugin, CAPBridgedPlugin {
169
174
  }
170
175
 
171
176
  let style = LiquidGlassTabBarStyle(rawValue: styleRaw) ?? .default
172
- tabBarOverlay?.attach(to: window)
177
+ tabBarOverlay?.attach(to: hostVC)
173
178
  tabBarOverlay?.configure(items: items, selectedIndex: selectedIndex, tintHex: tintHex, style: style)
174
179
  tabBarOverlay?.show()
175
180
  }
@@ -42,14 +42,18 @@ enum LiquidGlassTabBarStyle: String {
42
42
  /// app se compila contra el SDK iOS 26.
43
43
  ///
44
44
  /// **Decisión arquitectónica crítica**: este view controller se adjunta como
45
- /// CHILD del rootViewController del window, y el `UITabBar` vive como subview
46
- /// de `self.view`. Esto crea el view controller hierarchy completo que iOS 26
47
- /// necesita para aplicar el material Liquid Glass automáticamente al UITabBar.
45
+ /// CHILD del view controller que contiene el WKWebView de Capacitor
46
+ /// (`bridge?.viewController`), y el `UITabBar` vive como subview de
47
+ /// `self.view`. Esto crea el view controller hierarchy completo que iOS 26
48
+ /// necesita para aplicar el material Liquid Glass automáticamente al
49
+ /// UITabBar.
48
50
  ///
49
- /// Agregar el `UITabBar` directamente al `UIWindow` (sin view controller
50
- /// container) NO funciona iOS 26 omite el adopt automático y la pill se
51
- /// renderiza con un material translúcido genérico que se ve opaco en
52
- /// comparación con el material real de Music / App Store.
51
+ /// Por qué NO usar `window.rootViewController`: en Capacitor el rootVC del
52
+ /// window puede ser un container distinto al VC del webview. iOS 26 solo
53
+ /// aplica Liquid Glass auto cuando el UITabBar vive en la jerarquía del VC
54
+ /// que tiene el webview activo. Agregarlo al rootVC del window puede
55
+ /// romper el auto-adopt y dejarlo con material translúcido genérico opaco
56
+ /// (no el real de Music / App Store).
53
57
  ///
54
58
  /// Patrón inspirado en `stay-liquid` (alistairheath/stay-liquid GitHub).
55
59
  final class LiquidGlassTabBarOverlay: UIViewController {
@@ -63,59 +67,45 @@ final class LiquidGlassTabBarOverlay: UIViewController {
63
67
  private var items: [LiquidGlassTabItem] = []
64
68
  private weak var hostVC: UIViewController?
65
69
 
66
- /// Reemplaza `self.view` por una `PassThroughView` custom. El override
67
- /// de `hitTest` vive en la `UIView` (no en el `UIViewController`), así
68
- /// que necesitamos una subclase dedicada en lugar de override el VC.
69
- override func loadView() {
70
- let v = PassThroughView()
71
- v.allowedHitView = tabBar
72
- self.view = v
73
- }
74
-
75
70
  override func viewDidLoad() {
76
71
  super.viewDidLoad()
77
- // Background transparente solo el `UITabBar` (la pill flotante)
78
- // ocupa espacio visible. El resto del área es transparente y la
79
- // `PassThroughView` deja pasar los toques al webview por debajo.
72
+ // Background transparente. El `self.view` está sizado SOLO al rect
73
+ // del tab bar (leading/trailing/bottom al hostVC, sin top la
74
+ // altura la determina el intrinsic content size del UITabBar dentro).
75
+ // Por eso NO necesitamos `hitTest` override: el view en sí solo
76
+ // existe sobre el área de la pill, los taps fuera no llegan.
80
77
  view.backgroundColor = .clear
81
78
 
82
79
  tabBar.translatesAutoresizingMaskIntoConstraints = false
83
80
  tabBar.delegate = self
84
81
 
85
- // Default appearance: triggers Liquid Glass automatically on iOS 26+.
86
- // Sobreescrito en `configure(...)` si el caller pidió otro estilo.
87
- applyAppearance(tabBar, style: .default)
82
+ // CRÍTICO: NO setear appearance acá. iOS 26 adopta Liquid Glass
83
+ // automáticamente SOLO si el UITabBar mantiene su appearance default
84
+ // intacto. Tocar `standardAppearance` / `scrollEdgeAppearance` en
85
+ // CUALQUIER forma — incluso con `configureWithDefaultBackground()` —
86
+ // anula el adopt y deja un material translúcido genérico opaco.
87
+ // Solo los overrides intencionales (.ultraThin, .transparent) tocan
88
+ // el appearance, vía `applyAppearance(...)` desde `configure(...)`.
88
89
 
89
90
  view.addSubview(tabBar)
90
91
 
92
+ // UITabBar ocupa TODO el self.view — el view es del tamaño exacto
93
+ // de la pill gracias a las constraints del attach() (sin top).
91
94
  NSLayoutConstraint.activate([
92
95
  tabBar.leadingAnchor.constraint(equalTo: view.leadingAnchor),
93
96
  tabBar.trailingAnchor.constraint(equalTo: view.trailingAnchor),
97
+ tabBar.topAnchor.constraint(equalTo: view.topAnchor),
94
98
  tabBar.bottomAnchor.constraint(equalTo: view.bottomAnchor),
95
99
  ])
96
100
  }
97
101
 
98
- /// View que cubre todo el rootVC pero solo absorbe taps que aterrizan
99
- /// sobre `allowedHitView` (el `UITabBar` floating). El resto pasa al
100
- /// webview de Capacitor por debajo. Sin esto, este overlay bloquearía
101
- /// TODO el contenido de la app.
102
- private final class PassThroughView: UIView {
103
- weak var allowedHitView: UIView?
104
-
105
- override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
106
- let hit = super.hitTest(point, with: event)
107
- guard let hit, let allowed = allowedHitView else { return nil }
108
- if hit === allowed || hit.isDescendant(of: allowed) { return hit }
109
- return nil
110
- }
111
- }
112
-
113
- /// Adjunta este view controller como child del rootViewController del
114
- /// window. Idempotente: si ya está adjuntado al mismo root, no-op.
115
- func attach(to window: UIWindow) {
116
- guard let rootVC = window.rootViewController else { return }
117
- if self.parent === rootVC { return }
118
- // Si está adjuntado a otro VC (cambio de root entre sesiones),
102
+ /// Adjunta este view controller como child del view controller que
103
+ /// contiene el WKWebView de Capacitor (`bridge?.viewController`).
104
+ /// Idempotente: si ya está adjuntado al mismo host, no-op.
105
+ func attach(to hostVC: UIViewController?) {
106
+ guard let hostVC else { return }
107
+ if self.parent === hostVC { return }
108
+ // Si está adjuntado a otro VC (cambio de host entre sesiones),
119
109
  // detachar primero antes de re-adjuntar.
120
110
  if self.parent != nil {
121
111
  self.willMove(toParent: nil)
@@ -123,33 +113,44 @@ final class LiquidGlassTabBarOverlay: UIViewController {
123
113
  self.removeFromParent()
124
114
  }
125
115
 
126
- rootVC.addChild(self)
116
+ hostVC.addChild(self)
127
117
  self.view.translatesAutoresizingMaskIntoConstraints = false
128
- rootVC.view.addSubview(self.view)
118
+ hostVC.view.addSubview(self.view)
119
+ // SIN top constraint — la altura del view se deriva del intrinsic
120
+ // content size del UITabBar dentro (~50pt + safe-area-bottom).
121
+ // Replica del patrón stay-liquid (validado en producción) que
122
+ // permite a iOS 26 detectar este UITabBar como "floating tab bar"
123
+ // y aplicarle Liquid Glass automáticamente.
129
124
  NSLayoutConstraint.activate([
130
- self.view.leadingAnchor.constraint(equalTo: rootVC.view.leadingAnchor),
131
- self.view.trailingAnchor.constraint(equalTo: rootVC.view.trailingAnchor),
132
- self.view.topAnchor.constraint(equalTo: rootVC.view.topAnchor),
133
- self.view.bottomAnchor.constraint(equalTo: rootVC.view.bottomAnchor),
125
+ self.view.leadingAnchor.constraint(equalTo: hostVC.view.leadingAnchor),
126
+ self.view.trailingAnchor.constraint(equalTo: hostVC.view.trailingAnchor),
127
+ self.view.bottomAnchor.constraint(equalTo: hostVC.view.bottomAnchor),
134
128
  ])
135
- self.didMove(toParent: rootVC)
136
- self.hostVC = rootVC
129
+ self.didMove(toParent: hostVC)
130
+ self.hostVC = hostVC
137
131
  emitLayout()
138
132
  }
139
133
 
140
134
  /// Aplica el appearance correspondiente al estilo solicitado.
141
- /// - `default` / `liquidGlass`: Liquid Glass nativo iOS 26 (SDK 26 + runtime
142
- /// 26). En iOS < 26 cae al blur translúcido legacy.
135
+ /// - `default` / `liquidGlass`: **NO-OP** el UITabBar mantiene su
136
+ /// appearance default sin tocar para que iOS 26 aplique Liquid Glass
137
+ /// automáticamente. Cualquier touch al appearance (incluso
138
+ /// `configureWithDefaultBackground()`) rompe el auto-adopt.
143
139
  /// - `ultraThin`: blur mínimo `systemUltraThinMaterial` — más ver-through.
140
+ /// Override intencional que CANCELA Liquid Glass.
144
141
  /// - `transparent`: sin background ni blur — content behind se ve completo.
142
+ /// Override intencional que CANCELA Liquid Glass.
145
143
  private func applyAppearance(_ tabBar: UITabBar, style: LiquidGlassTabBarStyle) {
144
+ // Early-return para los estilos que confían en el adopt automático
145
+ // del sistema. Tocar appearance acá anula Liquid Glass.
146
+ if style == .default || style == .liquidGlass { return }
147
+
146
148
  let appearance = UITabBarAppearance()
147
149
  switch style {
148
150
  case .default, .liquidGlass:
149
- // En iOS 26+ con SDK 26, esto adopta Liquid Glass automáticamente.
150
- // NO hacer override de `backgroundEffect` — eso anula el adopt y
151
- // produce un material opaco genérico.
152
- appearance.configureWithDefaultBackground()
151
+ // Unreachable early-return arriba. Mantenido por exhaustividad
152
+ // del switch sobre el enum.
153
+ return
153
154
  case .ultraThin:
154
155
  appearance.configureWithDefaultBackground()
155
156
  appearance.backgroundEffect = UIBlurEffect(style: .systemUltraThinMaterial)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ajuarezso/capacitor-liquid-glass",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "iOS 26 Liquid Glass native chrome (TabBar, NavigationBar, Alerts, Sheets) for Capacitor apps. Falls back gracefully on iOS < 26 and Android.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",