react-native-collapsible-tabs-reanimated 0.1.0-beta
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 +21 -0
- package/README.md +232 -0
- package/lib/commonjs/Bar.js +247 -0
- package/lib/commonjs/Bar.js.map +1 -0
- package/lib/commonjs/Button.js +150 -0
- package/lib/commonjs/Button.js.map +1 -0
- package/lib/commonjs/Context.js +21 -0
- package/lib/commonjs/Context.js.map +1 -0
- package/lib/commonjs/FlashList.js +91 -0
- package/lib/commonjs/FlashList.js.map +1 -0
- package/lib/commonjs/Header.js +54 -0
- package/lib/commonjs/Header.js.map +1 -0
- package/lib/commonjs/Indicator.js +156 -0
- package/lib/commonjs/Indicator.js.map +1 -0
- package/lib/commonjs/Lazy.js +87 -0
- package/lib/commonjs/Lazy.js.map +1 -0
- package/lib/commonjs/LegendList.js +86 -0
- package/lib/commonjs/LegendList.js.map +1 -0
- package/lib/commonjs/List.js +83 -0
- package/lib/commonjs/List.js.map +1 -0
- package/lib/commonjs/Pager.js +93 -0
- package/lib/commonjs/Pager.js.map +1 -0
- package/lib/commonjs/Root.js +169 -0
- package/lib/commonjs/Root.js.map +1 -0
- package/lib/commonjs/ScrollView.js +85 -0
- package/lib/commonjs/ScrollView.js.map +1 -0
- package/lib/commonjs/StaticHeader.js +37 -0
- package/lib/commonjs/StaticHeader.js.map +1 -0
- package/lib/commonjs/StickyHeader.js +37 -0
- package/lib/commonjs/StickyHeader.js.map +1 -0
- package/lib/commonjs/Tab.js +86 -0
- package/lib/commonjs/Tab.js.map +1 -0
- package/lib/commonjs/flash-list.js +14 -0
- package/lib/commonjs/flash-list.js.map +1 -0
- package/lib/commonjs/index.js +128 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/legend-list.js +14 -0
- package/lib/commonjs/legend-list.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/useStableCallback.js +15 -0
- package/lib/commonjs/useStableCallback.js.map +1 -0
- package/lib/module/Bar.js +242 -0
- package/lib/module/Bar.js.map +1 -0
- package/lib/module/Button.js +145 -0
- package/lib/module/Button.js.map +1 -0
- package/lib/module/Context.js +16 -0
- package/lib/module/Context.js.map +1 -0
- package/lib/module/FlashList.js +86 -0
- package/lib/module/FlashList.js.map +1 -0
- package/lib/module/Header.js +49 -0
- package/lib/module/Header.js.map +1 -0
- package/lib/module/Indicator.js +151 -0
- package/lib/module/Indicator.js.map +1 -0
- package/lib/module/Lazy.js +82 -0
- package/lib/module/Lazy.js.map +1 -0
- package/lib/module/LegendList.js +81 -0
- package/lib/module/LegendList.js.map +1 -0
- package/lib/module/List.js +78 -0
- package/lib/module/List.js.map +1 -0
- package/lib/module/Pager.js +87 -0
- package/lib/module/Pager.js.map +1 -0
- package/lib/module/Root.js +165 -0
- package/lib/module/Root.js.map +1 -0
- package/lib/module/ScrollView.js +80 -0
- package/lib/module/ScrollView.js.map +1 -0
- package/lib/module/StaticHeader.js +32 -0
- package/lib/module/StaticHeader.js.map +1 -0
- package/lib/module/StickyHeader.js +32 -0
- package/lib/module/StickyHeader.js.map +1 -0
- package/lib/module/Tab.js +81 -0
- package/lib/module/Tab.js.map +1 -0
- package/lib/module/flash-list.js +4 -0
- package/lib/module/flash-list.js.map +1 -0
- package/lib/module/index.js +44 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/legend-list.js +4 -0
- package/lib/module/legend-list.js.map +1 -0
- package/lib/module/useStableCallback.js +11 -0
- package/lib/module/useStableCallback.js.map +1 -0
- package/lib/typescript/Bar.d.ts +22 -0
- package/lib/typescript/Bar.d.ts.map +1 -0
- package/lib/typescript/Button.d.ts +32 -0
- package/lib/typescript/Button.d.ts.map +1 -0
- package/lib/typescript/Context.d.ts +37 -0
- package/lib/typescript/Context.d.ts.map +1 -0
- package/lib/typescript/FlashList.d.ts +6 -0
- package/lib/typescript/FlashList.d.ts.map +1 -0
- package/lib/typescript/Header.d.ts +7 -0
- package/lib/typescript/Header.d.ts.map +1 -0
- package/lib/typescript/Indicator.d.ts +11 -0
- package/lib/typescript/Indicator.d.ts.map +1 -0
- package/lib/typescript/Lazy.d.ts +36 -0
- package/lib/typescript/Lazy.d.ts.map +1 -0
- package/lib/typescript/LegendList.d.ts +6 -0
- package/lib/typescript/LegendList.d.ts.map +1 -0
- package/lib/typescript/List.d.ts +6 -0
- package/lib/typescript/List.d.ts.map +1 -0
- package/lib/typescript/Pager.d.ts +15 -0
- package/lib/typescript/Pager.d.ts.map +1 -0
- package/lib/typescript/Root.d.ts +14 -0
- package/lib/typescript/Root.d.ts.map +1 -0
- package/lib/typescript/ScrollView.d.ts +6 -0
- package/lib/typescript/ScrollView.d.ts.map +1 -0
- package/lib/typescript/StaticHeader.d.ts +7 -0
- package/lib/typescript/StaticHeader.d.ts.map +1 -0
- package/lib/typescript/StickyHeader.d.ts +7 -0
- package/lib/typescript/StickyHeader.d.ts.map +1 -0
- package/lib/typescript/Tab.d.ts +31 -0
- package/lib/typescript/Tab.d.ts.map +1 -0
- package/lib/typescript/flash-list.d.ts +3 -0
- package/lib/typescript/flash-list.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +69 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/legend-list.d.ts +3 -0
- package/lib/typescript/legend-list.d.ts.map +1 -0
- package/lib/typescript/useStableCallback.d.ts +2 -0
- package/lib/typescript/useStableCallback.d.ts.map +1 -0
- package/package.json +112 -0
- package/src/Bar.tsx +359 -0
- package/src/Button.tsx +219 -0
- package/src/Context.tsx +44 -0
- package/src/FlashList.tsx +150 -0
- package/src/Header.tsx +45 -0
- package/src/Indicator.tsx +193 -0
- package/src/Lazy.tsx +110 -0
- package/src/LegendList.tsx +130 -0
- package/src/List.tsx +115 -0
- package/src/Pager.tsx +134 -0
- package/src/Root.tsx +194 -0
- package/src/ScrollView.tsx +116 -0
- package/src/StaticHeader.tsx +30 -0
- package/src/StickyHeader.tsx +30 -0
- package/src/Tab.tsx +89 -0
- package/src/flash-list.ts +2 -0
- package/src/index.ts +54 -0
- package/src/legend-list.ts +2 -0
- package/src/useStableCallback.ts +11 -0
package/src/Tab.tsx
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ReactNode, createContext, memo, useContext, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { StyleProp, ViewStyle } from 'react-native';
|
|
4
|
+
|
|
5
|
+
import { SharedValue, useAnimatedReaction, useSharedValue } from 'react-native-reanimated';
|
|
6
|
+
import { scheduleOnRN } from 'react-native-worklets';
|
|
7
|
+
|
|
8
|
+
import { useCollapsibleTabsContext } from './Context';
|
|
9
|
+
import { Lazy, type LazyProps } from './Lazy';
|
|
10
|
+
|
|
11
|
+
export type TabProps = {
|
|
12
|
+
index: number;
|
|
13
|
+
loader?: ReactNode;
|
|
14
|
+
children?: ReactNode | ((info: { isFocused: boolean; pageDecimal: SharedValue<number> }) => ReactNode);
|
|
15
|
+
disableLazyEntering?: boolean;
|
|
16
|
+
disablePreload?: boolean;
|
|
17
|
+
lazy?: boolean;
|
|
18
|
+
isLoading?: boolean;
|
|
19
|
+
isScreenFocused?: boolean;
|
|
20
|
+
loaderStyle?: StyleProp<ViewStyle>;
|
|
21
|
+
lazyProps?: Omit<LazyProps, 'children' | 'disableEntering' | 'focused' | 'placeholder' | 'placeholderStyle'>;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const Tab = ({
|
|
25
|
+
index,
|
|
26
|
+
loader,
|
|
27
|
+
loaderStyle,
|
|
28
|
+
lazyProps,
|
|
29
|
+
disableLazyEntering = true,
|
|
30
|
+
disablePreload = false,
|
|
31
|
+
lazy = true,
|
|
32
|
+
children,
|
|
33
|
+
isLoading = false,
|
|
34
|
+
isScreenFocused = true,
|
|
35
|
+
}: TabProps) => {
|
|
36
|
+
const { activeTabIndexValue, pageDecimal } = useCollapsibleTabsContext();
|
|
37
|
+
const [shouldPreload, setShouldPreload] = useState(false);
|
|
38
|
+
const [canMount, setCanMount] = useState(lazy === false);
|
|
39
|
+
|
|
40
|
+
const preloadLatched = useSharedValue(disablePreload);
|
|
41
|
+
const mountLatched = useSharedValue(lazy === false);
|
|
42
|
+
|
|
43
|
+
useAnimatedReaction(
|
|
44
|
+
() => pageDecimal.value,
|
|
45
|
+
(value) => {
|
|
46
|
+
if (!preloadLatched.value && Math.round(value) === index) {
|
|
47
|
+
preloadLatched.value = true;
|
|
48
|
+
scheduleOnRN(setShouldPreload, true);
|
|
49
|
+
}
|
|
50
|
+
if (!mountLatched.value && Math.abs(value - index) <= 1.5 && isScreenFocused) {
|
|
51
|
+
mountLatched.value = true;
|
|
52
|
+
scheduleOnRN(setCanMount, true);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
[index, isScreenFocused]
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const isFocused = index === activeTabIndexValue && isScreenFocused;
|
|
59
|
+
const isMounted = lazy ? (isFocused || shouldPreload) && !isLoading : true;
|
|
60
|
+
|
|
61
|
+
const renderChildren = () => {
|
|
62
|
+
if (lazy) {
|
|
63
|
+
if (!canMount) return null;
|
|
64
|
+
return (
|
|
65
|
+
<Lazy {...lazyProps} focused={isMounted && !isLoading} disableEntering={disableLazyEntering} placeholder={loader} placeholderStyle={loaderStyle}>
|
|
66
|
+
{typeof children === 'function' ? children({ isFocused, pageDecimal }) : children}
|
|
67
|
+
</Lazy>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return typeof children === 'function' ? children({ isFocused, pageDecimal }) : children;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return <TabSelfContextProvider index={index} isFocused={isFocused} isMounted={isMounted}>{renderChildren()}</TabSelfContextProvider>;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type TabSelfContextValue = { index: number; isFocused: boolean; isMounted: boolean };
|
|
78
|
+
|
|
79
|
+
const TabSelfContext = createContext({} as TabSelfContextValue);
|
|
80
|
+
|
|
81
|
+
const TabSelfContextProvider = memo(({ children, ...props }: TabSelfContextValue & { children: ReactNode }) => {
|
|
82
|
+
return <TabSelfContext.Provider value={props}>{children}</TabSelfContext.Provider>;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export const useTabSelfContext = () => useContext(TabSelfContext);
|
|
86
|
+
|
|
87
|
+
Tab.displayName = 'CollapsibleTabs.Tab';
|
|
88
|
+
|
|
89
|
+
export default memo(Tab);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import Bar from './Bar';
|
|
2
|
+
import Button from './Button';
|
|
3
|
+
import Header from './Header';
|
|
4
|
+
import { MaterialIndicator, SegmentIndicator } from './Indicator';
|
|
5
|
+
import { Lazy } from './Lazy';
|
|
6
|
+
import List from './List';
|
|
7
|
+
import Pager from './Pager';
|
|
8
|
+
import Root from './Root';
|
|
9
|
+
import ScrollView from './ScrollView';
|
|
10
|
+
import StaticHeader from './StaticHeader';
|
|
11
|
+
import StickyHeader from './StickyHeader';
|
|
12
|
+
import Tab from './Tab';
|
|
13
|
+
|
|
14
|
+
export { default as Bar } from './Bar';
|
|
15
|
+
export { default as Button } from './Button';
|
|
16
|
+
export { useCollapsibleTabsContext } from './Context';
|
|
17
|
+
export { default as Header } from './Header';
|
|
18
|
+
export { MaterialIndicator, SegmentIndicator } from './Indicator';
|
|
19
|
+
export { Lazy } from './Lazy';
|
|
20
|
+
export { default as List } from './List';
|
|
21
|
+
export { default as Pager } from './Pager';
|
|
22
|
+
export { default as Root } from './Root';
|
|
23
|
+
export { default as ScrollView } from './ScrollView';
|
|
24
|
+
export { default as StaticHeader } from './StaticHeader';
|
|
25
|
+
export { default as StickyHeader } from './StickyHeader';
|
|
26
|
+
export { default as Tab, useTabSelfContext } from './Tab';
|
|
27
|
+
|
|
28
|
+
export type { BarProps } from './Bar';
|
|
29
|
+
export type { ButtonProps, RenderTabLabelProps } from './Button';
|
|
30
|
+
export type { CollapsibleTabsContextValue, ItemLayout, ListScroller } from './Context';
|
|
31
|
+
export type { LazyPlaceholderInfo, LazyProps } from './Lazy';
|
|
32
|
+
export type { ListProps } from './List';
|
|
33
|
+
export type { PagerProps } from './Pager';
|
|
34
|
+
export type { CollapsibleTabsRootRef, RootProps } from './Root';
|
|
35
|
+
export type { ScrollViewProps } from './ScrollView';
|
|
36
|
+
export type { TabProps, TabSelfContextValue } from './Tab';
|
|
37
|
+
|
|
38
|
+
const CollapsibleTabs = {
|
|
39
|
+
Root,
|
|
40
|
+
Header,
|
|
41
|
+
StickyHeader,
|
|
42
|
+
StaticHeader,
|
|
43
|
+
Pager,
|
|
44
|
+
Tab,
|
|
45
|
+
List,
|
|
46
|
+
ScrollView,
|
|
47
|
+
Bar,
|
|
48
|
+
Button,
|
|
49
|
+
MaterialIndicator,
|
|
50
|
+
SegmentIndicator,
|
|
51
|
+
Lazy,
|
|
52
|
+
} as const;
|
|
53
|
+
|
|
54
|
+
export default CollapsibleTabs;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
export function useStableCallback<T extends (...args: any[]) => any>(callback?: T) {
|
|
4
|
+
const callbackRef = useRef(callback);
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
callbackRef.current = callback;
|
|
8
|
+
}, [callback]);
|
|
9
|
+
|
|
10
|
+
return useCallback((...args: Parameters<T>) => callbackRef.current?.(...args), []);
|
|
11
|
+
}
|