fix: Fix PreviewView overflowing on Android (#2001)

* fix: Run `addView` on UI Thread

* fix: Fix overflow of PreviewView
This commit is contained in:
Marc Rousavy 2023-10-14 13:17:05 +02:00 committed by GitHub
parent 315fcb68a8
commit fab5bdc0cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@ import android.view.Surface
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.UiThreadUtil
import com.mrousavy.camera.core.CameraPermissionError import com.mrousavy.camera.core.CameraPermissionError
import com.mrousavy.camera.core.CameraQueues import com.mrousavy.camera.core.CameraQueues
import com.mrousavy.camera.core.CameraSession import com.mrousavy.camera.core.CameraSession
@ -113,6 +114,7 @@ class CameraView(context: Context) :
init { init {
this.installHierarchyFitter() this.installHierarchyFitter()
clipToOutline = true
setupPreviewView() setupPreviewView()
cameraSession = CameraSession(context, cameraManager, { invokeOnInitialized() }, { error -> invokeOnError(error) }) cameraSession = CameraSession(context, cameraManager, { invokeOnInitialized() }, { error -> invokeOnError(error) })
} }
@ -156,8 +158,10 @@ class CameraView(context: Context) :
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
Gravity.CENTER Gravity.CENTER
) )
addView(previewView)
this.previewView = previewView this.previewView = previewView
UiThreadUtil.runOnUiThread {
addView(previewView)
}
} }
fun update(changedProps: ArrayList<String>) { fun update(changedProps: ArrayList<String>) {