@onekeyfe/react-native-bottom-tabs 6.7.0-32 → 6.7.0-34
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/android/src/main/java/com/onekey/bottomtabs/BottomTabsView.kt +88 -2
- package/android/src/main/java/com/onekey/bottomtabs/BottomTabsViewManager.kt +2 -2
- package/android/src/main/java/com/onekey/bottomtabs/events/TabDoublePressEvent.kt +7 -1
- package/docs/SPEC.md +41 -1
- package/ios/RCTBottomTabsComponentView.mm +4 -1
- package/ios/RCTBottomTabsContainerView.swift +118 -1
- package/lib/module/BottomTabs.js +3 -2
- package/lib/module/BottomTabsNativeComponent.ts +6 -1
- package/lib/typescript/src/BottomTabs.d.ts +4 -1
- package/lib/typescript/src/BottomTabsNativeComponent.d.ts +5 -1
- package/package.json +1 -1
- package/src/BottomTabs.tsx +9 -4
- package/src/BottomTabsNativeComponent.ts +6 -1
|
@@ -9,6 +9,7 @@ import androidx.appcompat.view.ContextThemeWrapper
|
|
|
9
9
|
import android.graphics.Color
|
|
10
10
|
import android.graphics.Canvas
|
|
11
11
|
import android.graphics.Outline
|
|
12
|
+
import android.graphics.Rect
|
|
12
13
|
import android.graphics.drawable.BitmapDrawable
|
|
13
14
|
import android.graphics.drawable.ColorDrawable
|
|
14
15
|
import android.graphics.drawable.Drawable
|
|
@@ -31,12 +32,16 @@ import android.view.ViewOutlineProvider
|
|
|
31
32
|
import android.view.animation.DecelerateInterpolator
|
|
32
33
|
import android.widget.FrameLayout
|
|
33
34
|
import android.widget.LinearLayout
|
|
35
|
+
import android.widget.ScrollView
|
|
34
36
|
import android.widget.TextView
|
|
35
37
|
import androidx.core.animation.doOnEnd
|
|
36
38
|
import androidx.core.graphics.ColorUtils
|
|
37
39
|
import androidx.core.view.ViewCompat
|
|
38
40
|
import androidx.core.view.WindowInsetsCompat
|
|
41
|
+
import androidx.core.view.forEach
|
|
39
42
|
import androidx.core.view.forEachIndexed
|
|
43
|
+
import androidx.core.widget.NestedScrollView
|
|
44
|
+
import androidx.recyclerview.widget.RecyclerView
|
|
40
45
|
import coil3.ImageLoader
|
|
41
46
|
import coil3.asDrawable
|
|
42
47
|
import coil3.request.ImageRequest
|
|
@@ -177,7 +182,7 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
|
|
|
177
182
|
private val floatingIndicatorDrawable = GradientDrawable()
|
|
178
183
|
|
|
179
184
|
var onTabSelectedListener: ((key: String) -> Unit)? = null
|
|
180
|
-
var onTabDoublePressedListener: ((key: String) -> Unit)? = null
|
|
185
|
+
var onTabDoublePressedListener: ((key: String, didScrollToTop: Boolean) -> Unit)? = null
|
|
181
186
|
var onNativeLayoutListener: ((width: Double, height: Double) -> Unit)? = null
|
|
182
187
|
var onTabBarMeasuredListener: ((height: Int) -> Unit)? = null
|
|
183
188
|
var disablePageAnimations = false
|
|
@@ -242,6 +247,10 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
|
|
|
242
247
|
private val floatingBarLocationOnScreen = IntArray(2)
|
|
243
248
|
private var lastPressedItemId = View.NO_ID
|
|
244
249
|
private var lastPressedTime = 0L
|
|
250
|
+
// Looked up by name: the pager lives in a package this one does not depend on.
|
|
251
|
+
private val collapsiblePagerClass: Class<*>? by lazy {
|
|
252
|
+
runCatching { Class.forName("com.reactnativepagerview.CollapsiblePagerHost") }.getOrNull()
|
|
253
|
+
}
|
|
245
254
|
private var defaultLabelTextSizes: Pair<Float, Float>? = null
|
|
246
255
|
private var barTintColor: Int? = null
|
|
247
256
|
private var activeIndicatorColor: ColorStateList? = null
|
|
@@ -1177,13 +1186,90 @@ class BottomTabsView(context: Context) : LinearLayout(context) {
|
|
|
1177
1186
|
now - lastPressedTime <= ViewConfiguration.getDoubleTapTimeout()
|
|
1178
1187
|
) {
|
|
1179
1188
|
lastPressedItemId = View.NO_ID
|
|
1180
|
-
onTabDoublePressedListener
|
|
1189
|
+
val listener = onTabDoublePressedListener ?: return
|
|
1190
|
+
val didScrollToTop = scrollSelectedTabToTop(key) ?: return
|
|
1191
|
+
listener(key, didScrollToTop)
|
|
1181
1192
|
return
|
|
1182
1193
|
}
|
|
1183
1194
|
lastPressedItemId = itemId
|
|
1184
1195
|
lastPressedTime = now
|
|
1185
1196
|
}
|
|
1186
1197
|
|
|
1198
|
+
/**
|
|
1199
|
+
* Animates every visible vertical scroller of the selected tab back to its
|
|
1200
|
+
* top. Returns false when all of them were already there, which tells JS the
|
|
1201
|
+
* double press may leave the page instead. A rejected pager request with no
|
|
1202
|
+
* accepted scroll returns null instead of implying that the page is at top.
|
|
1203
|
+
*/
|
|
1204
|
+
private fun scrollSelectedTabToTop(pressedKey: String): Boolean? {
|
|
1205
|
+
if (pressedKey != selectedItem) return false
|
|
1206
|
+
val scrollers = mutableListOf<View>()
|
|
1207
|
+
val pagers = mutableListOf<View>()
|
|
1208
|
+
collectScrolledViews(layoutHolder, scrollers, pagers)
|
|
1209
|
+
scrollers.forEach { view ->
|
|
1210
|
+
when (view) {
|
|
1211
|
+
is RecyclerView -> view.smoothScrollToPosition(0)
|
|
1212
|
+
is NestedScrollView -> view.smoothScrollTo(view.scrollX, 0)
|
|
1213
|
+
is ScrollView -> view.smoothScrollTo(view.scrollX, 0)
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
var didScrollToTop = scrollers.isNotEmpty()
|
|
1217
|
+
var rejectedPagerRequest = false
|
|
1218
|
+
pagers.forEach { pager ->
|
|
1219
|
+
if (scrollPagerToTop(pager)) didScrollToTop = true
|
|
1220
|
+
else rejectedPagerRequest = true
|
|
1221
|
+
}
|
|
1222
|
+
return when {
|
|
1223
|
+
didScrollToTop -> true
|
|
1224
|
+
rejectedPagerRequest -> null
|
|
1225
|
+
else -> false
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
private fun collectScrolledViews(
|
|
1230
|
+
view: View,
|
|
1231
|
+
scrollers: MutableList<View>,
|
|
1232
|
+
pagers: MutableList<View>,
|
|
1233
|
+
) {
|
|
1234
|
+
// Hidden tabs and pager siblings stay attached without being on screen.
|
|
1235
|
+
if (!view.isShown || !view.getGlobalVisibleRect(Rect())) return
|
|
1236
|
+
if (collapsiblePagerClass?.isInstance(view) == true) {
|
|
1237
|
+
// The pager keeps header state for its pages, so moving one of its
|
|
1238
|
+
// scrollers directly leaves the header out of sync. It scrolls itself.
|
|
1239
|
+
val pagerScrollers = mutableListOf<View>()
|
|
1240
|
+
val nestedPagers = mutableListOf<View>()
|
|
1241
|
+
(view as ViewGroup).forEach { child ->
|
|
1242
|
+
collectScrolledViews(child, pagerScrollers, nestedPagers)
|
|
1243
|
+
}
|
|
1244
|
+
if (pagerScrollers.isNotEmpty() || nestedPagers.isNotEmpty() || isPagerAwayFromTop(view)) {
|
|
1245
|
+
pagers.add(view)
|
|
1246
|
+
}
|
|
1247
|
+
return
|
|
1248
|
+
}
|
|
1249
|
+
if (
|
|
1250
|
+
(view is RecyclerView || view is NestedScrollView || view is ScrollView) &&
|
|
1251
|
+
view.canScrollVertically(-1)
|
|
1252
|
+
) {
|
|
1253
|
+
scrollers.add(view)
|
|
1254
|
+
}
|
|
1255
|
+
if (view is ViewGroup) {
|
|
1256
|
+
view.forEach { child -> collectScrolledViews(child, scrollers, pagers) }
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
private fun isPagerAwayFromTop(pager: View): Boolean =
|
|
1261
|
+
runCatching { pager.javaClass.getMethod("isAwayFromPageTop").invoke(pager) as Boolean }
|
|
1262
|
+
.onFailure { Log.w("BottomTabs", "Unable to read the collapsible pager top state", it) }
|
|
1263
|
+
.getOrDefault(false)
|
|
1264
|
+
|
|
1265
|
+
private fun scrollPagerToTop(pager: View): Boolean =
|
|
1266
|
+
runCatching {
|
|
1267
|
+
pager.javaClass
|
|
1268
|
+
.getMethod("tryScrollToTop", Int::class.javaPrimitiveType, Boolean::class.javaPrimitiveType)
|
|
1269
|
+
.invoke(pager, 0, true) as Boolean
|
|
1270
|
+
}.onFailure { Log.w("BottomTabs", "Unable to scroll the collapsible pager to top", it) }
|
|
1271
|
+
.getOrDefault(false)
|
|
1272
|
+
|
|
1187
1273
|
fun setIgnoreBottomInsets(ignore: Boolean) {
|
|
1188
1274
|
ignoreBottomInsets = ignore
|
|
1189
1275
|
bottomNavigation.setIgnoreBottomInsets(
|
|
@@ -35,8 +35,8 @@ class BottomTabsViewManager(context: ReactApplicationContext) :
|
|
|
35
35
|
eventDispatcher?.dispatchEvent(PageSelectedEvent(surfaceId, view.id, key))
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
view.onTabDoublePressedListener = { key ->
|
|
39
|
-
eventDispatcher?.dispatchEvent(TabDoublePressEvent(surfaceId, view.id, key))
|
|
38
|
+
view.onTabDoublePressedListener = { key, didScrollToTop ->
|
|
39
|
+
eventDispatcher?.dispatchEvent(TabDoublePressEvent(surfaceId, view.id, key, didScrollToTop))
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
view.onNativeLayoutListener = { width, height ->
|
|
@@ -4,12 +4,18 @@ import com.facebook.react.bridge.Arguments
|
|
|
4
4
|
import com.facebook.react.bridge.WritableMap
|
|
5
5
|
import com.facebook.react.uimanager.events.Event
|
|
6
6
|
|
|
7
|
-
class TabDoublePressEvent(
|
|
7
|
+
class TabDoublePressEvent(
|
|
8
|
+
surfaceId: Int,
|
|
9
|
+
viewTag: Int,
|
|
10
|
+
private val key: String,
|
|
11
|
+
private val didScrollToTop: Boolean,
|
|
12
|
+
) : Event<TabDoublePressEvent>(surfaceId, viewTag) {
|
|
8
13
|
override fun getEventName(): String = EVENT_NAME
|
|
9
14
|
|
|
10
15
|
override fun getEventData(): WritableMap {
|
|
11
16
|
return Arguments.createMap().apply {
|
|
12
17
|
putString("key", key)
|
|
18
|
+
putBoolean("didScrollToTop", didScrollToTop)
|
|
13
19
|
}
|
|
14
20
|
}
|
|
15
21
|
|
package/docs/SPEC.md
CHANGED
|
@@ -187,11 +187,44 @@ reselection never changes the selected page. A tab with `preventsDefault` emits
|
|
|
187
187
|
tab within the platform double-tap timeout (iOS 0.3 s; Android
|
|
188
188
|
`ViewConfiguration.getDoubleTapTimeout()`, 300 ms by default). Both presses still
|
|
189
189
|
emit `onPageSelected` first; the double press is an additional event, emitted
|
|
190
|
-
after the second press.
|
|
190
|
+
after the second press. A rejected pager top request with no accepted scroll
|
|
191
|
+
suppresses this additional event; both `onPageSelected` events still fire.
|
|
192
|
+
After the pair is handled, tracking resets, so a third quick press
|
|
191
193
|
starts a new pair. Double press is derived from accepted selections only: no
|
|
192
194
|
extra gesture recognizer is attached and single-press latency is unchanged.
|
|
193
195
|
JS-driven `selectedPage` changes do not count as presses.
|
|
194
196
|
|
|
197
|
+
Before `onTabDoublePress` is emitted, the selected tab's visible vertical
|
|
198
|
+
scrollers animate back to their top only when the pressed key matches the
|
|
199
|
+
selected scene. If `preventsDefault` leaves another tab selected, its scene
|
|
200
|
+
MUST remain untouched and `didScrollToTop` MUST be false. A prevented tab that
|
|
201
|
+
is already selected retains normal scroll-to-top behavior.
|
|
202
|
+
The event carries `didScrollToTop`: true only when at least one scroller was
|
|
203
|
+
away from its top and accepted the top request, false when all were already
|
|
204
|
+
there, so the host can decide what a double press at the top means. Rejection
|
|
205
|
+
MUST NOT be reported as success or as proof that the page is already at top.
|
|
206
|
+
On iOS, a standalone NativeList collection view delegates back to its direct
|
|
207
|
+
owner's `onekeyScrollToOffset:animated:` selector with offset zero and animation
|
|
208
|
+
enabled. This uses NativeList's existing explicit-command path to end an active
|
|
209
|
+
structural tail, invalidate stale scroll completions and own pending layout
|
|
210
|
+
before scrolling; BottomTabs MUST NOT also write that collection view's offset.
|
|
211
|
+
BottomTabs and NativeList native sources must ship together for this selector.
|
|
212
|
+
Scrollers inside a `CollapsiblePagerView` are never moved directly because the pager owns
|
|
213
|
+
their header state; the module calls the pager's own `tryScrollToTop` by name, as
|
|
214
|
+
it has no package dependency on the pager. A pager also counts as away from its
|
|
215
|
+
top when its `isAwayFromPageTop` reports a collapsed header over a body at top. Only visible scrollers count: hidden
|
|
216
|
+
tabs and off-screen pager pages are skipped. On iOS visibility is intersected
|
|
217
|
+
with the window and every clipping ancestor; a retained page fully clipped by
|
|
218
|
+
its pager MUST NOT count. On iOS a scroller must have content
|
|
219
|
+
taller than its viewport. Runtime verification: iOS 27 simulator (collapsible
|
|
220
|
+
pagers, pushed list pages, and a double press that also switches tabs). The
|
|
221
|
+
Android pressed-scene isolation regression passed on an API 36 emulator for
|
|
222
|
+
docked and floating bars; Android pager integration has not been run. The
|
|
223
|
+
Android pager lookup is reflective, so a minified release build still needs a run.
|
|
224
|
+
BottomTabs and Pager native sources must ship together for the acceptance-returning
|
|
225
|
+
entry point. Clipping-ancestor visibility and rejected-command event handling
|
|
226
|
+
are implemented in source; runtime acceptance for these cases remains pending.
|
|
227
|
+
|
|
195
228
|
Tab long press is not supported. The former `onTabLongPress` prop/event and the
|
|
196
229
|
native long-press recognizers were removed.
|
|
197
230
|
|
|
@@ -383,6 +416,13 @@ pages; release selects the nearest tab once; cancel restores; hidden bar, dark
|
|
|
383
416
|
mode, and 3-button navigation insets lay out correctly. Source compilation is
|
|
384
417
|
recorded separately from runtime acceptance.
|
|
385
418
|
|
|
419
|
+
`native-tests/android/BottomBlurTest.kt` includes
|
|
420
|
+
`testDoublePressOnlyScrollsThePressedScene`, inherited by the floating-style
|
|
421
|
+
suite. It covers a prevented press on another scene (no scroll, false), a
|
|
422
|
+
prevented press on the selected scene (scroll, true), and normal tab switching
|
|
423
|
+
followed by scroll-to-top, while preserving the other scene's offset. The same
|
|
424
|
+
cases remain required on iOS.
|
|
425
|
+
|
|
386
426
|
Vertical tab bar: `RCTBottomTabsContainerView.swift` (`currentTabBarPlacement`,
|
|
387
427
|
`updateTabBarPlacementAndSideAccessory`, `verticalTabBarPlatterFrame`).
|
|
388
428
|
Required iOS runtime cases on iPhone Duo: the outer display and landscape inner
|
|
@@ -144,7 +144,10 @@ static NSArray<NSDictionary *>* convertItemsToArray(const std::vector<RNBottomTa
|
|
|
144
144
|
if (!strongSelf) return;
|
|
145
145
|
auto emitter = std::static_pointer_cast<const RNBottomTabsViewEventEmitter>(strongSelf->_eventEmitter);
|
|
146
146
|
if (emitter) {
|
|
147
|
-
emitter->onTabDoublePress({
|
|
147
|
+
emitter->onTabDoublePress({
|
|
148
|
+
.key = std::string([[body objectForKey:@"key"] UTF8String] ?: ""),
|
|
149
|
+
.didScrollToTop = [[body objectForKey:@"didScrollToTop"] boolValue],
|
|
150
|
+
});
|
|
148
151
|
}
|
|
149
152
|
};
|
|
150
153
|
[_containerView setValue:onTabDoublePress forKey:@"onTabDoublePress"];
|
|
@@ -131,6 +131,10 @@ 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
|
|
@@ -1058,13 +1062,126 @@ class RCTBottomTabsContainerView: UIView {
|
|
|
1058
1062
|
let now = CACurrentMediaTime()
|
|
1059
1063
|
if lastPressedTabKey == key && now - lastPressedTabTime <= Self.doublePressInterval {
|
|
1060
1064
|
lastPressedTabKey = nil
|
|
1061
|
-
onTabDoublePress
|
|
1065
|
+
if let onTabDoublePress,
|
|
1066
|
+
let didScrollToTop = scrollSelectedTabToTop(pressedKey: key) {
|
|
1067
|
+
onTabDoublePress(["key": key, "didScrollToTop": didScrollToTop])
|
|
1068
|
+
}
|
|
1062
1069
|
return
|
|
1063
1070
|
}
|
|
1064
1071
|
lastPressedTabKey = key
|
|
1065
1072
|
lastPressedTabTime = now
|
|
1066
1073
|
}
|
|
1067
1074
|
|
|
1075
|
+
/// Animates every visible vertical scroller of the selected tab back to its
|
|
1076
|
+
/// top. Returns false when all of them were already there, which tells JS the
|
|
1077
|
+
/// double press may leave the page instead. A rejected pager request with no
|
|
1078
|
+
/// accepted scroll returns nil, so JS cannot mistake it for an already-top page.
|
|
1079
|
+
private func scrollSelectedTabToTop(pressedKey: String) -> Bool? {
|
|
1080
|
+
guard let tabBarController,
|
|
1081
|
+
filteredItems[safe: tabBarController.selectedIndex]?.key == pressedKey,
|
|
1082
|
+
let rootView = tabBarController.selectedViewController?.view,
|
|
1083
|
+
let window = rootView.window else {
|
|
1084
|
+
return false
|
|
1085
|
+
}
|
|
1086
|
+
var scrollViews: [UIScrollView] = []
|
|
1087
|
+
var pagers: [UIView] = []
|
|
1088
|
+
collectScrolledViews(in: rootView, window: window, scrollViews: &scrollViews, pagers: &pagers)
|
|
1089
|
+
let nativeListScrollSelector = NSSelectorFromString("onekeyScrollToOffset:animated:")
|
|
1090
|
+
for scrollView in scrollViews {
|
|
1091
|
+
if let owner = scrollView.superview, owner.responds(to: nativeListScrollSelector) {
|
|
1092
|
+
// NativeList must release structural-tail offset writes before scrolling.
|
|
1093
|
+
typealias ScrollToOffset = @convention(c) (AnyObject, Selector, Double, Bool) -> Void
|
|
1094
|
+
let scrollToOffset = unsafeBitCast(owner.method(for: nativeListScrollSelector), to: ScrollToOffset.self)
|
|
1095
|
+
scrollToOffset(owner, nativeListScrollSelector, 0, true)
|
|
1096
|
+
continue
|
|
1097
|
+
}
|
|
1098
|
+
let topOffset = -scrollView.adjustedContentInset.top
|
|
1099
|
+
scrollView.setContentOffset(
|
|
1100
|
+
CGPoint(x: scrollView.contentOffset.x, y: topOffset),
|
|
1101
|
+
animated: true
|
|
1102
|
+
)
|
|
1103
|
+
}
|
|
1104
|
+
var didScrollToTop = !scrollViews.isEmpty
|
|
1105
|
+
var rejectedPagerRequest = false
|
|
1106
|
+
for pager in pagers {
|
|
1107
|
+
if scrollPagerToTop(pager) {
|
|
1108
|
+
didScrollToTop = true
|
|
1109
|
+
} else {
|
|
1110
|
+
rejectedPagerRequest = true
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
return didScrollToTop ? true : (rejectedPagerRequest ? nil : false)
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
// Only content taller than its viewport can be scrolled back to the top.
|
|
1117
|
+
private func isVerticallyScrollable(_ scrollView: UIScrollView) -> Bool {
|
|
1118
|
+
let inset = scrollView.adjustedContentInset
|
|
1119
|
+
let viewportHeight = scrollView.bounds.height - inset.top - inset.bottom
|
|
1120
|
+
return scrollView.contentSize.height > viewportHeight + Self.scrollTopTolerance
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
private func collectScrolledViews(
|
|
1124
|
+
in view: UIView,
|
|
1125
|
+
window: UIWindow,
|
|
1126
|
+
scrollViews: inout [UIScrollView],
|
|
1127
|
+
pagers: inout [UIView]
|
|
1128
|
+
) {
|
|
1129
|
+
guard !view.isHidden, view.alpha > 0.01 else { return }
|
|
1130
|
+
// Pager siblings stay in the hierarchy off screen.
|
|
1131
|
+
var visibleRect = view.convert(view.bounds, to: window).intersection(window.bounds)
|
|
1132
|
+
var ancestor = view.superview
|
|
1133
|
+
while let clippingView = ancestor {
|
|
1134
|
+
if clippingView.clipsToBounds {
|
|
1135
|
+
visibleRect = visibleRect.intersection(clippingView.convert(clippingView.bounds, to: window))
|
|
1136
|
+
}
|
|
1137
|
+
ancestor = clippingView.superview
|
|
1138
|
+
}
|
|
1139
|
+
guard !visibleRect.isEmpty else { return }
|
|
1140
|
+
if let pagerClass = Self.collapsiblePagerClass, view.isKind(of: pagerClass) {
|
|
1141
|
+
// The pager keeps header state for its pages, so moving one of its
|
|
1142
|
+
// scrollers directly leaves the header out of sync. It scrolls itself.
|
|
1143
|
+
var pagerScrollViews: [UIScrollView] = []
|
|
1144
|
+
var nestedPagers: [UIView] = []
|
|
1145
|
+
for subview in view.subviews {
|
|
1146
|
+
collectScrolledViews(
|
|
1147
|
+
in: subview,
|
|
1148
|
+
window: window,
|
|
1149
|
+
scrollViews: &pagerScrollViews,
|
|
1150
|
+
pagers: &nestedPagers
|
|
1151
|
+
)
|
|
1152
|
+
}
|
|
1153
|
+
if !pagerScrollViews.isEmpty || !nestedPagers.isEmpty || isPagerAwayFromTop(view) {
|
|
1154
|
+
pagers.append(view)
|
|
1155
|
+
}
|
|
1156
|
+
return
|
|
1157
|
+
}
|
|
1158
|
+
if let scrollView = view as? UIScrollView,
|
|
1159
|
+
scrollView.isScrollEnabled,
|
|
1160
|
+
isVerticallyScrollable(scrollView),
|
|
1161
|
+
scrollView.contentOffset.y + scrollView.adjustedContentInset.top > Self.scrollTopTolerance {
|
|
1162
|
+
scrollViews.append(scrollView)
|
|
1163
|
+
}
|
|
1164
|
+
for subview in view.subviews {
|
|
1165
|
+
collectScrolledViews(in: subview, window: window, scrollViews: &scrollViews, pagers: &pagers)
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
private func isPagerAwayFromTop(_ pager: UIView) -> Bool {
|
|
1170
|
+
let selector = NSSelectorFromString("isAwayFromPageTop")
|
|
1171
|
+
guard pager.responds(to: selector) else { return false }
|
|
1172
|
+
typealias IsAwayFromPageTop = @convention(c) (AnyObject, Selector) -> Bool
|
|
1173
|
+
let isAwayFromPageTop = unsafeBitCast(pager.method(for: selector), to: IsAwayFromPageTop.self)
|
|
1174
|
+
return isAwayFromPageTop(pager, selector)
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
private func scrollPagerToTop(_ pager: UIView) -> Bool {
|
|
1178
|
+
let selector = NSSelectorFromString("tryScrollToTop:animated:")
|
|
1179
|
+
guard pager.responds(to: selector) else { return false }
|
|
1180
|
+
typealias ScrollToTop = @convention(c) (AnyObject, Selector, Int, Bool) -> Bool
|
|
1181
|
+
let scrollToTop = unsafeBitCast(pager.method(for: selector), to: ScrollToTop.self)
|
|
1182
|
+
return scrollToTop(pager, selector, 0, true)
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1068
1185
|
// MARK: - Bottom accessory placement
|
|
1069
1186
|
|
|
1070
1187
|
func handlePlacementChanged(_ placement: String) {
|
package/lib/module/BottomTabs.js
CHANGED
|
@@ -249,11 +249,12 @@ const BottomTabs = ({
|
|
|
249
249
|
});
|
|
250
250
|
const handleTabDoublePress = React.useCallback(event => {
|
|
251
251
|
const {
|
|
252
|
-
key
|
|
252
|
+
key,
|
|
253
|
+
didScrollToTop
|
|
253
254
|
} = event.nativeEvent;
|
|
254
255
|
const index = trimmedRoutes.findIndex(route => route.key === key);
|
|
255
256
|
if (index !== -1) {
|
|
256
|
-
onTabDoublePress?.(index);
|
|
257
|
+
onTabDoublePress?.(index, didScrollToTop);
|
|
257
258
|
}
|
|
258
259
|
}, [trimmedRoutes, onTabDoublePress]);
|
|
259
260
|
const handlePageSelected = React.useCallback(event => {
|
|
@@ -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>;
|
|
@@ -79,8 +79,11 @@ interface Props<Route extends BaseRoute> {
|
|
|
79
79
|
* Callback which is called when the same tab is pressed twice within the
|
|
80
80
|
* platform double-tap timeout, receives the index of the tab as argument.
|
|
81
81
|
* Each press still goes through `onIndexChange` / reselection first.
|
|
82
|
+
* The visible scrollers of the tab are already scrolling to the top when this
|
|
83
|
+
* runs; `didScrollToTop` is false when they were all at the top already.
|
|
84
|
+
* A rejected pager request with no accepted scroll skips this callback.
|
|
82
85
|
*/
|
|
83
|
-
onTabDoublePress?: (index: number) => void;
|
|
86
|
+
onTabDoublePress?: (index: number, didScrollToTop: boolean) => void;
|
|
84
87
|
/**
|
|
85
88
|
* Get lazy for the current screen. Uses true by default.
|
|
86
89
|
*/
|
|
@@ -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>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-bottom-tabs",
|
|
3
|
-
"version": "6.7.0-
|
|
3
|
+
"version": "6.7.0-34",
|
|
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
|
@@ -187,8 +187,11 @@ interface Props<Route extends BaseRoute> {
|
|
|
187
187
|
* Callback which is called when the same tab is pressed twice within the
|
|
188
188
|
* platform double-tap timeout, receives the index of the tab as argument.
|
|
189
189
|
* Each press still goes through `onIndexChange` / reselection first.
|
|
190
|
+
* The visible scrollers of the tab are already scrolling to the top when this
|
|
191
|
+
* runs; `didScrollToTop` is false when they were all at the top already.
|
|
192
|
+
* A rejected pager request with no accepted scroll skips this callback.
|
|
190
193
|
*/
|
|
191
|
-
onTabDoublePress?: (index: number) => void;
|
|
194
|
+
onTabDoublePress?: (index: number, didScrollToTop: boolean) => void;
|
|
192
195
|
/**
|
|
193
196
|
* Get lazy for the current screen. Uses true by default.
|
|
194
197
|
*/
|
|
@@ -529,11 +532,13 @@ const BottomTabs = <Route extends BaseRoute>({
|
|
|
529
532
|
});
|
|
530
533
|
|
|
531
534
|
const handleTabDoublePress = React.useCallback(
|
|
532
|
-
(
|
|
533
|
-
|
|
535
|
+
(
|
|
536
|
+
event: NativeSyntheticEvent<{ key: string; didScrollToTop: boolean }>
|
|
537
|
+
) => {
|
|
538
|
+
const { key, didScrollToTop } = event.nativeEvent;
|
|
534
539
|
const index = trimmedRoutes.findIndex((route) => route.key === key);
|
|
535
540
|
if (index !== -1) {
|
|
536
|
-
onTabDoublePress?.(index);
|
|
541
|
+
onTabDoublePress?.(index, didScrollToTop);
|
|
537
542
|
}
|
|
538
543
|
},
|
|
539
544
|
[trimmedRoutes, onTabDoublePress]
|
|
@@ -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>;
|