Skip to content

Commit 5a80ab9

Browse files
committed
docs: add gif examples to the Slider docs
1 parent 28d8b49 commit 5a80ab9

File tree

5 files changed

+88
-10
lines changed

5 files changed

+88
-10
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package io.monstarlab.mosaic.features
2+
3+
import android.content.res.Configuration
4+
import androidx.compose.foundation.layout.Column
5+
import androidx.compose.foundation.layout.Spacer
6+
import androidx.compose.foundation.layout.padding
7+
import androidx.compose.material3.MaterialTheme
8+
import androidx.compose.material3.Surface
9+
import androidx.compose.material3.Text
10+
import androidx.compose.runtime.Composable
11+
import androidx.compose.runtime.getValue
12+
import androidx.compose.runtime.mutableStateOf
13+
import androidx.compose.runtime.remember
14+
import androidx.compose.runtime.setValue
15+
import androidx.compose.ui.Modifier
16+
import androidx.compose.ui.tooling.preview.Preview
17+
import androidx.compose.ui.unit.dp
18+
import androidx.compose.ui.unit.sp
19+
import io.monstarlab.mosaic.slider.SliderColors
20+
import io.monstarlab.mosaic.slider.distribution.SliderValuesDistribution
21+
import io.monstarlab.mosaic.ui.theme.MosaicTheme
22+
import kotlin.math.roundToInt
23+
import androidx.compose.material3.Slider as MaterialSlider
24+
import io.monstarlab.mosaic.slider.Slider as MosaicSlider
25+
26+
@Composable
27+
@Preview()
28+
fun Test() {
29+
MosaicTheme {
30+
31+
Surface {
32+
var value by remember { mutableStateOf(50f) }
33+
val range = 0f..100f
34+
35+
Column(Modifier.padding(16.dp)) {
36+
37+
Text(
38+
"Sliders with different distributions\nValue: ${value.roundToInt()}",
39+
color = MaterialTheme.colorScheme.onSurface,
40+
)
41+
Spacer(modifier = Modifier.padding(8.dp))
42+
43+
Text(
44+
"Linear distribution",
45+
color = MaterialTheme.colorScheme.onSurface,
46+
fontSize = 12.sp
47+
)
48+
MosaicSlider(
49+
value = value,
50+
onValueChange = { value = it },
51+
colors = SliderColors(
52+
MaterialTheme.colorScheme.primary,
53+
MaterialTheme.colorScheme.error
54+
),
55+
range = range,
56+
)
57+
58+
Text(
59+
"Non-linear distribution",
60+
color = MaterialTheme.colorScheme.onSurface,
61+
fontSize = 12.sp
62+
)
63+
64+
MosaicSlider(
65+
value = value,
66+
onValueChange = { value = it },
67+
colors = SliderColors(
68+
MaterialTheme.colorScheme.primary,
69+
MaterialTheme.colorScheme.error
70+
),
71+
range = range,
72+
valueDistribution = remember {
73+
SliderValuesDistribution.checkpoints(
74+
0f to 0f,
75+
0.5f to 20f,
76+
1f to 100f
77+
)
78+
}
79+
)
80+
}
81+
}
82+
83+
}
84+
}

demo/src/main/java/io/monstarlab/mosaic/ui/theme/Theme.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,9 @@ fun MosaicTheme(
3939
dynamicColor: Boolean = true,
4040
content: @Composable () -> Unit,
4141
) {
42-
val colorScheme = when {
43-
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
44-
val context = LocalContext.current
45-
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
46-
}
47-
48-
darkTheme -> DarkColorScheme
49-
else -> LightColorScheme
50-
}
5142

5243
MaterialTheme(
53-
colorScheme = colorScheme,
44+
colorScheme = DarkColorScheme,
5445
typography = Typography,
5546
content = content,
5647
)
319 KB
Loading

docs/assets/example_distribution.gif

896 KB
Loading

docs/slider.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Following example has a custom thumb that displays current value and animates it
9898
Sometimes you want to limit slider range to some extent while still showing the full range. This can be done using `disabledRange`
9999
By specifying disabled range you limit where user can drag the thumb, thus making sure the values from the `disabledRange` wont be selected
100100

101+
![Disabled range](assets/example_disabled_range.gif)
101102

102103
You can specifiy the `disabledRange` in two ways, depending on how you manage the slider state
103104

@@ -139,6 +140,8 @@ Most of the Sliders have Linear values distribution, meaning that the values are
139140

140141
This allows you to control how the user interacts with the slider, the specific values that can be selected and how sensetive the slider is to the changes on some segments so that the users selection is more precise.
141142

143+
![Distributions](./assets/example_distribution.gif)
144+
142145
### Linear Values Distribution
143146
By default, Mosaic Slider will use `SliderValuesDistribution.Linear` which would arrange values in a linear fashion just like any other Slider
144147

0 commit comments

Comments
 (0)