@@ -15,11 +15,9 @@ import {
1515 Platform ,
1616} from 'react-native' ;
1717import {
18- HandlerStateChangeEvent ,
19- TapGestureHandler ,
20- PinchGestureHandler ,
21- State ,
22- GestureEvent ,
18+ GestureDetector ,
19+ Gesture ,
20+ GestureStateChangeEvent ,
2321} from 'react-native-gesture-handler' ;
2422import { ImageComponentOptionalProps , ImageComponentProps , ImageComponentState } from './types' ;
2523
@@ -157,8 +155,8 @@ class Image extends React.Component<ImageComponentProps, ImageComponentState> {
157155 private _getMaximumScale = ( ) : number => 2.5 ;
158156 private _getMinimumScale = ( ) : number => 1.0 ;
159157
160- private _handleImageZoomInOut = ( evt : HandlerStateChangeEvent ) => {
161- this . _debug ( 'double tab triggered' , '_scaleNum' , this . _lastScale , evt . nativeEvent , 'ratio' , this . _getRatio ( ) ) ;
158+ private _handleImageZoomInOut = ( evt : GestureStateChangeEvent < any > ) => {
159+ this . _debug ( 'double tab triggered' , '_scaleNum' , this . _lastScale , evt , 'ratio' , this . _getRatio ( ) ) ;
162160
163161 if ( this . _lastScale > this . _getMinimumScale ( ) ) {
164162 this . _translateXY . setOffset ( { x : 0 , y : 0 } ) ;
@@ -187,8 +185,8 @@ class Image extends React.Component<ImageComponentProps, ImageComponentState> {
187185 const newHeight = scale * oldHeight ;
188186 const padding = 50 ;
189187
190- let x = evt . nativeEvent . x as number ;
191- let y = evt . nativeEvent . y as number ;
188+ let x = evt . x as number ;
189+ let y = evt . y as number ;
192190
193191 const horizontalCenter = ( newWidth - SCREEN_WIDTH ) / 2 ;
194192 const verticalCenter = ( newHeight - SCREEN_HEIGHT ) / 2 ;
@@ -257,49 +255,45 @@ class Image extends React.Component<ImageComponentProps, ImageComponentState> {
257255
258256 private _onImageLoadEnd = ( ) => this . setState ( { loading : false } ) ;
259257
260- private _onPinchHandlerStateChange = ( evt : HandlerStateChangeEvent ) => {
261- if ( evt . nativeEvent . oldState === State . ACTIVE ) {
262- this . _debug ( '_onPinchHandlerStateChange' , evt . nativeEvent ) ;
258+ private _onPinchEnd = ( evt : GestureStateChangeEvent < any > ) => {
259+ this . _debug ( '_onPinchEnd' , evt ) ;
263260
264- let scale = evt . nativeEvent . scale as number ;
265- if ( scale < this . _getMinimumScale ( ) ) {
266- scale = this . _getMinimumScale ( ) ;
261+ let scale = evt . scale as number ;
262+ if ( scale < this . _getMinimumScale ( ) ) {
263+ scale = this . _getMinimumScale ( ) ;
267264
268- this . _setIsZooming ( false ) ;
269- } else {
270- scale = Math . min ( this . _getMaximumScale ( ) , scale ) ;
271- this . _setIsZooming ( true ) ;
272- }
265+ this . _setIsZooming ( false ) ;
266+ } else {
267+ scale = Math . min ( this . _getMaximumScale ( ) , scale ) ;
268+ this . _setIsZooming ( true ) ;
269+ }
273270
274- this . _lastScale = scale ;
271+ this . _lastScale = scale ;
275272
276- this . _translateXY . setOffset ( { x : 0 , y : 0 } ) ;
277- this . _lastOffset = { x : 0 , y : 0 } ;
278- Animated . parallel ( [
279- Animated . timing ( this . _scale , {
280- toValue : scale ,
281- duration : 250 ,
282- useNativeDriver : true ,
283- } ) ,
284- Animated . timing ( this . _translateXY , {
285- toValue : { x : 0 , y : 0 } ,
286- duration : 250 ,
287- useNativeDriver : true ,
288- } ) ,
289- ] ) . start ( ) ;
290- }
273+ this . _translateXY . setOffset ( { x : 0 , y : 0 } ) ;
274+ this . _lastOffset = { x : 0 , y : 0 } ;
275+ Animated . parallel ( [
276+ Animated . timing ( this . _scale , {
277+ toValue : scale ,
278+ duration : 250 ,
279+ useNativeDriver : true ,
280+ } ) ,
281+ Animated . timing ( this . _translateXY , {
282+ toValue : { x : 0 , y : 0 } ,
283+ duration : 250 ,
284+ useNativeDriver : true ,
285+ } ) ,
286+ ] ) . start ( ) ;
291287 } ;
292- private _onPinchGestureEvent = ( evt : GestureEvent ) => {
293- if ( evt . nativeEvent . state === State . ACTIVE ) {
294- const scale = this . _lastScale * ( evt . nativeEvent . scale as number ) ;
288+ private _onPinchUpdate = ( evt : GestureStateChangeEvent < any > ) => {
289+ const scale = this . _lastScale * ( evt . scale as number ) ;
295290
296- if ( scale < this . _getMinimumScale ( ) ) {
297- this . _scale . setValue ( this . _getMinimumScale ( ) ) ;
298- this . _setIsZooming ( false ) ;
299- } else {
300- this . _scale . setValue ( Math . min ( this . _getMaximumScale ( ) , scale ) ) ;
301- this . _setIsZooming ( true ) ;
302- }
291+ if ( scale < this . _getMinimumScale ( ) ) {
292+ this . _scale . setValue ( this . _getMinimumScale ( ) ) ;
293+ this . _setIsZooming ( false ) ;
294+ } else {
295+ this . _scale . setValue ( Math . min ( this . _getMaximumScale ( ) , scale ) ) ;
296+ this . _setIsZooming ( true ) ;
303297 }
304298 } ;
305299
@@ -373,6 +367,18 @@ class Image extends React.Component<ImageComponentProps, ImageComponentState> {
373367 return < Animated . View style = { footerAnim } > { innerComponent } </ Animated . View > ;
374368 } ;
375369
370+ private _gestureDoubleTap = ( ) => Gesture . Tap ( ) . maxDuration ( 250 ) . numberOfTaps ( 2 ) . onStart ( ( evt ) => {
371+ console . log ( '_gestureDoubleTap' , 'onStart' ) ;
372+ this . _handleImageZoomInOut ( evt ) ;
373+ } ) ;
374+ private _gesturePinch = ( ) => Gesture . Pinch ( ) . onEnd ( ( evt ) => {
375+ console . log ( '_gesturePinch' , 'onEnd' ) ;
376+ this . _onPinchEnd ( evt ) ;
377+ } ) . onUpdate ( ( evt ) => {
378+ console . log ( '_gesturePinch' , 'onUpdate' , evt ) ;
379+ this . _onPinchUpdate ( evt ) ;
380+ } ) ;
381+
376382 static getDerivedStateFromProps (
377383 nextProps : Readonly < ImageComponentProps > ,
378384 prevState : Readonly < ImageComponentState >
@@ -442,14 +448,9 @@ class Image extends React.Component<ImageComponentProps, ImageComponentState> {
442448 style = { moveObjStyle }
443449 { ...( this . state . isZooming || Platform . OS === 'ios' ? this . _panResponder . panHandlers : { } ) }
444450 renderToHardwareTextureAndroid >
445- < TapGestureHandler numberOfTaps = { 2 } onActivated = { this . _handleImageZoomInOut } >
446- < PinchGestureHandler
447- onGestureEvent = { this . _onPinchGestureEvent }
448- onHandlerStateChange = { this . _onPinchHandlerStateChange }
449- >
450- < RNImage source = { this . props . source } style = { computeImageStyle } onLoadEnd = { this . _onImageLoadEnd } />
451- </ PinchGestureHandler >
452- </ TapGestureHandler >
451+ < GestureDetector gesture = { Gesture . Exclusive ( this . _gestureDoubleTap ( ) , this . _gesturePinch ( ) ) } >
452+ < RNImage source = { this . props . source } style = { computeImageStyle } onLoadEnd = { this . _onImageLoadEnd } />
453+ </ GestureDetector >
453454 </ Animated . View >
454455 < SafeAreaView style = { styles . safeAreaContainer } pointerEvents = "none" >
455456 { this . _renderHeader ( ) }
0 commit comments