Skip to content

Commit e6ddc3b

Browse files
Merge pull request #16 from nisrulz/add/brush-overlay
Added dividerBrush to allow setting gradiant color
2 parents 14729fa + c92ce37 commit e6ddc3b

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ dependencies {
3737
}
3838
```
3939

40+
where `<version>` is one available in [![](https://www.jitpack.io/v/SmartToolFactory/Compose-BeforeAfter.svg)](https://www.jitpack.io/#SmartToolFactory/Compose-BeforeAfter)
41+
4042
## BeforeAfterImage
4143

4244
Image that takes two `ImageBitmaps as parameter and displays them based on specified order.
@@ -93,7 +95,7 @@ internal fun DefaultOverlay(
9395
height: Dp,
9496
position: Offset,
9597
overlayStyle: OverlayStyle
96-
)
98+
)
9799
```
98100

99101
```kotlin
@@ -226,7 +228,7 @@ fun BeforeAfterLayout(
226228
afterContent: @Composable () -> Unit,
227229
beforeLabel: @Composable BoxScope.() -> Unit = { BeforeLabel(contentOrder = contentOrder) },
228230
afterLabel: @Composable BoxScope.() -> Unit = { AfterLabel(contentOrder = contentOrder) },
229-
)
231+
)
230232
```
231233

232234

@@ -317,8 +319,8 @@ BeforeAfterLayout(
317319

318320
**Display before and after videos with Exoplayer**
319321

320-
### ⚠️ Note there is a bug with Exoplayer2.
321-
If you have a fix please open a PR or answer
322+
### ⚠️ Note there is a bug with Exoplayer2.
323+
If you have a fix please open a PR or answer
322324
[this question](https://stackoverflow.com/questions/73061216/exoplayer2-with-before-after-videos-changes-first-video-when-clip-and-shape-used)
323325
Both are appreciated greatly
324326

app/src/main/java/com/smarttoolfactory/composebeforeafter/demo/BeforeAfterImageDemo.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import androidx.compose.runtime.remember
2727
import androidx.compose.runtime.setValue
2828
import androidx.compose.ui.Modifier
2929
import androidx.compose.ui.draw.clip
30+
import androidx.compose.ui.graphics.Brush
3031
import androidx.compose.ui.graphics.Color
3132
import androidx.compose.ui.graphics.ImageBitmap
3233
import androidx.compose.ui.layout.ContentScale
@@ -103,7 +104,16 @@ fun BeforeAfterImageDemo() {
103104
.aspectRatio(4 / 3f),
104105
beforeImage = imageBefore,
105106
afterImage = imageAfter,
106-
contentScale = contentScale
107+
contentScale = contentScale,
108+
overlayStyle = OverlayStyle(
109+
dividerBrush = Brush.verticalGradient(
110+
listOf(
111+
Color.Red,
112+
Color.Blue,
113+
),
114+
),
115+
dividerWidth = 8.dp,
116+
)
107117
)
108118

109119
Spacer(modifier = Modifier.height(50.dp))

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import androidx.compose.ui.Alignment
1717
import androidx.compose.ui.Modifier
1818
import androidx.compose.ui.draw.shadow
1919
import androidx.compose.ui.geometry.Offset
20+
import androidx.compose.ui.graphics.Brush
2021
import androidx.compose.ui.graphics.Color
2122
import androidx.compose.ui.graphics.Shape
2223
import androidx.compose.ui.platform.LocalDensity
@@ -45,6 +46,7 @@ internal fun DefaultOverlay(
4546

4647
val verticalThumbMove = overlayStyle.verticalThumbMove
4748
val dividerColor = overlayStyle.dividerColor
49+
val dividerBrush = overlayStyle.dividerBrush
4850
val dividerWidth = overlayStyle.dividerWidth
4951
val thumbBackgroundColor = overlayStyle.thumbBackgroundColor
5052
val thumbTintColor = overlayStyle.thumbTintColor
@@ -90,7 +92,14 @@ internal fun DefaultOverlay(
9092
) {
9193
Canvas(modifier = Modifier.fillMaxSize()) {
9294

93-
drawLine(
95+
dividerBrush?.let {
96+
drawLine(
97+
dividerBrush,
98+
strokeWidth = dividerWidth.toPx(),
99+
start = Offset(linePosition, 0f),
100+
end = Offset(linePosition, size.height)
101+
)
102+
} ?: drawLine(
94103
dividerColor,
95104
strokeWidth = dividerWidth.toPx(),
96105
start = Offset(linePosition, 0f),
@@ -117,8 +126,9 @@ internal fun DefaultOverlay(
117126
/**
118127
* Values for styling [DefaultOverlay]
119128
* @param verticalThumbMove when true thumb can move vertically based on user touch
120-
* @param dividerColor color if divider line
121-
* @param dividerWidth width if divider line
129+
* @param dividerColor color of divider line
130+
* @param dividerBrush brush to set color gradiant in divider line
131+
* @param dividerWidth width of divider line
122132
* @param thumbBackgroundColor background color of thumb [Icon]
123133
* @param thumbTintColor tint color of thumb [Icon]
124134
* @param thumbShape shape of thumb [Icon]
@@ -131,6 +141,7 @@ internal fun DefaultOverlay(
131141
@Immutable
132142
class OverlayStyle(
133143
val dividerColor: Color = Color.White,
144+
val dividerBrush: Brush? = null,
134145
val dividerWidth: Dp = 1.5.dp,
135146
val verticalThumbMove: Boolean = false,
136147
val thumbBackgroundColor: Color = Color.White,

0 commit comments

Comments
 (0)