@onekeyfe/react-native-bottom-tabs 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.
- package/README.md +139 -48
- package/android/src/main/java/com/onekey/bottomtabs/BottomTabsDrawerManager.kt +15 -0
- package/android/src/main/java/com/onekey/bottomtabs/BottomTabsDrawerView.kt +276 -54
- package/android/src/main/java/com/onekey/bottomtabs/BottomTabsView.kt +426 -53
- package/android/src/main/java/com/onekey/bottomtabs/BottomTabsViewManager.kt +6 -5
- package/android/src/main/java/com/onekey/bottomtabs/FloatingTabBarStyle.kt +22 -6
- package/android/src/main/java/com/onekey/bottomtabs/events/TabDoublePressEvent.kt +7 -1
- package/docs/SPEC.md +212 -25
- package/ios/RCTBottomTabsComponentView.mm +4 -1
- package/ios/RCTBottomTabsContainerView.swift +263 -15
- package/ios/RCTBottomTabsDrawerComponentView.mm +24 -0
- package/ios/RCTBottomTabsDrawerContainerView.swift +314 -48
- package/ios/tests/BottomTabsDrawerReduceMotionTests.swift +231 -0
- package/lib/module/BottomTabs.js +85 -58
- package/lib/module/BottomTabsDrawerNativeComponent.ts +3 -0
- package/lib/module/BottomTabsNativeComponent.ts +6 -1
- package/lib/module/index.js +1 -0
- package/lib/typescript/src/BottomTabs.d.ts +23 -2
- package/lib/typescript/src/BottomTabsDrawerNativeComponent.d.ts +5 -0
- package/lib/typescript/src/BottomTabsNativeComponent.d.ts +5 -1
- package/lib/typescript/src/index.d.ts +1 -0
- package/package.json +1 -1
- package/react-native-bottom-tabs.podspec +6 -0
- package/src/BottomTabs.tsx +94 -44
- package/src/BottomTabsDrawerNativeComponent.ts +3 -0
- package/src/BottomTabsNativeComponent.ts +6 -1
- package/src/index.tsx +1 -0
|
@@ -131,10 +131,16 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
131
131
|
// Double press is derived from consecutive selection requests so no extra
|
|
132
132
|
// recognizer competes with the system tab bar gestures (iOS 26 drag-to-switch).
|
|
133
133
|
private static let doublePressInterval: CFTimeInterval = 0.3
|
|
134
|
+
private static let scrollTopTolerance: CGFloat = 1
|
|
135
|
+
// Looked up by name: the pager lives in a package this one does not depend on.
|
|
136
|
+
private static let collapsiblePagerClass: AnyClass? =
|
|
137
|
+
NSClassFromString("RNCCollapsiblePagerViewComponentView")
|
|
134
138
|
private var lastPressedTabKey: String?
|
|
135
139
|
private var lastPressedTabTime: CFTimeInterval = 0
|
|
136
140
|
/// Cached view controllers keyed by tab key to avoid unnecessary reparenting
|
|
137
141
|
private var cachedViewControllers: [String: UIViewController] = [:]
|
|
142
|
+
private var pendingIconUpdates = Set<Int>()
|
|
143
|
+
private var isIconUpdateScheduled = false
|
|
138
144
|
// Vertical tab bar (iPhone Duo side strip): last reported placement and the
|
|
139
145
|
// round accessory button drawn above the bar.
|
|
140
146
|
private var reportedTabBarPlacement: String?
|
|
@@ -147,8 +153,11 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
147
153
|
private var selectedIconRequestTokens: [Int: NSObject] = [:]
|
|
148
154
|
private var sideAccessoryRequestToken = NSObject()
|
|
149
155
|
private var isSideAccessoryLayoutScheduled = false
|
|
156
|
+
private var tabBarVisibilityAnimationGeneration = 0
|
|
150
157
|
private static let sideAccessorySize: CGFloat = 48
|
|
151
158
|
private static let sideAccessorySpacing: CGFloat = 12
|
|
159
|
+
private static let tabBarSlideAnimationDuration: TimeInterval = 0.28
|
|
160
|
+
private static let tabBarSlideClearance: CGFloat = 12
|
|
152
161
|
|
|
153
162
|
// MARK: - Props (set by Fabric ComponentView via KVC)
|
|
154
163
|
|
|
@@ -189,7 +198,10 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
189
198
|
}
|
|
190
199
|
|
|
191
200
|
@objc var tabBarHidden: Bool = false {
|
|
192
|
-
didSet {
|
|
201
|
+
didSet {
|
|
202
|
+
guard tabBarHidden != oldValue else { return }
|
|
203
|
+
updateTabBarHidden(animated: window != nil)
|
|
204
|
+
}
|
|
193
205
|
}
|
|
194
206
|
|
|
195
207
|
@objc var translucent: NSNumber? {
|
|
@@ -280,6 +292,13 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
280
292
|
}
|
|
281
293
|
}
|
|
282
294
|
|
|
295
|
+
override func didMoveToWindow() {
|
|
296
|
+
super.didMoveToWindow()
|
|
297
|
+
if window == nil, tabBarController != nil {
|
|
298
|
+
updateTabBarHidden(animated: false)
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
283
302
|
// MARK: - Layout
|
|
284
303
|
|
|
285
304
|
override func layoutSubviews() {
|
|
@@ -343,10 +362,13 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
343
362
|
let placement = currentTabBarPlacement()
|
|
344
363
|
if placement != reportedTabBarPlacement {
|
|
345
364
|
reportedTabBarPlacement = placement
|
|
365
|
+
if placement != "bottom" && tbc.tabBar.transform != .identity {
|
|
366
|
+
updateTabBarHidden(animated: false)
|
|
367
|
+
}
|
|
346
368
|
onTabBarPlacementChange?(["placement": placement])
|
|
347
369
|
// The bar's frame follows its placement, so the height reported for the
|
|
348
370
|
// previous placement is stale.
|
|
349
|
-
onTabBarMeasured?(["height": tabBarHidden ? 0 : Double(tbc.tabBar.
|
|
371
|
+
onTabBarMeasured?(["height": tabBarHidden ? 0 : Double(tbc.tabBar.bounds.size.height)])
|
|
350
372
|
}
|
|
351
373
|
|
|
352
374
|
guard placement != "bottom",
|
|
@@ -523,13 +545,13 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
523
545
|
rebuildViewControllers()
|
|
524
546
|
updateTabBarAppearance()
|
|
525
547
|
updateTintColors()
|
|
526
|
-
updateTabBarHidden()
|
|
548
|
+
updateTabBarHidden(animated: false)
|
|
527
549
|
updateSidebarAdaptable()
|
|
528
550
|
updateMinimizeBehavior()
|
|
529
551
|
|
|
530
552
|
DispatchQueue.main.async { [weak self] in
|
|
531
553
|
guard let self, let tbc = self.tabBarController else { return }
|
|
532
|
-
self.onTabBarMeasured?(["height": self.tabBarHidden ? 0 : Double(tbc.tabBar.
|
|
554
|
+
self.onTabBarMeasured?(["height": self.tabBarHidden ? 0 : Double(tbc.tabBar.bounds.size.height)])
|
|
533
555
|
}
|
|
534
556
|
}
|
|
535
557
|
|
|
@@ -664,6 +686,31 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
664
686
|
scheduleSideAccessoryLayout()
|
|
665
687
|
}
|
|
666
688
|
|
|
689
|
+
private func scheduleIconUpdate(at index: Int) {
|
|
690
|
+
pendingIconUpdates.insert(index)
|
|
691
|
+
guard !isIconUpdateScheduled else { return }
|
|
692
|
+
isIconUpdateScheduled = true
|
|
693
|
+
DispatchQueue.main.async { [weak self] in
|
|
694
|
+
guard let self else { return }
|
|
695
|
+
self.isIconUpdateScheduled = false
|
|
696
|
+
let indices = self.pendingIconUpdates
|
|
697
|
+
self.pendingIconUpdates.removeAll()
|
|
698
|
+
let allItems = self.parsedItems
|
|
699
|
+
for index in indices.sorted() {
|
|
700
|
+
guard allItems.indices.contains(index),
|
|
701
|
+
let vc = self.cachedViewControllers[allItems[index].key],
|
|
702
|
+
let item = vc.tabBarItem else { continue }
|
|
703
|
+
let symbol = allItems[index].sfSymbol ?? ""
|
|
704
|
+
let fallback = symbol.isEmpty ? nil : UIImage(systemName: symbol)
|
|
705
|
+
let image = self.loadedIcons[index] ?? fallback
|
|
706
|
+
let selectedImage = self.loadedSelectedIcons[index] ?? fallback ?? image
|
|
707
|
+
// Preserve the item and controller identities while artwork arrives.
|
|
708
|
+
item.image = self.bakeTint(image, self.inactiveTintColor)
|
|
709
|
+
item.selectedImage = self.bakeTint(selectedImage, self.activeTintColor)
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
667
714
|
// MARK: - Selection
|
|
668
715
|
|
|
669
716
|
private func updateSelectedTab() {
|
|
@@ -789,22 +836,110 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
789
836
|
}
|
|
790
837
|
}
|
|
791
838
|
|
|
792
|
-
private func
|
|
793
|
-
|
|
839
|
+
private func isSystemTabBarHidden(on tbc: UITabBarController) -> Bool {
|
|
840
|
+
#if compiler(>=6.0)
|
|
841
|
+
if #available(iOS 18.0, *) {
|
|
842
|
+
return tbc.isTabBarHidden || tbc.tabBar.isHidden || tbc.tabBar.alpha == 0
|
|
843
|
+
}
|
|
844
|
+
#endif
|
|
845
|
+
return tbc.tabBar.isHidden || tbc.tabBar.alpha == 0
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
private func applySystemTabBarHidden(_ hidden: Bool, on tbc: UITabBarController) {
|
|
794
849
|
// Keep UIKit's tab bar visibility state in sync on iOS 18+.
|
|
795
850
|
#if compiler(>=6.0)
|
|
796
851
|
if #available(iOS 18.0, *) {
|
|
797
|
-
tbc.setTabBarHidden(
|
|
852
|
+
tbc.setTabBarHidden(hidden, animated: false)
|
|
798
853
|
} else {
|
|
799
|
-
tbc.tabBar.isHidden =
|
|
854
|
+
tbc.tabBar.isHidden = hidden
|
|
800
855
|
}
|
|
801
856
|
#else
|
|
802
|
-
tbc.tabBar.isHidden =
|
|
857
|
+
tbc.tabBar.isHidden = hidden
|
|
803
858
|
#endif
|
|
859
|
+
if !hidden {
|
|
860
|
+
tbc.tabBar.isHidden = false
|
|
861
|
+
tbc.tabBar.alpha = 1.0
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
private func tabBarSlideOffset(for tbc: UITabBarController) -> CGFloat {
|
|
866
|
+
max(tbc.tabBar.bounds.size.height, 62) + Self.tabBarSlideClearance
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
private func updateTabBarHidden(animated: Bool = false) {
|
|
870
|
+
guard let tbc = tabBarController else { return }
|
|
871
|
+
tabBarVisibilityAnimationGeneration += 1
|
|
872
|
+
let generation = tabBarVisibilityAnimationGeneration
|
|
804
873
|
tbc.tabBar.isUserInteractionEnabled = !tabBarHidden
|
|
805
874
|
|
|
806
|
-
|
|
875
|
+
let shouldAnimate =
|
|
876
|
+
animated &&
|
|
877
|
+
currentTabBarPlacement() == "bottom" &&
|
|
878
|
+
bounds.width > 0 &&
|
|
879
|
+
bounds.height > 0
|
|
880
|
+
|
|
881
|
+
if !shouldAnimate {
|
|
882
|
+
UIView.performWithoutAnimation {
|
|
883
|
+
tbc.tabBar.layer.removeAllAnimations()
|
|
884
|
+
tbc.tabBar.transform = .identity
|
|
885
|
+
applySystemTabBarHidden(tabBarHidden, on: tbc)
|
|
886
|
+
tbc.view.layoutIfNeeded()
|
|
887
|
+
}
|
|
888
|
+
onTabBarMeasured?(["height": tabBarHidden ? 0 : Double(tbc.tabBar.bounds.size.height)])
|
|
889
|
+
scheduleSideAccessoryLayout()
|
|
890
|
+
return
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
if tabBarHidden {
|
|
894
|
+
// Keep UIKit's system visibility active while sliding down so layout passes
|
|
895
|
+
// triggered by concurrent navigation pushes do not snap tabBar.alpha to 0.
|
|
896
|
+
let slideOffset = tabBarSlideOffset(for: tbc)
|
|
897
|
+
onTabBarMeasured?(["height": 0.0])
|
|
898
|
+
scheduleSideAccessoryLayout()
|
|
899
|
+
UIView.animate(
|
|
900
|
+
withDuration: Self.tabBarSlideAnimationDuration,
|
|
901
|
+
delay: 0,
|
|
902
|
+
usingSpringWithDamping: 1.0,
|
|
903
|
+
initialSpringVelocity: 0,
|
|
904
|
+
options: [.beginFromCurrentState, .curveEaseOut, .allowUserInteraction],
|
|
905
|
+
animations: {
|
|
906
|
+
tbc.tabBar.transform = CGAffineTransform(translationX: 0, y: slideOffset)
|
|
907
|
+
},
|
|
908
|
+
completion: { [weak self, weak tbc] _ in
|
|
909
|
+
guard let self,
|
|
910
|
+
let tbc,
|
|
911
|
+
self.tabBarVisibilityAnimationGeneration == generation,
|
|
912
|
+
self.tabBarHidden else { return }
|
|
913
|
+
UIView.performWithoutAnimation {
|
|
914
|
+
tbc.tabBar.transform = .identity
|
|
915
|
+
self.applySystemTabBarHidden(true, on: tbc)
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
)
|
|
919
|
+
return
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
let wasSystemHidden = isSystemTabBarHidden(on: tbc)
|
|
923
|
+
UIView.performWithoutAnimation {
|
|
924
|
+
applySystemTabBarHidden(false, on: tbc)
|
|
925
|
+
tbc.view.layoutIfNeeded()
|
|
926
|
+
if wasSystemHidden {
|
|
927
|
+
let slideOffset = tabBarSlideOffset(for: tbc)
|
|
928
|
+
tbc.tabBar.transform = CGAffineTransform(translationX: 0, y: slideOffset)
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
onTabBarMeasured?(["height": Double(tbc.tabBar.bounds.size.height)])
|
|
807
932
|
scheduleSideAccessoryLayout()
|
|
933
|
+
UIView.animate(
|
|
934
|
+
withDuration: Self.tabBarSlideAnimationDuration,
|
|
935
|
+
delay: 0,
|
|
936
|
+
usingSpringWithDamping: 1.0,
|
|
937
|
+
initialSpringVelocity: 0,
|
|
938
|
+
options: [.beginFromCurrentState, .curveEaseOut, .allowUserInteraction],
|
|
939
|
+
animations: {
|
|
940
|
+
tbc.tabBar.transform = .identity
|
|
941
|
+
}
|
|
942
|
+
)
|
|
808
943
|
}
|
|
809
944
|
|
|
810
945
|
private func updateSidebarAdaptable() {
|
|
@@ -931,7 +1066,7 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
931
1066
|
scaledImage = image
|
|
932
1067
|
}
|
|
933
1068
|
self.loadedIcons[index] = scaledImage
|
|
934
|
-
self.
|
|
1069
|
+
self.scheduleIconUpdate(at: index)
|
|
935
1070
|
}
|
|
936
1071
|
continue
|
|
937
1072
|
}
|
|
@@ -956,7 +1091,7 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
956
1091
|
DispatchQueue.main.async {
|
|
957
1092
|
guard self.iconRequestTokens[index] === token else { return }
|
|
958
1093
|
self.loadedIcons[index] = image.resizeImageTo(size: self.iconSize)
|
|
959
|
-
self.
|
|
1094
|
+
self.scheduleIconUpdate(at: index)
|
|
960
1095
|
}
|
|
961
1096
|
})
|
|
962
1097
|
}
|
|
@@ -1004,7 +1139,7 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
1004
1139
|
scaledImage = image
|
|
1005
1140
|
}
|
|
1006
1141
|
self.loadedSelectedIcons[index] = scaledImage
|
|
1007
|
-
self.
|
|
1142
|
+
self.scheduleIconUpdate(at: index)
|
|
1008
1143
|
}
|
|
1009
1144
|
continue
|
|
1010
1145
|
}
|
|
@@ -1029,7 +1164,7 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
1029
1164
|
DispatchQueue.main.async {
|
|
1030
1165
|
guard self.selectedIconRequestTokens[index] === token else { return }
|
|
1031
1166
|
self.loadedSelectedIcons[index] = image.resizeImageTo(size: self.iconSize)
|
|
1032
|
-
self.
|
|
1167
|
+
self.scheduleIconUpdate(at: index)
|
|
1033
1168
|
}
|
|
1034
1169
|
})
|
|
1035
1170
|
}
|
|
@@ -1058,13 +1193,126 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
1058
1193
|
let now = CACurrentMediaTime()
|
|
1059
1194
|
if lastPressedTabKey == key && now - lastPressedTabTime <= Self.doublePressInterval {
|
|
1060
1195
|
lastPressedTabKey = nil
|
|
1061
|
-
onTabDoublePress
|
|
1196
|
+
if let onTabDoublePress,
|
|
1197
|
+
let didScrollToTop = scrollSelectedTabToTop(pressedKey: key) {
|
|
1198
|
+
onTabDoublePress(["key": key, "didScrollToTop": didScrollToTop])
|
|
1199
|
+
}
|
|
1062
1200
|
return
|
|
1063
1201
|
}
|
|
1064
1202
|
lastPressedTabKey = key
|
|
1065
1203
|
lastPressedTabTime = now
|
|
1066
1204
|
}
|
|
1067
1205
|
|
|
1206
|
+
/// Animates every visible vertical scroller of the selected tab back to its
|
|
1207
|
+
/// top. Returns false when all of them were already there, which tells JS the
|
|
1208
|
+
/// double press may leave the page instead. A rejected pager request with no
|
|
1209
|
+
/// accepted scroll returns nil, so JS cannot mistake it for an already-top page.
|
|
1210
|
+
private func scrollSelectedTabToTop(pressedKey: String) -> Bool? {
|
|
1211
|
+
guard let tabBarController,
|
|
1212
|
+
filteredItems[safe: tabBarController.selectedIndex]?.key == pressedKey,
|
|
1213
|
+
let rootView = tabBarController.selectedViewController?.view,
|
|
1214
|
+
let window = rootView.window else {
|
|
1215
|
+
return false
|
|
1216
|
+
}
|
|
1217
|
+
var scrollViews: [UIScrollView] = []
|
|
1218
|
+
var pagers: [UIView] = []
|
|
1219
|
+
collectScrolledViews(in: rootView, window: window, scrollViews: &scrollViews, pagers: &pagers)
|
|
1220
|
+
let nativeListScrollSelector = NSSelectorFromString("onekeyScrollToOffset:animated:")
|
|
1221
|
+
for scrollView in scrollViews {
|
|
1222
|
+
if let owner = scrollView.superview, owner.responds(to: nativeListScrollSelector) {
|
|
1223
|
+
// NativeList must release structural-tail offset writes before scrolling.
|
|
1224
|
+
typealias ScrollToOffset = @convention(c) (AnyObject, Selector, Double, Bool) -> Void
|
|
1225
|
+
let scrollToOffset = unsafeBitCast(owner.method(for: nativeListScrollSelector), to: ScrollToOffset.self)
|
|
1226
|
+
scrollToOffset(owner, nativeListScrollSelector, 0, true)
|
|
1227
|
+
continue
|
|
1228
|
+
}
|
|
1229
|
+
let topOffset = -scrollView.adjustedContentInset.top
|
|
1230
|
+
scrollView.setContentOffset(
|
|
1231
|
+
CGPoint(x: scrollView.contentOffset.x, y: topOffset),
|
|
1232
|
+
animated: true
|
|
1233
|
+
)
|
|
1234
|
+
}
|
|
1235
|
+
var didScrollToTop = !scrollViews.isEmpty
|
|
1236
|
+
var rejectedPagerRequest = false
|
|
1237
|
+
for pager in pagers {
|
|
1238
|
+
if scrollPagerToTop(pager) {
|
|
1239
|
+
didScrollToTop = true
|
|
1240
|
+
} else {
|
|
1241
|
+
rejectedPagerRequest = true
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
return didScrollToTop ? true : (rejectedPagerRequest ? nil : false)
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
// Only content taller than its viewport can be scrolled back to the top.
|
|
1248
|
+
private func isVerticallyScrollable(_ scrollView: UIScrollView) -> Bool {
|
|
1249
|
+
let inset = scrollView.adjustedContentInset
|
|
1250
|
+
let viewportHeight = scrollView.bounds.height - inset.top - inset.bottom
|
|
1251
|
+
return scrollView.contentSize.height > viewportHeight + Self.scrollTopTolerance
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
private func collectScrolledViews(
|
|
1255
|
+
in view: UIView,
|
|
1256
|
+
window: UIWindow,
|
|
1257
|
+
scrollViews: inout [UIScrollView],
|
|
1258
|
+
pagers: inout [UIView]
|
|
1259
|
+
) {
|
|
1260
|
+
guard !view.isHidden, view.alpha > 0.01 else { return }
|
|
1261
|
+
// Pager siblings stay in the hierarchy off screen.
|
|
1262
|
+
var visibleRect = view.convert(view.bounds, to: window).intersection(window.bounds)
|
|
1263
|
+
var ancestor = view.superview
|
|
1264
|
+
while let clippingView = ancestor {
|
|
1265
|
+
if clippingView.clipsToBounds {
|
|
1266
|
+
visibleRect = visibleRect.intersection(clippingView.convert(clippingView.bounds, to: window))
|
|
1267
|
+
}
|
|
1268
|
+
ancestor = clippingView.superview
|
|
1269
|
+
}
|
|
1270
|
+
guard !visibleRect.isEmpty else { return }
|
|
1271
|
+
if let pagerClass = Self.collapsiblePagerClass, view.isKind(of: pagerClass) {
|
|
1272
|
+
// The pager keeps header state for its pages, so moving one of its
|
|
1273
|
+
// scrollers directly leaves the header out of sync. It scrolls itself.
|
|
1274
|
+
var pagerScrollViews: [UIScrollView] = []
|
|
1275
|
+
var nestedPagers: [UIView] = []
|
|
1276
|
+
for subview in view.subviews {
|
|
1277
|
+
collectScrolledViews(
|
|
1278
|
+
in: subview,
|
|
1279
|
+
window: window,
|
|
1280
|
+
scrollViews: &pagerScrollViews,
|
|
1281
|
+
pagers: &nestedPagers
|
|
1282
|
+
)
|
|
1283
|
+
}
|
|
1284
|
+
if !pagerScrollViews.isEmpty || !nestedPagers.isEmpty || isPagerAwayFromTop(view) {
|
|
1285
|
+
pagers.append(view)
|
|
1286
|
+
}
|
|
1287
|
+
return
|
|
1288
|
+
}
|
|
1289
|
+
if let scrollView = view as? UIScrollView,
|
|
1290
|
+
scrollView.isScrollEnabled,
|
|
1291
|
+
isVerticallyScrollable(scrollView),
|
|
1292
|
+
scrollView.contentOffset.y + scrollView.adjustedContentInset.top > Self.scrollTopTolerance {
|
|
1293
|
+
scrollViews.append(scrollView)
|
|
1294
|
+
}
|
|
1295
|
+
for subview in view.subviews {
|
|
1296
|
+
collectScrolledViews(in: subview, window: window, scrollViews: &scrollViews, pagers: &pagers)
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
private func isPagerAwayFromTop(_ pager: UIView) -> Bool {
|
|
1301
|
+
let selector = NSSelectorFromString("isAwayFromPageTop")
|
|
1302
|
+
guard pager.responds(to: selector) else { return false }
|
|
1303
|
+
typealias IsAwayFromPageTop = @convention(c) (AnyObject, Selector) -> Bool
|
|
1304
|
+
let isAwayFromPageTop = unsafeBitCast(pager.method(for: selector), to: IsAwayFromPageTop.self)
|
|
1305
|
+
return isAwayFromPageTop(pager, selector)
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
private func scrollPagerToTop(_ pager: UIView) -> Bool {
|
|
1309
|
+
let selector = NSSelectorFromString("tryScrollToTop:animated:")
|
|
1310
|
+
guard pager.responds(to: selector) else { return false }
|
|
1311
|
+
typealias ScrollToTop = @convention(c) (AnyObject, Selector, Int, Bool) -> Bool
|
|
1312
|
+
let scrollToTop = unsafeBitCast(pager.method(for: selector), to: ScrollToTop.self)
|
|
1313
|
+
return scrollToTop(pager, selector, 0, true)
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1068
1316
|
// MARK: - Bottom accessory placement
|
|
1069
1317
|
|
|
1070
1318
|
func handlePlacementChanged(_ placement: String) {
|
|
@@ -13,9 +13,13 @@
|
|
|
13
13
|
@property(nonatomic) BOOL swipeEnabled;
|
|
14
14
|
@property(nonatomic) BOOL hapticFeedbackEnabled;
|
|
15
15
|
@property(nonatomic) double bottomBarHeight;
|
|
16
|
+
@property(nonatomic, copy) NSString *colorScheme;
|
|
17
|
+
@property(nonatomic) BOOL progressEventsEnabled;
|
|
16
18
|
@property(nonatomic, copy) void (^onDrawerOpenChange)(BOOL open);
|
|
19
|
+
@property(nonatomic, copy) void (^onDrawerProgress)(double progress);
|
|
17
20
|
- (void)insertChild:(UIView *)child atIndex:(NSInteger)index;
|
|
18
21
|
- (void)removeChildAtIndex:(NSInteger)index;
|
|
22
|
+
- (void)resendProgress;
|
|
19
23
|
@end
|
|
20
24
|
|
|
21
25
|
using namespace facebook::react;
|
|
@@ -45,6 +49,12 @@ using namespace facebook::react;
|
|
|
45
49
|
auto emitter = std::static_pointer_cast<const RNBottomTabsDrawerEventEmitter>(strongSelf->_eventEmitter);
|
|
46
50
|
if (emitter) emitter->onDrawerOpenChange({.open = (bool)open});
|
|
47
51
|
};
|
|
52
|
+
_drawer.onDrawerProgress = ^(double progress) {
|
|
53
|
+
auto strongSelf = weakSelf;
|
|
54
|
+
if (!strongSelf) return;
|
|
55
|
+
auto emitter = std::static_pointer_cast<const RNBottomTabsDrawerEventEmitter>(strongSelf->_eventEmitter);
|
|
56
|
+
if (emitter) emitter->onDrawerProgress({.progress = progress});
|
|
57
|
+
};
|
|
48
58
|
}
|
|
49
59
|
return self;
|
|
50
60
|
}
|
|
@@ -59,6 +69,14 @@ using namespace facebook::react;
|
|
|
59
69
|
[_drawer removeChildAtIndex:index];
|
|
60
70
|
}
|
|
61
71
|
|
|
72
|
+
- (void)updateEventEmitter:(EventEmitter::Shared const &)eventEmitter
|
|
73
|
+
{
|
|
74
|
+
[super updateEventEmitter:eventEmitter];
|
|
75
|
+
// Fabric applies a mount's props before its emitter, so a position reported
|
|
76
|
+
// then never left native; send the current one now.
|
|
77
|
+
[_drawer resendProgress];
|
|
78
|
+
}
|
|
79
|
+
|
|
62
80
|
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
|
63
81
|
{
|
|
64
82
|
const auto &next = *std::static_pointer_cast<const RNBottomTabsDrawerProps>(props);
|
|
@@ -69,6 +87,12 @@ using namespace facebook::react;
|
|
|
69
87
|
if (next.hapticFeedbackEnabled != previous.hapticFeedbackEnabled)
|
|
70
88
|
_drawer.hapticFeedbackEnabled = next.hapticFeedbackEnabled;
|
|
71
89
|
if (next.bottomBarHeight != previous.bottomBarHeight) _drawer.bottomBarHeight = next.bottomBarHeight;
|
|
90
|
+
if (next.colorScheme != previous.colorScheme) {
|
|
91
|
+
_drawer.colorScheme = next.colorScheme == RNBottomTabsDrawerColorScheme::Light ? @"light"
|
|
92
|
+
: next.colorScheme == RNBottomTabsDrawerColorScheme::Dark ? @"dark" : @"system";
|
|
93
|
+
}
|
|
94
|
+
if (next.progressEventsEnabled != previous.progressEventsEnabled)
|
|
95
|
+
_drawer.progressEventsEnabled = next.progressEventsEnabled;
|
|
72
96
|
[super updateProps:props oldProps:oldProps];
|
|
73
97
|
}
|
|
74
98
|
@end
|