fix: Fix PreviewView stretching on Android (now finally a real fix) (#2564)

* fix: Only resolve once SurfaceHolder actually resized

* fix: Fix onMeasure not being called for `PreviewView`

* fix: Auto-trigger layout computation on Surface Change

* fix: Add proper LayoutParams to `PreviewView`

* Format
This commit is contained in:
Marc Rousavy
2024-02-15 13:09:16 +01:00
committed by GitHub
parent 21042048ae
commit 5df5ca9adf
3 changed files with 52 additions and 31 deletions

View File

@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.content.Context
import android.hardware.camera2.CameraManager
import android.util.Log
import android.view.Gravity
import android.view.ScaleGestureDetector
import android.widget.FrameLayout
import com.facebook.react.bridge.ReadableMap
@@ -110,6 +111,11 @@ class CameraView(context: Context) :
clipToOutline = true
cameraSession = CameraSession(context, cameraManager, this)
previewView = cameraSession.createPreviewView(context)
previewView.layoutParams = LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT,
Gravity.CENTER
)
addView(previewView)
}