Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PinchGestureHandler not working on android

Tags:

react-native

import React from 'react'
import {View,Image,Animated, Button} from 'react-native'
import {PinchGestureHandler} from 'react-native-gesture-handler'
export default function pinchZoom(){
const scale=React.useRef(new Animated.Value(1)).current;
const HandlePinch=new Animated.event(
  [{nativeEvent:{scale:scale}}]
  ,
  {
    useNativeDriver: false
  })
const anime=new Animated.ValueXY(0,0)
    return(
      <View style={{flex:1}}>
      <PinchGestureHandler onGestureEvent={HandlePinch}>
         <Animated.Image source={{uri:'https://i.ytimg.com/vi/Z4ls0-ZGnU4/maxresdefault.jpg'}}
         style={{height:250,width:'100%',transform:[{scale:scale}]}}
         />
      </PinchGestureHandler>

      </View>
    )

}

i have an android device, and it is not working, dont know why please help!!!!! beside this PanGestureHandler working perfectly

like image 310
Vivek sharma Avatar asked May 11 '26 17:05

Vivek sharma


1 Answers

Enclose the <PinchGestureHandler> with <GestureHandlerRootView>

It should look like this:

<GestureHandlerRootView> 
 <PinchGestureHandler onGestureEvent={HandlePinch}>
         <Animated.Image source={{uri:'https://i.ytimg.com/vi/Z4ls0-ZGnU4/maxresdefault.jpg'}}
         style={{height:250,width:'100%',transform:[{scale:scale}]}}
         />
      </PinchGestureHandler>
</GestureHandlerRootView>

And don't forget to import it from react-native-gesture-handler

like image 159
Deepak Yadav Avatar answered May 14 '26 08:05

Deepak Yadav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!