Skip to content

Commit d303e4c

Browse files
update demos
1 parent 3c87dd0 commit d303e4c

File tree

18 files changed

+1106
-190
lines changed

18 files changed

+1106
-190
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Colorful sliders that can have Solid or Gradient colors for thumb or track which can have
33
thumb and track with varying sizes.
44

5+
| Dimensions | Gradient1 | Gradient2 | SliderWithTitle |
6+
| ----------|-----------| -----------| -----------|
7+
| <img src="./screenshots/slider1.gif"/> | <img src="./screenshots/slider2.gif"/> | <img src="./screenshots/slider3.gif"/> | <img src="./screenshots/slider4.gif"/> |
8+
9+
510
### ColorfulSlider
611
Sliders that can use Color or gradient for track, thumb, or tick colors with custom
712
thumb and track heights.

app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ dependencies {
5656
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
5757
implementation 'androidx.activity:activity-compose:1.4.0'
5858

59+
implementation 'com.google.accompanist:accompanist-systemuicontroller:0.24.3-alpha'
60+
implementation "com.google.accompanist:accompanist-pager:0.24.3-alpha"
61+
implementation "com.google.accompanist:accompanist-pager-indicators:0.24.3-alpha"
62+
5963
testImplementation 'junit:junit:4.13.2'
6064
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
6165
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.smarttoolfactory.composematerialslider.demo
1+
package com.smarttoolfactory.composematerialslider
22

33
import androidx.annotation.FloatRange
44
import androidx.compose.foundation.layout.Box
@@ -387,7 +387,7 @@ fun CheckeredColorfulSlider(
387387
coerceThumbInTrack = true,
388388
colors = MaterialSliderDefaults.materialColors(
389389
activeTrackColor = SliderBrushColor(brush = brush),
390-
inactiveTickColor = SliderBrushColor(color = ActiveTrackColor.copy(.24f))
390+
inactiveTrackColor = SliderBrushColor(color = Color.Transparent)
391391
),
392392
drawInactiveTrack = false
393393
)
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.smarttoolfactory.composematerialslider
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.setContent
6+
import androidx.compose.animation.ExperimentalAnimationApi
7+
import androidx.compose.foundation.layout.Column
8+
import androidx.compose.foundation.layout.fillMaxSize
9+
import androidx.compose.material.*
10+
import androidx.compose.runtime.Composable
11+
import androidx.compose.runtime.rememberCoroutineScope
12+
import androidx.compose.ui.Modifier
13+
import androidx.compose.ui.graphics.Color
14+
import androidx.compose.ui.unit.dp
15+
import com.google.accompanist.pager.*
16+
import com.smarttoolfactory.composematerialslider.demo.ColorfulSliderDemo
17+
import com.smarttoolfactory.composematerialslider.demo.SliderGradientDemo
18+
import com.smarttoolfactory.composematerialslider.demo.SliderGradientDemo2
19+
import com.smarttoolfactory.composematerialslider.demo.SliderPropertiesDemo
20+
import com.smarttoolfactory.composematerialslider.ui.theme.ComposeMaterialSliderTheme
21+
import kotlinx.coroutines.launch
22+
23+
@ExperimentalPagerApi
24+
class MainActivity : ComponentActivity() {
25+
override fun onCreate(savedInstanceState: Bundle?) {
26+
super.onCreate(savedInstanceState)
27+
setContent {
28+
ComposeMaterialSliderTheme {
29+
// A surface container using the 'background' color from the theme
30+
Surface(color = MaterialTheme.colors.background) {
31+
Column(
32+
modifier = Modifier.fillMaxSize()
33+
) {
34+
HomeContent()
35+
}
36+
}
37+
}
38+
}
39+
}
40+
}
41+
42+
@ExperimentalPagerApi
43+
@OptIn(ExperimentalAnimationApi::class)
44+
@Composable
45+
private fun HomeContent() {
46+
47+
val pagerState: PagerState = rememberPagerState(initialPage = 0)
48+
val coroutineScope = rememberCoroutineScope()
49+
50+
ScrollableTabRow(
51+
backgroundColor = Color(0xff00897B),
52+
contentColor = Color.White,
53+
edgePadding = 8.dp,
54+
// Our selected tab is our current page
55+
selectedTabIndex = pagerState.currentPage,
56+
// Override the indicator, using the provided pagerTabIndicatorOffset modifier
57+
indicator = { tabPositions ->
58+
TabRowDefaults.Indicator(
59+
Modifier.pagerTabIndicatorOffset(pagerState, tabPositions)
60+
)
61+
}
62+
) {
63+
// Add tabs for all of our pages
64+
tabList.forEachIndexed { index, title ->
65+
Tab(
66+
text = { Text(title) },
67+
selected = pagerState.currentPage == index,
68+
onClick = {
69+
coroutineScope.launch {
70+
pagerState.animateScrollToPage(index)
71+
}
72+
},
73+
)
74+
}
75+
}
76+
77+
HorizontalPager(
78+
state = pagerState,
79+
count = tabList.size
80+
) { page: Int ->
81+
82+
when (page) {
83+
0 -> ColorfulSliderDemo()
84+
1 -> SliderGradientDemo()
85+
2 -> SliderGradientDemo2()
86+
else -> SliderPropertiesDemo()
87+
}
88+
}
89+
}
90+
91+
internal val tabList =
92+
listOf(
93+
"Slider Dimensions",
94+
"Slider Gradients1",
95+
"Slider Gradients2",
96+
"Slider Properties",
97+
)
98+

0 commit comments

Comments
 (0)