rn-custom-ui 1.0.0
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/LICENSE +20 -0
- package/README.md +477 -0
- package/lib/module/assets/images/close.png +0 -0
- package/lib/module/components/CustomCheckbox/index.js +99 -0
- package/lib/module/components/CustomCheckbox/index.js.map +1 -0
- package/lib/module/components/CustomCheckbox/styles.js +213 -0
- package/lib/module/components/CustomCheckbox/styles.js.map +1 -0
- package/lib/module/components/CustomCheckbox/types.js +4 -0
- package/lib/module/components/CustomCheckbox/types.js.map +1 -0
- package/lib/module/components/closeButton/index.js +45 -0
- package/lib/module/components/closeButton/index.js.map +1 -0
- package/lib/module/components/closeButton/types.js +4 -0
- package/lib/module/components/closeButton/types.js.map +1 -0
- package/lib/module/components/customButton/index.js +176 -0
- package/lib/module/components/customButton/index.js.map +1 -0
- package/lib/module/components/customButton/styles.js +282 -0
- package/lib/module/components/customButton/styles.js.map +1 -0
- package/lib/module/components/customButton/types.js +4 -0
- package/lib/module/components/customButton/types.js.map +1 -0
- package/lib/module/components/customDropDown/DropDownBottomSheet.js +57 -0
- package/lib/module/components/customDropDown/DropDownBottomSheet.js.map +1 -0
- package/lib/module/components/customDropDown/DropDownList.js +51 -0
- package/lib/module/components/customDropDown/DropDownList.js.map +1 -0
- package/lib/module/components/customDropDown/DropDownListItem.js +38 -0
- package/lib/module/components/customDropDown/DropDownListItem.js.map +1 -0
- package/lib/module/components/customDropDown/DropDownListModal.js +63 -0
- package/lib/module/components/customDropDown/DropDownListModal.js.map +1 -0
- package/lib/module/components/customDropDown/index.js +143 -0
- package/lib/module/components/customDropDown/index.js.map +1 -0
- package/lib/module/components/customDropDown/styles.js +189 -0
- package/lib/module/components/customDropDown/styles.js.map +1 -0
- package/lib/module/components/customDropDown/types.js +4 -0
- package/lib/module/components/customDropDown/types.js.map +1 -0
- package/lib/module/components/customDropDown/utils.js +17 -0
- package/lib/module/components/customDropDown/utils.js.map +1 -0
- package/lib/module/components/customList/ListEmpty.js +33 -0
- package/lib/module/components/customList/ListEmpty.js.map +1 -0
- package/lib/module/components/customList/ListFooterLoader.js +14 -0
- package/lib/module/components/customList/ListFooterLoader.js.map +1 -0
- package/lib/module/components/customList/defaultKeyExtractor.js +9 -0
- package/lib/module/components/customList/defaultKeyExtractor.js.map +1 -0
- package/lib/module/components/customList/getFlashList.js +19 -0
- package/lib/module/components/customList/getFlashList.js.map +1 -0
- package/lib/module/components/customList/index.js +117 -0
- package/lib/module/components/customList/index.js.map +1 -0
- package/lib/module/components/customList/styles.js +45 -0
- package/lib/module/components/customList/styles.js.map +1 -0
- package/lib/module/components/customList/types.js +4 -0
- package/lib/module/components/customList/types.js.map +1 -0
- package/lib/module/components/customModal/ModalFooter.js +44 -0
- package/lib/module/components/customModal/ModalFooter.js.map +1 -0
- package/lib/module/components/customModal/index.js +132 -0
- package/lib/module/components/customModal/index.js.map +1 -0
- package/lib/module/components/customModal/styles.js +123 -0
- package/lib/module/components/customModal/styles.js.map +1 -0
- package/lib/module/components/customModal/types.js +4 -0
- package/lib/module/components/customModal/types.js.map +1 -0
- package/lib/module/components/customModal/useCustomModal.js +23 -0
- package/lib/module/components/customModal/useCustomModal.js.map +1 -0
- package/lib/module/components/customNumberPad/NumberPadKey.js +39 -0
- package/lib/module/components/customNumberPad/NumberPadKey.js.map +1 -0
- package/lib/module/components/customNumberPad/index.js +156 -0
- package/lib/module/components/customNumberPad/index.js.map +1 -0
- package/lib/module/components/customNumberPad/styles.js +131 -0
- package/lib/module/components/customNumberPad/styles.js.map +1 -0
- package/lib/module/components/customNumberPad/types.js +4 -0
- package/lib/module/components/customNumberPad/types.js.map +1 -0
- package/lib/module/components/customNumberPad/useNumberPadInput.js +44 -0
- package/lib/module/components/customNumberPad/useNumberPadInput.js.map +1 -0
- package/lib/module/components/customNumberPad/utils.js +38 -0
- package/lib/module/components/customNumberPad/utils.js.map +1 -0
- package/lib/module/components/customSlideTabs/AnimatedTabIndicator.js +66 -0
- package/lib/module/components/customSlideTabs/AnimatedTabIndicator.js.map +1 -0
- package/lib/module/components/customSlideTabs/TabBarItem.js +61 -0
- package/lib/module/components/customSlideTabs/TabBarItem.js.map +1 -0
- package/lib/module/components/customSlideTabs/TabScene.js +88 -0
- package/lib/module/components/customSlideTabs/TabScene.js.map +1 -0
- package/lib/module/components/customSlideTabs/index.js +277 -0
- package/lib/module/components/customSlideTabs/index.js.map +1 -0
- package/lib/module/components/customSlideTabs/styles.js +132 -0
- package/lib/module/components/customSlideTabs/styles.js.map +1 -0
- package/lib/module/components/customSlideTabs/tabBarScroll.js +65 -0
- package/lib/module/components/customSlideTabs/tabBarScroll.js.map +1 -0
- package/lib/module/components/customSlideTabs/types.js +4 -0
- package/lib/module/components/customSlideTabs/types.js.map +1 -0
- package/lib/module/components/loading/index.js +34 -0
- package/lib/module/components/loading/index.js.map +1 -0
- package/lib/module/customFunctions/array.js +61 -0
- package/lib/module/customFunctions/array.js.map +1 -0
- package/lib/module/customFunctions/async.js +62 -0
- package/lib/module/customFunctions/async.js.map +1 -0
- package/lib/module/customFunctions/date.js +109 -0
- package/lib/module/customFunctions/date.js.map +1 -0
- package/lib/module/customFunctions/general.js +29 -0
- package/lib/module/customFunctions/general.js.map +1 -0
- package/lib/module/customFunctions/id.js +20 -0
- package/lib/module/customFunctions/id.js.map +1 -0
- package/lib/module/customFunctions/index.js +29 -0
- package/lib/module/customFunctions/index.js.map +1 -0
- package/lib/module/customFunctions/number.js +94 -0
- package/lib/module/customFunctions/number.js.map +1 -0
- package/lib/module/customFunctions/object.js +39 -0
- package/lib/module/customFunctions/object.js.map +1 -0
- package/lib/module/customFunctions/string.js +63 -0
- package/lib/module/customFunctions/string.js.map +1 -0
- package/lib/module/customFunctions/types.js +2 -0
- package/lib/module/customFunctions/types.js.map +1 -0
- package/lib/module/customFunctions/validation.js +34 -0
- package/lib/module/customFunctions/validation.js.map +1 -0
- package/lib/module/customHooks/errors.js +61 -0
- package/lib/module/customHooks/errors.js.map +1 -0
- package/lib/module/customHooks/fetchJson.js +36 -0
- package/lib/module/customHooks/fetchJson.js.map +1 -0
- package/lib/module/customHooks/index.js +10 -0
- package/lib/module/customHooks/index.js.map +1 -0
- package/lib/module/customHooks/internal.js +49 -0
- package/lib/module/customHooks/internal.js.map +1 -0
- package/lib/module/customHooks/types.js +2 -0
- package/lib/module/customHooks/types.js.map +1 -0
- package/lib/module/customHooks/useApi.js +91 -0
- package/lib/module/customHooks/useApi.js.map +1 -0
- package/lib/module/customHooks/useLazyApi.js +80 -0
- package/lib/module/customHooks/useLazyApi.js.map +1 -0
- package/lib/module/customHooks/useMutation.js +69 -0
- package/lib/module/customHooks/useMutation.js.map +1 -0
- package/lib/module/customHooks/usePaginatedApi.js +127 -0
- package/lib/module/customHooks/usePaginatedApi.js.map +1 -0
- package/lib/module/customHooks/usePollingApi.js +37 -0
- package/lib/module/customHooks/usePollingApi.js.map +1 -0
- package/lib/module/index.js +13 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/multiply.js +6 -0
- package/lib/module/multiply.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/components/CustomCheckbox/index.d.ts +5 -0
- package/lib/typescript/src/components/CustomCheckbox/index.d.ts.map +1 -0
- package/lib/typescript/src/components/CustomCheckbox/styles.d.ts +67 -0
- package/lib/typescript/src/components/CustomCheckbox/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/CustomCheckbox/types.d.ts +28 -0
- package/lib/typescript/src/components/CustomCheckbox/types.d.ts.map +1 -0
- package/lib/typescript/src/components/closeButton/index.d.ts +4 -0
- package/lib/typescript/src/components/closeButton/index.d.ts.map +1 -0
- package/lib/typescript/src/components/closeButton/types.d.ts +8 -0
- package/lib/typescript/src/components/closeButton/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customButton/index.d.ts +5 -0
- package/lib/typescript/src/components/customButton/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customButton/styles.d.ts +231 -0
- package/lib/typescript/src/components/customButton/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customButton/types.d.ts +46 -0
- package/lib/typescript/src/components/customButton/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/DropDownBottomSheet.d.ts +18 -0
- package/lib/typescript/src/components/customDropDown/DropDownBottomSheet.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/DropDownList.d.ts +17 -0
- package/lib/typescript/src/components/customDropDown/DropDownList.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/DropDownListItem.d.ts +15 -0
- package/lib/typescript/src/components/customDropDown/DropDownListItem.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/DropDownListModal.d.ts +19 -0
- package/lib/typescript/src/components/customDropDown/DropDownListModal.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/index.d.ts +5 -0
- package/lib/typescript/src/components/customDropDown/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/styles.d.ts +190 -0
- package/lib/typescript/src/components/customDropDown/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/types.d.ts +37 -0
- package/lib/typescript/src/components/customDropDown/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/utils.d.ts +4 -0
- package/lib/typescript/src/components/customDropDown/utils.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/ListEmpty.d.ts +10 -0
- package/lib/typescript/src/components/customList/ListEmpty.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/ListFooterLoader.d.ts +3 -0
- package/lib/typescript/src/components/customList/ListFooterLoader.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/defaultKeyExtractor.d.ts +2 -0
- package/lib/typescript/src/components/customList/defaultKeyExtractor.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/getFlashList.d.ts +6 -0
- package/lib/typescript/src/components/customList/getFlashList.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/index.d.ts +11 -0
- package/lib/typescript/src/components/customList/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/styles.d.ts +42 -0
- package/lib/typescript/src/components/customList/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/types.d.ts +33 -0
- package/lib/typescript/src/components/customList/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customModal/ModalFooter.d.ts +12 -0
- package/lib/typescript/src/components/customModal/ModalFooter.d.ts.map +1 -0
- package/lib/typescript/src/components/customModal/index.d.ts +6 -0
- package/lib/typescript/src/components/customModal/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customModal/styles.d.ts +83 -0
- package/lib/typescript/src/components/customModal/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customModal/types.d.ts +36 -0
- package/lib/typescript/src/components/customModal/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customModal/useCustomModal.d.ts +8 -0
- package/lib/typescript/src/components/customModal/useCustomModal.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/NumberPadKey.d.ts +23 -0
- package/lib/typescript/src/components/customNumberPad/NumberPadKey.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/index.d.ts +7 -0
- package/lib/typescript/src/components/customNumberPad/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/styles.d.ts +37 -0
- package/lib/typescript/src/components/customNumberPad/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/types.d.ts +47 -0
- package/lib/typescript/src/components/customNumberPad/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/useNumberPadInput.d.ts +16 -0
- package/lib/typescript/src/components/customNumberPad/useNumberPadInput.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/utils.d.ts +4 -0
- package/lib/typescript/src/components/customNumberPad/utils.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/AnimatedTabIndicator.d.ts +16 -0
- package/lib/typescript/src/components/customSlideTabs/AnimatedTabIndicator.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/TabBarItem.d.ts +23 -0
- package/lib/typescript/src/components/customSlideTabs/TabBarItem.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/TabScene.d.ts +21 -0
- package/lib/typescript/src/components/customSlideTabs/TabScene.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/index.d.ts +5 -0
- package/lib/typescript/src/components/customSlideTabs/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/styles.d.ts +130 -0
- package/lib/typescript/src/components/customSlideTabs/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/tabBarScroll.d.ts +15 -0
- package/lib/typescript/src/components/customSlideTabs/tabBarScroll.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/types.d.ts +68 -0
- package/lib/typescript/src/components/customSlideTabs/types.d.ts.map +1 -0
- package/lib/typescript/src/components/loading/index.d.ts +7 -0
- package/lib/typescript/src/components/loading/index.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/array.d.ts +7 -0
- package/lib/typescript/src/customFunctions/array.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/async.d.ts +9 -0
- package/lib/typescript/src/customFunctions/async.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/date.d.ts +18 -0
- package/lib/typescript/src/customFunctions/date.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/general.d.ts +7 -0
- package/lib/typescript/src/customFunctions/general.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/id.d.ts +4 -0
- package/lib/typescript/src/customFunctions/id.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/index.d.ts +26 -0
- package/lib/typescript/src/customFunctions/index.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/number.d.ts +15 -0
- package/lib/typescript/src/customFunctions/number.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/object.d.ts +6 -0
- package/lib/typescript/src/customFunctions/object.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/string.d.ts +20 -0
- package/lib/typescript/src/customFunctions/string.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/types.d.ts +22 -0
- package/lib/typescript/src/customFunctions/types.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/validation.d.ts +11 -0
- package/lib/typescript/src/customFunctions/validation.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/errors.d.ts +16 -0
- package/lib/typescript/src/customHooks/errors.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/fetchJson.d.ts +5 -0
- package/lib/typescript/src/customHooks/fetchJson.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/index.d.ts +9 -0
- package/lib/typescript/src/customHooks/index.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/internal.d.ts +12 -0
- package/lib/typescript/src/customHooks/internal.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/types.d.ts +49 -0
- package/lib/typescript/src/customHooks/types.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/useApi.d.ts +13 -0
- package/lib/typescript/src/customHooks/useApi.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/useLazyApi.d.ts +14 -0
- package/lib/typescript/src/customHooks/useLazyApi.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/useMutation.d.ts +15 -0
- package/lib/typescript/src/customHooks/useMutation.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/usePaginatedApi.d.ts +19 -0
- package/lib/typescript/src/customHooks/usePaginatedApi.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/usePollingApi.d.ts +13 -0
- package/lib/typescript/src/customHooks/usePollingApi.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +11 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/multiply.d.ts +2 -0
- package/lib/typescript/src/multiply.d.ts.map +1 -0
- package/package.json +181 -0
- package/src/assets/images/close.png +0 -0
- package/src/components/CustomCheckbox/index.tsx +143 -0
- package/src/components/CustomCheckbox/styles.ts +146 -0
- package/src/components/CustomCheckbox/types.ts +33 -0
- package/src/components/closeButton/index.tsx +40 -0
- package/src/components/closeButton/types.ts +13 -0
- package/src/components/customButton/index.tsx +288 -0
- package/src/components/customButton/styles.ts +247 -0
- package/src/components/customButton/types.ts +71 -0
- package/src/components/customDropDown/DropDownBottomSheet.tsx +70 -0
- package/src/components/customDropDown/DropDownList.tsx +88 -0
- package/src/components/customDropDown/DropDownListItem.tsx +74 -0
- package/src/components/customDropDown/DropDownListModal.tsx +86 -0
- package/src/components/customDropDown/index.tsx +213 -0
- package/src/components/customDropDown/styles.ts +184 -0
- package/src/components/customDropDown/types.ts +48 -0
- package/src/components/customDropDown/utils.ts +24 -0
- package/src/components/customList/ListEmpty.tsx +36 -0
- package/src/components/customList/ListFooterLoader.tsx +11 -0
- package/src/components/customList/defaultKeyExtractor.ts +7 -0
- package/src/components/customList/getFlashList.ts +26 -0
- package/src/components/customList/index.tsx +142 -0
- package/src/components/customList/styles.ts +43 -0
- package/src/components/customList/types.ts +60 -0
- package/src/components/customModal/ModalFooter.tsx +57 -0
- package/src/components/customModal/index.tsx +166 -0
- package/src/components/customModal/styles.ts +131 -0
- package/src/components/customModal/types.ts +48 -0
- package/src/components/customModal/useCustomModal.ts +25 -0
- package/src/components/customNumberPad/NumberPadKey.tsx +81 -0
- package/src/components/customNumberPad/index.tsx +204 -0
- package/src/components/customNumberPad/styles.ts +146 -0
- package/src/components/customNumberPad/types.ts +53 -0
- package/src/components/customNumberPad/useNumberPadInput.ts +56 -0
- package/src/components/customNumberPad/utils.ts +54 -0
- package/src/components/customSlideTabs/AnimatedTabIndicator.tsx +103 -0
- package/src/components/customSlideTabs/TabBarItem.tsx +118 -0
- package/src/components/customSlideTabs/TabScene.tsx +136 -0
- package/src/components/customSlideTabs/index.tsx +385 -0
- package/src/components/customSlideTabs/styles.ts +136 -0
- package/src/components/customSlideTabs/tabBarScroll.ts +92 -0
- package/src/components/customSlideTabs/types.ts +87 -0
- package/src/components/loading/index.tsx +34 -0
- package/src/customFunctions/array.ts +83 -0
- package/src/customFunctions/async.ts +85 -0
- package/src/customFunctions/date.ts +158 -0
- package/src/customFunctions/general.ts +35 -0
- package/src/customFunctions/id.ts +25 -0
- package/src/customFunctions/index.ts +91 -0
- package/src/customFunctions/number.ts +139 -0
- package/src/customFunctions/object.ts +59 -0
- package/src/customFunctions/string.ts +119 -0
- package/src/customFunctions/types.ts +25 -0
- package/src/customFunctions/validation.ts +49 -0
- package/src/customHooks/errors.ts +87 -0
- package/src/customHooks/fetchJson.ts +49 -0
- package/src/customHooks/index.ts +20 -0
- package/src/customHooks/internal.ts +67 -0
- package/src/customHooks/types.ts +71 -0
- package/src/customHooks/useApi.ts +107 -0
- package/src/customHooks/useLazyApi.ts +92 -0
- package/src/customHooks/useMutation.ts +97 -0
- package/src/customHooks/usePaginatedApi.ts +168 -0
- package/src/customHooks/usePollingApi.ts +48 -0
- package/src/index.tsx +63 -0
- package/src/multiply.tsx +3 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Animated,
|
|
4
|
+
Dimensions,
|
|
5
|
+
FlatList,
|
|
6
|
+
View,
|
|
7
|
+
type LayoutChangeEvent,
|
|
8
|
+
type ListRenderItem,
|
|
9
|
+
type NativeScrollEvent,
|
|
10
|
+
type NativeSyntheticEvent,
|
|
11
|
+
} from 'react-native';
|
|
12
|
+
|
|
13
|
+
import AnimatedTabIndicator from './AnimatedTabIndicator';
|
|
14
|
+
import TabBarItem from './TabBarItem';
|
|
15
|
+
import TabScene from './TabScene';
|
|
16
|
+
import { styles } from './styles';
|
|
17
|
+
import {
|
|
18
|
+
buildTabLayoutMetrics,
|
|
19
|
+
getCenteredTabScrollOffset,
|
|
20
|
+
getCenteredTabScrollOffsetFromProgress,
|
|
21
|
+
getMaxTabScrollOffset,
|
|
22
|
+
} from './tabBarScroll';
|
|
23
|
+
import type { CustomSlideTabsProps, SlideTabItem } from './types';
|
|
24
|
+
|
|
25
|
+
const CustomSlideTabs = <TData = unknown, TError = unknown>({
|
|
26
|
+
tabs,
|
|
27
|
+
renderScene,
|
|
28
|
+
fetchSceneData,
|
|
29
|
+
initialIndex = 0,
|
|
30
|
+
lazy = true,
|
|
31
|
+
fetchWhenActive = true,
|
|
32
|
+
refetchOnRevisit = false,
|
|
33
|
+
keepPreviousSceneData = true,
|
|
34
|
+
onTabChange,
|
|
35
|
+
renderTab,
|
|
36
|
+
renderSceneHeader,
|
|
37
|
+
showSceneHeading = true,
|
|
38
|
+
animatedIndicator = true,
|
|
39
|
+
showUnderline = true,
|
|
40
|
+
tabBarStyle,
|
|
41
|
+
tabStyle,
|
|
42
|
+
activeTabStyle,
|
|
43
|
+
tabTextStyle,
|
|
44
|
+
activeTabTextStyle,
|
|
45
|
+
tabImageStyle,
|
|
46
|
+
activeTabImageStyle,
|
|
47
|
+
underlineStyle,
|
|
48
|
+
indicatorPillStyle,
|
|
49
|
+
sceneHeadingStyle,
|
|
50
|
+
sceneSubtitleStyle,
|
|
51
|
+
sceneHeaderStyle,
|
|
52
|
+
sceneContainerStyle,
|
|
53
|
+
sceneStyle,
|
|
54
|
+
pageWidth,
|
|
55
|
+
}: CustomSlideTabsProps<TData, TError>) => {
|
|
56
|
+
const [selectedIndex, setSelectedIndex] = useState(initialIndex);
|
|
57
|
+
const [visitedIndexes, setVisitedIndexes] = useState<Set<number>>(
|
|
58
|
+
() => new Set([initialIndex])
|
|
59
|
+
);
|
|
60
|
+
const [containerWidth, setContainerWidth] = useState(
|
|
61
|
+
pageWidth ?? Dimensions.get('window').width
|
|
62
|
+
);
|
|
63
|
+
const [tabWidthsVersion, setTabWidthsVersion] = useState(0);
|
|
64
|
+
|
|
65
|
+
const tabListRef = useRef<FlatList<SlideTabItem> | null>(null);
|
|
66
|
+
const pagerRef = useRef<FlatList<SlideTabItem> | null>(null);
|
|
67
|
+
const tabWidthsRef = useRef<number[]>([]);
|
|
68
|
+
const tabBarWidthRef = useRef(0);
|
|
69
|
+
const tabBarScrollXRef = useRef(0);
|
|
70
|
+
const tabLayoutMetricsRef = useRef(buildTabLayoutMetrics([]));
|
|
71
|
+
const pagerScrollX = useRef(new Animated.Value(0)).current;
|
|
72
|
+
const tabBarScrollX = useRef(new Animated.Value(0)).current;
|
|
73
|
+
|
|
74
|
+
const resolvedWidth = pageWidth ?? containerWidth;
|
|
75
|
+
|
|
76
|
+
const tabWidthsSnapshot = useMemo(
|
|
77
|
+
() =>
|
|
78
|
+
tabs.map((_, index) =>
|
|
79
|
+
tabWidthsVersion >= 0 ? tabWidthsRef.current[index] : undefined
|
|
80
|
+
),
|
|
81
|
+
[tabWidthsVersion, tabs]
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const tabLayoutMetrics = useMemo(() => {
|
|
85
|
+
const metrics = buildTabLayoutMetrics(tabWidthsSnapshot);
|
|
86
|
+
tabLayoutMetricsRef.current = metrics;
|
|
87
|
+
return metrics;
|
|
88
|
+
}, [tabWidthsSnapshot]);
|
|
89
|
+
|
|
90
|
+
const applyTabBarScroll = useCallback(
|
|
91
|
+
(offset: number, animated: boolean) => {
|
|
92
|
+
const maxOffset = getMaxTabScrollOffset(
|
|
93
|
+
tabLayoutMetricsRef.current,
|
|
94
|
+
tabBarWidthRef.current
|
|
95
|
+
);
|
|
96
|
+
const safeOffset = Math.min(maxOffset, Math.max(0, offset));
|
|
97
|
+
|
|
98
|
+
tabListRef.current?.scrollToOffset({
|
|
99
|
+
offset: safeOffset,
|
|
100
|
+
animated,
|
|
101
|
+
});
|
|
102
|
+
tabBarScrollXRef.current = safeOffset;
|
|
103
|
+
tabBarScrollX.setValue(safeOffset);
|
|
104
|
+
},
|
|
105
|
+
[tabBarScrollX]
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const scrollTabBarToIndex = useCallback(
|
|
109
|
+
(index: number, animated: boolean) => {
|
|
110
|
+
const nextOffset = getCenteredTabScrollOffset(
|
|
111
|
+
index,
|
|
112
|
+
tabLayoutMetricsRef.current,
|
|
113
|
+
tabBarWidthRef.current
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
if (nextOffset == null) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
applyTabBarScroll(nextOffset, animated);
|
|
121
|
+
},
|
|
122
|
+
[applyTabBarScroll]
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const scrollTabBarToProgress = useCallback(
|
|
126
|
+
(progress: number, animated: boolean) => {
|
|
127
|
+
const nextOffset = getCenteredTabScrollOffsetFromProgress(
|
|
128
|
+
progress,
|
|
129
|
+
tabLayoutMetricsRef.current,
|
|
130
|
+
tabBarWidthRef.current
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
if (nextOffset == null) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
applyTabBarScroll(nextOffset, animated);
|
|
138
|
+
},
|
|
139
|
+
[applyTabBarScroll]
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const handleTabMeasure = useCallback((index: number, width: number) => {
|
|
143
|
+
if (tabWidthsRef.current[index] === width) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
tabWidthsRef.current[index] = width;
|
|
148
|
+
setTabWidthsVersion((current) => current + 1);
|
|
149
|
+
}, []);
|
|
150
|
+
|
|
151
|
+
const scrollPagerToIndex = useCallback((index: number, animated = true) => {
|
|
152
|
+
pagerRef.current?.scrollToIndex({ index, animated });
|
|
153
|
+
}, []);
|
|
154
|
+
|
|
155
|
+
const selectTab = useCallback(
|
|
156
|
+
(index: number, animated = true) => {
|
|
157
|
+
if (index < 0 || index >= tabs.length) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
setSelectedIndex(index);
|
|
162
|
+
setVisitedIndexes((current) => {
|
|
163
|
+
const next = new Set(current);
|
|
164
|
+
next.add(index);
|
|
165
|
+
return next;
|
|
166
|
+
});
|
|
167
|
+
scrollPagerToIndex(index, animated);
|
|
168
|
+
onTabChange?.(index, tabs[index]!);
|
|
169
|
+
},
|
|
170
|
+
[onTabChange, scrollPagerToIndex, tabs]
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
const onPagerMomentumEnd = useCallback(
|
|
174
|
+
(event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
175
|
+
const offsetX = event.nativeEvent.contentOffset.x;
|
|
176
|
+
const nextIndex = Math.round(offsetX / resolvedWidth);
|
|
177
|
+
const safeIndex = Math.max(0, Math.min(nextIndex, tabs.length - 1));
|
|
178
|
+
|
|
179
|
+
if (safeIndex !== selectedIndex) {
|
|
180
|
+
setSelectedIndex(safeIndex);
|
|
181
|
+
setVisitedIndexes((current) => {
|
|
182
|
+
const next = new Set(current);
|
|
183
|
+
next.add(safeIndex);
|
|
184
|
+
return next;
|
|
185
|
+
});
|
|
186
|
+
onTabChange?.(safeIndex, tabs[safeIndex]!);
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
[onTabChange, resolvedWidth, selectedIndex, tabs]
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
const onContainerLayout = useCallback(
|
|
193
|
+
(event: LayoutChangeEvent) => {
|
|
194
|
+
if (!pageWidth) {
|
|
195
|
+
setContainerWidth(event.nativeEvent.layout.width);
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
[pageWidth]
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
const onTabBarLayout = useCallback(
|
|
202
|
+
(event: LayoutChangeEvent) => {
|
|
203
|
+
tabBarWidthRef.current = event.nativeEvent.layout.width;
|
|
204
|
+
scrollTabBarToIndex(selectedIndex, false);
|
|
205
|
+
},
|
|
206
|
+
[scrollTabBarToIndex, selectedIndex]
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
const onTabBarScroll = useMemo(
|
|
210
|
+
() =>
|
|
211
|
+
Animated.event(
|
|
212
|
+
[{ nativeEvent: { contentOffset: { x: tabBarScrollX } } }],
|
|
213
|
+
{
|
|
214
|
+
useNativeDriver: false,
|
|
215
|
+
listener: (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
216
|
+
tabBarScrollXRef.current = event.nativeEvent.contentOffset.x;
|
|
217
|
+
},
|
|
218
|
+
}
|
|
219
|
+
),
|
|
220
|
+
[tabBarScrollX]
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
const onPagerScroll = useMemo(
|
|
224
|
+
() =>
|
|
225
|
+
Animated.event(
|
|
226
|
+
[{ nativeEvent: { contentOffset: { x: pagerScrollX } } }],
|
|
227
|
+
{
|
|
228
|
+
useNativeDriver: false,
|
|
229
|
+
listener: (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
230
|
+
if (resolvedWidth <= 0) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const progress = event.nativeEvent.contentOffset.x / resolvedWidth;
|
|
235
|
+
scrollTabBarToProgress(progress, false);
|
|
236
|
+
},
|
|
237
|
+
}
|
|
238
|
+
),
|
|
239
|
+
[pagerScrollX, resolvedWidth, scrollTabBarToProgress]
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
useEffect(() => {
|
|
243
|
+
pagerScrollX.setValue(initialIndex * resolvedWidth);
|
|
244
|
+
}, [initialIndex, pagerScrollX, resolvedWidth]);
|
|
245
|
+
|
|
246
|
+
useEffect(() => {
|
|
247
|
+
tabWidthsRef.current = [];
|
|
248
|
+
setTabWidthsVersion((current) => current + 1);
|
|
249
|
+
}, [tabs]);
|
|
250
|
+
|
|
251
|
+
useEffect(() => {
|
|
252
|
+
scrollPagerToIndex(initialIndex, false);
|
|
253
|
+
scrollTabBarToIndex(initialIndex, false);
|
|
254
|
+
}, [initialIndex, scrollPagerToIndex, scrollTabBarToIndex]);
|
|
255
|
+
|
|
256
|
+
useEffect(() => {
|
|
257
|
+
if (tabLayoutMetrics.some((metric) => metric.width > 0)) {
|
|
258
|
+
scrollTabBarToIndex(selectedIndex, false);
|
|
259
|
+
}
|
|
260
|
+
}, [tabLayoutMetrics, scrollTabBarToIndex, selectedIndex]);
|
|
261
|
+
|
|
262
|
+
const tabBarData = useMemo(() => tabs, [tabs]);
|
|
263
|
+
|
|
264
|
+
const renderPagerItem: ListRenderItem<SlideTabItem> = useCallback(
|
|
265
|
+
({ item, index }) => (
|
|
266
|
+
<View style={{ width: resolvedWidth }}>
|
|
267
|
+
<TabScene
|
|
268
|
+
tab={item}
|
|
269
|
+
index={index}
|
|
270
|
+
isActive={selectedIndex === index}
|
|
271
|
+
shouldMount={!lazy || visitedIndexes.has(index)}
|
|
272
|
+
fetchSceneData={fetchSceneData}
|
|
273
|
+
fetchWhenActive={fetchWhenActive}
|
|
274
|
+
refetchOnRevisit={refetchOnRevisit}
|
|
275
|
+
keepPreviousSceneData={keepPreviousSceneData}
|
|
276
|
+
renderScene={renderScene}
|
|
277
|
+
renderSceneHeader={renderSceneHeader}
|
|
278
|
+
showSceneHeading={showSceneHeading}
|
|
279
|
+
sceneStyle={sceneStyle}
|
|
280
|
+
sceneHeaderStyle={sceneHeaderStyle}
|
|
281
|
+
sceneHeadingStyle={sceneHeadingStyle}
|
|
282
|
+
sceneSubtitleStyle={sceneSubtitleStyle}
|
|
283
|
+
/>
|
|
284
|
+
</View>
|
|
285
|
+
),
|
|
286
|
+
[
|
|
287
|
+
fetchSceneData,
|
|
288
|
+
fetchWhenActive,
|
|
289
|
+
keepPreviousSceneData,
|
|
290
|
+
lazy,
|
|
291
|
+
refetchOnRevisit,
|
|
292
|
+
renderScene,
|
|
293
|
+
renderSceneHeader,
|
|
294
|
+
resolvedWidth,
|
|
295
|
+
sceneHeaderStyle,
|
|
296
|
+
sceneHeadingStyle,
|
|
297
|
+
sceneStyle,
|
|
298
|
+
sceneSubtitleStyle,
|
|
299
|
+
selectedIndex,
|
|
300
|
+
showSceneHeading,
|
|
301
|
+
visitedIndexes,
|
|
302
|
+
]
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
return (
|
|
306
|
+
<View style={styles.container} onLayout={onContainerLayout}>
|
|
307
|
+
<View style={[styles.tabBar, tabBarStyle]} onLayout={onTabBarLayout}>
|
|
308
|
+
{animatedIndicator && (
|
|
309
|
+
<AnimatedTabIndicator
|
|
310
|
+
metrics={tabLayoutMetrics}
|
|
311
|
+
pagerScrollX={pagerScrollX}
|
|
312
|
+
tabBarScrollX={tabBarScrollX}
|
|
313
|
+
pageWidth={resolvedWidth}
|
|
314
|
+
initialScrollX={selectedIndex * resolvedWidth}
|
|
315
|
+
showPill
|
|
316
|
+
showUnderline={showUnderline}
|
|
317
|
+
pillStyle={indicatorPillStyle}
|
|
318
|
+
underlineStyle={underlineStyle}
|
|
319
|
+
/>
|
|
320
|
+
)}
|
|
321
|
+
<FlatList
|
|
322
|
+
ref={tabListRef}
|
|
323
|
+
horizontal
|
|
324
|
+
showsHorizontalScrollIndicator={false}
|
|
325
|
+
data={tabBarData}
|
|
326
|
+
keyExtractor={(item) => item.key}
|
|
327
|
+
contentContainerStyle={styles.tabBarContent}
|
|
328
|
+
scrollEventThrottle={16}
|
|
329
|
+
onScroll={onTabBarScroll}
|
|
330
|
+
renderItem={({ item, index }) => (
|
|
331
|
+
<TabBarItem
|
|
332
|
+
item={item}
|
|
333
|
+
index={index}
|
|
334
|
+
isActive={selectedIndex === index}
|
|
335
|
+
showUnderline={showUnderline}
|
|
336
|
+
useAnimatedIndicator={animatedIndicator}
|
|
337
|
+
renderTab={renderTab}
|
|
338
|
+
tabStyle={tabStyle}
|
|
339
|
+
activeTabStyle={activeTabStyle}
|
|
340
|
+
tabTextStyle={tabTextStyle}
|
|
341
|
+
activeTabTextStyle={activeTabTextStyle}
|
|
342
|
+
tabImageStyle={tabImageStyle}
|
|
343
|
+
activeTabImageStyle={activeTabImageStyle}
|
|
344
|
+
underlineStyle={underlineStyle}
|
|
345
|
+
onMeasure={handleTabMeasure}
|
|
346
|
+
onPress={selectTab}
|
|
347
|
+
/>
|
|
348
|
+
)}
|
|
349
|
+
/>
|
|
350
|
+
</View>
|
|
351
|
+
|
|
352
|
+
<Animated.FlatList
|
|
353
|
+
ref={pagerRef}
|
|
354
|
+
horizontal
|
|
355
|
+
pagingEnabled
|
|
356
|
+
bounces={false}
|
|
357
|
+
scrollEventThrottle={16}
|
|
358
|
+
showsHorizontalScrollIndicator={false}
|
|
359
|
+
data={tabBarData}
|
|
360
|
+
keyExtractor={(item) => `scene-${item.key}`}
|
|
361
|
+
style={[styles.pager, sceneContainerStyle]}
|
|
362
|
+
getItemLayout={(_, index) => ({
|
|
363
|
+
length: resolvedWidth,
|
|
364
|
+
offset: resolvedWidth * index,
|
|
365
|
+
index,
|
|
366
|
+
})}
|
|
367
|
+
onScroll={onPagerScroll}
|
|
368
|
+
onMomentumScrollEnd={onPagerMomentumEnd}
|
|
369
|
+
onScrollToIndexFailed={({ index }) => {
|
|
370
|
+
setTimeout(() => scrollPagerToIndex(index), 100);
|
|
371
|
+
}}
|
|
372
|
+
renderItem={renderPagerItem}
|
|
373
|
+
/>
|
|
374
|
+
</View>
|
|
375
|
+
);
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
export default CustomSlideTabs;
|
|
379
|
+
export type {
|
|
380
|
+
CustomSlideTabsProps,
|
|
381
|
+
SlideTabItem,
|
|
382
|
+
SlideTabSceneState,
|
|
383
|
+
SlideTabFetcher,
|
|
384
|
+
SlideTabIconComponent,
|
|
385
|
+
} from './types';
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StyleSheet,
|
|
3
|
+
type ImageStyle,
|
|
4
|
+
type TextStyle,
|
|
5
|
+
type ViewStyle,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
|
|
8
|
+
export const styles = StyleSheet.create({
|
|
9
|
+
container: {
|
|
10
|
+
flex: 1,
|
|
11
|
+
},
|
|
12
|
+
tabBar: {
|
|
13
|
+
flexGrow: 0,
|
|
14
|
+
position: 'relative',
|
|
15
|
+
overflow: 'hidden',
|
|
16
|
+
},
|
|
17
|
+
tabBarContent: {
|
|
18
|
+
paddingHorizontal: 12,
|
|
19
|
+
gap: 8,
|
|
20
|
+
},
|
|
21
|
+
tabItem: {
|
|
22
|
+
alignItems: 'center',
|
|
23
|
+
justifyContent: 'center',
|
|
24
|
+
paddingHorizontal: 14,
|
|
25
|
+
paddingVertical: 10,
|
|
26
|
+
minWidth: 88,
|
|
27
|
+
zIndex: 1,
|
|
28
|
+
},
|
|
29
|
+
tabItemTransparent: {
|
|
30
|
+
backgroundColor: 'transparent',
|
|
31
|
+
},
|
|
32
|
+
tabItemActive: {
|
|
33
|
+
backgroundColor: '#E7F1FF',
|
|
34
|
+
borderRadius: 10,
|
|
35
|
+
},
|
|
36
|
+
tabContent: {
|
|
37
|
+
flexDirection: 'row',
|
|
38
|
+
alignItems: 'center',
|
|
39
|
+
gap: 8,
|
|
40
|
+
},
|
|
41
|
+
tabImage: {
|
|
42
|
+
width: 18,
|
|
43
|
+
height: 18,
|
|
44
|
+
opacity: 0.7,
|
|
45
|
+
},
|
|
46
|
+
tabImageActive: {
|
|
47
|
+
opacity: 1,
|
|
48
|
+
},
|
|
49
|
+
tabText: {
|
|
50
|
+
fontSize: 13,
|
|
51
|
+
fontWeight: '600',
|
|
52
|
+
color: '#6C757D',
|
|
53
|
+
textTransform: 'uppercase',
|
|
54
|
+
letterSpacing: 0.4,
|
|
55
|
+
},
|
|
56
|
+
tabTextActive: {
|
|
57
|
+
color: '#0D6EFD',
|
|
58
|
+
},
|
|
59
|
+
underline: {
|
|
60
|
+
marginTop: 8,
|
|
61
|
+
height: 3,
|
|
62
|
+
width: '100%',
|
|
63
|
+
borderRadius: 2,
|
|
64
|
+
backgroundColor: '#0D6EFD',
|
|
65
|
+
},
|
|
66
|
+
indicatorPill: {
|
|
67
|
+
position: 'absolute',
|
|
68
|
+
top: 6,
|
|
69
|
+
bottom: 6,
|
|
70
|
+
borderRadius: 10,
|
|
71
|
+
backgroundColor: '#E7F1FF',
|
|
72
|
+
zIndex: 0,
|
|
73
|
+
},
|
|
74
|
+
indicatorUnderline: {
|
|
75
|
+
position: 'absolute',
|
|
76
|
+
bottom: 0,
|
|
77
|
+
height: 3,
|
|
78
|
+
borderRadius: 2,
|
|
79
|
+
backgroundColor: '#0D6EFD',
|
|
80
|
+
zIndex: 2,
|
|
81
|
+
},
|
|
82
|
+
badge: {
|
|
83
|
+
minWidth: 18,
|
|
84
|
+
height: 18,
|
|
85
|
+
borderRadius: 9,
|
|
86
|
+
paddingHorizontal: 5,
|
|
87
|
+
alignItems: 'center',
|
|
88
|
+
justifyContent: 'center',
|
|
89
|
+
backgroundColor: '#DC3545',
|
|
90
|
+
},
|
|
91
|
+
badgeText: {
|
|
92
|
+
fontSize: 10,
|
|
93
|
+
fontWeight: '700',
|
|
94
|
+
color: '#FFFFFF',
|
|
95
|
+
},
|
|
96
|
+
pager: {
|
|
97
|
+
flex: 1,
|
|
98
|
+
},
|
|
99
|
+
scene: {
|
|
100
|
+
flex: 1,
|
|
101
|
+
},
|
|
102
|
+
scenePlaceholder: {
|
|
103
|
+
flex: 1,
|
|
104
|
+
alignItems: 'center',
|
|
105
|
+
justifyContent: 'center',
|
|
106
|
+
padding: 20,
|
|
107
|
+
},
|
|
108
|
+
scenePlaceholderText: {
|
|
109
|
+
fontSize: 14,
|
|
110
|
+
color: '#6C757D',
|
|
111
|
+
},
|
|
112
|
+
sceneHeader: {
|
|
113
|
+
gap: 4,
|
|
114
|
+
marginBottom: 12,
|
|
115
|
+
},
|
|
116
|
+
sceneHeading: {
|
|
117
|
+
fontSize: 20,
|
|
118
|
+
fontWeight: '700',
|
|
119
|
+
color: '#212529',
|
|
120
|
+
},
|
|
121
|
+
sceneSubtitle: {
|
|
122
|
+
fontSize: 14,
|
|
123
|
+
color: '#6C757D',
|
|
124
|
+
lineHeight: 20,
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
export const defaultTheme = {
|
|
129
|
+
tabItem: styles.tabItem as ViewStyle,
|
|
130
|
+
tabItemActive: styles.tabItemActive as ViewStyle,
|
|
131
|
+
tabImage: styles.tabImage as ImageStyle,
|
|
132
|
+
tabImageActive: styles.tabImageActive as ImageStyle,
|
|
133
|
+
tabText: styles.tabText as TextStyle,
|
|
134
|
+
tabTextActive: styles.tabTextActive as TextStyle,
|
|
135
|
+
underline: styles.underline as ViewStyle,
|
|
136
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export const TAB_BAR_HORIZONTAL_PADDING = 12;
|
|
2
|
+
export const TAB_BAR_ITEM_GAP = 8;
|
|
3
|
+
|
|
4
|
+
export type TabLayoutMetric = {
|
|
5
|
+
offset: number;
|
|
6
|
+
width: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const buildTabLayoutMetrics = (
|
|
10
|
+
widths: Array<number | undefined>
|
|
11
|
+
): TabLayoutMetric[] => {
|
|
12
|
+
let offset = TAB_BAR_HORIZONTAL_PADDING;
|
|
13
|
+
|
|
14
|
+
return widths.map((width) => {
|
|
15
|
+
const safeWidth = width ?? 0;
|
|
16
|
+
const metric = { offset, width: safeWidth };
|
|
17
|
+
offset += safeWidth + TAB_BAR_ITEM_GAP;
|
|
18
|
+
return metric;
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const getMaxTabScrollOffset = (
|
|
23
|
+
metrics: TabLayoutMetric[],
|
|
24
|
+
tabBarWidth: number
|
|
25
|
+
) => {
|
|
26
|
+
if (metrics.length === 0 || tabBarWidth <= 0) {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const lastMetric = metrics[metrics.length - 1]!;
|
|
31
|
+
const contentWidth =
|
|
32
|
+
lastMetric.offset + lastMetric.width + TAB_BAR_HORIZONTAL_PADDING;
|
|
33
|
+
|
|
34
|
+
return Math.max(0, contentWidth - tabBarWidth);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const getCenteredTabScrollOffset = (
|
|
38
|
+
index: number,
|
|
39
|
+
metrics: TabLayoutMetric[],
|
|
40
|
+
tabBarWidth: number
|
|
41
|
+
): number | null => {
|
|
42
|
+
const layout = metrics[index];
|
|
43
|
+
|
|
44
|
+
if (!layout?.width || tabBarWidth <= 0) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const tabCenter = layout.offset + layout.width / 2;
|
|
49
|
+
const maxOffset = getMaxTabScrollOffset(metrics, tabBarWidth);
|
|
50
|
+
|
|
51
|
+
return Math.min(maxOffset, Math.max(0, tabCenter - tabBarWidth / 2));
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const getCenteredTabScrollOffsetFromProgress = (
|
|
55
|
+
progress: number,
|
|
56
|
+
metrics: TabLayoutMetric[],
|
|
57
|
+
tabBarWidth: number
|
|
58
|
+
): number | null => {
|
|
59
|
+
const { left, width } = getIndicatorAtProgress(progress, metrics);
|
|
60
|
+
|
|
61
|
+
if (width <= 0 || tabBarWidth <= 0) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const tabCenter = left + width / 2;
|
|
66
|
+
const maxOffset = getMaxTabScrollOffset(metrics, tabBarWidth);
|
|
67
|
+
|
|
68
|
+
return Math.min(maxOffset, Math.max(0, tabCenter - tabBarWidth / 2));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const getIndicatorAtProgress = (
|
|
72
|
+
progress: number,
|
|
73
|
+
metrics: TabLayoutMetric[]
|
|
74
|
+
): { left: number; width: number } => {
|
|
75
|
+
if (metrics.length === 0) {
|
|
76
|
+
return { left: TAB_BAR_HORIZONTAL_PADDING, width: 0 };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const maxIndex = metrics.length - 1;
|
|
80
|
+
const clampedProgress = Math.max(0, Math.min(progress, maxIndex));
|
|
81
|
+
const baseIndex = Math.min(Math.floor(clampedProgress), maxIndex);
|
|
82
|
+
const nextIndex = Math.min(baseIndex + 1, maxIndex);
|
|
83
|
+
const blend = clampedProgress - baseIndex;
|
|
84
|
+
|
|
85
|
+
const current = metrics[baseIndex]!;
|
|
86
|
+
const next = metrics[nextIndex]!;
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
left: current.offset + (next.offset - current.offset) * blend,
|
|
90
|
+
width: current.width + (next.width - current.width) * blend,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
ImageSourcePropType,
|
|
4
|
+
ImageStyle,
|
|
5
|
+
StyleProp,
|
|
6
|
+
TextStyle,
|
|
7
|
+
ViewStyle,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
|
|
10
|
+
import type { ApiFetcher } from '../../customHooks/types';
|
|
11
|
+
|
|
12
|
+
export type SlideTabIconComponent = ComponentType<{
|
|
13
|
+
size?: number;
|
|
14
|
+
color?: string;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}>;
|
|
17
|
+
|
|
18
|
+
export type SlideTabItem = {
|
|
19
|
+
key: string;
|
|
20
|
+
title: string;
|
|
21
|
+
/** Custom scene heading — defaults to title when omitted */
|
|
22
|
+
heading?: string;
|
|
23
|
+
/** Optional subtitle shown below scene heading */
|
|
24
|
+
subtitle?: string;
|
|
25
|
+
image?: ImageSourcePropType;
|
|
26
|
+
LeftIcon?: SlideTabIconComponent;
|
|
27
|
+
badge?: number | string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type SlideTabSceneState<TData, TError = unknown> = {
|
|
31
|
+
tab: SlideTabItem;
|
|
32
|
+
index: number;
|
|
33
|
+
isActive: boolean;
|
|
34
|
+
data: TData | null;
|
|
35
|
+
error: TError | null;
|
|
36
|
+
isIdle: boolean;
|
|
37
|
+
isLoading: boolean;
|
|
38
|
+
isSuccess: boolean;
|
|
39
|
+
isError: boolean;
|
|
40
|
+
refetch: () => Promise<TData | null | undefined>;
|
|
41
|
+
reset: () => void;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type CustomSlideTabsProps<TData = unknown, TError = unknown> = {
|
|
45
|
+
tabs: SlideTabItem[];
|
|
46
|
+
renderScene: (state: SlideTabSceneState<TData, TError>) => ReactNode;
|
|
47
|
+
fetchSceneData?: (
|
|
48
|
+
tab: SlideTabItem,
|
|
49
|
+
index: number,
|
|
50
|
+
signal?: AbortSignal
|
|
51
|
+
) => Promise<TData>;
|
|
52
|
+
initialIndex?: number;
|
|
53
|
+
lazy?: boolean;
|
|
54
|
+
fetchWhenActive?: boolean;
|
|
55
|
+
refetchOnRevisit?: boolean;
|
|
56
|
+
keepPreviousSceneData?: boolean;
|
|
57
|
+
onTabChange?: (index: number, tab: SlideTabItem) => void;
|
|
58
|
+
/** Fully custom tab label — overrides default title/image layout */
|
|
59
|
+
renderTab?: (
|
|
60
|
+
tab: SlideTabItem,
|
|
61
|
+
index: number,
|
|
62
|
+
isActive: boolean
|
|
63
|
+
) => ReactNode;
|
|
64
|
+
/** Custom scene heading — overrides heading/subtitle from tab config */
|
|
65
|
+
renderSceneHeader?: (state: SlideTabSceneState<TData, TError>) => ReactNode;
|
|
66
|
+
showSceneHeading?: boolean;
|
|
67
|
+
/** Animated sliding pill + underline on the tab bar */
|
|
68
|
+
animatedIndicator?: boolean;
|
|
69
|
+
showUnderline?: boolean;
|
|
70
|
+
tabBarStyle?: StyleProp<ViewStyle>;
|
|
71
|
+
tabStyle?: StyleProp<ViewStyle>;
|
|
72
|
+
activeTabStyle?: StyleProp<ViewStyle>;
|
|
73
|
+
tabTextStyle?: StyleProp<TextStyle>;
|
|
74
|
+
activeTabTextStyle?: StyleProp<TextStyle>;
|
|
75
|
+
tabImageStyle?: StyleProp<ImageStyle>;
|
|
76
|
+
activeTabImageStyle?: StyleProp<ImageStyle>;
|
|
77
|
+
underlineStyle?: StyleProp<ViewStyle>;
|
|
78
|
+
indicatorPillStyle?: StyleProp<ViewStyle>;
|
|
79
|
+
sceneHeadingStyle?: StyleProp<TextStyle>;
|
|
80
|
+
sceneSubtitleStyle?: StyleProp<TextStyle>;
|
|
81
|
+
sceneHeaderStyle?: StyleProp<ViewStyle>;
|
|
82
|
+
sceneContainerStyle?: StyleProp<ViewStyle>;
|
|
83
|
+
sceneStyle?: StyleProp<ViewStyle>;
|
|
84
|
+
pageWidth?: number;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export type SlideTabFetcher<TData> = ApiFetcher<TData>;
|