@onekeyfe/react-native-bottom-tabs 6.8.0-22 → 6.8.0-24
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 +39 -0
- package/ios/RCTBottomTabsContainerView.swift +92 -10
- package/lib/module/BottomTabs.js +4 -3
- package/package.json +1 -1
- package/src/BottomTabs.tsx +10 -7
package/docs/SPEC.md
CHANGED
|
@@ -548,6 +548,45 @@ placement and can draw one round accessory button above the vertical bar.
|
|
|
548
548
|
layout, tab rebuilds, tab bar hiding, icon loads, and changes to the traits
|
|
549
549
|
affecting `verticalBarEdge`.
|
|
550
550
|
|
|
551
|
+
## iOS tab scene sizing
|
|
552
|
+
|
|
553
|
+
Each tab's React scene is hosted in the root view of that tab's
|
|
554
|
+
`UIViewController`. Fabric owns the scene's frame, including any offset or size
|
|
555
|
+
from `getSceneStyle`. Native code never writes it. The scene has no
|
|
556
|
+
autoresizing mask and no Auto Layout constraints.
|
|
557
|
+
|
|
558
|
+
- `onNativeLayout` reports the size of the selected tab's page view once it is
|
|
559
|
+
in the window, and the container's size before that. It fires on container
|
|
560
|
+
layout, when the selected page changes size, and when the selected page
|
|
561
|
+
appears or reattaches to a window even if its bounds are unchanged.
|
|
562
|
+
- Loaded scenes and lazy placeholders use the reported page size with either
|
|
563
|
+
a native or custom tab bar. They fill the container until a measurement
|
|
564
|
+
arrives. For loaded scenes, `getSceneStyle` can override the size and position.
|
|
565
|
+
The default frame matches the visible page when the iPad sidebar
|
|
566
|
+
(`sidebarAdaptable`) takes part of the width.
|
|
567
|
+
- Autoresizing is not used because it applies the change in host bounds to the
|
|
568
|
+
frame Fabric already set. A tab view controller's view starts at screen size
|
|
569
|
+
and Fabric sizes the scene to the container. When the container is narrower
|
|
570
|
+
than the screen (an iPad split pane), the first resize to the container width
|
|
571
|
+
subtracted that difference again. The scene became 0 points wide: its content
|
|
572
|
+
still drew outside the scene's bounds, but UIKit hit-testing skipped it, so
|
|
573
|
+
the tab ignored every touch and scroll.
|
|
574
|
+
- A scene that is unmounted and reused by Fabric elsewhere keeps no mask, so it
|
|
575
|
+
is never resized by its next superview.
|
|
576
|
+
|
|
577
|
+
Acceptance:
|
|
578
|
+
|
|
579
|
+
- On an iPad in landscape split view, first-open every tab in each pane after
|
|
580
|
+
another tab, and after rotating. Each tab scene's frame equals its view
|
|
581
|
+
controller's view bounds, and the tab responds to taps and scrolls.
|
|
582
|
+
- With `sidebarAdaptable` and the sidebar shown, the `onNativeLayout` width
|
|
583
|
+
equals the selected page's width. The default scene and placeholder sizes
|
|
584
|
+
follow that width even with a custom tab bar and `tabBarHidden={false}`.
|
|
585
|
+
- Selecting a cached page or reattaching the tab container reports the visible
|
|
586
|
+
page's width and height even when the page and container bounds did not change.
|
|
587
|
+
- A route whose scene style sets its own offset or size keeps that frame after
|
|
588
|
+
UIKit layout passes.
|
|
589
|
+
|
|
551
590
|
## Threading and ownership
|
|
552
591
|
|
|
553
592
|
All gesture handling, animations, and timers run on the platform UI thread in
|
|
@@ -20,6 +20,60 @@ import React
|
|
|
20
20
|
)
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/// Root view of one tab's view controller. It hosts the React scene but never
|
|
24
|
+
/// writes the scene's frame: Fabric owns it, including any per-route
|
|
25
|
+
/// `getSceneStyle` offset or size.
|
|
26
|
+
///
|
|
27
|
+
/// The scene used to autoresize with this view. Autoresizing applies the change
|
|
28
|
+
/// in bounds on top of the frame Fabric set: a tab view controller's view
|
|
29
|
+
/// starts at screen size, Fabric sizes the scene to the narrower container (an
|
|
30
|
+
/// iPad split pane), and the first resize to the pane width subtracted the
|
|
31
|
+
/// difference again, leaving the scene 0 points wide. Its content still drew
|
|
32
|
+
/// but no longer received touches. The scene now has no autoresizing mask, and
|
|
33
|
+
/// the container reports the selected page's size to JS so Fabric lays the
|
|
34
|
+
/// scene out at the page size (it differs from the container when the iPad
|
|
35
|
+
/// sidebar takes part of the width).
|
|
36
|
+
final class BottomTabsPageView: UIView {
|
|
37
|
+
var onLayoutChange: ((BottomTabsPageView) -> Void)?
|
|
38
|
+
private var lastSize: CGSize = .zero
|
|
39
|
+
|
|
40
|
+
override func layoutSubviews() {
|
|
41
|
+
super.layoutSubviews()
|
|
42
|
+
let size = bounds.size
|
|
43
|
+
guard size != lastSize else { return }
|
|
44
|
+
lastSize = size
|
|
45
|
+
onLayoutChange?(self)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
override func didMoveToWindow() {
|
|
49
|
+
super.didMoveToWindow()
|
|
50
|
+
guard window != nil else { return }
|
|
51
|
+
// UIKit can update the page bounds after this attachment callback.
|
|
52
|
+
DispatchQueue.main.async { [weak self] in
|
|
53
|
+
guard let self, self.window != nil else { return }
|
|
54
|
+
self.onLayoutChange?(self)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
final class BottomTabsPageViewController: UIViewController {
|
|
60
|
+
var pageView: BottomTabsPageView { view as! BottomTabsPageView }
|
|
61
|
+
|
|
62
|
+
override func loadView() {
|
|
63
|
+
let pageView = BottomTabsPageView()
|
|
64
|
+
pageView.backgroundColor = .clear
|
|
65
|
+
pageView.clipsToBounds = true
|
|
66
|
+
view = pageView
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
override func viewDidAppear(_ animated: Bool) {
|
|
70
|
+
super.viewDidAppear(animated)
|
|
71
|
+
// A cached page can become selected without changing bounds or windows.
|
|
72
|
+
let page = pageView
|
|
73
|
+
page.onLayoutChange?(page)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
23
77
|
/// Bridges to OneKeyNamedSVG.shared in OneKeyImage without importing the OneKeyImage
|
|
24
78
|
/// Swift module (which transitively imports NitroModules C++ headers).
|
|
25
79
|
private enum OneKeyNamedSVGLoader {
|
|
@@ -138,7 +192,8 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
138
192
|
private var lastPressedTabKey: String?
|
|
139
193
|
private var lastPressedTabTime: CFTimeInterval = 0
|
|
140
194
|
/// Cached view controllers keyed by tab key to avoid unnecessary reparenting
|
|
141
|
-
private var cachedViewControllers: [String:
|
|
195
|
+
private var cachedViewControllers: [String: BottomTabsPageViewController] = [:]
|
|
196
|
+
private var isHandlingLayout = false
|
|
142
197
|
private var pendingIconUpdates = Set<Int>()
|
|
143
198
|
private var isIconUpdateScheduled = false
|
|
144
199
|
// Vertical tab bar (iPhone Duo side strip): last reported placement and the
|
|
@@ -520,10 +575,36 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
520
575
|
|
|
521
576
|
setupTabBarControllerIfNeeded()
|
|
522
577
|
tabBarController?.view.frame = bounds
|
|
523
|
-
|
|
578
|
+
// Settle the selected page's frame first so the size reported below is
|
|
579
|
+
// the current one, not the page's size before this pass.
|
|
580
|
+
isHandlingLayout = true
|
|
581
|
+
tabBarController?.view.layoutIfNeeded()
|
|
582
|
+
isHandlingLayout = false
|
|
583
|
+
emitSceneLayout()
|
|
524
584
|
scheduleSideAccessoryLayout()
|
|
525
585
|
}
|
|
526
586
|
|
|
587
|
+
/// Reports the size React lays every tab scene out at: the selected page's
|
|
588
|
+
/// bounds (narrower than the container when the iPad sidebar is shown), or
|
|
589
|
+
/// the container's bounds until that page is in the window.
|
|
590
|
+
private func emitSceneLayout() {
|
|
591
|
+
var size = bounds.size
|
|
592
|
+
if let page = tabBarController?.selectedViewController?.viewIfLoaded,
|
|
593
|
+
page.window != nil,
|
|
594
|
+
page.bounds.width > 0, page.bounds.height > 0 {
|
|
595
|
+
size = page.bounds.size
|
|
596
|
+
}
|
|
597
|
+
guard size.width > 0 && size.height > 0 else { return }
|
|
598
|
+
onNativeLayout?(["width": Double(size.width), "height": Double(size.height)])
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
private func pageDidChangeLayout(_ page: BottomTabsPageView) {
|
|
602
|
+
// handleLayout emits once after its own layout pass.
|
|
603
|
+
guard !isHandlingLayout,
|
|
604
|
+
page === tabBarController?.selectedViewController?.viewIfLoaded else { return }
|
|
605
|
+
emitSceneLayout()
|
|
606
|
+
}
|
|
607
|
+
|
|
527
608
|
private func setupTabBarControllerIfNeeded() {
|
|
528
609
|
guard tabBarController == nil else { return }
|
|
529
610
|
guard let parentVC = self.reactViewController() else { return }
|
|
@@ -578,13 +659,11 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
578
659
|
usedKeys.insert(tabData.key)
|
|
579
660
|
|
|
580
661
|
// Reuse cached VC or create a new one
|
|
581
|
-
let vc:
|
|
662
|
+
let vc: BottomTabsPageViewController
|
|
582
663
|
if let cached = cachedViewControllers[tabData.key] {
|
|
583
664
|
vc = cached
|
|
584
665
|
} else {
|
|
585
|
-
vc =
|
|
586
|
-
vc.view.backgroundColor = .clear
|
|
587
|
-
vc.view.clipsToBounds = true
|
|
666
|
+
vc = BottomTabsPageViewController()
|
|
588
667
|
cachedViewControllers[tabData.key] = vc
|
|
589
668
|
}
|
|
590
669
|
|
|
@@ -594,13 +673,16 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
594
673
|
if childView.superview !== vc.view {
|
|
595
674
|
childView.removeFromSuperview()
|
|
596
675
|
vc.view.addSubview(childView)
|
|
597
|
-
//
|
|
598
|
-
//
|
|
676
|
+
// Neither Auto Layout constraints (they conflict with the frames
|
|
677
|
+
// Fabric sets on later mounts) nor autoresizing (it applies bounds
|
|
678
|
+
// deltas to a frame Fabric already set): the frame stays Fabric's.
|
|
599
679
|
childView.translatesAutoresizingMaskIntoConstraints = true
|
|
600
|
-
childView.autoresizingMask = [
|
|
601
|
-
childView.frame = vc.view.bounds
|
|
680
|
+
childView.autoresizingMask = []
|
|
602
681
|
}
|
|
603
682
|
}
|
|
683
|
+
vc.pageView.onLayoutChange = { [weak self] page in
|
|
684
|
+
self?.pageDidChangeLayout(page)
|
|
685
|
+
}
|
|
604
686
|
|
|
605
687
|
// Configure tab bar item
|
|
606
688
|
let icon = loadedIcons[originalIndex]
|
package/lib/module/BottomTabs.js
CHANGED
|
@@ -298,7 +298,7 @@ const BottomTabs = ({
|
|
|
298
298
|
width,
|
|
299
299
|
height
|
|
300
300
|
} = event.nativeEvent;
|
|
301
|
-
setMeasuredDimensions({
|
|
301
|
+
setMeasuredDimensions(previous => previous?.width === width && previous.height === height ? previous : {
|
|
302
302
|
width,
|
|
303
303
|
height
|
|
304
304
|
});
|
|
@@ -325,6 +325,7 @@ const BottomTabs = ({
|
|
|
325
325
|
});
|
|
326
326
|
}
|
|
327
327
|
}, [renderCustomTabBar]);
|
|
328
|
+
const sceneSize = isIOS || !renderCustomTabBar ? measuredDimensions : styles.fullWidth;
|
|
328
329
|
return /*#__PURE__*/_jsx(BottomTabBarHeightContext.Provider, {
|
|
329
330
|
value: tabBarHeight,
|
|
330
331
|
children: /*#__PURE__*/_jsxs(DrawerHostWithProgress, {
|
|
@@ -377,7 +378,7 @@ const BottomTabs = ({
|
|
|
377
378
|
}) !== false && !loaded.includes(route.key)) {
|
|
378
379
|
return /*#__PURE__*/_jsx(View, {
|
|
379
380
|
collapsable: false,
|
|
380
|
-
style: styles.fullWidth,
|
|
381
|
+
style: isIOS ? [styles.screen, sceneSize] : styles.fullWidth,
|
|
381
382
|
children: renderLazyPlaceholder?.({
|
|
382
383
|
route
|
|
383
384
|
})
|
|
@@ -391,7 +392,7 @@ const BottomTabs = ({
|
|
|
391
392
|
route
|
|
392
393
|
});
|
|
393
394
|
return /*#__PURE__*/_jsx(View, {
|
|
394
|
-
style: [styles.screen,
|
|
395
|
+
style: [styles.screen, sceneSize, customStyle],
|
|
395
396
|
collapsable: false,
|
|
396
397
|
pointerEvents: focused ? "auto" : "none",
|
|
397
398
|
accessibilityElementsHidden: !focused,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-bottom-tabs",
|
|
3
|
-
"version": "6.8.0-
|
|
3
|
+
"version": "6.8.0-24",
|
|
4
4
|
"description": "Native bottom tabs (tab bar + scene container) for React Native on iOS and Android",
|
|
5
5
|
"source": "./src/index.tsx",
|
|
6
6
|
"main": "./lib/module/index.js",
|
package/src/BottomTabs.tsx
CHANGED
|
@@ -610,7 +610,11 @@ const BottomTabs = <Route extends BaseRoute>({
|
|
|
610
610
|
const handleNativeLayout = React.useCallback(
|
|
611
611
|
(event: NativeSyntheticEvent<{ width: number; height: number }>) => {
|
|
612
612
|
const { width, height } = event.nativeEvent;
|
|
613
|
-
setMeasuredDimensions(
|
|
613
|
+
setMeasuredDimensions((previous) =>
|
|
614
|
+
previous?.width === width && previous.height === height
|
|
615
|
+
? previous
|
|
616
|
+
: { width, height }
|
|
617
|
+
);
|
|
614
618
|
},
|
|
615
619
|
[setMeasuredDimensions]
|
|
616
620
|
);
|
|
@@ -646,6 +650,9 @@ const BottomTabs = <Route extends BaseRoute>({
|
|
|
646
650
|
}
|
|
647
651
|
}, [renderCustomTabBar]);
|
|
648
652
|
|
|
653
|
+
const sceneSize =
|
|
654
|
+
isIOS || !renderCustomTabBar ? measuredDimensions : styles.fullWidth;
|
|
655
|
+
|
|
649
656
|
return (
|
|
650
657
|
<BottomTabBarHeightContext.Provider value={tabBarHeight}>
|
|
651
658
|
<DrawerHostWithProgress
|
|
@@ -707,7 +714,7 @@ const BottomTabs = <Route extends BaseRoute>({
|
|
|
707
714
|
<View
|
|
708
715
|
key={route.key}
|
|
709
716
|
collapsable={false}
|
|
710
|
-
style={styles.fullWidth}
|
|
717
|
+
style={isIOS ? [styles.screen, sceneSize] : styles.fullWidth}
|
|
711
718
|
>
|
|
712
719
|
{renderLazyPlaceholder?.({ route })}
|
|
713
720
|
</View>
|
|
@@ -722,11 +729,7 @@ const BottomTabs = <Route extends BaseRoute>({
|
|
|
722
729
|
return (
|
|
723
730
|
<View
|
|
724
731
|
key={route.key}
|
|
725
|
-
style={[
|
|
726
|
-
styles.screen,
|
|
727
|
-
renderCustomTabBar ? styles.fullWidth : measuredDimensions,
|
|
728
|
-
customStyle,
|
|
729
|
-
]}
|
|
732
|
+
style={[styles.screen, sceneSize, customStyle]}
|
|
730
733
|
collapsable={false}
|
|
731
734
|
pointerEvents={focused ? "auto" : "none"}
|
|
732
735
|
accessibilityElementsHidden={!focused}
|