Skip to content

Commit

Permalink
Fix SegmentedSwitch rendering in RTL (#452)
Browse files Browse the repository at this point in the history
fix SegmentedSwitch rendering in RTL
  • Loading branch information
hrach committed Jun 8, 2023
1 parent 90af80d commit 05d85e1
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions ui/src/main/java/kiwi/orbit/compose/ui/controls/SegmentedSwitch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import kiwi.orbit.compose.ui.OrbitTheme
import kiwi.orbit.compose.ui.controls.field.FieldMessage
Expand Down Expand Up @@ -241,19 +243,24 @@ private fun SelectionOutline(
label = "SegmentedSwitchSelectedOffset",
)
val brushColor = OrbitTheme.colors.info.normal
val isRtl = LocalLayoutDirection.current == LayoutDirection.Rtl
Canvas(
modifier = Modifier
.padding(1.dp)
.fillMaxSize(),
onDraw = {
val size = size.copy(width = size.width / optionsCount)
val rectSize = size.copy(width = size.width / optionsCount)
val topLeft = Offset(
x = when (isRtl) {
false -> animatedOffset * rectSize.width
true -> size.width - ((animatedOffset + 1) * rectSize.width)
},
y = 0f,
)
drawRoundRect(
brush = SolidColor(brushColor),
topLeft = Offset(
x = animatedOffset * size.width,
y = 0f,
),
size = size,
topLeft = topLeft,
size = rectSize,
cornerRadius = CornerRadius(5.dp.toPx(), 5.dp.toPx()),
style = Stroke(width = 2.dp.toPx()),
)
Expand Down

0 comments on commit 05d85e1

Please sign in to comment.