Skip to content

Commit c4513d6

Browse files
committed
fixes pan and pinch issue in android
1 parent bac909e commit c4513d6

File tree

6 files changed

+30
-21
lines changed

6 files changed

+30
-21
lines changed

example/CropImage.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import React from 'react';
2-
import {View, StyleSheet, TouchableOpacity, Text} from 'react-native';
2+
import {
3+
View,
4+
StyleSheet,
5+
TouchableOpacity,
6+
Text,
7+
Dimensions,
8+
} from 'react-native';
39
import Routes from './Routes';
410
import Crop from 'react-native-avatar-crop';
511

12+
const {width: SCREEN_WIDTH} = Dimensions.get('window');
13+
614
type CropImageProps = {
715
route: {params: {uri: string; width: number; height: number}};
816
navigation: {
@@ -43,11 +51,9 @@ const CropImage = ({route, navigation}: CropImageProps): JSX.Element => {
4351
<Crop
4452
source={{uri}}
4553
imageSize={{width, height}}
46-
width={300}
47-
height={300}
48-
cropArea={{width: 200, height: 150}}
49-
cropShape={'rect'}
50-
resizeMode={'contain'}
54+
width={SCREEN_WIDTH}
55+
height={SCREEN_WIDTH}
56+
cropArea={{width: SCREEN_WIDTH / 1.3, height: SCREEN_WIDTH / 1.3}}
5157
onCrop={cropCallback => (crop = cropCallback)}
5258
/>
5359
<View style={styles.padding20} />

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@react-navigation/stack": "^5.14.5",
1818
"react": "17.0.1",
1919
"react-native": "0.64.2",
20-
"react-native-avatar-crop": "^0.0.5",
20+
"react-native-avatar-crop": "^0.0.6",
2121
"react-native-gesture-handler": "^1.10.3",
2222
"react-native-image-picker": "^4.0.6",
2323
"react-native-image-size": "^1.1.3",

example/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5601,10 +5601,10 @@ react-is@^16.13.0, react-is@^16.7.0, react-is@^16.8.1:
56015601
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
56025602
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
56035603

5604-
react-native-avatar-crop@^0.0.5:
5605-
version "0.0.5"
5606-
resolved "https://registry.yarnpkg.com/react-native-avatar-crop/-/react-native-avatar-crop-0.0.5.tgz#46b04a791dcfcd15ae0e483d3716cc936a3dcaf0"
5607-
integrity sha512-3rZjgn9vC41jj9bO0GdwNcLQmAYodbG3pQWmMDfP3ddUO9sL93zEOm3E/ZSj4N3/5LBUCGW66euiHZlwAfu0og==
5604+
react-native-avatar-crop@^0.0.6:
5605+
version "0.0.6"
5606+
resolved "https://registry.yarnpkg.com/react-native-avatar-crop/-/react-native-avatar-crop-0.0.6.tgz#d8ab66db5015af950a37c4e46f62756a3e5283b0"
5607+
integrity sha512-ploV7UtMp0BfEs3meKloBeuGRd+VeX0PTOMtaH/s8TDIwhOeGD0zT/Go6VvkrIIUDKrwR8W26wbCk9/O5+rb3Q==
56085608

56095609
react-native-codegen@^0.0.6:
56105610
version "0.0.6"

package/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-avatar-crop",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "Crop component to crop profile images",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

package/src/crop/index.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,15 @@ const Crop = (props: CropProps): JSX.Element => {
358358
cropShape === 'circle' ? Math.max(cropArea.height, cropArea.width) : 0;
359359

360360
return (
361-
<PinchGestureHandler
362-
onGestureEvent={onPinchGestureEvent}
363-
onHandlerStateChange={onPinchGestureStateChange}>
364-
<PanGestureHandler
365-
onGestureEvent={onPanGestureEvent}
366-
onHandlerStateChange={onPanGestureStateChange}>
361+
<PanGestureHandler
362+
minPointers={1}
363+
maxPointers={1}
364+
onGestureEvent={onPanGestureEvent}
365+
onHandlerStateChange={onPanGestureStateChange}>
366+
<PinchGestureHandler
367+
minPointers={2}
368+
onGestureEvent={onPinchGestureEvent}
369+
onHandlerStateChange={onPinchGestureStateChange}>
367370
<View style={{width, height, backgroundColor}}>
368371
<MaskedView
369372
style={styles.mask}
@@ -419,8 +422,8 @@ const Crop = (props: CropProps): JSX.Element => {
419422
/>
420423
</View>
421424
</View>
422-
</PanGestureHandler>
423-
</PinchGestureHandler>
425+
</PinchGestureHandler>
426+
</PanGestureHandler>
424427
);
425428
};
426429

0 commit comments

Comments
 (0)