Skip to content

Commit

Permalink
fix: Fix Camera not starting because PreviewView isn't laid out
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Mar 18, 2024
1 parent babed3c commit ad746d5
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions package/android/src/main/java/com/mrousavy/camera/CameraView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ class CameraView(context: Context) :
private var fpsGraph: FpsGraphView? = null

init {
this.installHierarchyFitter()
clipToOutline = true
cameraSession = CameraSession(context, this)
previewView = PreviewView(context).also {
it.installHierarchyFitter()
it.implementationMode = PreviewView.ImplementationMode.PERFORMANCE
it.layoutParams = LayoutParams(
LayoutParams.MATCH_PARENT,
Expand All @@ -142,21 +142,6 @@ class CameraView(context: Context) :
}
}

override fun onLayout(
changed: Boolean,
left: Int,
top: Int,
right: Int,
bottom: Int
) {
val width = right - left
val height = bottom - top

// In React Native, subview layouts aren't automatically updated - so we manually re-layout the PreviewView.
previewView.layout(0, 0, width, height)
postInvalidate(left, top, right, bottom)
}

fun destroy() {
cameraSession.close()
}
Expand Down

0 comments on commit ad746d5

Please sign in to comment.