Skip to content

Commit

Permalink
Extract SliderIndicator as component
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelekol committed Dec 27, 2024
1 parent 67f5bd7 commit 76db135
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.animation.Crossfade
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -22,12 +18,10 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
Expand All @@ -40,6 +34,7 @@ import io.horizontalsystems.bankwallet.modules.main.MainModule
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme
import io.horizontalsystems.bankwallet.ui.compose.components.ButtonPrimaryYellow
import io.horizontalsystems.bankwallet.ui.compose.components.RadialBackground
import io.horizontalsystems.bankwallet.ui.compose.components.SliderIndicator
import io.horizontalsystems.bankwallet.ui.compose.components.body_grey
import io.horizontalsystems.bankwallet.ui.compose.components.title3_leah
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -106,7 +101,10 @@ private fun StaticContent(
Spacer(Modifier.weight(2f))
Spacer(Modifier.height(326.dp))
Spacer(Modifier.weight(1f))
SliderIndicator(viewModel.slides, pagerState.currentPage)
SliderIndicator(
total = pageCount,
current = pagerState.currentPage
)
Spacer(Modifier.weight(1f))
//Text
Column(
Expand Down Expand Up @@ -158,29 +156,6 @@ private fun StaticContent(
}
}

@Composable
private fun SliderIndicator(slides: List<IntroModule.IntroSliderData>, currentPage: Int) {
Row(
modifier = Modifier.height(30.dp),
horizontalArrangement = Arrangement.spacedBy(4.dp),
verticalAlignment = Alignment.CenterVertically
) {
slides.forEachIndexed { index, _ ->
SliderCell(index == currentPage)
}
}
}

@Composable
private fun SliderCell(highlighted: Boolean) {
Box(
modifier = Modifier
.clip(RoundedCornerShape(2.dp))
.background(if (highlighted) ComposeAppTheme.colors.jacob else ComposeAppTheme.colors.steel20)
.size(width = 20.dp, height = 4.dp),
)
}

@Composable
private fun SlidingContent(
slideData: IntroModule.IntroSliderData,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.horizontalsystems.bankwallet.ui.compose.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme

@Composable
fun SliderIndicator(total: Int, current: Int) {
Row(
modifier = Modifier.height(30.dp),
horizontalArrangement = Arrangement.spacedBy(4.dp),
verticalAlignment = Alignment.CenterVertically
) {
repeat(total) { index ->
Box(
modifier = Modifier
.clip(RoundedCornerShape(2.dp))
.background(if (index == current) ComposeAppTheme.colors.jacob else ComposeAppTheme.colors.steel20)
.size(width = 20.dp, height = 4.dp),
)
}
}
}

0 comments on commit 76db135

Please sign in to comment.