Skip to content

Commit 3f12579

Browse files
committed
feat: add prop to disable swipe
1 parent 3218dab commit 3f12579

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ const MyGallery = () => {
9292
const openGallery = () => setIsOpen(true);
9393
const closeGallery = () => setIsOpen(false);
9494

95-
const renderHeaderComponent = (image: any, currentIndex: number) => {
95+
const renderHeaderComponent = (image: ImageObject, currentIndex: number) => {
9696
return <Header currentIndex={currentIndex} />;
9797
};
9898

99-
const renderFooterComponent = (image: any, currentIndex: number) => {
99+
const renderFooterComponent = (image: ImageObject, currentIndex: number) => {
100100
return <Footer total={images.length} currentIndex={currentIndex} />;
101101
};
102102

example/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ const App = () => {
2828
const closeGallery = () => setIsOpen(false);
2929
const closeCustomGallery = () => setIsCustomGalleryOpen(false);
3030

31-
const renderHeaderComponent = (_image: any, currentIndex: number) => {
31+
const renderHeaderComponent = (_image: ImageObject, currentIndex: number) => {
3232
return <Header currentIndex={currentIndex} />;
3333
};
3434

35-
const renderFooterComponent = (_image: any, currentIndex: number) => {
35+
const renderFooterComponent = (_image: ImageObject, currentIndex: number) => {
3636
return <Footer total={images.length} currentIndex={currentIndex} />;
3737
};
3838

src/ImageGallery.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from 'react-native';
1111
import { ImageObject, IProps, RenderImageProps } from './types';
1212
import ImagePreview from './ImagePreview';
13-
import PanContainer from './PanContainer';
13+
import SwipeContainer from './SwipeContainer';
1414

1515
const { height: deviceHeight, width: deviceWidth } = Dimensions.get('window');
1616

@@ -37,6 +37,7 @@ const ImageGallery = (props: IProps & typeof defaultProps) => {
3737
thumbColor,
3838
thumbResizeMode,
3939
thumbSize,
40+
disableSwipe,
4041
} = props;
4142

4243
const [activeIndex, setActiveIndex] = useState(0);
@@ -148,7 +149,11 @@ const ImageGallery = (props: IProps & typeof defaultProps) => {
148149
return (
149150
<Modal animationType={isOpen ? 'slide' : 'fade'} visible={isOpen}>
150151
<View style={styles.container}>
151-
<PanContainer setIsDragging={setIsDragging} close={close}>
152+
<SwipeContainer
153+
disableSwipe={disableSwipe}
154+
setIsDragging={setIsDragging}
155+
close={close}
156+
>
152157
<FlatList
153158
initialScrollIndex={initialIndex}
154159
getItemLayout={getImageLayout}
@@ -162,7 +167,7 @@ const ImageGallery = (props: IProps & typeof defaultProps) => {
162167
scrollEnabled={!isDragging}
163168
showsHorizontalScrollIndicator={false}
164169
/>
165-
</PanContainer>
170+
</SwipeContainer>
166171
{hideThumbs ? null : (
167172
<FlatList
168173
initialScrollIndex={initialIndex}

src/PanContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const PanContainer = ({
1414
setIsDragging,
1515
}: {
1616
children: any;
17-
close: any;
17+
close: () => void;
1818
setIsDragging: any;
1919
}) => {
2020
const translationXY = useRef(new Animated.ValueXY()).current;

src/SwipeContainer.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import PanContainer from './PanContainer';
3+
4+
const SwipeContainer = ({
5+
children,
6+
close,
7+
setIsDragging,
8+
disableSwipe,
9+
}: {
10+
children: any;
11+
close: () => void;
12+
setIsDragging: any;
13+
disableSwipe?: boolean;
14+
}) => {
15+
return disableSwipe ? (
16+
<>{children}</>
17+
) : (
18+
<PanContainer setIsDragging={setIsDragging} close={close}>
19+
{children}
20+
</PanContainer>
21+
);
22+
};
23+
24+
export default SwipeContainer;

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface IProps {
1111
thumbColor?: string;
1212
thumbSize?: number;
1313
thumbResizeMode?: ImageResizeMode;
14+
disableSwipe?: boolean;
1415

1516
renderCustomThumb?: (
1617
item: ImageObject,

0 commit comments

Comments
 (0)