@r0b0t3d/react-native-collapsible 1.2.0-alpha.2 → 1.2.1

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.
Files changed (44) hide show
  1. package/lib/commonjs/components/CollapsibleContainer.js +1 -1
  2. package/lib/commonjs/components/CollapsibleContainer.js.map +1 -1
  3. package/lib/commonjs/components/header/CollapsibleHeaderContainer.js +2 -4
  4. package/lib/commonjs/components/header/CollapsibleHeaderContainer.js.map +1 -1
  5. package/lib/commonjs/components/header/StickyView.js +1 -1
  6. package/lib/commonjs/components/header/StickyView.js.map +1 -1
  7. package/lib/commonjs/components/pullToRefresh/RefreshControl.js +10 -0
  8. package/lib/commonjs/components/pullToRefresh/RefreshControl.js.map +1 -1
  9. package/lib/commonjs/components/scrollable/CollapsibleFlatList.js +10 -2
  10. package/lib/commonjs/components/scrollable/CollapsibleFlatList.js.map +1 -1
  11. package/lib/commonjs/components/scrollable/CollapsibleScrollView.js +5 -1
  12. package/lib/commonjs/components/scrollable/CollapsibleScrollView.js.map +1 -1
  13. package/lib/commonjs/components/scrollable/useAnimatedScroll.js +7 -5
  14. package/lib/commonjs/components/scrollable/useAnimatedScroll.js.map +1 -1
  15. package/lib/commonjs/withCollapsibleContext.js +11 -3
  16. package/lib/commonjs/withCollapsibleContext.js.map +1 -1
  17. package/lib/module/components/CollapsibleContainer.js +2 -1
  18. package/lib/module/components/CollapsibleContainer.js.map +1 -1
  19. package/lib/module/components/header/CollapsibleHeaderContainer.js +3 -5
  20. package/lib/module/components/header/CollapsibleHeaderContainer.js.map +1 -1
  21. package/lib/module/components/header/StickyView.js +1 -1
  22. package/lib/module/components/header/StickyView.js.map +1 -1
  23. package/lib/module/components/pullToRefresh/RefreshControl.js +11 -1
  24. package/lib/module/components/pullToRefresh/RefreshControl.js.map +1 -1
  25. package/lib/module/components/scrollable/CollapsibleFlatList.js +10 -2
  26. package/lib/module/components/scrollable/CollapsibleFlatList.js.map +1 -1
  27. package/lib/module/components/scrollable/CollapsibleScrollView.js +5 -1
  28. package/lib/module/components/scrollable/CollapsibleScrollView.js.map +1 -1
  29. package/lib/module/components/scrollable/useAnimatedScroll.js +7 -5
  30. package/lib/module/components/scrollable/useAnimatedScroll.js.map +1 -1
  31. package/lib/module/withCollapsibleContext.js +11 -3
  32. package/lib/module/withCollapsibleContext.js.map +1 -1
  33. package/lib/typescript/components/scrollable/useAnimatedScroll.d.ts +4 -2
  34. package/lib/typescript/types.d.ts +8 -1
  35. package/package.json +1 -1
  36. package/src/components/CollapsibleContainer.tsx +6 -8
  37. package/src/components/header/CollapsibleHeaderContainer.tsx +2 -5
  38. package/src/components/header/StickyView.tsx +1 -1
  39. package/src/components/pullToRefresh/RefreshControl.tsx +9 -1
  40. package/src/components/scrollable/CollapsibleFlatList.tsx +8 -0
  41. package/src/components/scrollable/CollapsibleScrollView.tsx +5 -0
  42. package/src/components/scrollable/useAnimatedScroll.ts +14 -6
  43. package/src/types.ts +9 -1
  44. package/src/withCollapsibleContext.tsx +7 -2
@@ -6,6 +6,7 @@ import {
6
6
  useAnimatedScrollHandler,
7
7
  useSharedValue,
8
8
  } from 'react-native-reanimated';
9
+ import type { ScrollToIndexParams } from 'src/types';
9
10
  import useCollapsibleContext from '../../hooks/useCollapsibleContext';
10
11
  import useInternalCollapsibleContext from '../../hooks/useInternalCollapsibleContext';
11
12
 
