@rdlabo/capacitor-native-ui 0.0.0-stage → 1.2.1
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/LICENSE +21 -0
- package/Package.swift +23 -0
- package/README.md +53 -2
- package/RdlaboCapacitorNativeUi.podspec +17 -0
- package/android/build.gradle +69 -0
- package/android/proguard-rules.pro +0 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/dev/rdlabo/capacitor/nativeui/NativeUI.kt +51 -0
- package/android/src/main/java/dev/rdlabo/capacitor/nativeui/NativeUIPlugin.kt +192 -0
- package/android/src/main/java/dev/rdlabo/capacitor/nativeui/NativeUISnapshot.kt +57 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/core.d.ts +4 -0
- package/dist/core.js +3 -0
- package/dist/native/activation.d.ts +14 -0
- package/dist/native/activation.d.ts.map +1 -0
- package/dist/native/activation.js +305 -0
- package/dist/native/activation.js.map +1 -0
- package/dist/native/components/index.d.ts +19 -0
- package/dist/native/components/index.d.ts.map +1 -0
- package/dist/native/components/index.js +38 -0
- package/dist/native/components/index.js.map +1 -0
- package/dist/native/components/ion-back-button.d.ts +10 -0
- package/dist/native/components/ion-back-button.d.ts.map +1 -0
- package/dist/native/components/ion-back-button.js +21 -0
- package/dist/native/components/ion-back-button.js.map +1 -0
- package/dist/native/components/ion-button.d.ts +10 -0
- package/dist/native/components/ion-button.d.ts.map +1 -0
- package/dist/native/components/ion-button.js +25 -0
- package/dist/native/components/ion-button.js.map +1 -0
- package/dist/native/components/ion-buttons.d.ts +11 -0
- package/dist/native/components/ion-buttons.d.ts.map +1 -0
- package/dist/native/components/ion-buttons.js +30 -0
- package/dist/native/components/ion-buttons.js.map +1 -0
- package/dist/native/components/ion-fab.d.ts +10 -0
- package/dist/native/components/ion-fab.d.ts.map +1 -0
- package/dist/native/components/ion-fab.js +132 -0
- package/dist/native/components/ion-fab.js.map +1 -0
- package/dist/native/components/ion-menu-button.d.ts +13 -0
- package/dist/native/components/ion-menu-button.d.ts.map +1 -0
- package/dist/native/components/ion-menu-button.js +44 -0
- package/dist/native/components/ion-menu-button.js.map +1 -0
- package/dist/native/components/ion-segment.d.ts +11 -0
- package/dist/native/components/ion-segment.d.ts.map +1 -0
- package/dist/native/components/ion-segment.js +30 -0
- package/dist/native/components/ion-segment.js.map +1 -0
- package/dist/native/components/ion-tab-bar.d.ts +11 -0
- package/dist/native/components/ion-tab-bar.d.ts.map +1 -0
- package/dist/native/components/ion-tab-bar.js +50 -0
- package/dist/native/components/ion-tab-bar.js.map +1 -0
- package/dist/native/components/searchable-tabs.d.ts +20 -0
- package/dist/native/components/searchable-tabs.d.ts.map +1 -0
- package/dist/native/components/searchable-tabs.js +413 -0
- package/dist/native/components/searchable-tabs.js.map +1 -0
- package/dist/native/definitions.d.ts +255 -0
- package/dist/native/definitions.d.ts.map +1 -0
- package/dist/native/definitions.js +0 -0
- package/dist/native/extensions.d.ts +31 -0
- package/dist/native/extensions.d.ts.map +1 -0
- package/dist/native/extensions.js +122 -0
- package/dist/native/extensions.js.map +1 -0
- package/dist/native/foldable/fold-state.d.ts +5 -0
- package/dist/native/foldable/fold-state.d.ts.map +1 -0
- package/dist/native/foldable/fold-state.js +15 -0
- package/dist/native/foldable/fold-state.js.map +1 -0
- package/dist/native/foldable/types.d.ts +12 -0
- package/dist/native/foldable/types.d.ts.map +1 -0
- package/dist/native/foldable/types.js +0 -0
- package/dist/native/html.d.ts +9 -0
- package/dist/native/html.d.ts.map +1 -0
- package/dist/native/html.js +188 -0
- package/dist/native/html.js.map +1 -0
- package/dist/native/index.d.ts +10 -0
- package/dist/native/index.d.ts.map +1 -0
- package/dist/native/index.js +28 -0
- package/dist/native/index.js.map +1 -0
- package/dist/native/legacy-layout.d.ts +5 -0
- package/dist/native/legacy-layout.d.ts.map +1 -0
- package/dist/native/legacy-layout.js +27 -0
- package/dist/native/legacy-layout.js.map +1 -0
- package/dist/native/overlays/content.d.ts +4 -0
- package/dist/native/overlays/content.d.ts.map +1 -0
- package/dist/native/overlays/content.js +51 -0
- package/dist/native/overlays/content.js.map +1 -0
- package/dist/native/overlays/controller.d.ts +8 -0
- package/dist/native/overlays/controller.d.ts.map +1 -0
- package/dist/native/overlays/controller.js +285 -0
- package/dist/native/overlays/controller.js.map +1 -0
- package/dist/native/overlays/dialog-animation.d.ts +9 -0
- package/dist/native/overlays/dialog-animation.d.ts.map +1 -0
- package/dist/native/overlays/dialog-animation.js +53 -0
- package/dist/native/overlays/dialog-animation.js.map +1 -0
- package/dist/native/overlays/dismiss-animation.d.ts +4 -0
- package/dist/native/overlays/dismiss-animation.d.ts.map +1 -0
- package/dist/native/overlays/dismiss-animation.js +18 -0
- package/dist/native/overlays/dismiss-animation.js.map +1 -0
- package/dist/native/overlays/focus.d.ts +5 -0
- package/dist/native/overlays/focus.d.ts.map +1 -0
- package/dist/native/overlays/focus.js +59 -0
- package/dist/native/overlays/focus.js.map +1 -0
- package/dist/native/overlays/popover.d.ts +12 -0
- package/dist/native/overlays/popover.d.ts.map +1 -0
- package/dist/native/overlays/popover.js +110 -0
- package/dist/native/overlays/popover.js.map +1 -0
- package/dist/native/overlays/styles.d.ts +11 -0
- package/dist/native/overlays/styles.d.ts.map +1 -0
- package/dist/native/overlays/styles.js +167 -0
- package/dist/native/overlays/styles.js.map +1 -0
- package/dist/native/prehide.d.ts +8 -0
- package/dist/native/prehide.d.ts.map +1 -0
- package/dist/native/prehide.js +238 -0
- package/dist/native/prehide.js.map +1 -0
- package/dist/native/runtime.d.ts +7 -0
- package/dist/native/runtime.d.ts.map +1 -0
- package/dist/native/runtime.js +788 -0
- package/dist/native/runtime.js.map +1 -0
- package/dist/native/shared/bridge.d.ts +6 -0
- package/dist/native/shared/bridge.d.ts.map +1 -0
- package/dist/native/shared/bridge.js +18 -0
- package/dist/native/shared/bridge.js.map +1 -0
- package/dist/native/shared/candidate.d.ts +25 -0
- package/dist/native/shared/candidate.d.ts.map +1 -0
- package/dist/native/shared/candidate.js +106 -0
- package/dist/native/shared/candidate.js.map +1 -0
- package/dist/native/shared/clipping.d.ts +5 -0
- package/dist/native/shared/clipping.d.ts.map +1 -0
- package/dist/native/shared/clipping.js +26 -0
- package/dist/native/shared/clipping.js.map +1 -0
- package/dist/native/shared/crossfade.d.ts +12 -0
- package/dist/native/shared/crossfade.d.ts.map +1 -0
- package/dist/native/shared/crossfade.js +67 -0
- package/dist/native/shared/crossfade.js.map +1 -0
- package/dist/native/shared/diagnostics.d.ts +4 -0
- package/dist/native/shared/diagnostics.d.ts.map +1 -0
- package/dist/native/shared/diagnostics.js +18 -0
- package/dist/native/shared/diagnostics.js.map +1 -0
- package/dist/native/shared/dom.d.ts +46 -0
- package/dist/native/shared/dom.d.ts.map +1 -0
- package/dist/native/shared/dom.js +180 -0
- package/dist/native/shared/dom.js.map +1 -0
- package/dist/native/shared/events.d.ts +15 -0
- package/dist/native/shared/events.d.ts.map +1 -0
- package/dist/native/shared/events.js +17 -0
- package/dist/native/shared/events.js.map +1 -0
- package/dist/native/shared/icons.d.ts +8 -0
- package/dist/native/shared/icons.d.ts.map +1 -0
- package/dist/native/shared/icons.js +61 -0
- package/dist/native/shared/icons.js.map +1 -0
- package/dist/native/shared/modal.d.ts +10 -0
- package/dist/native/shared/modal.d.ts.map +1 -0
- package/dist/native/shared/modal.js +160 -0
- package/dist/native/shared/modal.js.map +1 -0
- package/dist/native/shared/projection-id.d.ts +4 -0
- package/dist/native/shared/projection-id.d.ts.map +1 -0
- package/dist/native/shared/projection-id.js +7 -0
- package/dist/native/shared/projection-id.js.map +1 -0
- package/dist/native/shared/toolbar-options.d.ts +9 -0
- package/dist/native/shared/toolbar-options.d.ts.map +1 -0
- package/dist/native/shared/toolbar-options.js +36 -0
- package/dist/native/shared/toolbar-options.js.map +1 -0
- package/dist/native/shared/vertical-bars-geometry.d.ts +10 -0
- package/dist/native/shared/vertical-bars-geometry.d.ts.map +1 -0
- package/dist/native/shared/vertical-bars-geometry.js +85 -0
- package/dist/native/shared/vertical-bars-geometry.js.map +1 -0
- package/dist/native/startup.d.ts +8 -0
- package/dist/native/startup.d.ts.map +1 -0
- package/dist/native/startup.js +86 -0
- package/dist/native/startup.js.map +1 -0
- package/dist/native/vertical-bars-web-search.d.ts +10 -0
- package/dist/native/vertical-bars-web-search.d.ts.map +1 -0
- package/dist/native/vertical-bars-web-search.js +90 -0
- package/dist/native/vertical-bars-web-search.js.map +1 -0
- package/dist/native/vertical-bars-web.d.ts +5 -0
- package/dist/native/vertical-bars-web.d.ts.map +1 -0
- package/dist/native/vertical-bars-web.js +421 -0
- package/dist/native/vertical-bars-web.js.map +1 -0
- package/dist/native-integration/index.d.ts +25 -0
- package/dist/native-integration/index.d.ts.map +1 -0
- package/dist/native-integration/index.js +33 -0
- package/dist/native-integration/index.js.map +1 -0
- package/dist/vertical-bars.d.ts +6 -0
- package/dist/vertical-bars.js +5 -0
- package/docs/configuration.md +187 -0
- package/docs/framework-independent.md +82 -0
- package/docs/migration.md +206 -0
- package/docs/native-mini-player.md +47 -0
- package/docs/native-ui-extensions.md +365 -0
- package/docs/native-ui.md +409 -0
- package/docs/setup.md +205 -0
- package/docs/vertical-bars.md +379 -0
- package/ios/Sources/NativeUIPlugin/Components/NativeUIButton.swift +71 -0
- package/ios/Sources/NativeUIPlugin/Components/NativeUIButtons.swift +24 -0
- package/ios/Sources/NativeUIPlugin/Components/NativeUIComponents.swift +19 -0
- package/ios/Sources/NativeUIPlugin/Components/NativeUIFab.swift +80 -0
- package/ios/Sources/NativeUIPlugin/Components/NativeUISearchController.swift +439 -0
- package/ios/Sources/NativeUIPlugin/Components/NativeUISegment.swift +91 -0
- package/ios/Sources/NativeUIPlugin/Components/NativeUITabBar.swift +218 -0
- package/ios/Sources/NativeUIPlugin/Components/NativeUIVerticalBars.swift +590 -0
- package/ios/Sources/NativeUIPlugin/Components/NativeUIVerticalSearch.swift +118 -0
- package/ios/Sources/NativeUIPlugin/Extensions/NativeUI.swift +178 -0
- package/ios/Sources/NativeUIPlugin/Extensions/NativeUIRendering.swift +38 -0
- package/ios/Sources/NativeUIPlugin/NativeUIPlugin.swift +615 -0
- package/ios/Sources/NativeUIPlugin/Overlays/NativeUIOverlayController.swift +119 -0
- package/ios/Sources/NativeUIPlugin/Overlays/NativeUIOverlayHost.swift +75 -0
- package/ios/Sources/NativeUIPlugin/Shared/NativeUIControlRendering.swift +21 -0
- package/ios/Sources/NativeUIPlugin/Shared/NativeUICrossfade.swift +35 -0
- package/ios/Sources/NativeUIPlugin/Shared/NativeUIHost.swift +8 -0
- package/ios/Sources/NativeUIPlugin/Shared/NativeUISnapshot.swift +161 -0
- package/ios/Sources/NativeUIPlugin/Shared/NativeUIVerticalBarsGeometry.swift +52 -0
- package/ios/Tests/NativeUIPluginTests/NativeUIExtensionTests.swift +165 -0
- package/ios/Tests/NativeUIPluginTests/NativeUISnapshotTests.swift +805 -0
- package/package.json +89 -4
- package/src/core.ts +15 -0
- package/src/native/activation.ts +394 -0
- package/src/native/components/index.ts +45 -0
- package/src/native/components/ion-back-button.ts +22 -0
- package/src/native/components/ion-button.ts +25 -0
- package/src/native/components/ion-buttons.ts +37 -0
- package/src/native/components/ion-fab.ts +151 -0
- package/src/native/components/ion-menu-button.ts +37 -0
- package/src/native/components/ion-segment.ts +27 -0
- package/src/native/components/ion-tab-bar.ts +50 -0
- package/src/native/components/searchable-tabs.ts +499 -0
- package/src/native/definitions.ts +324 -0
- package/src/native/extensions.ts +176 -0
- package/src/native/foldable/fold-state.ts +10 -0
- package/src/native/foldable/types.ts +4 -0
- package/src/native/html.ts +193 -0
- package/src/native/index.ts +41 -0
- package/src/native/legacy-layout.ts +21 -0
- package/src/native/overlays/content.ts +51 -0
- package/src/native/overlays/controller.ts +349 -0
- package/src/native/overlays/dialog-animation.ts +53 -0
- package/src/native/overlays/dismiss-animation.ts +15 -0
- package/src/native/overlays/focus.ts +64 -0
- package/src/native/overlays/popover.ts +120 -0
- package/src/native/overlays/styles.ts +181 -0
- package/src/native/prehide.ts +285 -0
- package/src/native/runtime.ts +988 -0
- package/src/native/shared/bridge.ts +18 -0
- package/src/native/shared/candidate.ts +162 -0
- package/src/native/shared/clipping.ts +24 -0
- package/src/native/shared/crossfade.ts +67 -0
- package/src/native/shared/diagnostics.ts +13 -0
- package/src/native/shared/dom.ts +304 -0
- package/src/native/shared/events.ts +14 -0
- package/src/native/shared/icons.ts +57 -0
- package/src/native/shared/modal.ts +157 -0
- package/src/native/shared/projection-id.ts +2 -0
- package/src/native/shared/toolbar-options.ts +53 -0
- package/src/native/shared/vertical-bars-geometry.ts +80 -0
- package/src/native/startup.ts +84 -0
- package/src/native/vertical-bars-web-search.ts +86 -0
- package/src/native/vertical-bars-web.ts +498 -0
- package/src/native-integration/index.ts +49 -0
- package/src/vertical-bars.ts +11 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
|
|
3
|
+
enum NativeUITabBar {
|
|
4
|
+
struct Anchor: Decodable, Equatable {
|
|
5
|
+
let x: Double
|
|
6
|
+
let y: Double
|
|
7
|
+
var isValid: Bool { [0, 0.5, 1].contains(x) && [0, 1].contains(y) }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/// Optimistic tab selection until the Web selected state catches up (or times out).
|
|
11
|
+
struct PendingSelection: Equatable {
|
|
12
|
+
var id: String
|
|
13
|
+
var until: CFAbsoluteTime
|
|
14
|
+
static func start(_ id: String, ttl: CFTimeInterval = 1) -> PendingSelection {
|
|
15
|
+
PendingSelection(id: id, until: CFAbsoluteTimeGetCurrent() + ttl)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static let kind = NativeUIComponent.tabBar
|
|
20
|
+
/// Tab bars waiting for an iOS 26 title-layout warmup after the next `fit`.
|
|
21
|
+
private static var pendingTitleWarmup = Set<ObjectIdentifier>()
|
|
22
|
+
|
|
23
|
+
static func make(_ node: NativeUIControl, rendering: NativeUIControlRendering, delegate: UITabBarDelegate) -> UITabBar {
|
|
24
|
+
let control = UITabBar()
|
|
25
|
+
configureLayout(control)
|
|
26
|
+
control.delegate = delegate
|
|
27
|
+
update(control, node: node, rendering: rendering)
|
|
28
|
+
return control
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static func configureLayout(_ tabBar: UITabBar) {
|
|
32
|
+
// The reader accepts icon-top tabs. Keep that layout local to the native
|
|
33
|
+
// bar instead of letting the iPad idiom turn it into inline items.
|
|
34
|
+
if #available(iOS 17.0, *) {
|
|
35
|
+
tabBar.traitOverrides.horizontalSizeClass = .compact
|
|
36
|
+
tabBar.traitOverrides.verticalSizeClass = .regular
|
|
37
|
+
}
|
|
38
|
+
tabBar.itemPositioning = .fill
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static func update(_ tabBar: UITabBar, node: NativeUIControl, rendering: NativeUIControlRendering) {
|
|
42
|
+
var pending: PendingSelection?
|
|
43
|
+
update(tabBar, node: node, rendering: rendering, pendingSelection: &pending)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static func update(_ tabBar: UITabBar, node: NativeUIControl, rendering: NativeUIControlRendering,
|
|
47
|
+
pendingSelection: inout PendingSelection?) {
|
|
48
|
+
let items = node.items
|
|
49
|
+
let ids = items.map(\.id)
|
|
50
|
+
var needsTitleWarmup = false
|
|
51
|
+
// Keep UIKit's item identities and interaction state across DOM selection updates.
|
|
52
|
+
if tabBar.items?.map({ $0.accessibilityIdentifier ?? "" }) != ids {
|
|
53
|
+
tabBar.items = items.map { item in
|
|
54
|
+
let tab = UITabBarItem(title: item.content.label, image: rendering.image(item.content), tag: 0)
|
|
55
|
+
tab.accessibilityIdentifier = item.id
|
|
56
|
+
return tab
|
|
57
|
+
}
|
|
58
|
+
needsTitleWarmup = true
|
|
59
|
+
}
|
|
60
|
+
let nativeItems = tabBar.items ?? []
|
|
61
|
+
for (tab, item) in zip(nativeItems, items) {
|
|
62
|
+
let title = item.content.label
|
|
63
|
+
if tab.title != title {
|
|
64
|
+
tab.title = title
|
|
65
|
+
needsTitleWarmup = true
|
|
66
|
+
}
|
|
67
|
+
let icon = rendering.image(item.content)
|
|
68
|
+
if tab.image !== icon {
|
|
69
|
+
tab.image = icon
|
|
70
|
+
needsTitleWarmup = true
|
|
71
|
+
}
|
|
72
|
+
if tab.selectedImage !== icon { tab.selectedImage = icon }
|
|
73
|
+
tab.isEnabled = !item.content.disabled
|
|
74
|
+
tab.accessibilityLabel = item.content.accessibilityLabel
|
|
75
|
+
if applyTypography(item.content, to: tab) { needsTitleWarmup = true }
|
|
76
|
+
applyBadge(item.content.badge, to: tab, rendering: rendering)
|
|
77
|
+
}
|
|
78
|
+
let domSelected = zip(nativeItems, items).first { $0.1.content.selected }
|
|
79
|
+
let selectedItem = domSelected?.0
|
|
80
|
+
if let pending = pendingSelection {
|
|
81
|
+
let pendingItem = zip(nativeItems, items).first { $0.1.id == pending.id }
|
|
82
|
+
let expired = CFAbsoluteTimeGetCurrent() >= pending.until
|
|
83
|
+
let unavailable = pendingItem == nil || pendingItem!.1.content.disabled
|
|
84
|
+
if unavailable || expired {
|
|
85
|
+
// Ionic rejected the tap, the item vanished, or the echo timed out.
|
|
86
|
+
pendingSelection = nil
|
|
87
|
+
if tabBar.selectedItem !== selectedItem { tabBar.selectedItem = selectedItem }
|
|
88
|
+
} else if domSelected?.1.id == pending.id {
|
|
89
|
+
pendingSelection = nil
|
|
90
|
+
if tabBar.selectedItem !== selectedItem { tabBar.selectedItem = selectedItem }
|
|
91
|
+
} else if tabBar.selectedItem !== pendingItem!.0 {
|
|
92
|
+
// Keep the optimistic native selection until the Web selected state catches up.
|
|
93
|
+
tabBar.selectedItem = pendingItem!.0
|
|
94
|
+
}
|
|
95
|
+
} else if tabBar.selectedItem !== selectedItem {
|
|
96
|
+
tabBar.selectedItem = selectedItem
|
|
97
|
+
}
|
|
98
|
+
tabBar.semanticContentAttribute = node.rtl ? .forceRightToLeft : .forceLeftToRight
|
|
99
|
+
tabBar.accessibilityIdentifier = node.id
|
|
100
|
+
// Warm after `fit` settles geometry — not on every motion-driven frame sync.
|
|
101
|
+
if needsTitleWarmup { pendingTitleWarmup.insert(ObjectIdentifier(tabBar)) }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@discardableResult
|
|
105
|
+
static func applyTypography(_ content: NativeUIItemContent, to item: UITabBarItem) -> Bool {
|
|
106
|
+
let weight: UIFont.Weight
|
|
107
|
+
switch content.fontWeight {
|
|
108
|
+
case ..<150: weight = .ultraLight
|
|
109
|
+
case ..<250: weight = .thin
|
|
110
|
+
case ..<350: weight = .light
|
|
111
|
+
case ..<450: weight = .regular
|
|
112
|
+
case ..<550: weight = .medium
|
|
113
|
+
case ..<650: weight = .semibold
|
|
114
|
+
case ..<750: weight = .bold
|
|
115
|
+
case ..<850: weight = .heavy
|
|
116
|
+
default: weight = .black
|
|
117
|
+
}
|
|
118
|
+
let font = UIFont.systemFont(ofSize: content.fontSize, weight: weight)
|
|
119
|
+
var changed = false
|
|
120
|
+
for state in [UIControl.State.normal, .selected] {
|
|
121
|
+
if item.titleTextAttributes(for: state)?[.font] as? UIFont != font {
|
|
122
|
+
item.setTitleTextAttributes([.font: font], for: state)
|
|
123
|
+
changed = true
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return changed
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static func applyBadge(_ badge: NativeUIBadge?, to item: UITabBarItem, rendering: NativeUIControlRendering) {
|
|
130
|
+
// nil removes a badge; an empty string keeps the native notification dot.
|
|
131
|
+
item.badgeValue = badge?.value
|
|
132
|
+
item.accessibilityValue = badge?.value
|
|
133
|
+
item.badgeColor = badge.map { rendering.color($0.color) }
|
|
134
|
+
let attributes = badge.map { [NSAttributedString.Key.foregroundColor: rendering.color($0.textColor)] }
|
|
135
|
+
item.setBadgeTextAttributes(attributes, for: .normal)
|
|
136
|
+
item.setBadgeTextAttributes(attributes, for: .selected)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static func fit(_ tabBar: UITabBar, node: NativeUIControl, bounds: CGRect) -> Bool {
|
|
140
|
+
// Place a new bar before asking UIKit for its safe-area-dependent size.
|
|
141
|
+
// Measuring at the initial zero frame makes a restored iPad bar 5pt shorter.
|
|
142
|
+
if tabBar.bounds.isEmpty {
|
|
143
|
+
tabBar.frame = bounds
|
|
144
|
+
tabBar.layoutIfNeeded()
|
|
145
|
+
}
|
|
146
|
+
let fitted = tabBar.sizeThatFits(bounds.size)
|
|
147
|
+
var size = CGSize(width: bounds.width,
|
|
148
|
+
height: max(bounds.height, fitted.height))
|
|
149
|
+
if tabBar.bounds.size != size { tabBar.bounds.size = size }
|
|
150
|
+
tabBar.layoutIfNeeded()
|
|
151
|
+
// UIKit's tab content occupies only part of UITabBar's outer frame.
|
|
152
|
+
// Align that content to ion-tab-bar, whose CSS already owns placement.
|
|
153
|
+
guard var content = contentFrame(tabBar) else {
|
|
154
|
+
return false
|
|
155
|
+
}
|
|
156
|
+
// Reserve ion-tab-bar's width for the tab content, excluding UIKit's outer gutters.
|
|
157
|
+
// UIKit can cap the content width for a small number of items.
|
|
158
|
+
// Do not keep expanding the outer frame beyond its natural size.
|
|
159
|
+
size.width = min(bounds.width + tabBar.bounds.width - content.width,
|
|
160
|
+
max(bounds.width, fitted.width))
|
|
161
|
+
if abs(tabBar.bounds.width - size.width) > 0.1 {
|
|
162
|
+
tabBar.bounds.size = size
|
|
163
|
+
tabBar.layoutIfNeeded()
|
|
164
|
+
guard let measured = contentFrame(tabBar) else {
|
|
165
|
+
return false
|
|
166
|
+
}
|
|
167
|
+
content = measured
|
|
168
|
+
}
|
|
169
|
+
// UIKit owns the adaptive platter size, including changes after badge/title updates.
|
|
170
|
+
// Preserve the DOM placement anchor instead of requiring identical item widths.
|
|
171
|
+
let anchor = node.tabBarAnchor
|
|
172
|
+
let x = anchor?.x ?? 0
|
|
173
|
+
let y = anchor?.y ?? 0
|
|
174
|
+
let center = CGPoint(x: bounds.minX + (bounds.width - content.width) * x - content.minX + size.width / 2,
|
|
175
|
+
y: bounds.minY + (bounds.height - content.height) * y - content.minY + size.height / 2)
|
|
176
|
+
if tabBar.center != center { tabBar.center = center }
|
|
177
|
+
if pendingTitleWarmup.remove(ObjectIdentifier(tabBar)) != nil {
|
|
178
|
+
warmUnselectedTitleLayout(tabBar)
|
|
179
|
+
}
|
|
180
|
+
return true
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/// iOS 26 only: programmatically visit each unselected item so UIKit measures
|
|
184
|
+
/// its title the same way a user tap would. Selection does not call the
|
|
185
|
+
/// tab-bar delegate. No-op on iOS 27+, where first paint already matches Web.
|
|
186
|
+
static func warmUnselectedTitleLayout(_ tabBar: UITabBar) {
|
|
187
|
+
let version = ProcessInfo.processInfo.operatingSystemVersion
|
|
188
|
+
guard version.majorVersion == 26, let items = tabBar.items, items.count > 1 else { return }
|
|
189
|
+
let selected = tabBar.selectedItem
|
|
190
|
+
UIView.performWithoutAnimation {
|
|
191
|
+
for item in items where item !== selected {
|
|
192
|
+
tabBar.selectedItem = item
|
|
193
|
+
tabBar.layoutIfNeeded()
|
|
194
|
+
}
|
|
195
|
+
if tabBar.selectedItem !== selected {
|
|
196
|
+
tabBar.selectedItem = selected
|
|
197
|
+
tabBar.layoutIfNeeded()
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private static func contentFrame(_ tabBar: UITabBar) -> CGRect? {
|
|
203
|
+
contentFrames(tabBar).reduce(nil) { (result: CGRect?, frame) in result.map { $0.union(frame) } ?? frame }
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
static func contentFrames(_ tabBar: UITabBar) -> [CGRect] {
|
|
207
|
+
contentViews(tabBar).map { $0.frame }
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
static func contentViews(_ tabBar: UITabBar) -> [UIView] {
|
|
211
|
+
func containsControl(_ view: UIView) -> Bool {
|
|
212
|
+
view is UIControl || view.subviews.contains(where: containsControl)
|
|
213
|
+
}
|
|
214
|
+
return tabBar.subviews
|
|
215
|
+
.filter { !$0.isHidden && $0.alpha > 0 && containsControl($0) }
|
|
216
|
+
.filter { !$0.frame.isEmpty }
|
|
217
|
+
}
|
|
218
|
+
}
|