Skip to content

Commit 88bce23

Browse files
committed
chore: update import path for Gallery component and enhance type definitions
- Change import path for Gallery component to use local source - Update GalleryComponent type to support refs - Modify GalleryProps to exclude 'renderItem' from FlatListProps
1 parent 7f9b50e commit 88bce23

File tree

3 files changed

+59
-9
lines changed

3 files changed

+59
-9
lines changed

example/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
View,
88
} from 'react-native';
99
import React, { useRef } from 'react';
10-
import Gallery, { GalleryRef } from '@duocvo/react-native-gesture-image';
10+
import Gallery, { GalleryRef } from '../../src/index';
1111

1212
const image1 = require('../assets/image1.jpeg');
1313
const image2 = require('../assets/image2.jpeg');

src/Type.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,73 @@ import type {
77
} from 'react-native';
88
import type { SharedValue } from 'react-native-reanimated';
99

10+
/**
11+
* Props for the ImageViewer component
12+
*/
1013
export interface ImageViewerProps {
14+
/** The image source to display */
1115
source: ImageSourcePropType;
16+
/** Optional styles to apply to the image */
1217
imageStyle?: ImageStyle;
18+
/** Whether to enable pan down to close gesture */
1319
enablePanDownToClose?: boolean;
20+
/** Shared value for layout translation on Y axis */
1421
layoutTranslateY: SharedValue<number>;
22+
/** Callback function when the viewer is closed */
1523
onClose?: () => void;
1624
}
25+
26+
/**
27+
* Props for the Gallery component
28+
*/
1729
export interface GalleryProps
18-
extends Omit<FlatListProps<ImageSourcePropType>, 'data'> {
30+
extends Omit<FlatListProps<ImageSourcePropType>, 'data' | 'renderItem'> {
31+
/** Array of image sources to display in the gallery */
1932
data: ImageSourcePropType[];
33+
/** Optional styles to apply to the gallery container */
2034
style?: ViewStyle;
35+
/** Optional styles to apply to each image */
2136
imageStyle?: ImageStyle;
37+
/** Optional styles to apply to the gallery container */
2238
containerStyle?: ViewStyle;
39+
/** Optional styles to apply to the content container */
2340
contentContainerStyle?: ViewStyle;
41+
/** Color of the backdrop (default: 'black') */
2442
backdropColor?: string;
43+
/** Initial index to display (default: 0) */
2544
initialIndex?: number;
45+
/** Whether to enable pan down to close gesture */
2646
enablePanDownToClose?: boolean;
47+
/** Function to render header content */
2748
renderHeader?: () => React.ReactNode;
49+
/** Function to render footer content */
2850
renderFooter?: () => React.ReactNode;
2951
}
52+
53+
/**
54+
* Reference methods for the Gallery component
55+
*/
3056
export interface GalleryRef {
57+
/** Show the gallery at the specified index */
3158
show: (index?: number) => void;
59+
/** Hide the gallery */
3260
hide: () => void;
61+
/** Whether the gallery is currently visible */
3362
isVisible: boolean;
3463
}
64+
65+
/**
66+
* Internal control interface for the Gallery component
67+
*/
3568
export interface GalleryControl {
69+
/** Show the gallery at the specified index */
3670
show: (index?: number) => void;
71+
/** Hide the gallery */
3772
hide: () => void;
73+
/** Shared value indicating whether the gallery is visible */
3874
isVisible: SharedValue<boolean>;
75+
/** Shared value for translation on Y axis */
3976
translateY: SharedValue<number>;
77+
/** Reference to the FlatList component */
4078
flatListRef: React.RefObject<FlatList>;
4179
}

src/index.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
import type { GalleryRef, GalleryProps, ImageViewerProps } from './Type';
2-
import type { ComponentType } from 'react';
3-
4-
export type { GalleryRef, GalleryProps, ImageViewerProps };
5-
1+
import type {
2+
GalleryRef as GalleryRefType,
3+
GalleryProps as GalleryPropsType,
4+
ImageViewerProps as ImageViewerPropsType,
5+
} from './Type';
6+
import type {
7+
ComponentType,
8+
ForwardRefExoticComponent,
9+
RefAttributes,
10+
} from 'react';
611
import GalleryImpl from './Gallery';
712
import ImageViewerImpl from './ImageViewer';
813

9-
const GalleryComponent: ComponentType<GalleryProps> = GalleryImpl;
10-
const ImageViewerComponent: ComponentType<ImageViewerProps> = ImageViewerImpl;
14+
const GalleryComponent: ForwardRefExoticComponent<
15+
GalleryPropsType & RefAttributes<GalleryRefType>
16+
> = GalleryImpl;
17+
const ImageViewerComponent: ComponentType<ImageViewerPropsType> =
18+
ImageViewerImpl;
19+
20+
export type GalleryRef = GalleryRefType;
21+
export type GalleryProps = GalleryPropsType;
22+
export type ImageViewerProps = ImageViewerPropsType;
1123

1224
export { ImageViewerComponent as ImageViewer };
1325
export default GalleryComponent;

0 commit comments

Comments
 (0)