Skip to content

Commit 2f22fe4

Browse files
authored
Added fadedEdge compose extension (#375)
1 parent 0d90afb commit 2f22fe4

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

core/ui/src/main/java/com/shifthackz/aisdv1/core/extensions/ComposableExtensions.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@ package com.shifthackz.aisdv1.core.extensions
33
import androidx.compose.foundation.clickable
44
import androidx.compose.foundation.interaction.MutableInteractionSource
55
import androidx.compose.material3.LocalTextStyle
6+
import androidx.compose.material3.MaterialTheme
67
import androidx.compose.runtime.Composable
78
import androidx.compose.runtime.remember
89
import androidx.compose.ui.Modifier
10+
import androidx.compose.ui.draw.drawWithContent
11+
import androidx.compose.ui.graphics.BlendMode
12+
import androidx.compose.ui.graphics.Brush
13+
import androidx.compose.ui.graphics.Color
14+
import androidx.compose.ui.graphics.CompositingStrategy
15+
import androidx.compose.ui.graphics.graphicsLayer
916
import androidx.compose.ui.platform.LocalDensity
1017
import androidx.compose.ui.text.TextStyle
1118
import androidx.compose.ui.text.rememberTextMeasurer
1219
import androidx.compose.ui.unit.Dp
20+
import androidx.compose.ui.unit.dp
1321
import com.shifthackz.aisdv1.core.common.extensions.EmptyLambda
1422

1523
@Composable
@@ -25,3 +33,20 @@ fun measureTextWidth(text: String, style: TextStyle = LocalTextStyle.current): D
2533
val widthInPixels = textMeasurer.measure(text, style).size.width
2634
return with(LocalDensity.current) { widthInPixels.toDp() }
2735
}
36+
37+
@Composable
38+
fun Modifier.fadedEdge(color: Color = MaterialTheme.colorScheme.background, gradientOffset: Dp = 0.dp) =
39+
graphicsLayer(compositingStrategy = CompositingStrategy.Offscreen)
40+
.drawWithContent {
41+
drawContent()
42+
drawRect(
43+
brush = Brush.verticalGradient(
44+
startY = gradientOffset.toPx(),
45+
colors = listOf(
46+
color,
47+
Color.Transparent,
48+
)
49+
),
50+
blendMode = BlendMode.DstIn,
51+
)
52+
}

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/donate/DonateScreen.kt

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package com.shifthackz.aisdv1.presentation.screen.donate
44

55
import androidx.compose.animation.AnimatedContent
6-
import androidx.compose.foundation.Canvas
76
import androidx.compose.foundation.Image
87
import androidx.compose.foundation.layout.Arrangement
98
import androidx.compose.foundation.layout.Box
@@ -38,7 +37,6 @@ import androidx.compose.ui.Modifier
3837
import androidx.compose.ui.draw.clip
3938
import androidx.compose.ui.draw.drawBehind
4039
import androidx.compose.ui.geometry.CornerRadius
41-
import androidx.compose.ui.graphics.Brush
4240
import androidx.compose.ui.graphics.Color
4341
import androidx.compose.ui.layout.ContentScale
4442
import androidx.compose.ui.platform.LocalContext
@@ -49,6 +47,7 @@ import androidx.compose.ui.tooling.preview.Preview
4947
import androidx.compose.ui.unit.dp
5048
import androidx.compose.ui.unit.sp
5149
import com.shifthackz.aisdv1.core.common.extensions.openUrl
50+
import com.shifthackz.aisdv1.core.extensions.fadedEdge
5251
import com.shifthackz.aisdv1.domain.entity.Supporter
5352
import com.shifthackz.aisdv1.presentation.widget.item.SupporterItem
5453
import com.shifthackz.android.core.mvi.MviComponent
@@ -175,11 +174,12 @@ private fun DonateScreenContent(
175174
) { contentVisible ->
176175
if (contentVisible) {
177176
if (state.supporters.isNotEmpty()) {
177+
val shadowHeight = 150.dp
178178
Box(
179-
modifier = Modifier.fillMaxSize(),
179+
modifier = Modifier.fillMaxSize()
180+
.fadedEdge(gradientOffset = shadowHeight),
180181
contentAlignment = Alignment.BottomCenter,
181182
) {
182-
val shadowHeight = 150.dp
183183
LazyColumn(
184184
modifier = Modifier.fillMaxSize(),
185185
) {
@@ -227,19 +227,6 @@ private fun DonateScreenContent(
227227
Spacer(modifier = Modifier.height(shadowHeight + 32.dp))
228228
}
229229
}
230-
val shadowGradient = Brush.verticalGradient(
231-
listOf(
232-
Color.Transparent,
233-
MaterialTheme.colorScheme.background,
234-
)
235-
)
236-
Canvas(
237-
modifier = Modifier
238-
.fillMaxWidth()
239-
.height(shadowHeight),
240-
) {
241-
drawRect(shadowGradient)
242-
}
243230
}
244231
}
245232
} else {

0 commit comments

Comments
 (0)