Skip to content

Commit

Permalink
fix: Stop orientation listener updates on camera close (#3139)
Browse files Browse the repository at this point in the history
* Fix: clear orientation listener on close

* fix: Rename and move comment

---------

Co-authored-by: Marc Rousavy <[email protected]>
  • Loading branch information
ldalzottomp and mrousavy authored Aug 20, 2024
1 parent d88d819 commit 54dbf5f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class CameraSession(internal val context: Context, internal val callback: Callba
override fun close() {
Log.i(TAG, "Closing CameraSession...")
isDestroyed = true
orientationManager.stopOrientationUpdates()
runOnUiThread {
lifecycleRegistry.currentState = Lifecycle.State.DESTROYED
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,17 @@ class OrientationManager(private val context: Context, private val callback: Cal
}
}

fun stopOrientationUpdates() {
displayManager.unregisterDisplayListener(displayListener)
orientationListener.disable()
}

fun setTargetOutputOrientation(targetOrientation: OutputOrientation) {
Log.i(TAG, "Target Orientation changed $targetOutputOrientation -> $targetOrientation!")
targetOutputOrientation = targetOrientation

// remove previous listeners if attached
displayManager.unregisterDisplayListener(displayListener)
orientationListener.disable()
// remove previous listeners if we have any
stopOrientationUpdates()

when (targetOrientation) {
OutputOrientation.DEVICE -> {
Expand Down

0 comments on commit 54dbf5f

Please sign in to comment.