react-native-ultra-carousel 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/package.json +81 -0
- package/src/animations/basic/fade.ts +51 -0
- package/src/animations/basic/overlap.ts +69 -0
- package/src/animations/basic/parallax.ts +65 -0
- package/src/animations/basic/peek.ts +79 -0
- package/src/animations/basic/scale.ts +63 -0
- package/src/animations/basic/scaleFade.ts +73 -0
- package/src/animations/basic/slide.ts +53 -0
- package/src/animations/basic/slideFade.ts +60 -0
- package/src/animations/basic/vertical.ts +50 -0
- package/src/animations/basic/verticalFade.ts +60 -0
- package/src/animations/index.ts +45 -0
- package/src/animations/registry.ts +175 -0
- package/src/animations/types.ts +11 -0
- package/src/animations/utils.ts +75 -0
- package/src/components/AutoPlayController.tsx +38 -0
- package/src/components/Carousel.tsx +371 -0
- package/src/components/CarouselItem.tsx +98 -0
- package/src/components/Pagination/BarPagination.tsx +141 -0
- package/src/components/Pagination/CustomPagination.tsx +48 -0
- package/src/components/Pagination/DotPagination.tsx +137 -0
- package/src/components/Pagination/NumberPagination.tsx +117 -0
- package/src/components/Pagination/Pagination.tsx +82 -0
- package/src/components/Pagination/ProgressPagination.tsx +70 -0
- package/src/components/Pagination/index.ts +11 -0
- package/src/components/ParallaxImage.tsx +89 -0
- package/src/gestures/FlingGestureManager.ts +49 -0
- package/src/gestures/PanGestureManager.ts +202 -0
- package/src/gestures/ScrollViewCompat.ts +28 -0
- package/src/gestures/types.ts +6 -0
- package/src/hooks/useAnimationProgress.ts +33 -0
- package/src/hooks/useAutoPlay.ts +115 -0
- package/src/hooks/useCarousel.ts +118 -0
- package/src/hooks/useCarouselGesture.ts +109 -0
- package/src/hooks/useItemAnimation.ts +44 -0
- package/src/hooks/usePagination.ts +39 -0
- package/src/hooks/useSnapPoints.ts +31 -0
- package/src/hooks/useVirtualization.ts +63 -0
- package/src/index.ts +71 -0
- package/src/plugins/PluginManager.ts +150 -0
- package/src/plugins/types.ts +6 -0
- package/src/types/animation.ts +72 -0
- package/src/types/carousel.ts +188 -0
- package/src/types/gesture.ts +42 -0
- package/src/types/index.ts +41 -0
- package/src/types/pagination.ts +65 -0
- package/src/types/plugin.ts +27 -0
- package/src/utils/accessibility.ts +71 -0
- package/src/utils/constants.ts +45 -0
- package/src/utils/layout.ts +115 -0
- package/src/utils/math.ts +78 -0
- package/src/utils/platform.ts +33 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file useSnapPoints hook
|
|
3
|
+
* @description Computes snap points for carousel items based on layout parameters
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useMemo } from 'react';
|
|
7
|
+
import type { SnapAlignment } from '../types';
|
|
8
|
+
import { calculateSnapPoints } from '../utils/layout';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Computes an array of snap point offsets for the carousel.
|
|
12
|
+
*
|
|
13
|
+
* @param totalItems - Number of items
|
|
14
|
+
* @param itemSize - Width or height of each item
|
|
15
|
+
* @param gap - Gap between items
|
|
16
|
+
* @param containerSize - Width or height of the container
|
|
17
|
+
* @param alignment - Snap alignment mode
|
|
18
|
+
* @returns Memoized array of snap point offsets
|
|
19
|
+
*/
|
|
20
|
+
export const useSnapPoints = (
|
|
21
|
+
totalItems: number,
|
|
22
|
+
itemSize: number,
|
|
23
|
+
gap: number,
|
|
24
|
+
containerSize: number,
|
|
25
|
+
alignment: SnapAlignment
|
|
26
|
+
): number[] => {
|
|
27
|
+
return useMemo(
|
|
28
|
+
() => calculateSnapPoints(totalItems, itemSize, gap, containerSize, alignment),
|
|
29
|
+
[totalItems, itemSize, gap, containerSize, alignment]
|
|
30
|
+
);
|
|
31
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file useVirtualization hook
|
|
3
|
+
* @description Computes which items should be rendered based on current scroll position
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useDerivedValue, type SharedValue } from 'react-native-reanimated';
|
|
7
|
+
import { DEFAULT_RENDER_BUFFER } from '../utils/constants';
|
|
8
|
+
|
|
9
|
+
/** Return type of the virtualization hook */
|
|
10
|
+
export interface VirtualizationResult {
|
|
11
|
+
/** Indices of items that should be rendered */
|
|
12
|
+
visibleIndices: SharedValue<number[]>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Determines which carousel items should be rendered for performance.
|
|
17
|
+
* Only items within the visible range + buffer are rendered.
|
|
18
|
+
*
|
|
19
|
+
* @param scrollOffset - Current scroll offset shared value
|
|
20
|
+
* @param totalItems - Total number of items
|
|
21
|
+
* @param itemSize - Width or height of each item
|
|
22
|
+
* @param gap - Gap between items
|
|
23
|
+
* @param containerSize - Width or height of the container
|
|
24
|
+
* @param maxRenderItems - Max items to render (0 = all)
|
|
25
|
+
* @param renderBuffer - Extra items outside viewport to render
|
|
26
|
+
* @returns Object containing the array of visible indices
|
|
27
|
+
*/
|
|
28
|
+
export const useVirtualization = (
|
|
29
|
+
scrollOffset: SharedValue<number>,
|
|
30
|
+
totalItems: number,
|
|
31
|
+
itemSize: number,
|
|
32
|
+
gap: number,
|
|
33
|
+
containerSize: number,
|
|
34
|
+
maxRenderItems: number = 0,
|
|
35
|
+
renderBuffer: number = DEFAULT_RENDER_BUFFER
|
|
36
|
+
): VirtualizationResult => {
|
|
37
|
+
const stepSize = itemSize + gap;
|
|
38
|
+
|
|
39
|
+
const visibleIndices = useDerivedValue(() => {
|
|
40
|
+
if (maxRenderItems === 0 || totalItems <= maxRenderItems) {
|
|
41
|
+
return Array.from({ length: totalItems }, (_, i) => i);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (stepSize === 0) {
|
|
45
|
+
return [0];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const currentIndex = Math.round(scrollOffset.value / stepSize);
|
|
49
|
+
const visibleCount = Math.ceil(containerSize / stepSize) + 1;
|
|
50
|
+
const halfVisible = Math.ceil(visibleCount / 2);
|
|
51
|
+
const start = Math.max(0, currentIndex - halfVisible - renderBuffer);
|
|
52
|
+
const end = Math.min(totalItems - 1, currentIndex + halfVisible + renderBuffer);
|
|
53
|
+
|
|
54
|
+
const indices: number[] = [];
|
|
55
|
+
for (let i = start; i <= end; i++) {
|
|
56
|
+
indices.push(i);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return indices;
|
|
60
|
+
}, [totalItems, stepSize, containerSize, maxRenderItems, renderBuffer]);
|
|
61
|
+
|
|
62
|
+
return { visibleIndices };
|
|
63
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file react-native-ultra-carousel
|
|
3
|
+
* @description The Ultimate Carousel Ecosystem for React Native
|
|
4
|
+
* @author toankhontech
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// === Components ===
|
|
9
|
+
export { Carousel } from './components/Carousel';
|
|
10
|
+
export { Pagination } from './components/Pagination';
|
|
11
|
+
export { ParallaxImage } from './components/ParallaxImage';
|
|
12
|
+
|
|
13
|
+
// === Hooks ===
|
|
14
|
+
export { useCarousel } from './hooks/useCarousel';
|
|
15
|
+
export type { UseCarouselReturn } from './hooks/useCarousel';
|
|
16
|
+
export { useAnimationProgress } from './hooks/useAnimationProgress';
|
|
17
|
+
export { useItemAnimation } from './hooks/useItemAnimation';
|
|
18
|
+
export { useCarouselGesture } from './hooks/useCarouselGesture';
|
|
19
|
+
export { useAutoPlay } from './hooks/useAutoPlay';
|
|
20
|
+
export type { UseAutoPlayReturn } from './hooks/useAutoPlay';
|
|
21
|
+
export { useSnapPoints } from './hooks/useSnapPoints';
|
|
22
|
+
export { usePagination } from './hooks/usePagination';
|
|
23
|
+
|
|
24
|
+
// === Animations ===
|
|
25
|
+
export {
|
|
26
|
+
slideAnimation,
|
|
27
|
+
fadeAnimation,
|
|
28
|
+
slideFadeAnimation,
|
|
29
|
+
scaleAnimation,
|
|
30
|
+
scaleFadeAnimation,
|
|
31
|
+
verticalAnimation,
|
|
32
|
+
verticalFadeAnimation,
|
|
33
|
+
parallaxAnimation,
|
|
34
|
+
overlapAnimation,
|
|
35
|
+
peekAnimation,
|
|
36
|
+
registerPreset,
|
|
37
|
+
getPreset,
|
|
38
|
+
getPresetMeta,
|
|
39
|
+
getAllPresetNames,
|
|
40
|
+
getAllPresetMeta,
|
|
41
|
+
isPresetRegistered,
|
|
42
|
+
} from './animations';
|
|
43
|
+
|
|
44
|
+
// === Plugin System ===
|
|
45
|
+
export { createPlugin, PluginManager } from './plugins/PluginManager';
|
|
46
|
+
|
|
47
|
+
// === Types ===
|
|
48
|
+
export type {
|
|
49
|
+
CarouselProps,
|
|
50
|
+
CarouselRef,
|
|
51
|
+
PresetName,
|
|
52
|
+
CarouselDirection,
|
|
53
|
+
SnapAlignment,
|
|
54
|
+
RenderItemInfo,
|
|
55
|
+
GestureConfig,
|
|
56
|
+
AutoPlayConfig,
|
|
57
|
+
AnimatedItemStyle,
|
|
58
|
+
AnimationPresetFn,
|
|
59
|
+
CustomAnimationFn,
|
|
60
|
+
AnimationPresetMeta,
|
|
61
|
+
CarouselPlugin,
|
|
62
|
+
CreatePluginOptions,
|
|
63
|
+
PaginationConfig,
|
|
64
|
+
PaginationRenderInfo,
|
|
65
|
+
PaginationType,
|
|
66
|
+
PaginationPosition,
|
|
67
|
+
BasePaginationProps,
|
|
68
|
+
GestureState,
|
|
69
|
+
PanGestureConfig,
|
|
70
|
+
SnapResult,
|
|
71
|
+
} from './types';
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Plugin manager
|
|
3
|
+
* @description Registry and lifecycle manager for carousel plugins
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { CarouselPlugin, CreatePluginOptions } from './types';
|
|
7
|
+
import type { CarouselRef, AnimatedItemStyle } from '../types';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a carousel plugin with the given options.
|
|
11
|
+
*
|
|
12
|
+
* @param options - Plugin configuration including lifecycle hooks
|
|
13
|
+
* @returns A fully typed CarouselPlugin instance
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const analyticsPlugin = createPlugin({
|
|
18
|
+
* name: 'analytics',
|
|
19
|
+
* onIndexChange: (index) => {
|
|
20
|
+
* analytics.track('carousel_swipe', { index });
|
|
21
|
+
* },
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export const createPlugin = (options: CreatePluginOptions): CarouselPlugin => {
|
|
26
|
+
return { ...options };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Manages a collection of plugins for a carousel instance.
|
|
31
|
+
* Handles lifecycle calls and animation composition.
|
|
32
|
+
*/
|
|
33
|
+
export class PluginManager {
|
|
34
|
+
private plugins: CarouselPlugin[] = [];
|
|
35
|
+
private initialized = false;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new PluginManager instance.
|
|
39
|
+
*
|
|
40
|
+
* @param plugins - Initial array of plugins to manage
|
|
41
|
+
*/
|
|
42
|
+
constructor(plugins: CarouselPlugin[] = []) {
|
|
43
|
+
this.plugins = [...plugins];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Registers a new plugin.
|
|
48
|
+
*
|
|
49
|
+
* @param plugin - The plugin to add
|
|
50
|
+
*/
|
|
51
|
+
register(plugin: CarouselPlugin): void {
|
|
52
|
+
if (this.plugins.some((p) => p.name === plugin.name)) {
|
|
53
|
+
console.warn(
|
|
54
|
+
`[ultra-carousel] Plugin "${plugin.name}" is already registered. Skipping.`
|
|
55
|
+
);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.plugins.push(plugin);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Removes a plugin by name.
|
|
63
|
+
*
|
|
64
|
+
* @param name - Name of the plugin to remove
|
|
65
|
+
*/
|
|
66
|
+
unregister(name: string): void {
|
|
67
|
+
const index = this.plugins.findIndex((p) => p.name === name);
|
|
68
|
+
if (index !== -1) {
|
|
69
|
+
this.plugins[index].onDestroy?.();
|
|
70
|
+
this.plugins.splice(index, 1);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Initializes all registered plugins with the carousel ref.
|
|
76
|
+
*
|
|
77
|
+
* @param carousel - The carousel instance ref
|
|
78
|
+
*/
|
|
79
|
+
init(carousel: CarouselRef): void {
|
|
80
|
+
if (this.initialized) return;
|
|
81
|
+
this.plugins.forEach((plugin) => {
|
|
82
|
+
plugin.onInit?.(carousel);
|
|
83
|
+
});
|
|
84
|
+
this.initialized = true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Calls onAnimate on all plugins and merges returned styles.
|
|
89
|
+
* This runs on the UI thread (worklet context).
|
|
90
|
+
*
|
|
91
|
+
* @param progress - Current animation progress
|
|
92
|
+
* @param index - Current item index
|
|
93
|
+
* @returns Merged animated style from all plugins
|
|
94
|
+
*/
|
|
95
|
+
animate(progress: number, index: number): AnimatedItemStyle {
|
|
96
|
+
'worklet';
|
|
97
|
+
const mergedStyle: AnimatedItemStyle = {};
|
|
98
|
+
|
|
99
|
+
for (const plugin of this.plugins) {
|
|
100
|
+
if (plugin.onAnimate) {
|
|
101
|
+
const result = plugin.onAnimate(progress, index);
|
|
102
|
+
if (result) {
|
|
103
|
+
if (result.opacity !== undefined) {
|
|
104
|
+
mergedStyle.opacity = result.opacity;
|
|
105
|
+
}
|
|
106
|
+
if (result.zIndex !== undefined) {
|
|
107
|
+
mergedStyle.zIndex = result.zIndex;
|
|
108
|
+
}
|
|
109
|
+
if (result.transform) {
|
|
110
|
+
mergedStyle.transform = [
|
|
111
|
+
...(mergedStyle.transform ?? []),
|
|
112
|
+
...result.transform,
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return mergedStyle;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Notifies all plugins of an index change.
|
|
124
|
+
*
|
|
125
|
+
* @param index - The new active index
|
|
126
|
+
*/
|
|
127
|
+
notifyIndexChange(index: number): void {
|
|
128
|
+
this.plugins.forEach((plugin) => {
|
|
129
|
+
plugin.onIndexChange?.(index);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Destroys all plugins and cleans up.
|
|
135
|
+
*/
|
|
136
|
+
destroy(): void {
|
|
137
|
+
this.plugins.forEach((plugin) => {
|
|
138
|
+
plugin.onDestroy?.();
|
|
139
|
+
});
|
|
140
|
+
this.plugins = [];
|
|
141
|
+
this.initialized = false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Returns the number of registered plugins.
|
|
146
|
+
*/
|
|
147
|
+
get count(): number {
|
|
148
|
+
return this.plugins.length;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Animation type definitions
|
|
3
|
+
* @description Types for animation presets, styles, and configuration
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Style object returned by animation functions */
|
|
7
|
+
export interface AnimatedItemStyle {
|
|
8
|
+
transform?: Array<
|
|
9
|
+
| { translateX: number }
|
|
10
|
+
| { translateY: number }
|
|
11
|
+
| { scale: number }
|
|
12
|
+
| { scaleX: number }
|
|
13
|
+
| { scaleY: number }
|
|
14
|
+
| { rotate: string }
|
|
15
|
+
| { rotateX: string }
|
|
16
|
+
| { rotateY: string }
|
|
17
|
+
| { rotateZ: string }
|
|
18
|
+
| { skewX: string }
|
|
19
|
+
| { skewY: string }
|
|
20
|
+
| { perspective: number }
|
|
21
|
+
>;
|
|
22
|
+
opacity?: number;
|
|
23
|
+
zIndex?: number;
|
|
24
|
+
elevation?: number;
|
|
25
|
+
borderRadius?: number;
|
|
26
|
+
overflow?: 'visible' | 'hidden';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Animation preset function signature.
|
|
31
|
+
* All presets must follow this contract.
|
|
32
|
+
*
|
|
33
|
+
* @param progress - Normalized scroll progress: 0 = active, -1 = prev, +1 = next
|
|
34
|
+
* @param config - Optional configuration overrides
|
|
35
|
+
* @returns Animated style to apply to the carousel item
|
|
36
|
+
*/
|
|
37
|
+
export type AnimationPresetFn = (
|
|
38
|
+
progress: number,
|
|
39
|
+
config?: Record<string, number>
|
|
40
|
+
) => AnimatedItemStyle;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Custom animation function signature (extended version with more context).
|
|
44
|
+
*
|
|
45
|
+
* @param progress - Normalized progress for this item
|
|
46
|
+
* @param index - Item index in the data array
|
|
47
|
+
* @param totalItems - Total number of items
|
|
48
|
+
* @param config - Optional configuration overrides
|
|
49
|
+
* @returns Animated style to apply to the carousel item
|
|
50
|
+
*/
|
|
51
|
+
export type CustomAnimationFn = (
|
|
52
|
+
progress: number,
|
|
53
|
+
index: number,
|
|
54
|
+
totalItems: number,
|
|
55
|
+
config?: Record<string, number>
|
|
56
|
+
) => AnimatedItemStyle;
|
|
57
|
+
|
|
58
|
+
/** Metadata for a registered animation preset */
|
|
59
|
+
export interface AnimationPresetMeta {
|
|
60
|
+
/** Unique preset name */
|
|
61
|
+
name: string;
|
|
62
|
+
/** Human-readable description */
|
|
63
|
+
description: string;
|
|
64
|
+
/** Difficulty level */
|
|
65
|
+
difficulty: 'Easy' | 'Medium' | 'Hard';
|
|
66
|
+
/** Phase when it was added */
|
|
67
|
+
phase: 1 | 2 | 3;
|
|
68
|
+
/** The animation function */
|
|
69
|
+
animation: AnimationPresetFn;
|
|
70
|
+
/** Default configuration values */
|
|
71
|
+
defaults: Record<string, number>;
|
|
72
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Core type definitions for react-native-ultra-carousel
|
|
3
|
+
* @description All public-facing types used across the carousel ecosystem
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ViewStyle, StyleProp } from 'react-native';
|
|
7
|
+
import type { SharedValue } from 'react-native-reanimated';
|
|
8
|
+
import type { PanGesture } from 'react-native-gesture-handler';
|
|
9
|
+
import type { AnimatedItemStyle, CustomAnimationFn } from './animation';
|
|
10
|
+
import type { CarouselPlugin } from './plugin';
|
|
11
|
+
import type { PaginationConfig, PaginationRenderInfo } from './pagination';
|
|
12
|
+
|
|
13
|
+
/** All available animation preset names */
|
|
14
|
+
export type PresetName =
|
|
15
|
+
| 'slide'
|
|
16
|
+
| 'fade'
|
|
17
|
+
| 'slide-fade'
|
|
18
|
+
| 'scale'
|
|
19
|
+
| 'scale-fade'
|
|
20
|
+
| 'vertical'
|
|
21
|
+
| 'vertical-fade'
|
|
22
|
+
| 'parallax'
|
|
23
|
+
| 'overlap'
|
|
24
|
+
| 'peek'
|
|
25
|
+
| 'stack'
|
|
26
|
+
| 'tinder'
|
|
27
|
+
| 'coverflow'
|
|
28
|
+
| 'cube'
|
|
29
|
+
| 'flip'
|
|
30
|
+
| 'wheel'
|
|
31
|
+
| 'accordion'
|
|
32
|
+
| 'zoom'
|
|
33
|
+
| 'rotate'
|
|
34
|
+
| 'depth'
|
|
35
|
+
| 'newspaper'
|
|
36
|
+
| 'origami'
|
|
37
|
+
| 'carousel-3d'
|
|
38
|
+
| 'wave'
|
|
39
|
+
| 'spiral'
|
|
40
|
+
| 'glitch'
|
|
41
|
+
| 'morph'
|
|
42
|
+
| 'shutter'
|
|
43
|
+
| 'domino'
|
|
44
|
+
| 'elastic'
|
|
45
|
+
| 'blur-slide'
|
|
46
|
+
| 'windmill'
|
|
47
|
+
| 'film-strip'
|
|
48
|
+
| 'helix'
|
|
49
|
+
| 'gravity';
|
|
50
|
+
|
|
51
|
+
/** Direction of carousel scrolling */
|
|
52
|
+
export type CarouselDirection = 'horizontal' | 'vertical';
|
|
53
|
+
|
|
54
|
+
/** Snap alignment within the container */
|
|
55
|
+
export type SnapAlignment = 'start' | 'center' | 'end';
|
|
56
|
+
|
|
57
|
+
/** Information passed to renderItem callback */
|
|
58
|
+
export interface RenderItemInfo<T> {
|
|
59
|
+
/** The data item */
|
|
60
|
+
item: T;
|
|
61
|
+
/** Index in the data array */
|
|
62
|
+
index: number;
|
|
63
|
+
/** Animated progress value for this item */
|
|
64
|
+
animationProgress: SharedValue<number>;
|
|
65
|
+
/** Whether this item is currently active */
|
|
66
|
+
isActive: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Gesture configuration for fine-tuning */
|
|
70
|
+
export interface GestureConfig {
|
|
71
|
+
/** Minimum horizontal distance before gesture activates (default: 10) */
|
|
72
|
+
activeOffsetX?: number | [number, number];
|
|
73
|
+
/** Minimum vertical distance before gesture activates */
|
|
74
|
+
activeOffsetY?: number | [number, number];
|
|
75
|
+
/** Velocity threshold for fling gesture (default: 500) */
|
|
76
|
+
velocityThreshold?: number;
|
|
77
|
+
/** Enable/disable fling gesture (default: true) */
|
|
78
|
+
enableFling?: boolean;
|
|
79
|
+
/** Callback to customize the pan gesture */
|
|
80
|
+
onConfigurePanGesture?: (gesture: PanGesture) => void;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Auto play configuration */
|
|
84
|
+
export interface AutoPlayConfig {
|
|
85
|
+
/** Enable auto play (default: false) */
|
|
86
|
+
enabled: boolean;
|
|
87
|
+
/** Interval between slides in ms (default: 3000) */
|
|
88
|
+
interval?: number;
|
|
89
|
+
/** Pause on user interaction (default: true) */
|
|
90
|
+
pauseOnInteraction?: boolean;
|
|
91
|
+
/** Direction: forward or backward (default: 'forward') */
|
|
92
|
+
direction?: 'forward' | 'backward';
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Main Carousel component props */
|
|
96
|
+
export interface CarouselProps<T> {
|
|
97
|
+
/** Array of data items */
|
|
98
|
+
data: T[];
|
|
99
|
+
/** Render function for each item */
|
|
100
|
+
renderItem: (info: RenderItemInfo<T>) => React.ReactNode;
|
|
101
|
+
|
|
102
|
+
/** Animation preset name or custom animation function */
|
|
103
|
+
preset?: PresetName | CustomAnimationFn;
|
|
104
|
+
/** Animation configuration overrides for the selected preset */
|
|
105
|
+
animationConfig?: Record<string, number>;
|
|
106
|
+
|
|
107
|
+
/** Container width (default: screen width) */
|
|
108
|
+
width?: number;
|
|
109
|
+
/** Container height (default: auto) */
|
|
110
|
+
height?: number;
|
|
111
|
+
/** Individual item width (default: container width) */
|
|
112
|
+
itemWidth?: number;
|
|
113
|
+
/** Individual item height (default: container height) */
|
|
114
|
+
itemHeight?: number;
|
|
115
|
+
/** Scroll direction (default: 'horizontal') */
|
|
116
|
+
direction?: CarouselDirection;
|
|
117
|
+
/** Number of items visible at once (default: 1) */
|
|
118
|
+
visibleItems?: number;
|
|
119
|
+
/** Gap between items in pixels (default: 0) */
|
|
120
|
+
gap?: number;
|
|
121
|
+
/** Snap alignment (default: 'center') */
|
|
122
|
+
snapAlignment?: SnapAlignment;
|
|
123
|
+
|
|
124
|
+
/** Enable infinite loop (default: false) */
|
|
125
|
+
loop?: boolean;
|
|
126
|
+
/** Initial active index (default: 0) */
|
|
127
|
+
initialIndex?: number;
|
|
128
|
+
/** Enable/disable user interaction (default: true) */
|
|
129
|
+
enabled?: boolean;
|
|
130
|
+
|
|
131
|
+
/** Enable auto play (default: false) */
|
|
132
|
+
autoPlay?: boolean | AutoPlayConfig;
|
|
133
|
+
/** Auto play interval in ms (default: 3000) */
|
|
134
|
+
autoPlayInterval?: number;
|
|
135
|
+
|
|
136
|
+
/** Enable/configure pagination */
|
|
137
|
+
pagination?: boolean | PaginationConfig;
|
|
138
|
+
|
|
139
|
+
/** Gesture configuration */
|
|
140
|
+
gestureConfig?: GestureConfig;
|
|
141
|
+
|
|
142
|
+
/** Called when active index changes */
|
|
143
|
+
onIndexChange?: (index: number) => void;
|
|
144
|
+
/** Called when scroll begins */
|
|
145
|
+
onScrollStart?: () => void;
|
|
146
|
+
/** Called when scroll ends */
|
|
147
|
+
onScrollEnd?: (index: number) => void;
|
|
148
|
+
/** Shared value updated with scroll progress */
|
|
149
|
+
scrollProgress?: SharedValue<number>;
|
|
150
|
+
|
|
151
|
+
/** Array of plugins to apply */
|
|
152
|
+
plugins?: CarouselPlugin[];
|
|
153
|
+
|
|
154
|
+
/** Max items to render (virtualization). 0 = render all (default: 0) */
|
|
155
|
+
maxRenderItems?: number;
|
|
156
|
+
/** Buffer items outside visible area (default: 2) */
|
|
157
|
+
renderBuffer?: number;
|
|
158
|
+
|
|
159
|
+
/** Enable accessibility features (default: true) */
|
|
160
|
+
accessible?: boolean;
|
|
161
|
+
/** Carousel label for screen readers */
|
|
162
|
+
accessibilityLabel?: string;
|
|
163
|
+
|
|
164
|
+
/** Container style */
|
|
165
|
+
style?: StyleProp<ViewStyle>;
|
|
166
|
+
/** Item container style */
|
|
167
|
+
itemStyle?: StyleProp<ViewStyle>;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Carousel instance methods (exposed via ref) */
|
|
171
|
+
export interface CarouselRef {
|
|
172
|
+
/** Scroll to specific index */
|
|
173
|
+
scrollTo: (index: number, animated?: boolean) => void;
|
|
174
|
+
/** Go to next item */
|
|
175
|
+
next: (animated?: boolean) => void;
|
|
176
|
+
/** Go to previous item */
|
|
177
|
+
prev: (animated?: boolean) => void;
|
|
178
|
+
/** Get current active index */
|
|
179
|
+
getCurrentIndex: () => number;
|
|
180
|
+
/** Start auto play */
|
|
181
|
+
startAutoPlay: () => void;
|
|
182
|
+
/** Stop auto play */
|
|
183
|
+
stopAutoPlay: () => void;
|
|
184
|
+
/** Pause auto play (resumes on next interaction) */
|
|
185
|
+
pauseAutoPlay: () => void;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export type { PaginationConfig, PaginationRenderInfo };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Gesture type definitions
|
|
3
|
+
* @description Types for gesture handling and touch interaction
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Gesture state during a pan interaction */
|
|
7
|
+
export interface GestureState {
|
|
8
|
+
/** Current translation in X axis */
|
|
9
|
+
translationX: number;
|
|
10
|
+
/** Current translation in Y axis */
|
|
11
|
+
translationY: number;
|
|
12
|
+
/** Current velocity in X axis */
|
|
13
|
+
velocityX: number;
|
|
14
|
+
/** Current velocity in Y axis */
|
|
15
|
+
velocityY: number;
|
|
16
|
+
/** Whether the gesture is currently active */
|
|
17
|
+
isActive: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Configuration for the pan gesture manager */
|
|
21
|
+
export interface PanGestureConfig {
|
|
22
|
+
/** Active offset thresholds for X axis */
|
|
23
|
+
activeOffsetX: [number, number];
|
|
24
|
+
/** Active offset thresholds for Y axis */
|
|
25
|
+
activeOffsetY: [number, number];
|
|
26
|
+
/** Velocity threshold for fling detection */
|
|
27
|
+
velocityThreshold: number;
|
|
28
|
+
/** Whether the carousel scrolls horizontally */
|
|
29
|
+
isHorizontal: boolean;
|
|
30
|
+
/** Width/height of each item (for snap calculations) */
|
|
31
|
+
itemSize: number;
|
|
32
|
+
/** Whether fling gesture is enabled */
|
|
33
|
+
enableFling: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Result of snap point calculation */
|
|
37
|
+
export interface SnapResult {
|
|
38
|
+
/** Target index to snap to */
|
|
39
|
+
targetIndex: number;
|
|
40
|
+
/** Target offset in pixels */
|
|
41
|
+
targetOffset: number;
|
|
42
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Type re-exports
|
|
3
|
+
* @description Central export point for all public types
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type {
|
|
7
|
+
CarouselProps,
|
|
8
|
+
CarouselRef,
|
|
9
|
+
PresetName,
|
|
10
|
+
CarouselDirection,
|
|
11
|
+
SnapAlignment,
|
|
12
|
+
RenderItemInfo,
|
|
13
|
+
GestureConfig,
|
|
14
|
+
AutoPlayConfig,
|
|
15
|
+
} from './carousel';
|
|
16
|
+
|
|
17
|
+
export type {
|
|
18
|
+
AnimatedItemStyle,
|
|
19
|
+
AnimationPresetFn,
|
|
20
|
+
CustomAnimationFn,
|
|
21
|
+
AnimationPresetMeta,
|
|
22
|
+
} from './animation';
|
|
23
|
+
|
|
24
|
+
export type {
|
|
25
|
+
GestureState,
|
|
26
|
+
PanGestureConfig,
|
|
27
|
+
SnapResult,
|
|
28
|
+
} from './gesture';
|
|
29
|
+
|
|
30
|
+
export type {
|
|
31
|
+
PaginationConfig,
|
|
32
|
+
PaginationRenderInfo,
|
|
33
|
+
PaginationType,
|
|
34
|
+
PaginationPosition,
|
|
35
|
+
BasePaginationProps,
|
|
36
|
+
} from './pagination';
|
|
37
|
+
|
|
38
|
+
export type {
|
|
39
|
+
CarouselPlugin,
|
|
40
|
+
CreatePluginOptions,
|
|
41
|
+
} from './plugin';
|