Skip to content

Commit 3814471

Browse files
add OverLayStyle for setting default overlay properties
1 parent dda21b9 commit 3814471

File tree

1 file changed

+44
-21
lines changed

1 file changed

+44
-21
lines changed

image/src/main/java/com/smarttoolfactory/image/beforeafter/DefaultOverlay.kt

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.*
88
import androidx.compose.foundation.shape.CircleShape
99
import androidx.compose.material.Icon
1010
import androidx.compose.runtime.Composable
11+
import androidx.compose.runtime.Immutable
1112
import androidx.compose.ui.Alignment
1213
import androidx.compose.ui.Modifier
1314
import androidx.compose.ui.draw.shadow
@@ -30,33 +31,27 @@ import com.smarttoolfactory.image.R
3031
* @param height of the [BeforeAfterImage] or [BeforeAfterLayout]. You should get height from
3132
* scope of these Composables and pass to calculate bounds correctly
3233
* @param position current position or progress of before/after
33-
* @param verticalThumbMove when true thumb can move vertically based on user touch
34-
* @param lineColor color if divider line
35-
* @param thumbBackgroundColor background color of thumb [Icon]
36-
* @param thumbTintColor tint color of thumb [Icon]
37-
* @param thumbShape shape of thumb [Icon]
38-
* @param thumbElevation elevation of thumb [Icon]
39-
* @param thumbResource drawable resource that should be used with thumb
40-
* @param thumbSize size of the thumb in dp
41-
* @param thumbPositionPercent vertical position of thumb if [verticalThumbMove] is false
42-
* It's between [0f-100f] to set thumb's vertical position in layout
4334
*/
4435
@Composable
4536
internal fun DefaultOverlay(
4637
width: Dp,
4738
height: Dp,
4839
position: Offset,
49-
verticalThumbMove: Boolean = false,
50-
lineColor: Color = Color.White,
51-
thumbBackgroundColor: Color = Color.White,
52-
thumbTintColor: Color = Color.Gray,
53-
thumbShape: Shape = CircleShape,
54-
thumbElevation: Dp = 2.dp,
55-
@DrawableRes thumbResource: Int = R.drawable.baseline_swap_horiz_24,
56-
thumbSize: Dp = 36.dp,
57-
@FloatRange(from = 0.0, to = 100.0) thumbPositionPercent: Float = 85f,
40+
overlayStyle: OverlayStyle
5841
) {
5942

43+
val verticalThumbMove = overlayStyle.verticalThumbMove
44+
val dividerColor = overlayStyle.dividerColor
45+
val dividerWidth = overlayStyle.dividerWidth
46+
val thumbBackgroundColor = overlayStyle.thumbBackgroundColor
47+
val thumbTintColor = overlayStyle.thumbTintColor
48+
val thumbShape = overlayStyle.thumbShape
49+
val thumbElevation = overlayStyle.thumbElevation
50+
val thumbResource = overlayStyle.thumbResource
51+
val thumbSize = overlayStyle.thumbSize
52+
val thumbPositionPercent = overlayStyle.thumbPositionPercent
53+
54+
6055
var thumbPosX = position.x
6156
var thumbPosY = position.y
6257

@@ -93,8 +88,8 @@ internal fun DefaultOverlay(
9388
Canvas(modifier = Modifier.fillMaxSize()) {
9489

9590
drawLine(
96-
lineColor,
97-
strokeWidth = 1.5.dp.toPx(),
91+
dividerColor,
92+
strokeWidth = dividerWidth.toPx(),
9893
start = Offset(linePosition, 0f),
9994
end = Offset(linePosition, size.height)
10095
)
@@ -115,3 +110,31 @@ internal fun DefaultOverlay(
115110
)
116111
}
117112
}
113+
114+
/**
115+
* Values for styling [DefaultOverlay]
116+
* @param verticalThumbMove when true thumb can move vertically based on user touch
117+
* @param dividerColor color if divider line
118+
* @param dividerWidth width if divider line
119+
* @param thumbBackgroundColor background color of thumb [Icon]
120+
* @param thumbTintColor tint color of thumb [Icon]
121+
* @param thumbShape shape of thumb [Icon]
122+
* @param thumbElevation elevation of thumb [Icon]
123+
* @param thumbResource drawable resource that should be used with thumb
124+
* @param thumbSize size of the thumb in dp
125+
* @param thumbPositionPercent vertical position of thumb if [verticalThumbMove] is false
126+
* It's between [0f-100f] to set thumb's vertical position in layout
127+
*/
128+
@Immutable
129+
class OverlayStyle(
130+
val dividerColor: Color = Color.White,
131+
val dividerWidth: Dp = 1.5.dp,
132+
val verticalThumbMove: Boolean = false,
133+
val thumbBackgroundColor: Color = Color.White,
134+
val thumbTintColor: Color = Color.Gray,
135+
val thumbShape: Shape = CircleShape,
136+
val thumbElevation: Dp = 2.dp,
137+
@DrawableRes val thumbResource: Int = R.drawable.baseline_swap_horiz_24,
138+
val thumbSize: Dp = 36.dp,
139+
@FloatRange(from = 0.0, to = 100.0) val thumbPositionPercent: Float = 85f,
140+
)

0 commit comments

Comments
 (0)