fix: Fix Only the original thread that created a view hierarchy can touch it's views error (#2278)

* fix: Fix `Only the original thread that created a view hierarchy can touch its views` error

* fix: Also call `SurfaceHolder` method on UI Thread
This commit is contained in:
Marc Rousavy 2023-12-12 12:00:29 +01:00 committed by GitHub
parent 7fccee226c
commit 263065048c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,6 +9,7 @@ import android.view.Gravity
import android.view.SurfaceHolder
import android.view.SurfaceView
import android.widget.FrameLayout
import com.facebook.react.bridge.UiThreadUtil
import com.mrousavy.camera.extensions.bigger
import com.mrousavy.camera.extensions.getMaximumPreviewSize
import com.mrousavy.camera.extensions.getPreviewTargetSize
@ -21,19 +22,21 @@ import kotlin.math.roundToInt
class PreviewView(context: Context, callback: SurfaceHolder.Callback) : SurfaceView(context) {
var size: Size = getMaximumPreviewSize()
set(value) {
field = value
UiThreadUtil.runOnUiThread {
Log.i(TAG, "Resizing PreviewView to ${value.width} x ${value.height}...")
holder.setFixedSize(value.width, value.height)
requestLayout()
invalidate()
field = value
}
}
var resizeMode: ResizeMode = ResizeMode.COVER
set(value) {
if (value != field) {
field = value
UiThreadUtil.runOnUiThread {
requestLayout()
invalidate()
}
field = value
}
init {