-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improve the text items * Fix auto-scrolling on mobile * Fix ChoiceItem on mobile * WIP: Add progress bar * Fix the progress bar * Refactor the progress bar composable
- Loading branch information
1 parent
248980e
commit 2d6f71d
Showing
8 changed files
with
140 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
composeApp/src/commonMain/kotlin/ui/screen/lesson/composable/LessonProgressBar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package ui.screen.lesson.composable | ||
|
||
import androidx.compose.animation.core.animateFloatAsState | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.coerceAtMost | ||
import androidx.compose.ui.unit.dp | ||
import ui.screen.lesson.LessonProgressViewState | ||
import ui.theme.Gray | ||
|
||
|
||
@Composable | ||
fun LessonProgressBar( | ||
viewState: LessonProgressViewState, | ||
modifier: Modifier = Modifier, | ||
progressBarWidth: Dp = 124.dp, | ||
) { | ||
Box(modifier = modifier) { | ||
val progressPercent by animateFloatAsState( | ||
targetValue = viewState.done / viewState.total.toFloat(), | ||
) | ||
// background (total) | ||
ProgressBarLine(width = progressBarWidth, color = Gray) | ||
// foreground (progress) | ||
val progressWidth = (progressBarWidth * progressPercent).coerceAtMost(progressBarWidth) | ||
ProgressBarLine(width = progressWidth, color = MaterialTheme.colors.primary) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun ProgressBarLine( | ||
width: Dp, | ||
color: Color, | ||
modifier: Modifier = Modifier, | ||
) { | ||
Spacer( | ||
modifier.height(8.dp) | ||
.width(width) | ||
.background(color, RoundedCornerShape(percent = 50)) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters