Skip to content

Commit bc7ad47

Browse files
committed
chore(accounthome): move version info to BottomBar; draw with gradient
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent c364904 commit bc7ad47

2 files changed

Lines changed: 154 additions & 10 deletions

File tree

app/src/main/java/com/getcode/ui/utils/Modifier.kt

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import androidx.compose.foundation.border
77
import androidx.compose.foundation.clickable
88
import androidx.compose.foundation.combinedClickable
99
import androidx.compose.foundation.interaction.MutableInteractionSource
10+
import androidx.compose.foundation.lazy.LazyListState
11+
import androidx.compose.foundation.lazy.grid.LazyGridState
1012
import androidx.compose.material.ripple.rememberRipple
1113
import androidx.compose.runtime.Composable
1214
import androidx.compose.runtime.getValue
@@ -27,6 +29,7 @@ import androidx.compose.ui.graphics.RectangleShape
2729
import androidx.compose.ui.graphics.Shape
2830
import androidx.compose.ui.graphics.drawscope.ContentDrawScope
2931
import androidx.compose.ui.graphics.graphicsLayer
32+
import androidx.compose.ui.graphics.takeOrElse
3033
import androidx.compose.ui.input.pointer.pointerInteropFilter
3134
import androidx.compose.ui.layout.layout
3235
import androidx.compose.ui.layout.onPlaced
@@ -37,6 +40,7 @@ import androidx.compose.ui.unit.DpSize
3740
import androidx.compose.ui.unit.dp
3841
import androidx.compose.ui.unit.offset
3942
import com.getcode.theme.BrandLight
43+
import com.getcode.theme.CodeTheme
4044

4145
inline fun Modifier.addIf(
4246
predicate: Boolean,
@@ -235,4 +239,130 @@ fun Modifier.drawWithGradient(
235239
blendMode = blendMode
236240
)
237241
}
242+
}
243+
244+
private val gradientSize
245+
@Composable get() = CodeTheme.dimens.staticGrid.x8
246+
247+
fun Modifier.verticalScrollStateGradient(
248+
scrollState: LazyListState,
249+
color: Color = Color.Unspecified,
250+
showAtStart: Boolean = true,
251+
showAtEnd: Boolean = true,
252+
isLongGradient: Boolean = false,
253+
): Modifier = composed {
254+
val backgroundColor = color.takeOrElse { CodeTheme.colors.background }
255+
val gradientSizePx =
256+
with(LocalDensity.current) { gradientSize.toPx() } * if (isLongGradient) 1.5f else 1f
257+
this
258+
.addIf(showAtStart && !scrollState.isScrolledToStart()) {
259+
Modifier.drawWithGradient(
260+
color = backgroundColor,
261+
startY = { gradientSizePx },
262+
endY = { 0f },
263+
)
264+
}
265+
.addIf(showAtEnd && !scrollState.isScrolledToEnd()) {
266+
Modifier.drawWithGradient(
267+
color = backgroundColor,
268+
startY = { size.height - gradientSizePx },
269+
)
270+
}
271+
}
272+
273+
fun Modifier.horizontalScrollStateGradient(
274+
scrollState: LazyListState,
275+
color: Color,
276+
showAtStart: Boolean = true,
277+
showAtEnd: Boolean = true,
278+
): Modifier = composed {
279+
val gradientSizePx =
280+
with(LocalDensity.current) { gradientSize.toPx() }
281+
this
282+
.addIf(showAtStart && !scrollState.isScrolledToStart()) {
283+
Modifier.drawWithContent {
284+
drawContent()
285+
drawRect(
286+
brush = Brush.horizontalGradient(
287+
colors = listOf(
288+
color,
289+
Color.Transparent,
290+
),
291+
startX = 0f,
292+
endX = gradientSizePx,
293+
),
294+
)
295+
}
296+
}
297+
.addIf(showAtEnd && !scrollState.isScrolledToEnd()) {
298+
Modifier.drawWithContent {
299+
drawContent()
300+
drawRect(
301+
brush = Brush.horizontalGradient(
302+
colors = listOf(
303+
Color.Transparent,
304+
color,
305+
),
306+
startX = size.width - gradientSizePx,
307+
endX = size.width,
308+
),
309+
)
310+
}
311+
}
312+
}
313+
314+
fun Modifier.verticalScrollStateGradient(
315+
scrollState: LazyGridState,
316+
color: Color,
317+
showAtStart: Boolean = true,
318+
showAtEnd: Boolean = true,
319+
): Modifier = composed {
320+
val gradientSizePx =
321+
with(LocalDensity.current) { gradientSize.toPx() }
322+
this
323+
.addIf(showAtStart && !scrollState.isVerticallyScrolledToStart()) {
324+
Modifier.drawWithGradient(
325+
color = color,
326+
startY = { gradientSizePx },
327+
endY = { 0f },
328+
)
329+
}
330+
.addIf(showAtEnd && !scrollState.isVerticallyScrolledToEnd()) {
331+
Modifier.drawWithGradient(
332+
color = color,
333+
startY = { size.height - gradientSizePx },
334+
)
335+
}
336+
}
337+
338+
fun LazyListState.isScrolledToEnd(): Boolean {
339+
val lastItem = layoutInfo.visibleItemsInfo.lastOrNull()
340+
return lastItem == null ||
341+
(lastItem.index == layoutInfo.totalItemsCount - 1 && lastItem.size + lastItem.offset <= layoutInfo.viewportEndOffset)
342+
}
343+
344+
fun LazyListState.isScrolledToStart(): Boolean {
345+
val firstItem = layoutInfo.visibleItemsInfo.firstOrNull()
346+
return firstItem == null || firstItem.offset == 0
347+
}
348+
349+
fun LazyGridState.isVerticallyScrolledToEnd(): Boolean {
350+
val lastItem = layoutInfo.visibleItemsInfo.lastOrNull()
351+
return lastItem == null ||
352+
(lastItem.index == layoutInfo.totalItemsCount - 1 && lastItem.size.height + lastItem.offset.y <= layoutInfo.viewportEndOffset)
353+
}
354+
355+
fun LazyGridState.isVerticallyScrolledToStart(): Boolean {
356+
val firstItem = layoutInfo.visibleItemsInfo.firstOrNull()
357+
return firstItem == null || firstItem.offset.y == 0
358+
}
359+
360+
fun Modifier.footerShadow() = this.drawWithContent {
361+
drawContent()
362+
drawRect(
363+
brush = Brush.verticalGradient(
364+
endY = size.height * 0.12f,
365+
colors = listOf(Color(0x10000000), Color.Transparent),
366+
),
367+
)
238368
}

