@@ -13,8 +13,12 @@ import androidx.compose.foundation.shape.CircleShape
1313import androidx.compose.material.Icon
1414import androidx.compose.runtime.Composable
1515import androidx.compose.runtime.Immutable
16+ import androidx.compose.runtime.derivedStateOf
17+ import androidx.compose.runtime.getValue
18+ import androidx.compose.runtime.remember
1619import androidx.compose.ui.Alignment
1720import androidx.compose.ui.Modifier
21+ import androidx.compose.ui.draw.clip
1822import androidx.compose.ui.draw.shadow
1923import androidx.compose.ui.geometry.Offset
2024import androidx.compose.ui.graphics.Brush
@@ -56,6 +60,15 @@ internal fun DefaultOverlay(
5660 val thumbSize = overlayStyle.thumbSize
5761 val thumbPositionPercent = overlayStyle.thumbPositionPercent
5862
63+ val shadow by remember {
64+ derivedStateOf {
65+ if (thumbBackgroundColor == Color .Transparent ) {
66+ 0 .dp
67+ } else {
68+ thumbElevation
69+ }
70+ }
71+ }
5972
6073 var thumbPosX = position.x
6174 var thumbPosY = position.y
@@ -72,17 +85,16 @@ internal fun DefaultOverlay(
7285 val horizontalOffset = imageWidthInPx / 2
7386 val verticalOffset = imageHeightInPx / 2
7487
88+ val thumbMinY = - verticalOffset + thumbRadius
89+ val thumbMaxY = verticalOffset - thumbRadius
90+
7591 linePosition = thumbPosX.coerceIn(0f , imageWidthInPx)
7692 thumbPosX - = horizontalOffset
7793
7894 thumbPosY = if (verticalThumbMove) {
79- (thumbPosY - verticalOffset)
80- .coerceIn(
81- - verticalOffset + thumbRadius,
82- verticalOffset - thumbRadius
83- )
95+ (thumbPosY - verticalOffset).coerceIn(thumbMinY, thumbMaxY)
8496 } else {
85- (( imageHeightInPx * thumbPositionPercent / 100f - thumbRadius ) - verticalOffset)
97+ (imageHeightInPx * thumbPositionPercent / 100f ) - verticalOffset
8698 }
8799 }
88100
@@ -115,7 +127,8 @@ internal fun DefaultOverlay(
115127 .offset {
116128 IntOffset (thumbPosX.toInt(), thumbPosY.toInt())
117129 }
118- .shadow(thumbElevation, thumbShape)
130+ .clip(thumbShape)
131+ .shadow(shadow)
119132 .background(thumbBackgroundColor)
120133 .size(thumbSize)
121134 .padding(4 .dp)
@@ -150,5 +163,5 @@ class OverlayStyle(
150163 val thumbElevation : Dp = 2 .dp,
151164 @DrawableRes val thumbResource : Int = R .drawable.baseline_swap_horiz_24,
152165 val thumbSize : Dp = 36 .dp,
153- @FloatRange(from = 0.0 , to = 100.0 ) val thumbPositionPercent : Float = 85f ,
166+ @FloatRange(from = 0.0 , to = 100.0 ) val thumbPositionPercent : Float = 50f ,
154167)
0 commit comments