Skip to content

Commit

Permalink
feat(Demo): Update demo application
Browse files Browse the repository at this point in the history
  • Loading branch information
levinzonr authored May 7, 2024
1 parent ec914e2 commit 393862c
Show file tree
Hide file tree
Showing 140 changed files with 521 additions and 16,711 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</p>

<p align="center" style="font-size: 15px;">
<strong>Mosaic</strong> is acollection of Jetpack Compose UI components and utilities. It is designed to accelerate the development process by providing a rich set of tools and components that are ready to use out of the box. These components are highly customizable ensuring to fit in your use case.
<strong>Mosaic</strong> is a collection of Jetpack Compose UI components and utilities. It is designed to accelerate the development process by providing a rich set of tools and components that are ready to use out of the box. These components are highly customizable ensuring to fit in your use case.
</p>


Expand All @@ -15,6 +15,7 @@
### 🎛️ [Mosaic Slider](./slider/)
Mosaic Slider is a highly customizable slider component that allows precise customization of values distribution and disabled ranges. Its API is similar to Material sliders, making it easy to integrate into existing projects.

![Disabled range](./docs/assets/example_disabled_range.gif)


## Contributing
Expand Down
1 change: 1 addition & 0 deletions demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies {
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.compose.bom))
implementation(libs.androidx.navigation.compose)
implementation(libs.compose.material3)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
Expand Down
125 changes: 125 additions & 0 deletions demo/src/main/java/io/monstarlab/mosaic/HomeScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package io.monstarlab.mosaic

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomeScreen(
onSliderClick: () -> Unit,
onCarouselClick: () -> Unit,
modifier: Modifier = Modifier,
) = Scaffold(
modifier = modifier,
topBar = { TopAppBar(title = { Text(text = "Mosaic Demo") }) },
) {
Column(
verticalArrangement = Arrangement.spacedBy(32.dp),
modifier = Modifier
.padding(it)
.fillMaxSize()
.padding(16.dp),
) {
Image(
painter = painterResource(id = R.drawable.ic_mosaic_log),
contentDescription = "logo",
modifier = Modifier
.size(150.dp)
.align(Alignment.CenterHorizontally),
)

Text(
text = "Collection of Jetpack Compose UI components and utilities.",
modifier = Modifier.align(Alignment.CenterHorizontally),
textAlign = TextAlign.Center,
)

Column {
Row(
horizontalArrangement = Arrangement.spacedBy(16.dp),
modifier = Modifier,
) {
DemoButton(
resource = R.drawable.ic_slider,
text = "Slider",
modifier = Modifier.weight(0.3f),
onClick = onSliderClick,
)

DemoButton(
resource = R.drawable.ic_carousel,
text = "Carousel",
modifier = Modifier.weight(0.3f),
onClick = onCarouselClick,
)

Spacer(modifier = Modifier.weight(0.3f))
}
}
}
}

@Composable
private fun DemoButton(
resource: Int,
text: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
) {
Surface(
modifier = modifier.aspectRatio(1f),
shape = RoundedCornerShape(16.dp),
shadowElevation = 16.dp,
tonalElevation = 2.dp,
onClick = onClick,
) {
Column(verticalArrangement = Arrangement.SpaceBetween) {
Spacer(modifier = Modifier)

Icon(
painter = painterResource(id = resource),
contentDescription = text,
tint = MaterialTheme.colorScheme.primary,
modifier = Modifier
.size(60.dp)
.align(Alignment.CenterHorizontally),
)

Text(
text = text,
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(bottom = 16.dp),
style = MaterialTheme.typography.titleMedium,
)
}
}
}

@Preview
@Composable
private fun PreviewHomeScreen() {
HomeScreen({}, {})
}
25 changes: 23 additions & 2 deletions demo/src/main/java/io/monstarlab/mosaic/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import io.monstarlab.mosaic.features.SliderDemo
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import io.monstarlab.mosaic.demos.SliderDemo
import io.monstarlab.mosaic.ui.theme.MosaicTheme

class MainActivity : ComponentActivity() {
Expand All @@ -17,7 +20,25 @@ class MainActivity : ComponentActivity() {
enableEdgeToEdge()
setContent {
MosaicTheme {
SliderDemo()
val navController = rememberNavController()
NavHost(
navController = navController,
startDestination = Routes.Home.value,
) {
composable(Routes.Home.value) {
HomeScreen(
onSliderClick = {
navController.navigate(Routes.SliderDemo.value)
},
onCarouselClick = {
},
)
}

composable(Routes.SliderDemo.value) {
SliderDemo()
}
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions demo/src/main/java/io/monstarlab/mosaic/Routes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.monstarlab.mosaic

enum class Routes(val value: String) {
Home("home"),
SliderDemo("slider-demo"),
}
Loading

0 comments on commit 393862c

Please sign in to comment.