@@ -14,11 +15,13 @@ const { height: wHeight } = Dimensions.get('window');
14
15
  type Props = {
15
16
  headerSnappable: boolean;
16
17
  scrollTo: (yValue: number, animated?: boolean) => void;
18
+ scrollToIndex: (params: ScrollToIndexParams) => void;
17
19
  };
18
20
 
19
21
  export default function useAnimatedScroll({
20
22
  headerSnappable,
21
23
  scrollTo,
24
+ scrollToIndex,
22
25
  }: Props) {
23
26
  const scrollDirection = useSharedValue('unknown');
24
27
  const { scrollY } = useCollapsibleContext();
@@ -31,11 +34,15 @@ export default function useAnimatedScroll({
31
34
  }
32
35
  }, []);
33
36
 
34
- const collapse = useCallback(() => {
35
- scrollTo(
36
- Math.min(fixedHeaderHeight.value || 0, firstStickyViewY.value || 0)
37
- );
38
- }, [scrollTo]);
37
+ const collapse = useCallback(
38
+ (animated = true) => {
39
+ scrollTo(
40
+ Math.min(fixedHeaderHeight.value || 0, firstStickyViewY.value || 0),
41
+ animated
42
+ );
43
+ },
44
+ [scrollTo]
45
+ );
39
46
 
40
47
  const expand = useCallback(() => scrollTo(0), [scrollTo]);
41
48
 
@@ -44,8 +51,9 @@ export default function useAnimatedScroll({
44
51
  collapse,
45
52
  expand,
46
53
  scrollTo,
54
+ scrollToIndex,
47
55
  });
48
- }, [setCollapsibleHandlers, collapse, expand, scrollTo]);
56
+ }, [setCollapsibleHandlers, collapse, expand, scrollTo, scrollToIndex]);
49
57
 
50
58
  const scrollHandler = useAnimatedScrollHandler(
51
59
  {
package/src/types.ts CHANGED
@@ -2,10 +2,18 @@ import type React from 'react';
2
2
  import type { View } from 'react-native';
3
3
  import type Animated from 'react-native-reanimated';
4
4
 
5
+ export type ScrollToIndexParams = {
6
+ animated?: boolean | null;
7
+ index: number;
8
+ viewOffset?: number;
9
+ viewPosition?: number;
10
+ };
11
+
5
12
  export type CollapsibleHandles = {
6
- collapse: () => void;
13
+ collapse: (animated?: boolean) => void;
7
14
  expand: () => void;
8
15
  scrollTo: (offset: number, animate?: boolean) => void;
16
+ scrollToIndex: (params: ScrollToIndexParams) => void;
9
17
  };
10
18
 
11
19
  export type CollapsibleContextType = CollapsibleHandles & {
@@ -34,6 +34,8 @@ export default function withCollapsibleContext<T>(Component: FC<T>) {
34
34
  const scrollViewRef = useRef<View>(null);
35
35
 
36
36
  const setCollapsibleHandlers = useCallback((handlers) => {
37
+ console.log({ handlers });
38
+
37
39
  collapsibleHandlers.current = handlers;
38
40
  }, []);
39
41
 
@@ -138,7 +140,7 @@ export default function withCollapsibleContext<T>(Component: FC<T>) {
138
140
  0
139
141
  );
140
142
  headerHeight.value = withTiming(totalHeight, {
141
- duration: fixedHeaderHeight.value === 0 ? 0 : 200,
143
+ duration: fixedHeaderHeight.value === 0 ? 0 : 10,
142
144
  });
143
145
  fixedHeaderHeight.value = totalHeight;
144
146
  // Try refresh sticky positions
@@ -153,10 +155,13 @@ export default function withCollapsibleContext<T>(Component: FC<T>) {
153
155
 
154
156
  const context = useMemo(() => {
155
157
  return {
156
- collapse: () => collapsibleHandlers.current?.collapse(),
158
+ collapse: (animated?: boolean) =>
159
+ collapsibleHandlers.current?.collapse(animated),
157
160
  expand: () => collapsibleHandlers.current?.expand(),
158
161
  scrollTo: (offset: number, animate?: boolean) =>
159
162
  collapsibleHandlers.current?.scrollTo(offset, animate),
163
+ scrollToIndex: (params: any) =>
164
+ collapsibleHandlers.current?.scrollToIndex(params),
160
165
  headerHeight,
161
166
  scrollY,
162
167
  headerCollapsed,