@onekeyfe/react-native-bottom-tabs 6.7.0-alpha.466 → 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
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
import XCTest
|
|
3
|
+
@testable import BottomTabsModule
|
|
4
|
+
|
|
5
|
+
/// Reduce Motion cross-fades: when a faded transition reports, and what takes
|
|
6
|
+
/// it over. Runs without an app host.
|
|
7
|
+
@MainActor
|
|
8
|
+
final class BottomTabsDrawerReduceMotionTests: XCTestCase {
|
|
9
|
+
func testUserCloseReportsOnceWhenTheFadeEnds() throws {
|
|
10
|
+
let fixture = Fixture(open: true)
|
|
11
|
+
defer { fixture.close() }
|
|
12
|
+
|
|
13
|
+
XCTAssertTrue(fixture.drawer.accessibilityPerformEscape())
|
|
14
|
+
try fixture.requireFade()
|
|
15
|
+
XCTAssertEqual(fixture.progress, 0, "the final state shows under the snapshot")
|
|
16
|
+
XCTAssertEqual(fixture.events, [], "nothing is reported while the fade runs")
|
|
17
|
+
XCTAssertEqual(fixture.stableOpen, true)
|
|
18
|
+
|
|
19
|
+
XCTAssertTrue(fixture.waitUntil { !fixture.isFading })
|
|
20
|
+
XCTAssertEqual(fixture.events, [false])
|
|
21
|
+
XCTAssertEqual(fixture.fadingAtEvent, [false], "the report waits for the snapshot to go")
|
|
22
|
+
XCTAssertEqual(fixture.stableOpen, false)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
func testDragTakingOverTheFadeDropsItsStaleClose() throws {
|
|
26
|
+
let fixture = Fixture(open: true)
|
|
27
|
+
defer { fixture.close() }
|
|
28
|
+
XCTAssertTrue(fixture.drawer.accessibilityPerformEscape())
|
|
29
|
+
try fixture.requireFade()
|
|
30
|
+
|
|
31
|
+
fixture.pan(.began)
|
|
32
|
+
XCTAssertFalse(fixture.isFading)
|
|
33
|
+
// A close reported here would echo back as `open = false` and cancel the drag.
|
|
34
|
+
XCTAssertEqual(fixture.events, [])
|
|
35
|
+
fixture.pan(.changed, dx: fixture.menuWidth * 0.9)
|
|
36
|
+
XCTAssertEqual(fixture.progress, 0.9, accuracy: 0.001)
|
|
37
|
+
fixture.pan(.ended)
|
|
38
|
+
XCTAssertTrue(fixture.waitUntil { !fixture.isAnimating })
|
|
39
|
+
|
|
40
|
+
XCTAssertEqual(fixture.progress, 1)
|
|
41
|
+
XCTAssertEqual(fixture.stableOpen, true)
|
|
42
|
+
XCTAssertEqual(fixture.events, [], "reopening lands on the state JS already has")
|
|
43
|
+
fixture.wait(0.3)
|
|
44
|
+
XCTAssertEqual(fixture.events, [])
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
func testDragTakingOverTheFadeReportsItsOwnClose() throws {
|
|
48
|
+
let fixture = Fixture(open: true)
|
|
49
|
+
defer { fixture.close() }
|
|
50
|
+
XCTAssertTrue(fixture.drawer.accessibilityPerformEscape())
|
|
51
|
+
try fixture.requireFade()
|
|
52
|
+
|
|
53
|
+
fixture.pan(.began)
|
|
54
|
+
fixture.pan(.changed, dx: fixture.menuWidth * 0.2)
|
|
55
|
+
fixture.pan(.ended)
|
|
56
|
+
XCTAssertTrue(fixture.waitUntil { !fixture.isAnimating })
|
|
57
|
+
|
|
58
|
+
XCTAssertEqual(fixture.progress, 0)
|
|
59
|
+
XCTAssertEqual(fixture.events, [false])
|
|
60
|
+
fixture.wait(0.3)
|
|
61
|
+
XCTAssertEqual(fixture.events, [false])
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
func testResizeLandsTheFadeAtOnce() throws {
|
|
65
|
+
let fixture = Fixture(open: true)
|
|
66
|
+
defer { fixture.close() }
|
|
67
|
+
XCTAssertTrue(fixture.drawer.accessibilityPerformEscape())
|
|
68
|
+
try fixture.requireFade()
|
|
69
|
+
|
|
70
|
+
fixture.drawer.frame.size.width = 420
|
|
71
|
+
fixture.drawer.layoutIfNeeded()
|
|
72
|
+
XCTAssertFalse(fixture.isFading)
|
|
73
|
+
XCTAssertEqual(fixture.events, [false])
|
|
74
|
+
XCTAssertEqual(fixture.stableOpen, false)
|
|
75
|
+
fixture.wait(0.3)
|
|
76
|
+
XCTAssertEqual(fixture.events, [false], "the replaced fade does not report again")
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
func testNewerRequestsTakeOverTheFadeAndItsCompletion() throws {
|
|
80
|
+
let fixture = Fixture(open: true)
|
|
81
|
+
defer { fixture.close() }
|
|
82
|
+
XCTAssertTrue(fixture.drawer.accessibilityPerformEscape())
|
|
83
|
+
try fixture.requireFade()
|
|
84
|
+
|
|
85
|
+
// JS closes too: same target, so the landing is no longer a user event.
|
|
86
|
+
fixture.drawer.open = false
|
|
87
|
+
// JS reopens: a newer fade replaces the first, keeping one snapshot.
|
|
88
|
+
fixture.drawer.open = true
|
|
89
|
+
try fixture.requireFade()
|
|
90
|
+
XCTAssertEqual(fixture.drawer.subviews.count, 3)
|
|
91
|
+
XCTAssertEqual(fixture.progress, 1)
|
|
92
|
+
|
|
93
|
+
XCTAssertTrue(fixture.waitUntil { !fixture.isFading })
|
|
94
|
+
fixture.wait(0.3)
|
|
95
|
+
XCTAssertEqual(fixture.events, [])
|
|
96
|
+
XCTAssertEqual(fixture.stableOpen, true)
|
|
97
|
+
XCTAssertEqual(fixture.drawer.subviews.count, 2)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
func testTouchesLandOnTheHostUntilTheFadeEnds() throws {
|
|
101
|
+
// Closing: the menu still shows, over a page already back in place.
|
|
102
|
+
let closing = Fixture(open: true)
|
|
103
|
+
defer { closing.close() }
|
|
104
|
+
let inMenu = CGPoint(x: closing.menuWidth / 2, y: 100)
|
|
105
|
+
XCTAssertTrue(closing.drawer.accessibilityPerformEscape())
|
|
106
|
+
try closing.requireFade()
|
|
107
|
+
XCTAssertTrue(closing.hit(inMenu) === closing.drawer, "not the page under the shown menu")
|
|
108
|
+
XCTAssertTrue(closing.waitUntil { !closing.isFading })
|
|
109
|
+
XCTAssertTrue(closing.hit(inMenu) === closing.page)
|
|
110
|
+
|
|
111
|
+
// Opening: the page still shows, over a menu and dim already open.
|
|
112
|
+
let opening = Fixture(open: false)
|
|
113
|
+
defer { opening.close() }
|
|
114
|
+
let onDim = CGPoint(x: opening.menuWidth + 20, y: 100)
|
|
115
|
+
opening.drawer.open = true
|
|
116
|
+
try opening.requireFade()
|
|
117
|
+
XCTAssertTrue(opening.hit(inMenu) === opening.drawer, "not the menu under the shown page")
|
|
118
|
+
XCTAssertTrue(opening.hit(onDim) === opening.drawer, "not the dim, which would close")
|
|
119
|
+
XCTAssertTrue(opening.waitUntil { !opening.isFading })
|
|
120
|
+
XCTAssertTrue(opening.hit(inMenu) === opening.menu)
|
|
121
|
+
XCTAssertTrue(opening.hit(onDim) is UIButton)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
func testDisablingOrDetachingDropsThePendingClose() throws {
|
|
125
|
+
let disabled = Fixture(open: true)
|
|
126
|
+
defer { disabled.close() }
|
|
127
|
+
XCTAssertTrue(disabled.drawer.accessibilityPerformEscape())
|
|
128
|
+
try disabled.requireFade()
|
|
129
|
+
disabled.drawer.enabled = false
|
|
130
|
+
XCTAssertFalse(disabled.isFading)
|
|
131
|
+
disabled.wait(0.3)
|
|
132
|
+
XCTAssertEqual(disabled.events, [])
|
|
133
|
+
|
|
134
|
+
let detached = Fixture(open: true)
|
|
135
|
+
defer { detached.close() }
|
|
136
|
+
XCTAssertTrue(detached.drawer.accessibilityPerformEscape())
|
|
137
|
+
try detached.requireFade()
|
|
138
|
+
detached.drawer.removeFromSuperview()
|
|
139
|
+
XCTAssertFalse(detached.isFading)
|
|
140
|
+
// Like an interrupted settle, it returns to the last state JS was told.
|
|
141
|
+
XCTAssertEqual(detached.progress, 1)
|
|
142
|
+
detached.wait(0.3)
|
|
143
|
+
XCTAssertEqual(detached.events, [])
|
|
144
|
+
detached.window.addSubview(detached.drawer)
|
|
145
|
+
XCTAssertEqual(detached.progress, 1)
|
|
146
|
+
XCTAssertEqual(detached.events, [])
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@MainActor
|
|
151
|
+
private final class Fixture {
|
|
152
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 390, height: 844))
|
|
153
|
+
let drawer = RCTBottomTabsDrawerContainerView(frame: CGRect(x: 0, y: 0, width: 390, height: 844))
|
|
154
|
+
let menu = UIView()
|
|
155
|
+
let page = UIView()
|
|
156
|
+
private(set) var events: [Bool] = []
|
|
157
|
+
private(set) var fadingAtEvent: [Bool] = []
|
|
158
|
+
private let recognizer = FakePan(target: nil, action: nil)
|
|
159
|
+
|
|
160
|
+
/// An enabled drawer that already rests at `open`, as the prop echo leaves it.
|
|
161
|
+
init(open: Bool) {
|
|
162
|
+
drawer.isReduceMotionEnabled = { true }
|
|
163
|
+
drawer.makeFadeSnapshot = { _ in UIView() }
|
|
164
|
+
drawer.insertChild(menu, atIndex: 0)
|
|
165
|
+
drawer.insertChild(page, atIndex: 1)
|
|
166
|
+
drawer.swipeEnabled = true
|
|
167
|
+
drawer.enabled = true
|
|
168
|
+
// Outside a window, the drawer lands on a target without animating.
|
|
169
|
+
drawer.open = open
|
|
170
|
+
window.addSubview(drawer)
|
|
171
|
+
window.isHidden = false
|
|
172
|
+
drawer.layoutIfNeeded()
|
|
173
|
+
drawer.onDrawerOpenChange = { [unowned self] open in
|
|
174
|
+
self.events.append(open)
|
|
175
|
+
self.fadingAtEvent.append(self.isFading)
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
var menuWidth: CGFloat { drawer.bounds.width * 0.8 }
|
|
180
|
+
var progress: CGFloat { value("progress") ?? -1 }
|
|
181
|
+
var stableOpen: Bool? { value("stableOpen") }
|
|
182
|
+
var isFading: Bool { value("fadeSnapshot") as UIView? != nil }
|
|
183
|
+
var isAnimating: Bool { value("displayLink") as CADisplayLink? != nil }
|
|
184
|
+
|
|
185
|
+
func requireFade(file: StaticString = #filePath, line: UInt = #line) throws {
|
|
186
|
+
_ = try XCTUnwrap(value("fadeSnapshot") as UIView?, "Reduce Motion should cross-fade",
|
|
187
|
+
file: file, line: line)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/// The view UIKit would deliver a touch at `point` to.
|
|
191
|
+
func hit(_ point: CGPoint) -> UIView? { drawer.hitTest(point, with: nil) }
|
|
192
|
+
|
|
193
|
+
/// Delivers one recognizer callback, as UIKit does for the drawer's pan.
|
|
194
|
+
func pan(_ state: UIGestureRecognizer.State, dx: CGFloat = 0) {
|
|
195
|
+
recognizer.fakeState = state
|
|
196
|
+
recognizer.fakeTranslation = CGPoint(x: dx, y: 0)
|
|
197
|
+
drawer.perform(NSSelectorFromString("handlePan:"), with: recognizer)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
func wait(_ seconds: TimeInterval) {
|
|
201
|
+
RunLoop.main.run(until: Date().addingTimeInterval(seconds))
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
func waitUntil(timeout: TimeInterval = 2, _ condition: () -> Bool) -> Bool {
|
|
205
|
+
let deadline = Date().addingTimeInterval(timeout)
|
|
206
|
+
while !condition() && Date() < deadline { wait(0.01) }
|
|
207
|
+
return condition()
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
func close() {
|
|
211
|
+
drawer.removeFromSuperview()
|
|
212
|
+
window.isHidden = true
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private func value<T>(_ name: String) -> T? {
|
|
216
|
+
Mirror(reflecting: drawer).descendant(name) as? T
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private final class FakePan: UIPanGestureRecognizer {
|
|
221
|
+
var fakeState: UIGestureRecognizer.State = .possible
|
|
222
|
+
var fakeTranslation = CGPoint.zero
|
|
223
|
+
|
|
224
|
+
override var state: UIGestureRecognizer.State {
|
|
225
|
+
get { fakeState }
|
|
226
|
+
set { fakeState = newValue }
|
|
227
|
+
}
|
|
228
|
+
override var numberOfTouches: Int { 1 }
|
|
229
|
+
override func translation(in view: UIView?) -> CGPoint { fakeTranslation }
|
|
230
|
+
override func velocity(in view: UIView?) -> CGPoint { .zero }
|
|
231
|
+
}
|
package/lib/module/BottomTabs.js
CHANGED
|
@@ -76,11 +76,65 @@ export const resolveTabIconSource = icon => {
|
|
|
76
76
|
scale: resolved?.scale ?? 1
|
|
77
77
|
};
|
|
78
78
|
};
|
|
79
|
+
const defaultGetBadge = ({
|
|
80
|
+
route
|
|
81
|
+
}) => route.badge;
|
|
82
|
+
const defaultGetBadgeBackgroundColor = ({
|
|
83
|
+
route
|
|
84
|
+
}) => route.badgeBackgroundColor;
|
|
85
|
+
const defaultGetBadgeTextColor = ({
|
|
86
|
+
route
|
|
87
|
+
}) => route.badgeTextColor;
|
|
88
|
+
const defaultGetLazy = ({
|
|
89
|
+
route
|
|
90
|
+
}) => route.lazy;
|
|
91
|
+
const defaultGetLabelText = ({
|
|
92
|
+
route
|
|
93
|
+
}) => route.title;
|
|
94
|
+
const defaultGetHidden = ({
|
|
95
|
+
route
|
|
96
|
+
}) => route.hidden;
|
|
97
|
+
const defaultGetActiveTintColor = ({
|
|
98
|
+
route
|
|
99
|
+
}) => route.activeTintColor;
|
|
100
|
+
const defaultGetTestID = ({
|
|
101
|
+
route
|
|
102
|
+
}) => route.testID;
|
|
103
|
+
const defaultGetRole = ({
|
|
104
|
+
route
|
|
105
|
+
}) => route.role;
|
|
106
|
+
const defaultGetSceneStyle = ({
|
|
107
|
+
route
|
|
108
|
+
}) => route.style;
|
|
109
|
+
const defaultGetPreventsDefault = ({
|
|
110
|
+
route
|
|
111
|
+
}) => route.preventsDefault;
|
|
112
|
+
const defaultGetFreezeOnBlur = ({
|
|
113
|
+
route
|
|
114
|
+
}) => route.freezeOnBlur;
|
|
79
115
|
const defaultGetIcon = ({
|
|
80
116
|
route,
|
|
81
117
|
focused
|
|
82
118
|
}) => route.unfocusedIcon ? focused ? route.focusedIcon : route.unfocusedIcon : route.focusedIcon;
|
|
83
119
|
const ANDROID_MAX_TABS = 100;
|
|
120
|
+
// Progress events start one commit after mount: during the mount itself the
|
|
121
|
+
// iOS event emitter and an animated host's worklet handler are not attached
|
|
122
|
+
// yet, so the current position native sends on enabling would be lost. The
|
|
123
|
+
// state lives here so that commit re-renders only the host, not the tabs.
|
|
124
|
+
function DrawerHostWithProgress({
|
|
125
|
+
host: Host,
|
|
126
|
+
...props
|
|
127
|
+
}) {
|
|
128
|
+
const hasProgressHandler = props.onDrawerProgress != null;
|
|
129
|
+
const [mounted, setMounted] = React.useState(false);
|
|
130
|
+
React.useEffect(() => {
|
|
131
|
+
if (hasProgressHandler) setMounted(true);
|
|
132
|
+
}, [hasProgressHandler]);
|
|
133
|
+
return /*#__PURE__*/_jsx(Host, {
|
|
134
|
+
...props,
|
|
135
|
+
progressEventsEnabled: mounted && hasProgressHandler
|
|
136
|
+
});
|
|
137
|
+
}
|
|
84
138
|
const BottomTabs = ({
|
|
85
139
|
navigationState,
|
|
86
140
|
renderScene,
|
|
@@ -91,48 +145,27 @@ const BottomTabs = ({
|
|
|
91
145
|
drawerOpen = false,
|
|
92
146
|
drawerSwipeEnabled = false,
|
|
93
147
|
onDrawerOpenChange,
|
|
148
|
+
onDrawerProgress,
|
|
149
|
+
drawerHostComponent: DrawerHost = NativeBottomTabsDrawer,
|
|
150
|
+
drawerColorScheme,
|
|
94
151
|
rippleColor,
|
|
95
152
|
tabBarActiveTintColor: activeTintColor,
|
|
96
153
|
tabBarInactiveTintColor: inactiveTintColor,
|
|
97
|
-
getBadge =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}) => route.badgeBackgroundColor,
|
|
103
|
-
getBadgeTextColor = ({
|
|
104
|
-
route
|
|
105
|
-
}) => route.badgeTextColor,
|
|
106
|
-
getLazy = ({
|
|
107
|
-
route
|
|
108
|
-
}) => route.lazy,
|
|
109
|
-
getLabelText = ({
|
|
110
|
-
route
|
|
111
|
-
}) => route.title,
|
|
154
|
+
getBadge = defaultGetBadge,
|
|
155
|
+
getBadgeBackgroundColor = defaultGetBadgeBackgroundColor,
|
|
156
|
+
getBadgeTextColor = defaultGetBadgeTextColor,
|
|
157
|
+
getLazy = defaultGetLazy,
|
|
158
|
+
getLabelText = defaultGetLabelText,
|
|
112
159
|
getIcon = defaultGetIcon,
|
|
113
|
-
getHidden =
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
getTestID = ({
|
|
120
|
-
route
|
|
121
|
-
}) => route.testID,
|
|
122
|
-
getRole = ({
|
|
123
|
-
route
|
|
124
|
-
}) => route.role,
|
|
125
|
-
getSceneStyle = ({
|
|
126
|
-
route
|
|
127
|
-
}) => route.style,
|
|
128
|
-
getPreventsDefault = ({
|
|
129
|
-
route
|
|
130
|
-
}) => route.preventsDefault,
|
|
160
|
+
getHidden = defaultGetHidden,
|
|
161
|
+
getActiveTintColor = defaultGetActiveTintColor,
|
|
162
|
+
getTestID = defaultGetTestID,
|
|
163
|
+
getRole = defaultGetRole,
|
|
164
|
+
getSceneStyle = defaultGetSceneStyle,
|
|
165
|
+
getPreventsDefault = defaultGetPreventsDefault,
|
|
131
166
|
hapticFeedbackEnabled = false,
|
|
132
167
|
labeled = Platform.OS !== "android" ? true : undefined,
|
|
133
|
-
getFreezeOnBlur =
|
|
134
|
-
route
|
|
135
|
-
}) => route.freezeOnBlur,
|
|
168
|
+
getFreezeOnBlur = defaultGetFreezeOnBlur,
|
|
136
169
|
tabBar: renderCustomTabBar,
|
|
137
170
|
tabBarStyle,
|
|
138
171
|
tabLabelStyle,
|
|
@@ -178,24 +211,16 @@ const BottomTabs = ({
|
|
|
178
211
|
route,
|
|
179
212
|
focused: false
|
|
180
213
|
})), [getIcon, trimmedRoutes]);
|
|
181
|
-
// Focused (solid) icons — also stable; handed to
|
|
214
|
+
// Focused (solid) icons — also stable; handed to native as selectedIcons so
|
|
215
|
+
// both iOS and Android swap focused artwork synchronously on the UI thread
|
|
216
|
+
// without waiting for a JS round-trip.
|
|
182
217
|
const focusedIcons = React.useMemo(() => trimmedRoutes.map(route => getIcon({
|
|
183
218
|
route,
|
|
184
219
|
focused: true
|
|
185
220
|
})), [getIcon, trimmedRoutes]);
|
|
186
|
-
|
|
187
|
-
// JS (it has no selectedImage equivalent).
|
|
188
|
-
const focusKeyedIcons = React.useMemo(() => trimmedRoutes.map(route => getIcon({
|
|
189
|
-
route,
|
|
190
|
-
focused: route.key === focusedKey
|
|
191
|
-
})), [focusedKey, getIcon, trimmedRoutes]);
|
|
192
|
-
|
|
193
|
-
// iOS hands both states to UIKit (image + selectedImage) so the focused
|
|
194
|
-
// artwork swaps natively, in sync with the selection animation, instead of
|
|
195
|
-
// waiting for a JS round-trip. Android keeps the focusedKey-driven array.
|
|
196
|
-
const icons = isIOS ? unfocusedIcons : focusKeyedIcons;
|
|
221
|
+
const icons = unfocusedIcons;
|
|
197
222
|
const items = React.useMemo(() => trimmedRoutes.map((route, index) => {
|
|
198
|
-
const icon =
|
|
223
|
+
const icon = unfocusedIcons[index];
|
|
199
224
|
const isSfSymbol = isAppleSymbol(icon);
|
|
200
225
|
if (Platform.OS === "android" && isSfSymbol) {
|
|
201
226
|
console.warn("SF Symbols are not supported on Android. Use require() or pass uri to load an image instead.");
|
|
@@ -234,11 +259,8 @@ const BottomTabs = ({
|
|
|
234
259
|
route
|
|
235
260
|
})
|
|
236
261
|
};
|
|
237
|
-
}), [trimmedRoutes,
|
|
262
|
+
}), [trimmedRoutes, unfocusedIcons, getLabelText, getBadge, getBadgeBackgroundColor, getBadgeTextColor, getActiveTintColor, getHidden, getTestID, getRole, getPreventsDefault]);
|
|
238
263
|
const resolvedIconAssets = React.useMemo(() => icons.map(icon => resolveTabIconSource(icon)), [icons]);
|
|
239
|
-
|
|
240
|
-
// Focused (solid) assets passed to iOS as selectedImage. iOS only — Android
|
|
241
|
-
// ignores selectedIcons and keeps swapping via the focusedKey array above.
|
|
242
264
|
const resolvedSelectedIconAssets = React.useMemo(() => focusedIcons.map(icon => resolveTabIconSource(icon)), [focusedIcons]);
|
|
243
265
|
const jumpTo = useLatestCallback(key => {
|
|
244
266
|
const index = trimmedRoutes.findIndex(route => route.key === key);
|
|
@@ -249,11 +271,12 @@ const BottomTabs = ({
|
|
|
249
271
|
});
|
|
250
272
|
const handleTabDoublePress = React.useCallback(event => {
|
|
251
273
|
const {
|
|
252
|
-
key
|
|
274
|
+
key,
|
|
275
|
+
didScrollToTop
|
|
253
276
|
} = event.nativeEvent;
|
|
254
277
|
const index = trimmedRoutes.findIndex(route => route.key === key);
|
|
255
278
|
if (index !== -1) {
|
|
256
|
-
onTabDoublePress?.(index);
|
|
279
|
+
onTabDoublePress?.(index, didScrollToTop);
|
|
257
280
|
}
|
|
258
281
|
}, [trimmedRoutes, onTabDoublePress]);
|
|
259
282
|
const handlePageSelected = React.useCallback(event => {
|
|
@@ -304,14 +327,17 @@ const BottomTabs = ({
|
|
|
304
327
|
}, [renderCustomTabBar]);
|
|
305
328
|
return /*#__PURE__*/_jsx(BottomTabBarHeightContext.Provider, {
|
|
306
329
|
value: tabBarHeight,
|
|
307
|
-
children: /*#__PURE__*/_jsxs(
|
|
330
|
+
children: /*#__PURE__*/_jsxs(DrawerHostWithProgress, {
|
|
331
|
+
host: DrawerHost,
|
|
308
332
|
style: styles.fullWidth,
|
|
309
333
|
enabled: !!renderDrawerContent,
|
|
310
334
|
open: drawerOpen,
|
|
311
335
|
swipeEnabled: drawerSwipeEnabled,
|
|
312
336
|
hapticFeedbackEnabled: hapticFeedbackEnabled,
|
|
313
337
|
bottomBarHeight: tabBarHeight ?? 0,
|
|
338
|
+
colorScheme: drawerColorScheme,
|
|
314
339
|
onDrawerOpenChange: event => onDrawerOpenChange?.(event.nativeEvent.open),
|
|
340
|
+
onDrawerProgress: onDrawerProgress,
|
|
315
341
|
children: [/*#__PURE__*/_jsx(View, {
|
|
316
342
|
collapsable: false,
|
|
317
343
|
style: styles.drawerMenu,
|
|
@@ -326,7 +352,7 @@ const BottomTabs = ({
|
|
|
326
352
|
style: styles.fullWidth,
|
|
327
353
|
items: items,
|
|
328
354
|
icons: renderCustomTabBar ? undefined : resolvedIconAssets,
|
|
329
|
-
selectedIcons:
|
|
355
|
+
selectedIcons: !renderCustomTabBar ? resolvedSelectedIconAssets : undefined,
|
|
330
356
|
selectedPage: focusedKey,
|
|
331
357
|
tabBarHidden: props.tabBarHidden ?? !!renderCustomTabBar,
|
|
332
358
|
onTabDoublePress: handleTabDoublePress,
|
|
@@ -399,7 +425,8 @@ const styles = StyleSheet.create({
|
|
|
399
425
|
},
|
|
400
426
|
drawerMenu: {
|
|
401
427
|
position: "absolute",
|
|
402
|
-
width
|
|
428
|
+
// Must match the native drawer width so menu descendants lay out to its edge.
|
|
429
|
+
width: "80%",
|
|
403
430
|
height: "100%"
|
|
404
431
|
},
|
|
405
432
|
screen: {
|
|
@@ -11,7 +11,10 @@ export interface BottomTabsDrawerNativeProps extends ViewProps {
|
|
|
11
11
|
swipeEnabled?: CodegenTypes.WithDefault<boolean, false>;
|
|
12
12
|
hapticFeedbackEnabled?: CodegenTypes.WithDefault<boolean, false>;
|
|
13
13
|
bottomBarHeight?: CodegenTypes.Double;
|
|
14
|
+
colorScheme?: CodegenTypes.WithDefault<"system" | "light" | "dark", "system">;
|
|
15
|
+
progressEventsEnabled?: CodegenTypes.WithDefault<boolean, false>;
|
|
14
16
|
onDrawerOpenChange?: CodegenTypes.DirectEventHandler<Readonly<{ open: boolean }>>;
|
|
17
|
+
onDrawerProgress?: CodegenTypes.DirectEventHandler<Readonly<{ progress: CodegenTypes.Double }>>;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
export default codegenNativeComponent<BottomTabsDrawerNativeProps>(
|
|
@@ -8,6 +8,11 @@ import {
|
|
|
8
8
|
// @ts-ignore
|
|
9
9
|
import type { ImageSource } from 'react-native/Libraries/Image/ImageSource';
|
|
10
10
|
|
|
11
|
+
export type OnTabDoublePressEventData = Readonly<{
|
|
12
|
+
key: string;
|
|
13
|
+
didScrollToTop: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
|
|
11
16
|
export type OnPageSelectedEventData = Readonly<{
|
|
12
17
|
key: string;
|
|
13
18
|
}>;
|
|
@@ -47,7 +52,7 @@ export interface BottomTabsNativeProps extends ViewProps {
|
|
|
47
52
|
items: BottomTabsItems;
|
|
48
53
|
selectedPage: string;
|
|
49
54
|
onPageSelected?: CodegenTypes.DirectEventHandler<OnPageSelectedEventData>;
|
|
50
|
-
onTabDoublePress?: CodegenTypes.DirectEventHandler<
|
|
55
|
+
onTabDoublePress?: CodegenTypes.DirectEventHandler<OnTabDoublePressEventData>;
|
|
51
56
|
onTabBarMeasured?: CodegenTypes.DirectEventHandler<OnTabBarMeasured>;
|
|
52
57
|
onNativeLayout?: CodegenTypes.DirectEventHandler<OnNativeLayout>;
|
|
53
58
|
icons?: ReadonlyArray<ImageSource>;
|
package/lib/module/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export default BottomTabs;
|
|
|
11
11
|
* Utilities
|
|
12
12
|
*/
|
|
13
13
|
export { SceneMap } from "./SceneMap.js";
|
|
14
|
+
export { default as BottomTabsDrawerNative } from './BottomTabsDrawerNativeComponent';
|
|
14
15
|
export { useBottomTabBarHeight } from "./utils/useBottomTabBarHeight.js";
|
|
15
16
|
export { BottomTabBarHeightContext } from "./utils/BottomTabBarHeightContext.js";
|
|
16
17
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import type { NativeSyntheticEvent } from "react-native";
|
|
2
3
|
import { type ColorValue, type ImageSourcePropType, type StyleProp, type ViewStyle } from "react-native";
|
|
3
4
|
import type { BaseRoute, BottomTabIconSource, NamedIcon, NavigationState, TabBarPlacement, TabRole } from "./types";
|
|
5
|
+
import NativeBottomTabsDrawer from "./BottomTabsDrawerNativeComponent";
|
|
4
6
|
import { type RNBottomTabsAccessoryViewProps } from "./BottomAccessoryView";
|
|
5
7
|
type ResolvedTabIconSource = {
|
|
6
8
|
uri: string;
|
|
@@ -19,6 +21,22 @@ interface Props<Route extends BaseRoute> {
|
|
|
19
21
|
drawerSwipeEnabled?: boolean;
|
|
20
22
|
/** Reports a completed user target so the external open state can follow it. */
|
|
21
23
|
onDrawerOpenChange?: (open: boolean) => void;
|
|
24
|
+
/**
|
|
25
|
+
* The drawer's visual progress (0 closed, 1 open) on every frame it moves.
|
|
26
|
+
* Passed to the drawer host as is, so a Reanimated handler can run it on the
|
|
27
|
+
* UI thread when `drawerHostComponent` is an animated component. Native sends
|
|
28
|
+
* no progress events without this handler.
|
|
29
|
+
*/
|
|
30
|
+
onDrawerProgress?: (event: NativeSyntheticEvent<Readonly<{
|
|
31
|
+
progress: number;
|
|
32
|
+
}>>) => void;
|
|
33
|
+
/** Host for the native drawer, e.g. `Animated.createAnimatedComponent(BottomTabsDrawerNative)`. */
|
|
34
|
+
drawerHostComponent?: React.ComponentType<React.ComponentProps<typeof NativeBottomTabsDrawer>>;
|
|
35
|
+
/**
|
|
36
|
+
* Palette for the page's overlay, shadow and edge while the drawer is open.
|
|
37
|
+
* Defaults to the platform appearance; pass the app theme when it can differ.
|
|
38
|
+
*/
|
|
39
|
+
drawerColorScheme?: "light" | "dark";
|
|
22
40
|
/**
|
|
23
41
|
* A tab bar style that adapts to each platform.
|
|
24
42
|
*
|
|
@@ -79,8 +97,11 @@ interface Props<Route extends BaseRoute> {
|
|
|
79
97
|
* Callback which is called when the same tab is pressed twice within the
|
|
80
98
|
* platform double-tap timeout, receives the index of the tab as argument.
|
|
81
99
|
* Each press still goes through `onIndexChange` / reselection first.
|
|
100
|
+
* The visible scrollers of the tab are already scrolling to the top when this
|
|
101
|
+
* runs; `didScrollToTop` is false when they were all at the top already.
|
|
102
|
+
* A rejected pager request with no accepted scroll skips this callback.
|
|
82
103
|
*/
|
|
83
|
-
onTabDoublePress?: (index: number) => void;
|
|
104
|
+
onTabDoublePress?: (index: number, didScrollToTop: boolean) => void;
|
|
84
105
|
/**
|
|
85
106
|
* Get lazy for the current screen. Uses true by default.
|
|
86
107
|
*/
|
|
@@ -236,6 +257,6 @@ interface Props<Route extends BaseRoute> {
|
|
|
236
257
|
*/
|
|
237
258
|
onSideAccessoryPress?: () => void;
|
|
238
259
|
}
|
|
239
|
-
declare const BottomTabs: <Route extends BaseRoute>({ navigationState, renderScene, renderLazyPlaceholder, onIndexChange, onTabDoublePress, renderDrawerContent, drawerOpen, drawerSwipeEnabled, onDrawerOpenChange, rippleColor, tabBarActiveTintColor: activeTintColor, tabBarInactiveTintColor: inactiveTintColor, getBadge, getBadgeBackgroundColor, getBadgeTextColor, getLazy, getLabelText, getIcon, getHidden, getActiveTintColor, getTestID, getRole, getSceneStyle, getPreventsDefault, hapticFeedbackEnabled, labeled, getFreezeOnBlur, tabBar: renderCustomTabBar, tabBarStyle, tabLabelStyle, renderBottomAccessoryView, activeIndicatorColor, androidBottomBlurEnabled, delayedFreeze, onTabBarPlacementChange, sideAccessoryIcon, sideAccessoryLabel, onSideAccessoryPress, ...props }: Props<Route>) => React.JSX.Element;
|
|
260
|
+
declare const BottomTabs: <Route extends BaseRoute>({ navigationState, renderScene, renderLazyPlaceholder, onIndexChange, onTabDoublePress, renderDrawerContent, drawerOpen, drawerSwipeEnabled, onDrawerOpenChange, onDrawerProgress, drawerHostComponent: DrawerHost, drawerColorScheme, rippleColor, tabBarActiveTintColor: activeTintColor, tabBarInactiveTintColor: inactiveTintColor, getBadge, getBadgeBackgroundColor, getBadgeTextColor, getLazy, getLabelText, getIcon, getHidden, getActiveTintColor, getTestID, getRole, getSceneStyle, getPreventsDefault, hapticFeedbackEnabled, labeled, getFreezeOnBlur, tabBar: renderCustomTabBar, tabBarStyle, tabLabelStyle, renderBottomAccessoryView, activeIndicatorColor, androidBottomBlurEnabled, delayedFreeze, onTabBarPlacementChange, sideAccessoryIcon, sideAccessoryLabel, onSideAccessoryPress, ...props }: Props<Route>) => React.JSX.Element;
|
|
240
261
|
export default BottomTabs;
|
|
241
262
|
//# sourceMappingURL=BottomTabs.d.ts.map
|
|
@@ -5,9 +5,14 @@ export interface BottomTabsDrawerNativeProps extends ViewProps {
|
|
|
5
5
|
swipeEnabled?: CodegenTypes.WithDefault<boolean, false>;
|
|
6
6
|
hapticFeedbackEnabled?: CodegenTypes.WithDefault<boolean, false>;
|
|
7
7
|
bottomBarHeight?: CodegenTypes.Double;
|
|
8
|
+
colorScheme?: CodegenTypes.WithDefault<"system" | "light" | "dark", "system">;
|
|
9
|
+
progressEventsEnabled?: CodegenTypes.WithDefault<boolean, false>;
|
|
8
10
|
onDrawerOpenChange?: CodegenTypes.DirectEventHandler<Readonly<{
|
|
9
11
|
open: boolean;
|
|
10
12
|
}>>;
|
|
13
|
+
onDrawerProgress?: CodegenTypes.DirectEventHandler<Readonly<{
|
|
14
|
+
progress: CodegenTypes.Double;
|
|
15
|
+
}>>;
|
|
11
16
|
}
|
|
12
17
|
declare const _default: import("react-native").HostComponent<BottomTabsDrawerNativeProps>;
|
|
13
18
|
export default _default;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type CodegenTypes, type ColorValue, type ProcessedColorValue, type ViewProps } from 'react-native';
|
|
2
2
|
import type { ImageSource } from 'react-native/Libraries/Image/ImageSource';
|
|
3
|
+
export type OnTabDoublePressEventData = Readonly<{
|
|
4
|
+
key: string;
|
|
5
|
+
didScrollToTop: boolean;
|
|
6
|
+
}>;
|
|
3
7
|
export type OnPageSelectedEventData = Readonly<{
|
|
4
8
|
key: string;
|
|
5
9
|
}>;
|
|
@@ -31,7 +35,7 @@ export interface BottomTabsNativeProps extends ViewProps {
|
|
|
31
35
|
items: BottomTabsItems;
|
|
32
36
|
selectedPage: string;
|
|
33
37
|
onPageSelected?: CodegenTypes.DirectEventHandler<OnPageSelectedEventData>;
|
|
34
|
-
onTabDoublePress?: CodegenTypes.DirectEventHandler<
|
|
38
|
+
onTabDoublePress?: CodegenTypes.DirectEventHandler<OnTabDoublePressEventData>;
|
|
35
39
|
onTabBarMeasured?: CodegenTypes.DirectEventHandler<OnTabBarMeasured>;
|
|
36
40
|
onNativeLayout?: CodegenTypes.DirectEventHandler<OnNativeLayout>;
|
|
37
41
|
icons?: ReadonlyArray<ImageSource>;
|
|
@@ -7,6 +7,7 @@ export default BottomTabs;
|
|
|
7
7
|
* Utilities
|
|
8
8
|
*/
|
|
9
9
|
export { SceneMap } from './SceneMap';
|
|
10
|
+
export { default as BottomTabsDrawerNative } from './BottomTabsDrawerNativeComponent';
|
|
10
11
|
export { useBottomTabBarHeight } from './utils/useBottomTabBarHeight';
|
|
11
12
|
export { BottomTabBarHeightContext } from './utils/BottomTabBarHeightContext';
|
|
12
13
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-bottom-tabs",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.8.0-2",
|
|
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",
|
|
@@ -19,6 +19,7 @@ Pod::Spec.new do |s|
|
|
|
19
19
|
"ios/**/*.{swift}",
|
|
20
20
|
"ios/**/*.{h,m,mm,cpp}",
|
|
21
21
|
]
|
|
22
|
+
s.exclude_files = "ios/tests/**/*"
|
|
22
23
|
|
|
23
24
|
s.static_framework = true
|
|
24
25
|
|
|
@@ -34,5 +35,10 @@ Pod::Spec.new do |s|
|
|
|
34
35
|
|
|
35
36
|
s.dependency "OneKeyImage"
|
|
36
37
|
|
|
38
|
+
s.test_spec "Tests" do |test_spec|
|
|
39
|
+
test_spec.source_files = "ios/tests/**/*.swift"
|
|
40
|
+
test_spec.pod_target_xcconfig = { "PRODUCT_MODULE_NAME" => "BottomTabsModuleTests" }
|
|
41
|
+
end
|
|
42
|
+
|
|
37
43
|
install_modules_dependencies(s)
|
|
38
44
|
end
|