世博相机变焦

5 javascript android ios react-native expo

这是我第一次在 React Native 中使用捏合手势处理程序...我正在尝试使用 Expo 创建一个可缩放相机。我正在做的是:

const handlePinch = (nativeEvent) => {
   const { scale, velocity } = nativeEvent;

   let newZoom =
     velocity > 0
       ? zoom + scale * velocity * (Platform.OS === "ios" ? 0.01 : 25)
       : zoom -
         scale * Math.abs(velocity) * (Platform.OS === "ios" ? 0.02 : 50);

   if (newZoom < 0) newZoom = 0;
   else if (newZoom > 0.5) newZoom = 0.5;

   setZoom(newZoom);
};

...

<ExpoCamera
    ...
    zoom={zoom}
    ...
  >
Run Code Online (Sandbox Code Playgroud)

工作但不太顺利...有没有更好的方法来做到这一点?