mirror of
https://github.com/status-im/react-native-image-viewing.git
synced 2026-08-30 19:31:10 +00:00
Add option to disable double tap to zoom on Android
This commit is contained in:
@@ -59,17 +59,18 @@ const [visible, setIsVisible] = useState(false);
|
||||
|
||||
## Props
|
||||
|
||||
| Prop name | Description | Type | Required |
|
||||
| --------------------- | ----------------------------------------------------- | ----------------------- | -------- |
|
||||
| `images` | Array of images to display | ImageSource[] | true |
|
||||
| `imageIndex` | Current index of image to display | number | true |
|
||||
| `visible` | Is modal shown or not | boolean | true |
|
||||
| `onRequestClose` | Function called to close the modal | function | true |
|
||||
| `animationType` | Animation modal presented with: default `fade` | `none`, `fade`, `slide` | false |
|
||||
| `backgroundColor` | Background color of the modal in HEX (#000000EE) | string | false |
|
||||
| `swipeToCloseEnabled` | Close modal with swipe up or down: default `true` | boolean | false |
|
||||
| `HeaderComponent` | Header component, gets current `imageIndex` as a prop | component, function | false |
|
||||
| `FooterComponent` | Footer component, gets current `imageIndex` as a prop | component, function | false |
|
||||
| Prop name | Description | Type | Required |
|
||||
| ------------------------ | ------------------------------------------------------------- | ----------------------- | -------- |
|
||||
| `images` | Array of images to display | ImageSource[] | true |
|
||||
| `imageIndex` | Current index of image to display | number | true |
|
||||
| `visible` | Is modal shown or not | boolean | true |
|
||||
| `onRequestClose` | Function called to close the modal | function | true |
|
||||
| `animationType` | Animation modal presented with: default `fade` | `none`, `fade`, `slide` | false |
|
||||
| `backgroundColor` | Background color of the modal in HEX (#000000EE) | string | false |
|
||||
| `swipeToCloseEnabled` | Close modal with swipe up or down: default `true` | boolean | false |
|
||||
| `doubleTapToZoomEnabled` | Zoom image by double tap on it (Android only): default `true` | boolean | false |
|
||||
| `HeaderComponent` | Header component, gets current `imageIndex` as a prop | component, function | false |
|
||||
| `FooterComponent` | Footer component, gets current `imageIndex` as a prop | component, function | false |
|
||||
|
||||
- ImageSource is an object like { uri: '<http location || file path>' }
|
||||
|
||||
|
||||
@@ -34,13 +34,15 @@ type Props = {
|
||||
onRequestClose: () => void;
|
||||
onZoom: (isZoomed: boolean) => void;
|
||||
swipeToCloseEnabled?: boolean;
|
||||
doubleTapToZoomEnabled?: boolean;
|
||||
};
|
||||
|
||||
const ImageItem = ({
|
||||
imageSrc,
|
||||
onZoom,
|
||||
onRequestClose,
|
||||
swipeToCloseEnabled = true
|
||||
swipeToCloseEnabled = true,
|
||||
doubleTapToZoomEnabled = true
|
||||
}: Props) => {
|
||||
const imageContainer = React.createRef();
|
||||
const imageDimensions = useImageDimensions(imageSrc);
|
||||
@@ -62,7 +64,8 @@ const ImageItem = ({
|
||||
const [panHandlers, scaleValue, translateValue] = useZoomPanResponder({
|
||||
initialScale: scale || 1,
|
||||
initialTranslate: translate || { x: 0, y: 0 },
|
||||
onZoom: onZoomPerformed
|
||||
onZoom: onZoomPerformed,
|
||||
doubleTapToZoomEnabled
|
||||
});
|
||||
|
||||
const imagesStyles = getImageStyles(
|
||||
|
||||
Vendored
+1
@@ -14,6 +14,7 @@ declare type Props = {
|
||||
onRequestClose: () => void;
|
||||
onZoom: (isZoomed: boolean) => void;
|
||||
swipeToCloseEnabled?: boolean;
|
||||
doubleTapToZoomEnabled?: boolean;
|
||||
};
|
||||
|
||||
declare const _default: React.MemoExoticComponent<({
|
||||
|
||||
@@ -32,6 +32,7 @@ type Props = {
|
||||
animationType?: "none" | "fade" | "slide";
|
||||
backgroundColor?: string;
|
||||
swipeToCloseEnabled?: boolean;
|
||||
doubleTapToZoomEnabled?: boolean;
|
||||
HeaderComponent?: ComponentType<{ imageIndex: number }>;
|
||||
FooterComponent?: ComponentType<{ imageIndex: number }>;
|
||||
};
|
||||
@@ -49,6 +50,7 @@ function ImageViewing({
|
||||
animationType = DEFAULT_ANIMATION_TYPE,
|
||||
backgroundColor = DEFAULT_BG_COLOR,
|
||||
swipeToCloseEnabled,
|
||||
doubleTapToZoomEnabled,
|
||||
HeaderComponent,
|
||||
FooterComponent
|
||||
}: Props) {
|
||||
@@ -112,6 +114,7 @@ function ImageViewing({
|
||||
imageSrc={imageSrc}
|
||||
onRequestClose={onRequestCloseEnhanced}
|
||||
swipeToCloseEnabled={swipeToCloseEnabled}
|
||||
doubleTapToZoomEnabled={doubleTapToZoomEnabled}
|
||||
/>
|
||||
)}
|
||||
onMomentumScrollEnd={onScroll}
|
||||
|
||||
@@ -36,12 +36,14 @@ type Props = {
|
||||
initialScale: number;
|
||||
initialTranslate: Position;
|
||||
onZoom: (isZoomed: boolean) => void;
|
||||
doubleTapToZoomEnabled: boolean;
|
||||
};
|
||||
|
||||
const useZoomPanResponder = ({
|
||||
initialScale,
|
||||
initialTranslate,
|
||||
onZoom
|
||||
onZoom,
|
||||
doubleTapToZoomEnabled
|
||||
}: Props): Readonly<[
|
||||
GestureResponderHandlers,
|
||||
Animated.Value,
|
||||
@@ -129,7 +131,7 @@ const useZoomPanResponder = ({
|
||||
lastTapTS && tapTS - lastTapTS < DOUBLE_TAP_DELAY
|
||||
);
|
||||
|
||||
if (isDoubleTapPerformed) {
|
||||
if (doubleTapToZoomEnabled && isDoubleTapPerformed) {
|
||||
const isScaled = currentTranslate.x !== initialTranslate.x; // currentScale !== initialScale;
|
||||
const { pageX: touchX, pageY: touchY } = event.nativeEvent.touches[0];
|
||||
const targetScale = SCALE_MAX;
|
||||
@@ -184,7 +186,7 @@ const useZoomPanResponder = ({
|
||||
gestureState: PanResponderGestureState
|
||||
) => {
|
||||
// Don't need to handle move because double tap in progress (was handled in onStart)
|
||||
if (isDoubleTapPerformed) return;
|
||||
if (doubleTapToZoomEnabled && isDoubleTapPerformed) return;
|
||||
|
||||
if (
|
||||
numberInitialTouches === 1 &&
|
||||
|
||||
Reference in New Issue
Block a user