Skip to content

Commit

Permalink
Replace if with when in LeaningSideHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
ldeso committed Mar 29, 2024
1 parent 6563b07 commit 4a1d54c
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ enum class LeaningSide { LEFT, RIGHT }

/**
* Call [onLeaningSideChanged] when the side that the device is currently leaning towards, which is
* calculated from the orientation in degrees returned by [orientationProvider], changes from the
* current [LeaningSide] that is returned by [leaningSideProvider].
* calculated from the orientation in degrees returned by [orientationProvider], becomes different
* to the [LeaningSide] that is returned by [leaningSideProvider].
*/
@Composable
fun LeaningSideHandler(
Expand All @@ -35,9 +35,8 @@ fun LeaningSideHandler(
val orientation = orientationProvider()
val leaningSide = leaningSideProvider()

val isChangingFromLeftToRight = leaningSide == LeaningSide.LEFT && orientation in 10 until 170
val isChangingFromRightToLeft = leaningSide == LeaningSide.RIGHT && orientation in 190 until 350
if (isChangingFromLeftToRight || isChangingFromRightToLeft) {
onLeaningSideChanged()
when (leaningSide) {
LeaningSide.LEFT -> if (orientation in 10 until 170) onLeaningSideChanged()
LeaningSide.RIGHT -> if (orientation in 190 until 350) onLeaningSideChanged()
}
}

0 comments on commit 4a1d54c

Please sign in to comment.