react-native-header-motion 0.1.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 +479 -0
- package/lib/module/components/FlatList.js +64 -0
- package/lib/module/components/FlatList.js.map +1 -0
- package/lib/module/components/Header.js +19 -0
- package/lib/module/components/Header.js.map +1 -0
- package/lib/module/components/HeaderBase.js +59 -0
- package/lib/module/components/HeaderBase.js.map +1 -0
- package/lib/module/components/HeaderMotion.js +84 -0
- package/lib/module/components/HeaderMotion.js.map +1 -0
- package/lib/module/components/ScrollManager.js +39 -0
- package/lib/module/components/ScrollManager.js.map +1 -0
- package/lib/module/components/ScrollView.js +47 -0
- package/lib/module/components/ScrollView.js.map +1 -0
- package/lib/module/components/index.js +9 -0
- package/lib/module/components/index.js.map +1 -0
- package/lib/module/context.js +5 -0
- package/lib/module/context.js.map +1 -0
- package/lib/module/hooks/index.js +6 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/hooks/useActiveScrollId.js +47 -0
- package/lib/module/hooks/useActiveScrollId.js.map +1 -0
- package/lib/module/hooks/useMotionProgress.js +58 -0
- package/lib/module/hooks/useMotionProgress.js.map +1 -0
- package/lib/module/hooks/useScrollManager.js +150 -0
- package/lib/module/hooks/useScrollManager.js.map +1 -0
- package/lib/module/index.js +42 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/defaults.js +10 -0
- package/lib/module/utils/defaults.js.map +1 -0
- package/lib/module/utils/index.js +5 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/module/utils/values.js +11 -0
- package/lib/module/utils/values.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/components/FlatList.d.ts +30 -0
- package/lib/typescript/src/components/FlatList.d.ts.map +1 -0
- package/lib/typescript/src/components/Header.d.ts +19 -0
- package/lib/typescript/src/components/Header.d.ts.map +1 -0
- package/lib/typescript/src/components/HeaderBase.d.ts +34 -0
- package/lib/typescript/src/components/HeaderBase.d.ts.map +1 -0
- package/lib/typescript/src/components/HeaderMotion.d.ts +52 -0
- package/lib/typescript/src/components/HeaderMotion.d.ts.map +1 -0
- package/lib/typescript/src/components/ScrollManager.d.ts +40 -0
- package/lib/typescript/src/components/ScrollManager.d.ts.map +1 -0
- package/lib/typescript/src/components/ScrollView.d.ts +24 -0
- package/lib/typescript/src/components/ScrollView.d.ts.map +1 -0
- package/lib/typescript/src/components/index.d.ts +7 -0
- package/lib/typescript/src/components/index.d.ts.map +1 -0
- package/lib/typescript/src/context.d.ts +14 -0
- package/lib/typescript/src/context.d.ts.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +4 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useActiveScrollId.d.ts +32 -0
- package/lib/typescript/src/hooks/useActiveScrollId.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useMotionProgress.d.ts +38 -0
- package/lib/typescript/src/hooks/useMotionProgress.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useScrollManager.d.ts +37 -0
- package/lib/typescript/src/hooks/useScrollManager.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +51 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +43 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils/defaults.d.ts +6 -0
- package/lib/typescript/src/utils/defaults.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +3 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/values.d.ts +3 -0
- package/lib/typescript/src/utils/values.d.ts.map +1 -0
- package/package.json +164 -0
- package/src/components/FlatList.tsx +72 -0
- package/src/components/Header.tsx +30 -0
- package/src/components/HeaderBase.tsx +51 -0
- package/src/components/HeaderMotion.tsx +183 -0
- package/src/components/ScrollManager.tsx +58 -0
- package/src/components/ScrollView.tsx +58 -0
- package/src/components/index.ts +6 -0
- package/src/context.ts +20 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useActiveScrollId.ts +59 -0
- package/src/hooks/useMotionProgress.ts +56 -0
- package/src/hooks/useScrollManager.ts +186 -0
- package/src/index.ts +76 -0
- package/src/types.ts +62 -0
- package/src/utils/defaults.ts +16 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/values.ts +6 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MotionProgress } from '../types';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
type HeaderRenderChildren = (props: MotionProgress) => ReactNode;
|
|
4
|
+
export interface HeaderMotionHeaderProps {
|
|
5
|
+
/**
|
|
6
|
+
* Render function that receives motion progress props.
|
|
7
|
+
* Use this to animate your header based on scroll progress and to provide measurement functions to the elements of the header.
|
|
8
|
+
*/
|
|
9
|
+
children: HeaderRenderChildren;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Header component for providing motion progress properties to animated headers.
|
|
13
|
+
* Must be used within a HeaderMotion component.
|
|
14
|
+
*
|
|
15
|
+
* Use to pass props to the header components in React Navigation / Expo Router, which cannot access HeaderMotion's context and `useMotionProgress` otherwise.`
|
|
16
|
+
*/
|
|
17
|
+
export declare function HeaderMotionHeader({ children }: HeaderMotionHeaderProps): ReactNode;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=Header.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Header.d.ts","sourceRoot":"","sources":["../../../../src/components/Header.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,KAAK,oBAAoB,GAAG,CAAC,KAAK,EAAE,cAAc,KAAK,SAAS,CAAC;AAEjE,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,QAAQ,EAAE,oBAAoB,CAAC;CAChC;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,QAAQ,EAAE,EAAE,uBAAuB,aASvE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ViewProps } from 'react-native';
|
|
2
|
+
import { type AnimatedProps } from 'react-native-reanimated';
|
|
3
|
+
export type HeaderBaseProps = ViewProps;
|
|
4
|
+
export type AnimatedHeaderBaseProps = AnimatedProps<ViewProps>;
|
|
5
|
+
/**
|
|
6
|
+
* Base header component with absolute positioning.
|
|
7
|
+
* Provides a foundation for building headers that need to be positioned absolutely.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* <HeaderBase
|
|
12
|
+
* onLayout={measureTotalHeight}
|
|
13
|
+
* >
|
|
14
|
+
* ...
|
|
15
|
+
* </HeaderBase>
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function HeaderBase({ style, ...rest }: HeaderBaseProps): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
/**
|
|
20
|
+
* Animated version of HeaderBase using Reanimated's Animated.View.
|
|
21
|
+
* Use this when you need to animate the header based on scroll progress.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <AnimatedHeaderBase
|
|
26
|
+
* onLayout={measureTotalHeight}
|
|
27
|
+
* style={[{ paddingTop: insets.top }, animatedStyle]}
|
|
28
|
+
* >
|
|
29
|
+
* ...
|
|
30
|
+
* </AnimatedHeaderBase>
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function AnimatedHeaderBase({ style, ...rest }: AnimatedHeaderBaseProps): import("react/jsx-runtime").JSX.Element;
|
|
34
|
+
//# sourceMappingURL=HeaderBase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HeaderBase.d.ts","sourceRoot":"","sources":["../../../../src/components/HeaderBase.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAChE,OAAiB,EAAE,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAEvE,MAAM,MAAM,eAAe,GAAG,SAAS,CAAC;AACxC,MAAM,MAAM,uBAAuB,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;AAE/D;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,EAAE,eAAe,2CAE7D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,GAAG,IAAI,EACR,EAAE,uBAAuB,2CAEzB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type ExtrapolationType, type SharedValue } from 'react-native-reanimated';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import type { MeasureAnimatedHeader, ProgressThreshold } from '../types';
|
|
4
|
+
export interface HeaderMotionProps<T extends string> {
|
|
5
|
+
/**
|
|
6
|
+
* The threshold at which the header animation completes (reaches progress = 1).
|
|
7
|
+
* Can be a fixed number or a function that calculates based on the result of {@link measureDynamic}.
|
|
8
|
+
*
|
|
9
|
+
* Defaults to a function that returns the return value of `measureDynamic` unchanged.
|
|
10
|
+
*/
|
|
11
|
+
progressThreshold?: ProgressThreshold;
|
|
12
|
+
/**
|
|
13
|
+
* Function to measure a dimension of choice of the animated element of the header.
|
|
14
|
+
*
|
|
15
|
+
* Receives the layout change event from React Native.
|
|
16
|
+
*
|
|
17
|
+
* This function can be further accessed when rendering headers from `HeaderMotion.Header` or `useMotionProgress` - should be passed to the `onLayout` prop of such. If used, can be used for dynamic calculation of the {@link progressThreshold}.
|
|
18
|
+
*
|
|
19
|
+
* Defaults to measuring the height from the event.
|
|
20
|
+
*/
|
|
21
|
+
measureDynamic?: MeasureAnimatedHeader;
|
|
22
|
+
/**
|
|
23
|
+
* Mode for measuring dynamic header height.
|
|
24
|
+
* - 'mount': Only measure once on mount
|
|
25
|
+
* - 'update': Update measurement on every layout recalculation of the component that {@link measureDynamic} was provided to as the `onLayout` property
|
|
26
|
+
* @default 'mount'
|
|
27
|
+
*/
|
|
28
|
+
measureDynamicMode?: 'update' | 'mount';
|
|
29
|
+
/**
|
|
30
|
+
* Shared value for tracking the active scroll ID in multi-scroll scenarios (e.g. tabs).
|
|
31
|
+
* When provided, the header animation will sync across multiple scroll views.
|
|
32
|
+
*/
|
|
33
|
+
activeScrollId?: SharedValue<T>;
|
|
34
|
+
/**
|
|
35
|
+
* Extrapolation type for the progress animation.
|
|
36
|
+
* Controls how the progress value behaves outside the threshold range.
|
|
37
|
+
*
|
|
38
|
+
* You may want to modify it to achieve some animations for the overscroll scenarios.
|
|
39
|
+
* @default Extrapolation.CLAMP
|
|
40
|
+
*/
|
|
41
|
+
progressExtrapolation?: ExtrapolationType;
|
|
42
|
+
/** Child components that will have access to the header motion context */
|
|
43
|
+
children: ReactNode;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Context provider component for HeaderMotion.
|
|
47
|
+
* Manages header animation state and provides it to child components via context.
|
|
48
|
+
* @template T - The type of scroll ID string
|
|
49
|
+
*/
|
|
50
|
+
declare function HeaderMotionContextProvider<T extends string>({ progressThreshold, measureDynamic, measureDynamicMode, activeScrollId, progressExtrapolation, children, }: HeaderMotionProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
51
|
+
export { HeaderMotionContextProvider };
|
|
52
|
+
//# sourceMappingURL=HeaderMotion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HeaderMotion.d.ts","sourceRoot":"","sources":["../../../../src/components/HeaderMotion.tsx"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,iBAAiB,EACtB,KAAK,WAAW,EACjB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EACV,qBAAqB,EAErB,iBAAiB,EAElB,MAAM,UAAU,CAAC;AAQlB,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,MAAM;IACjD;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;;;;;;;OAQG;IACH,cAAc,CAAC,EAAE,qBAAqB,CAAC;IACvC;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;IACxC;;;OAGG;IACH,cAAc,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAChC;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,iBAAiB,CAAC;IAC1C,0EAA0E;IAC1E,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;GAIG;AACH,iBAAS,2BAA2B,CAAC,CAAC,SAAS,MAAM,EAAE,EACrD,iBAA8C,EAC9C,cAAwC,EACxC,kBAA4B,EAC5B,cAAc,EACd,qBAA2C,EAC3C,QAAQ,GACT,EAAE,iBAAiB,CAAC,CAAC,CAAC,2CAqGtB;AAED,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ScrollManagerConfig } from '../types';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
type ScrollManagerRenderChildren = (scrollableProps: ScrollManagerConfig['scrollableProps'], options: ScrollManagerConfig['headerMotionContext']) => ReactNode;
|
|
4
|
+
export interface HeaderMotionScrollManagerProps {
|
|
5
|
+
/**
|
|
6
|
+
* Optional unique identifier for this scroll view.
|
|
7
|
+
* Use this when you have multiple scroll views (e.g., in tabs) to track them separately.
|
|
8
|
+
*/
|
|
9
|
+
scrollId?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Render function that receives scroll props and header context.
|
|
12
|
+
* Use this to create custom scroll implementations that integrate with HeaderMotion.
|
|
13
|
+
*/
|
|
14
|
+
children: ScrollManagerRenderChildren;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* ScrollManager component that provides scroll tracking functionality for custom scroll implementations. Uses {@link useScrollManager} under the hood.
|
|
18
|
+
* Must be used within a HeaderMotion component.
|
|
19
|
+
*
|
|
20
|
+
* This is useful when you need to use a scroll component that isn't directly supported
|
|
21
|
+
* (like a custom scroll view or third-party list components).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <HeaderMotion>
|
|
26
|
+
* <HeaderMotion.ScrollManager>
|
|
27
|
+
* {(scrollableProps, { originalHeaderHeight }) => (
|
|
28
|
+
* <CustomScrollView {...scrollableProps}>
|
|
29
|
+
* <View style={{ paddingTop: originalHeaderHeight }}>
|
|
30
|
+
* <Text>Content</Text>
|
|
31
|
+
* </View>
|
|
32
|
+
* </CustomScrollView>
|
|
33
|
+
* )}
|
|
34
|
+
* </HeaderMotion.ScrollManager>
|
|
35
|
+
* </HeaderMotion>
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function HeaderMotionScrollManager({ children, scrollId, }: HeaderMotionScrollManagerProps): ReactNode;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=ScrollManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScrollManager.d.ts","sourceRoot":"","sources":["../../../../src/components/ScrollManager.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,KAAK,2BAA2B,GAAG,CACjC,eAAe,EAAE,mBAAmB,CAAC,iBAAiB,CAAC,EACvD,OAAO,EAAE,mBAAmB,CAAC,qBAAqB,CAAC,KAChD,SAAS,CAAC;AAEf,MAAM,WAAW,8BAA8B;IAC7C;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,QAAQ,EAAE,2BAA2B,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,yBAAyB,CAAC,EACxC,QAAQ,EACR,QAAQ,GACT,EAAE,8BAA8B,aAUhC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type AnimatedScrollViewProps } from 'react-native-reanimated';
|
|
2
|
+
export type HeaderMotionScrollViewProps = AnimatedScrollViewProps & {
|
|
3
|
+
/**
|
|
4
|
+
* Optional unique identifier for this scroll view.
|
|
5
|
+
* Use this when you have multiple scroll views (e.g. in tabs) to track them separately.
|
|
6
|
+
*/
|
|
7
|
+
scrollId?: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Animated ScrollView component that integrates with HeaderMotion.
|
|
11
|
+
* Automatically handles scroll tracking and header animation synchronization.
|
|
12
|
+
* Must be used within a HeaderMotion component.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* <HeaderMotion>
|
|
17
|
+
* <HeaderMotion.ScrollView>
|
|
18
|
+
* <MyScrollableContent />
|
|
19
|
+
* </HeaderMotion.ScrollView>
|
|
20
|
+
* </HeaderMotion>
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function HeaderMotionScrollView({ scrollId, children, contentContainerStyle, ...props }: HeaderMotionScrollViewProps): import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
//# sourceMappingURL=ScrollView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScrollView.d.ts","sourceRoot":"","sources":["../../../../src/components/ScrollView.tsx"],"names":[],"mappings":"AAAA,OAAiB,EACf,KAAK,uBAAuB,EAC7B,MAAM,yBAAyB,CAAC;AAGjC,MAAM,MAAM,2BAA2B,GAAG,uBAAuB,GAAG;IAClE;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,QAAQ,EACR,QAAQ,EACR,qBAAqB,EACrB,GAAG,KAAK,EACT,EAAE,2BAA2B,2CAyB7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type SharedValue } from 'react-native-reanimated';
|
|
2
|
+
import type { MeasureAnimatedHeaderAndSet, Progress, ScrollValues } from './types';
|
|
3
|
+
interface HeaderMotionContextType {
|
|
4
|
+
progress: Progress;
|
|
5
|
+
measureTotalHeight: MeasureAnimatedHeaderAndSet;
|
|
6
|
+
measureDynamic: MeasureAnimatedHeaderAndSet;
|
|
7
|
+
scrollValues: SharedValue<ScrollValues>;
|
|
8
|
+
activeScrollId: SharedValue<string> | undefined;
|
|
9
|
+
progressThreshold: number;
|
|
10
|
+
originalHeaderHeight: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const HeaderMotionContext: import("react").Context<HeaderMotionContextType | null>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EACV,2BAA2B,EAC3B,QAAQ,EACR,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,UAAU,uBAAuB;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,kBAAkB,EAAE,2BAA2B,CAAC;IAChD,cAAc,EAAE,2BAA2B,CAAC;IAC5C,YAAY,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;IACxC,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAChD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAED,eAAO,MAAM,mBAAmB,yDACqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ActiveScrollIdValues, SetActiveScrollId } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to manage active scroll ID for multi-scroll scenarios (e.g. tabs with different scroll views).
|
|
4
|
+
* Returns both a state value and a shared value, along with a setter function.
|
|
5
|
+
*
|
|
6
|
+
* Use this when you have multiple scroll views (like in a tabbed interface) and need to
|
|
7
|
+
* track which one is currently active. Pass the shared value to `HeaderMotion`'s `activeScrollId` prop.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of the scroll ID string
|
|
10
|
+
* @param initialActiveScrollId - The initial active scroll ID
|
|
11
|
+
* @returns A tuple containing:
|
|
12
|
+
* - `[0]`: Object with `state` (React state) and `sv` (shared value) for the active scroll ID
|
|
13
|
+
* - `[1]`: Function to set the active scroll ID
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* function TabbedScrollView() {
|
|
18
|
+
* const [activeScroll, setActiveScroll] = useActiveScrollId('tab1');
|
|
19
|
+
*
|
|
20
|
+
* return (
|
|
21
|
+
* <HeaderMotion activeScrollId={activeScroll.sv}>
|
|
22
|
+
* <Tabs onTabChange={setActiveScroll}>
|
|
23
|
+
* <Tab id="tab1" />
|
|
24
|
+
* <Tab id="tab2" />
|
|
25
|
+
* </Tabs>
|
|
26
|
+
* </HeaderMotion>
|
|
27
|
+
* );
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function useActiveScrollId<T extends string>(initialActiveScrollId: T): [ActiveScrollIdValues<T>, SetActiveScrollId<T>];
|
|
32
|
+
//# sourceMappingURL=useActiveScrollId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useActiveScrollId.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useActiveScrollId.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,qBAAqB,EAAE,CAAC,GACvB,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAuBjD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { MotionProgress } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to access motion progress values and measuring functions for header animations.
|
|
4
|
+
* Returns the progress value (0-1), threshold, and measurement functions.
|
|
5
|
+
*
|
|
6
|
+
* Must be used within a {@link HeaderMotion} component.
|
|
7
|
+
*
|
|
8
|
+
* @returns Motion progress values and measuring functions:
|
|
9
|
+
* - `progress`: Shared value from 0 to 1
|
|
10
|
+
* - `progressThreshold`: The threshold at which animation completes
|
|
11
|
+
* - `measureTotalHeight`: Function to measure total header height. Should be passed to the `onLayout` prop of the base of a header, to let scrollables account for the total header height
|
|
12
|
+
* - `measureDynamic`: Function to measure a dimension of choice of the animated element of the header - should be passed to the `onLayout` prop of such. If used, can be used for dynamic calculation of the {@link progressThreshold}.
|
|
13
|
+
*
|
|
14
|
+
* @throws Error if used outside of a {@link HeaderMotion} component
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* function MyHeader() {
|
|
19
|
+
* const { progress, progressThreshold, measureTotalHeight, measureDynamic } = useMotionProgress();
|
|
20
|
+
* const dynamicStyle = useAnimatedStyle(() => {
|
|
21
|
+
* const translateY = interpolate(
|
|
22
|
+
* progress.value,
|
|
23
|
+
* [0, 1],
|
|
24
|
+
* [0, -progressThreshold],
|
|
25
|
+
* Extrapolation.CLAMP,
|
|
26
|
+
* )
|
|
27
|
+
* return { transform: [{ translateY }] }
|
|
28
|
+
* })
|
|
29
|
+
* return (
|
|
30
|
+
* <AnimatedHeaderBase onLayout={measureTotalHeight}>
|
|
31
|
+
* <Animated.View onLayout={measureDynamic} style={dynamicStyle} />
|
|
32
|
+
* </AnimatedHeaderBase>
|
|
33
|
+
* )
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function useMotionProgress(): MotionProgress;
|
|
38
|
+
//# sourceMappingURL=useMotionProgress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMotionProgress.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useMotionProgress.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAgBlD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ScrollManagerConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook that manages scroll tracking and synchronization for header animations.
|
|
4
|
+
* Returns props to apply to scrollable components and additional values that help with adjusting styling of the scrollables to header's dimensions.
|
|
5
|
+
*
|
|
6
|
+
* This hook handles:
|
|
7
|
+
* - Scroll position tracking
|
|
8
|
+
* - Synchronization between multiple scroll views (when using multiple scroll IDs)
|
|
9
|
+
* - Content container minimum height calculations for cases where one of the tracked scrollables does not take enough space to reach the progress threshold/
|
|
10
|
+
*
|
|
11
|
+
* Must be used within a HeaderMotion component.
|
|
12
|
+
*
|
|
13
|
+
* @param scrollId - Optional unique identifier for the related scrollable.
|
|
14
|
+
* Use when you have multiple scrollables (e.g., in tabs).
|
|
15
|
+
* @returns Configuration object containing:
|
|
16
|
+
* - `scrollableProps`: Props to apply to scrollable component (onScroll, scrollEventThrottle, ref)
|
|
17
|
+
* - `headerMotionContext`: Header context values (originalHeaderHeight, minHeightContentContainerStyle)
|
|
18
|
+
*
|
|
19
|
+
* @throws Error if used outside of a HeaderMotion component
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* function CustomScrollComponent() {
|
|
24
|
+
* const { scrollableProps, headerMotionContext } = useScrollManager('myScroll');
|
|
25
|
+
*
|
|
26
|
+
* return (
|
|
27
|
+
* <CustomScrollView {...scrollableProps}>
|
|
28
|
+
* <View style={{ paddingTop: headerMotionContext.originalHeaderHeight }}>
|
|
29
|
+
* Content
|
|
30
|
+
* </View>
|
|
31
|
+
* </CustomScrollView>
|
|
32
|
+
* );
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function useScrollManager(scrollId?: string): ScrollManagerConfig;
|
|
37
|
+
//# sourceMappingURL=useScrollManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScrollManager.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useScrollManager.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,mBAAmB,EAAgB,MAAM,UAAU,CAAC;AAGlE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAwIvE"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AnimatedHeaderBase, HeaderBase, HeaderMotionFlatList, HeaderMotionHeader, HeaderMotionScrollManager, HeaderMotionScrollView, type HeaderMotionFlatListProps, type HeaderMotionHeaderProps, type HeaderMotionProps, type HeaderMotionScrollManagerProps, type HeaderMotionScrollViewProps } from './components';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Compound component type for HeaderMotion.
|
|
5
|
+
* Provides the main context provider and sub-components for building collapsible headers.
|
|
6
|
+
*/
|
|
7
|
+
type HeaderMotionComponent = {
|
|
8
|
+
/** Main context provider component */
|
|
9
|
+
<T extends string>(props: HeaderMotionProps<T>): ReactElement;
|
|
10
|
+
/** Component for providing motion progress properties to animated headers.
|
|
11
|
+
* Use to pass props to the header components in React Navigation / Expo Router, which cannot access HeaderMotion's context and `useMotionProgress` otherwise.
|
|
12
|
+
*/
|
|
13
|
+
Header: typeof HeaderMotionHeader;
|
|
14
|
+
/** Component for custom scroll implementations */
|
|
15
|
+
ScrollManager: typeof HeaderMotionScrollManager;
|
|
16
|
+
/** Animated ScrollView component with header motion integration */
|
|
17
|
+
ScrollView: typeof HeaderMotionScrollView;
|
|
18
|
+
/** Animated FlatList component with header motion integration */
|
|
19
|
+
FlatList: typeof HeaderMotionFlatList;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Main HeaderMotion component.
|
|
23
|
+
* A compound component that provides context for collapsible header animations.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* <HeaderMotion>
|
|
28
|
+
* <HeaderMotion.Header>
|
|
29
|
+
* {(headerProps) => (
|
|
30
|
+
* <Stack.Screen
|
|
31
|
+
* options={{
|
|
32
|
+
* header: () => (
|
|
33
|
+
* <MyAnimatedHeader {...headerProps} />
|
|
34
|
+
* ),
|
|
35
|
+
* }}
|
|
36
|
+
* />
|
|
37
|
+
* )}
|
|
38
|
+
* </HeaderMotion.Header>
|
|
39
|
+
* <HeaderMotion.ScrollView>
|
|
40
|
+
* <MyScrollableContent />
|
|
41
|
+
* </HeaderMotion.ScrollView>
|
|
42
|
+
* </HeaderMotion>
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare const HeaderMotion: HeaderMotionComponent;
|
|
46
|
+
export default HeaderMotion;
|
|
47
|
+
export * from './hooks';
|
|
48
|
+
export type * from './types';
|
|
49
|
+
export { AnimatedHeaderBase, HeaderBase };
|
|
50
|
+
export type { HeaderMotionFlatListProps, HeaderMotionHeaderProps, HeaderMotionProps, HeaderMotionScrollManagerProps, HeaderMotionScrollViewProps, };
|
|
51
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,UAAU,EAEV,oBAAoB,EACpB,kBAAkB,EAClB,yBAAyB,EACzB,sBAAsB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,KAAK,8BAA8B,EACnC,KAAK,2BAA2B,EACjC,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1C;;;GAGG;AACH,KAAK,qBAAqB,GAAG;IAC3B,sCAAsC;IACtC,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC;IAC9D;;OAEG;IACH,MAAM,EAAE,OAAO,kBAAkB,CAAC;IAClC,kDAAkD;IAClD,aAAa,EAAE,OAAO,yBAAyB,CAAC;IAChD,mEAAmE;IACnE,UAAU,EAAE,OAAO,sBAAsB,CAAC;IAC1C,iEAAiE;IACjE,QAAQ,EAAE,OAAO,oBAAoB,CAAC;CACvC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,QAAA,MAAM,YAAY,EAAkC,qBAAqB,CAAC;AAM1E,eAAe,YAAY,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,mBAAmB,SAAS,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,CAAC;AAC1C,YAAY,EACV,yBAAyB,EACzB,uBAAuB,EACvB,iBAAiB,EACjB,8BAA8B,EAC9B,2BAA2B,GAC5B,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { LayoutChangeEvent, ScrollViewProps } from 'react-native';
|
|
2
|
+
import type { AnimatedRef, SharedValue } from 'react-native-reanimated';
|
|
3
|
+
import { DEFAULT_SCROLL_ID } from './utils/defaults';
|
|
4
|
+
export type Progress = SharedValue<number>;
|
|
5
|
+
export type ProgressThreshold = number | ((measuredHeaderValue: number) => number);
|
|
6
|
+
export type MeasureAnimatedHeader = (e: LayoutChangeEvent) => number;
|
|
7
|
+
export type MeasureAnimatedHeaderAndSet = (e: LayoutChangeEvent) => void;
|
|
8
|
+
export type ActiveScrollIdValues<T extends string = string> = {
|
|
9
|
+
state: T;
|
|
10
|
+
sv: SharedValue<T>;
|
|
11
|
+
};
|
|
12
|
+
export type SetActiveScrollId<T extends string> = (newId: T) => void;
|
|
13
|
+
export interface ScrollValue {
|
|
14
|
+
min: number;
|
|
15
|
+
current: number;
|
|
16
|
+
}
|
|
17
|
+
export type ScrollValues = Record<string, ScrollValue> & {
|
|
18
|
+
[key in typeof DEFAULT_SCROLL_ID]?: ScrollValue;
|
|
19
|
+
};
|
|
20
|
+
export type WithCollapsibleHeaderProps<T extends Record<string, unknown> = Record<string, unknown>> = T & MotionProgress;
|
|
21
|
+
export type WithCollapsiblePagedHeaderProps<Tab extends string = string, T extends Record<string, unknown> = Record<string, unknown>> = WithCollapsibleHeaderProps<T> & {
|
|
22
|
+
onTabChange: (newTab: Tab) => void;
|
|
23
|
+
activeTab: Tab;
|
|
24
|
+
};
|
|
25
|
+
export interface MotionProgress {
|
|
26
|
+
progress: Progress;
|
|
27
|
+
progressThreshold: number;
|
|
28
|
+
measureTotalHeight: MeasureAnimatedHeaderAndSet;
|
|
29
|
+
measureDynamic: MeasureAnimatedHeaderAndSet;
|
|
30
|
+
}
|
|
31
|
+
export interface ScrollManagerHeaderMotionContext {
|
|
32
|
+
originalHeaderHeight: number;
|
|
33
|
+
minHeightContentContainerStyle: {} | {
|
|
34
|
+
minHeight: number;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export interface ScrollManagerConfig {
|
|
38
|
+
scrollableProps: Required<Pick<ScrollViewProps, 'onScroll' | 'scrollEventThrottle'>> & {
|
|
39
|
+
ref: AnimatedRef<any>;
|
|
40
|
+
};
|
|
41
|
+
headerMotionContext: ScrollManagerHeaderMotionContext;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;AAE3C,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,CAAC,CAAC,mBAAmB,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;AAC9C,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,EAAE,iBAAiB,KAAK,MAAM,CAAC;AACrE,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;AAEzE,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IAC5D,KAAK,EAAE,CAAC,CAAC;IACT,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;CACpB,CAAC;AACF,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAErE,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AACD,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG;KACtD,GAAG,IAAI,OAAO,iBAAiB,CAAC,CAAC,EAAE,WAAW;CAChD,CAAC;AAEF,MAAM,MAAM,0BAA0B,CACpC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACzD,CAAC,GAAG,cAAc,CAAC;AAEvB,MAAM,MAAM,+BAA+B,CACzC,GAAG,SAAS,MAAM,GAAG,MAAM,EAC3B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACzD,0BAA0B,CAAC,CAAC,CAAC,GAAG;IAClC,WAAW,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IACnC,SAAS,EAAE,GAAG,CAAC;CAChB,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,QAAQ,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kBAAkB,EAAE,2BAA2B,CAAC;IAChD,cAAc,EAAE,2BAA2B,CAAC;CAC7C;AAED,MAAM,WAAW,gCAAgC;IAC/C,oBAAoB,EAAE,MAAM,CAAC;IAC7B,8BAA8B,EAC1B,EAAE,GACF;QACE,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACP;AAED,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,QAAQ,CACvB,IAAI,CAAC,eAAe,EAAE,UAAU,GAAG,qBAAqB,CAAC,CAC1D,GAAG;QACF,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;KACvB,CAAC;IACF,mBAAmB,EAAE,gCAAgC,CAAC;CACvD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { MeasureAnimatedHeader, ProgressThreshold } from '../types';
|
|
2
|
+
declare const DEFAULT_PROGRESS_THRESHOLD: ProgressThreshold;
|
|
3
|
+
declare const DEFAULT_MEASURE_DYNAMIC: MeasureAnimatedHeader;
|
|
4
|
+
declare const DEFAULT_SCROLL_ID = "__HEADER_MOTION_DEFAULT_SCROLL_ID__";
|
|
5
|
+
export { DEFAULT_MEASURE_DYNAMIC, DEFAULT_PROGRESS_THRESHOLD, DEFAULT_SCROLL_ID, };
|
|
6
|
+
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../../src/utils/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAEzE,QAAA,MAAM,0BAA0B,EAAE,iBACb,CAAC;AACtB,QAAA,MAAM,uBAAuB,EAAE,qBACF,CAAC;AAI9B,QAAA,MAAM,iBAAiB,wCAAwC,CAAC;AAEhE,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,iBAAiB,GAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../../../../src/utils/values.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,wBAAgB,qBAAqB,IAAI,WAAW,CAGnD"}
|