fix: Apply correct initial rotation on Android (#368)
* fix: Apply correct initial rotation * Make `rotation` a property getter * Update CameraView.kt
This commit is contained in:
@@ -109,12 +109,14 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
|
||||
private val scaleGestureListener: ScaleGestureDetector.SimpleOnScaleGestureListener
|
||||
private val scaleGestureDetector: ScaleGestureDetector
|
||||
private val touchEventListener: OnTouchListener
|
||||
private val orientationEventListener: OrientationEventListener
|
||||
|
||||
private val lifecycleRegistry: LifecycleRegistry
|
||||
private var hostLifecycleState: Lifecycle.State
|
||||
|
||||
private var rotation: Int = Surface.ROTATION_0
|
||||
private val rotation: Int
|
||||
get() {
|
||||
return context.displayRotation
|
||||
}
|
||||
|
||||
private var minZoom: Float = 1f
|
||||
private var maxZoom: Float = 1f
|
||||
@@ -169,17 +171,7 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
|
||||
}
|
||||
scaleGestureDetector = ScaleGestureDetector(context, scaleGestureListener)
|
||||
touchEventListener = OnTouchListener { _, event -> return@OnTouchListener scaleGestureDetector.onTouchEvent(event) }
|
||||
orientationEventListener = object : OrientationEventListener(context) {
|
||||
override fun onOrientationChanged(orientation : Int) {
|
||||
rotation = when (orientation) {
|
||||
in 45..134 -> Surface.ROTATION_270
|
||||
in 135..224 -> Surface.ROTATION_180
|
||||
in 225..314 -> Surface.ROTATION_90
|
||||
else -> Surface.ROTATION_0
|
||||
}
|
||||
}
|
||||
}
|
||||
orientationEventListener.enable()
|
||||
|
||||
|
||||
hostLifecycleState = Lifecycle.State.INITIALIZED
|
||||
lifecycleRegistry = LifecycleRegistry(this)
|
||||
@@ -216,7 +208,6 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
|
||||
|
||||
fun finalize() {
|
||||
mHybridData.resetNative()
|
||||
orientationEventListener.disable()
|
||||
}
|
||||
|
||||
private external fun initHybrid(): HybridData
|
||||
@@ -275,7 +266,7 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
|
||||
configureSession()
|
||||
}
|
||||
if (shouldReconfigureZoom) {
|
||||
val zoomClamped = max(min(zoom.toFloat(), maxZoom), minZoom)
|
||||
val zoomClamped = max(min(zoom, maxZoom), minZoom)
|
||||
camera!!.cameraControl.setZoomRatio(zoomClamped)
|
||||
}
|
||||
if (shouldReconfigureTorch) {
|
||||
|
||||
Reference in New Issue
Block a user