@@ -226,7 +226,8 @@ private fun setupInteractionControls(
226226 var shouldIgnoreScroll = false
227227 val handler = Handler (Looper .getMainLooper())
228228 var resetIgnore: Runnable ? = null
229-
229+ var initialZoomLevel = 0f
230+ var accumulatedDelta = 0f
230231 // Pinch-to-zoom gesture detector
231232 val scaleGestureDetector = ScaleGestureDetector (
232233 previewView.context,
@@ -254,6 +255,7 @@ private fun setupInteractionControls(
254255 }
255256
256257 override fun onScaleEnd (detector : ScaleGestureDetector ) {
258+ initialZoomLevel = cameraInfo.zoomState.value?.zoomRatio ? : 1f
257259 resetIgnore = Runnable { shouldIgnoreScroll = false }
258260 previewView.postDelayed(resetIgnore, 500 )
259261 }
@@ -263,9 +265,10 @@ private fun setupInteractionControls(
263265 val gestureDetector = GestureDetector (
264266 previewView.context,
265267 object : GestureDetector .OnGestureListener {
266- private var accumulatedDelta = 0f
268+
267269
268270 override fun onDown (e : MotionEvent ): Boolean {
271+ initialZoomLevel = cameraInfo.zoomState.value?.zoomRatio ? : 1f
269272 accumulatedDelta = 0f
270273 return true
271274 }
@@ -292,7 +295,6 @@ private fun setupInteractionControls(
292295 accumulatedDelta + = distanceY
293296
294297 val deltaZoom = accumulatedDelta / 1000f
295- val initialZoomLevel = cameraInfo.zoomState.value?.zoomRatio ? : 1f
296298 val maxZoom = cameraInfo.zoomState.value?.maxZoomRatio ? : 1f
297299 val minZoom = cameraInfo.zoomState.value?.minZoomRatio ? : 1f
298300
@@ -321,6 +323,7 @@ private fun setupInteractionControls(
321323
322324 if (event.action == MotionEvent .ACTION_UP ) {
323325 animateZoomReset(cameraInfo, cameraControl)
326+ initialZoomLevel = cameraInfo.zoomState.value?.zoomRatio ? : 1f
324327 }
325328 }
326329 true
0 commit comments