app/src/main/java/com/getcode/view/main/account/AccountHome.kt

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.width
1313
import androidx.compose.foundation.layout.wrapContentHeight
1414
import androidx.compose.foundation.lazy.LazyColumn
1515
import androidx.compose.foundation.lazy.items
16+
import androidx.compose.foundation.lazy.rememberLazyListState
1617
import androidx.compose.material.Divider
1718
import androidx.compose.material.Icon
1819
import androidx.compose.material.Text
@@ -47,11 +48,12 @@ import com.getcode.navigation.screens.BuySellScreen
4748
import com.getcode.navigation.screens.DepositKinScreen
4849
import com.getcode.navigation.screens.FaqScreen
4950
import com.getcode.navigation.screens.WithdrawalAmountScreen
50-
import com.getcode.theme.BrandLight
5151
import com.getcode.theme.CodeTheme
5252
import com.getcode.theme.White10
53+
import com.getcode.ui.components.CodeScaffold
5354
import com.getcode.ui.utils.getActivity
5455
import com.getcode.ui.utils.rememberedClickable
56+
import com.getcode.ui.utils.verticalScrollStateGradient
5557
import kotlinx.coroutines.delay
5658
import kotlinx.coroutines.launch
5759

@@ -86,6 +88,7 @@ fun AccountHome(
8688
navigator.push(BuySellScreen)
8789
}
8890
}
91+
8992
AccountPage.DEPOSIT -> navigator.push(DepositKinScreen)
9093
AccountPage.WITHDRAW -> navigator.push(WithdrawalAmountScreen)
9194
AccountPage.FAQ -> navigator.push(FaqScreen)
@@ -120,18 +123,11 @@ fun AccountHome(
120123
}
121124
}
122125

123-
LazyColumn(modifier = Modifier.fillMaxSize()) {
124-
items(dataState.items, key = { it.type }, contentType = { it }) { item ->
125-
ListItem(item = item) {
126-
handleItemClicked(item.type)
127-
}
128-
}
129-
130-
item {
126+
CodeScaffold(
127+
bottomBar = {
131128
Box(modifier = Modifier.fillMaxWidth()) {
132129
Text(
133130
modifier = Modifier
134-
.padding(top = CodeTheme.dimens.grid.x7)
135131
.fillMaxWidth()
136132
.align(Alignment.Center),
137133
text = "Version ${BuildConfig.VERSION_NAME} • Build ${BuildConfig.VERSION_CODE}",
@@ -142,6 +138,24 @@ fun AccountHome(
142138
)
143139
}
144140
}
141+
) { padding ->
142+
val listState = rememberLazyListState()
143+
LazyColumn(
144+
modifier = Modifier
145+
.fillMaxSize()
146+
.padding(padding)
147+
.verticalScrollStateGradient(
148+
scrollState = listState,
149+
isLongGradient = true,
150+
),
151+
state = listState,
152+
) {
153+
items(dataState.items, key = { it.type }, contentType = { it }) { item ->
154+
ListItem(item = item) {
155+
handleItemClicked(item.type)
156+
}
157+
}
158+
}
145159
}
146160
}
147161

0 commit comments

Comments
 (0)