Skip to content

Commit

Permalink
Improve the showcase
Browse files Browse the repository at this point in the history
- Apply the material theme
- Replace rememberSaveable with remember to avoid error in config changes
- Use onClick lambda directly
  • Loading branch information
mahozad committed Aug 26, 2021
1 parent a77e9be commit e5dec1f
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions test/src/main/kotlin/chart/test/ShowcaseActivity.kt
Expand Up @@ -8,14 +8,9 @@ import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView
import ir.mahozad.android.PieChart
Expand All @@ -33,12 +28,12 @@ class ShowcaseActivity : AppCompatActivity() {
)

setContent {
var slices by rememberSaveable { mutableStateOf(sliceItems) }
// MaterialTheme {
PieChartView(slices) {
slices = generateRandomNumbers().map { PieChart.Slice(it, generateRandomColor()) }
var slices by remember { mutableStateOf(sliceItems) }
MaterialTheme {
PieChartView(slices) {
slices = generateRandomNumbers().map { PieChart.Slice(it, generateRandomColor()) }
}
}
// }
}
}

Expand Down Expand Up @@ -77,7 +72,7 @@ class ShowcaseActivity : AppCompatActivity() {
AndroidView(
modifier = Modifier
.fillMaxSize()
.clickable { onClick() },
.clickable(onClick = onClick),
factory = { context ->
PieChart(context).apply {
slices = sliceItems
Expand Down

0 comments on commit e5dec1f

Please sign in to comment.