@onekeyfe/react-native-bottom-tabs 6.7.0-alpha.475 → 6.8.0-3
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
package/src/BottomTabs.tsx
CHANGED
|
@@ -128,6 +128,24 @@ interface Props<Route extends BaseRoute> {
|
|
|
128
128
|
drawerSwipeEnabled?: boolean;
|
|
129
129
|
/** Reports a completed user target so the external open state can follow it. */
|
|
130
130
|
onDrawerOpenChange?: (open: boolean) => void;
|
|
131
|
+
/**
|
|
132
|
+
* The drawer's visual progress (0 closed, 1 open) on every frame it moves.
|
|
133
|
+
* Passed to the drawer host as is, so a Reanimated handler can run it on the
|
|
134
|
+
* UI thread when `drawerHostComponent` is an animated component. Native sends
|
|
135
|
+
* no progress events without this handler.
|
|
136
|
+
*/
|
|
137
|
+
onDrawerProgress?: (
|
|
138
|
+
event: NativeSyntheticEvent<Readonly<{ progress: number }>>
|
|
139
|
+
) => void;
|
|
140
|
+
/** Host for the native drawer, e.g. `Animated.createAnimatedComponent(BottomTabsDrawerNative)`. */
|
|
141
|
+
drawerHostComponent?: React.ComponentType<
|
|
142
|
+
React.ComponentProps<typeof NativeBottomTabsDrawer>
|
|
143
|
+
>;
|
|
144
|
+
/**
|
|
145
|
+
* Palette for the page's overlay, shadow and edge while the drawer is open.
|
|
146
|
+
* Defaults to the platform appearance; pass the app theme when it can differ.
|
|
147
|
+
*/
|
|
148
|
+
drawerColorScheme?: "light" | "dark";
|
|
131
149
|
/**
|
|
132
150
|
* A tab bar style that adapts to each platform.
|
|
133
151
|
*
|
|
@@ -187,8 +205,11 @@ interface Props<Route extends BaseRoute> {
|
|
|
187
205
|
* Callback which is called when the same tab is pressed twice within the
|
|
188
206
|
* platform double-tap timeout, receives the index of the tab as argument.
|
|
189
207
|
* Each press still goes through `onIndexChange` / reselection first.
|
|
208
|
+
* The visible scrollers of the tab are already scrolling to the top when this
|
|
209
|
+
* runs; `didScrollToTop` is false when they were all at the top already.
|
|
210
|
+
* A rejected pager request with no accepted scroll skips this callback.
|
|
190
211
|
*/
|
|
191
|
-
onTabDoublePress?: (index: number) => void;
|
|
212
|
+
onTabDoublePress?: (index: number, didScrollToTop: boolean) => void;
|
|
192
213
|
/**
|
|
193
214
|
* Get lazy for the current screen. Uses true by default.
|
|
194
215
|
*/
|
|
@@ -332,6 +353,24 @@ interface Props<Route extends BaseRoute> {
|
|
|
332
353
|
onSideAccessoryPress?: () => void;
|
|
333
354
|
}
|
|
334
355
|
|
|
356
|
+
const defaultGetBadge = ({ route }: { route: BaseRoute }) => route.badge;
|
|
357
|
+
const defaultGetBadgeBackgroundColor = ({ route }: { route: BaseRoute }) =>
|
|
358
|
+
route.badgeBackgroundColor;
|
|
359
|
+
const defaultGetBadgeTextColor = ({ route }: { route: BaseRoute }) =>
|
|
360
|
+
route.badgeTextColor;
|
|
361
|
+
const defaultGetLazy = ({ route }: { route: BaseRoute }) => route.lazy;
|
|
362
|
+
const defaultGetLabelText = ({ route }: { route: BaseRoute }) => route.title;
|
|
363
|
+
const defaultGetHidden = ({ route }: { route: BaseRoute }) => route.hidden;
|
|
364
|
+
const defaultGetActiveTintColor = ({ route }: { route: BaseRoute }) =>
|
|
365
|
+
route.activeTintColor;
|
|
366
|
+
const defaultGetTestID = ({ route }: { route: BaseRoute }) => route.testID;
|
|
367
|
+
const defaultGetRole = ({ route }: { route: BaseRoute }) => route.role;
|
|
368
|
+
const defaultGetSceneStyle = ({ route }: { route: BaseRoute }) => route.style;
|
|
369
|
+
const defaultGetPreventsDefault = ({ route }: { route: BaseRoute }) =>
|
|
370
|
+
route.preventsDefault;
|
|
371
|
+
const defaultGetFreezeOnBlur = ({ route }: { route: BaseRoute }) =>
|
|
372
|
+
route.freezeOnBlur;
|
|
373
|
+
|
|
335
374
|
const defaultGetIcon = ({
|
|
336
375
|
route,
|
|
337
376
|
focused,
|
|
@@ -347,6 +386,26 @@ const defaultGetIcon = ({
|
|
|
347
386
|
|
|
348
387
|
const ANDROID_MAX_TABS = 100;
|
|
349
388
|
|
|
389
|
+
type DrawerHostProps = React.ComponentProps<typeof NativeBottomTabsDrawer>;
|
|
390
|
+
|
|
391
|
+
// Progress events start one commit after mount: during the mount itself the
|
|
392
|
+
// iOS event emitter and an animated host's worklet handler are not attached
|
|
393
|
+
// yet, so the current position native sends on enabling would be lost. The
|
|
394
|
+
// state lives here so that commit re-renders only the host, not the tabs.
|
|
395
|
+
function DrawerHostWithProgress({
|
|
396
|
+
host: Host,
|
|
397
|
+
...props
|
|
398
|
+
}: DrawerHostProps & { host: React.ComponentType<DrawerHostProps> }) {
|
|
399
|
+
const hasProgressHandler = props.onDrawerProgress != null;
|
|
400
|
+
const [mounted, setMounted] = React.useState(false);
|
|
401
|
+
React.useEffect(() => {
|
|
402
|
+
if (hasProgressHandler) setMounted(true);
|
|
403
|
+
}, [hasProgressHandler]);
|
|
404
|
+
return (
|
|
405
|
+
<Host {...props} progressEventsEnabled={mounted && hasProgressHandler} />
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
|
|
350
409
|
const BottomTabs = <Route extends BaseRoute>({
|
|
351
410
|
navigationState,
|
|
352
411
|
renderScene,
|
|
@@ -357,25 +416,27 @@ const BottomTabs = <Route extends BaseRoute>({
|
|
|
357
416
|
drawerOpen = false,
|
|
358
417
|
drawerSwipeEnabled = false,
|
|
359
418
|
onDrawerOpenChange,
|
|
419
|
+
onDrawerProgress,
|
|
420
|
+
drawerHostComponent: DrawerHost = NativeBottomTabsDrawer,
|
|
421
|
+
drawerColorScheme,
|
|
360
422
|
rippleColor,
|
|
361
423
|
tabBarActiveTintColor: activeTintColor,
|
|
362
424
|
tabBarInactiveTintColor: inactiveTintColor,
|
|
363
|
-
getBadge =
|
|
364
|
-
getBadgeBackgroundColor =
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
getLabelText = ({ route }: { route: Route }) => route.title,
|
|
425
|
+
getBadge = defaultGetBadge,
|
|
426
|
+
getBadgeBackgroundColor = defaultGetBadgeBackgroundColor,
|
|
427
|
+
getBadgeTextColor = defaultGetBadgeTextColor,
|
|
428
|
+
getLazy = defaultGetLazy,
|
|
429
|
+
getLabelText = defaultGetLabelText,
|
|
369
430
|
getIcon = defaultGetIcon,
|
|
370
|
-
getHidden =
|
|
371
|
-
getActiveTintColor =
|
|
372
|
-
getTestID =
|
|
373
|
-
getRole =
|
|
374
|
-
getSceneStyle =
|
|
375
|
-
getPreventsDefault =
|
|
431
|
+
getHidden = defaultGetHidden,
|
|
432
|
+
getActiveTintColor = defaultGetActiveTintColor,
|
|
433
|
+
getTestID = defaultGetTestID,
|
|
434
|
+
getRole = defaultGetRole,
|
|
435
|
+
getSceneStyle = defaultGetSceneStyle,
|
|
436
|
+
getPreventsDefault = defaultGetPreventsDefault,
|
|
376
437
|
hapticFeedbackEnabled = false,
|
|
377
438
|
labeled = Platform.OS !== "android" ? true : undefined,
|
|
378
|
-
getFreezeOnBlur =
|
|
439
|
+
getFreezeOnBlur = defaultGetFreezeOnBlur,
|
|
379
440
|
tabBar: renderCustomTabBar,
|
|
380
441
|
tabBarStyle,
|
|
381
442
|
tabLabelStyle,
|
|
@@ -438,33 +499,20 @@ const BottomTabs = <Route extends BaseRoute>({
|
|
|
438
499
|
() => trimmedRoutes.map((route) => getIcon({ route, focused: false })),
|
|
439
500
|
[getIcon, trimmedRoutes]
|
|
440
501
|
);
|
|
441
|
-
// Focused (solid) icons — also stable; handed to
|
|
502
|
+
// Focused (solid) icons — also stable; handed to native as selectedIcons so
|
|
503
|
+
// both iOS and Android swap focused artwork synchronously on the UI thread
|
|
504
|
+
// without waiting for a JS round-trip.
|
|
442
505
|
const focusedIcons = React.useMemo(
|
|
443
506
|
() => trimmedRoutes.map((route) => getIcon({ route, focused: true })),
|
|
444
507
|
[getIcon, trimmedRoutes]
|
|
445
508
|
);
|
|
446
|
-
// Legacy single array driven by focusedKey. Android still swaps the icon in
|
|
447
|
-
// JS (it has no selectedImage equivalent).
|
|
448
|
-
const focusKeyedIcons = React.useMemo(
|
|
449
|
-
() =>
|
|
450
|
-
trimmedRoutes.map((route) =>
|
|
451
|
-
getIcon({
|
|
452
|
-
route,
|
|
453
|
-
focused: route.key === focusedKey,
|
|
454
|
-
})
|
|
455
|
-
),
|
|
456
|
-
[focusedKey, getIcon, trimmedRoutes]
|
|
457
|
-
);
|
|
458
509
|
|
|
459
|
-
|
|
460
|
-
// artwork swaps natively, in sync with the selection animation, instead of
|
|
461
|
-
// waiting for a JS round-trip. Android keeps the focusedKey-driven array.
|
|
462
|
-
const icons = isIOS ? unfocusedIcons : focusKeyedIcons;
|
|
510
|
+
const icons = unfocusedIcons;
|
|
463
511
|
|
|
464
512
|
const items: BottomTabsItems[number][] = React.useMemo(
|
|
465
513
|
() =>
|
|
466
514
|
trimmedRoutes.map((route, index) => {
|
|
467
|
-
const icon =
|
|
515
|
+
const icon = unfocusedIcons[index];
|
|
468
516
|
const isSfSymbol = isAppleSymbol(icon);
|
|
469
517
|
|
|
470
518
|
if (Platform.OS === "android" && isSfSymbol) {
|
|
@@ -495,7 +543,7 @@ const BottomTabs = <Route extends BaseRoute>({
|
|
|
495
543
|
}),
|
|
496
544
|
[
|
|
497
545
|
trimmedRoutes,
|
|
498
|
-
|
|
546
|
+
unfocusedIcons,
|
|
499
547
|
getLabelText,
|
|
500
548
|
getBadge,
|
|
501
549
|
getBadgeBackgroundColor,
|
|
@@ -513,8 +561,6 @@ const BottomTabs = <Route extends BaseRoute>({
|
|
|
513
561
|
[icons]
|
|
514
562
|
);
|
|
515
563
|
|
|
516
|
-
// Focused (solid) assets passed to iOS as selectedImage. iOS only — Android
|
|
517
|
-
// ignores selectedIcons and keeps swapping via the focusedKey array above.
|
|
518
564
|
const resolvedSelectedIconAssets = React.useMemo(
|
|
519
565
|
() => focusedIcons.map((icon) => resolveTabIconSource(icon)),
|
|
520
566
|
[focusedIcons]
|
|
@@ -529,11 +575,13 @@ const BottomTabs = <Route extends BaseRoute>({
|
|
|
529
575
|
});
|
|
530
576
|
|
|
531
577
|
const handleTabDoublePress = React.useCallback(
|
|
532
|
-
(
|
|
533
|
-
|
|
578
|
+
(
|
|
579
|
+
event: NativeSyntheticEvent<{ key: string; didScrollToTop: boolean }>
|
|
580
|
+
) => {
|
|
581
|
+
const { key, didScrollToTop } = event.nativeEvent;
|
|
534
582
|
const index = trimmedRoutes.findIndex((route) => route.key === key);
|
|
535
583
|
if (index !== -1) {
|
|
536
|
-
onTabDoublePress?.(index);
|
|
584
|
+
onTabDoublePress?.(index, didScrollToTop);
|
|
537
585
|
}
|
|
538
586
|
},
|
|
539
587
|
[trimmedRoutes, onTabDoublePress]
|
|
@@ -600,16 +648,19 @@ const BottomTabs = <Route extends BaseRoute>({
|
|
|
600
648
|
|
|
601
649
|
return (
|
|
602
650
|
<BottomTabBarHeightContext.Provider value={tabBarHeight}>
|
|
603
|
-
<
|
|
651
|
+
<DrawerHostWithProgress
|
|
652
|
+
host={DrawerHost}
|
|
604
653
|
style={styles.fullWidth}
|
|
605
654
|
enabled={!!renderDrawerContent}
|
|
606
655
|
open={drawerOpen}
|
|
607
656
|
swipeEnabled={drawerSwipeEnabled}
|
|
608
657
|
hapticFeedbackEnabled={hapticFeedbackEnabled}
|
|
609
658
|
bottomBarHeight={tabBarHeight ?? 0}
|
|
659
|
+
colorScheme={drawerColorScheme}
|
|
610
660
|
onDrawerOpenChange={(event) =>
|
|
611
661
|
onDrawerOpenChange?.(event.nativeEvent.open)
|
|
612
662
|
}
|
|
663
|
+
onDrawerProgress={onDrawerProgress}
|
|
613
664
|
>
|
|
614
665
|
<View collapsable={false} style={styles.drawerMenu}>
|
|
615
666
|
{Platform.OS !== "web" ? renderDrawerContent?.() : null}
|
|
@@ -623,9 +674,7 @@ const BottomTabs = <Route extends BaseRoute>({
|
|
|
623
674
|
items={items}
|
|
624
675
|
icons={renderCustomTabBar ? undefined : resolvedIconAssets}
|
|
625
676
|
selectedIcons={
|
|
626
|
-
|
|
627
|
-
? resolvedSelectedIconAssets
|
|
628
|
-
: undefined
|
|
677
|
+
!renderCustomTabBar ? resolvedSelectedIconAssets : undefined
|
|
629
678
|
}
|
|
630
679
|
selectedPage={focusedKey}
|
|
631
680
|
tabBarHidden={props.tabBarHidden ?? !!renderCustomTabBar}
|
|
@@ -717,7 +766,7 @@ const BottomTabs = <Route extends BaseRoute>({
|
|
|
717
766
|
</View>
|
|
718
767
|
) : null}
|
|
719
768
|
</View>
|
|
720
|
-
</
|
|
769
|
+
</DrawerHostWithProgress>
|
|
721
770
|
</BottomTabBarHeightContext.Provider>
|
|
722
771
|
);
|
|
723
772
|
};
|
|
@@ -730,7 +779,8 @@ const styles = StyleSheet.create({
|
|
|
730
779
|
},
|
|
731
780
|
drawerMenu: {
|
|
732
781
|
position: "absolute",
|
|
733
|
-
width
|
|
782
|
+
// Must match the native drawer width so menu descendants lay out to its edge.
|
|
783
|
+
width: "80%",
|
|
734
784
|
height: "100%",
|
|
735
785
|
},
|
|
736
786
|
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/src/index.tsx
CHANGED
|
@@ -9,6 +9,7 @@ export default BottomTabs;
|
|
|
9
9
|
* Utilities
|
|
10
10
|
*/
|
|
11
11
|
export { SceneMap } from './SceneMap';
|
|
12
|
+
export { default as BottomTabsDrawerNative } from './BottomTabsDrawerNativeComponent';
|
|
12
13
|
export { useBottomTabBarHeight } from './utils/useBottomTabBarHeight';
|
|
13
14
|
export { BottomTabBarHeightContext } from './utils/BottomTabBarHeightContext';
|
|
14
15
|
|