bytebeats / compose-charts

Simple Jetpack Compose Charts for multi-platform. Including Android, Web, Desktop.
MIT License
163 stars 17 forks source link

@Preview is not working with PieChart #27

Closed crroush closed 2 years ago

crroush commented 2 years ago
@Preview
@Composable
fun PieChartPreview() {
    Box(modifier = Modifier.height(150.dp)) {
        PieChart(
            pieChartData = PieChartData(
                slices = listOf(
                    PieChartData.Slice(25F, Color.Red),
                    PieChartData.Slice(45F, Color.Green),
                    PieChartData.Slice(20F, Color.Blue),
                ),
            ),
            sliceDrawer = SimpleSliceDrawer(sliceThickness = 100f)
        )
    }
}

I am using a Android Studio 2021.1.1 Patch 3, with Jetpack Compose 1.1.1 I can display the chart no problem on my device

crizzis commented 2 years ago

Which IDE? Have you tried the interactive preview?

The issue might be that there's no way to disable the chart animation, and even using snap() does not make the preview render correctly. It always renders the initial frame instead, with no values whasoever. I had the same issue with BarChart.

@bytebeats Any chance of making animation optional?

bytebeats commented 2 years ago

@crizzis @crroush @Preview failed to work for:

$ adb shell am start -n "me.bytebeats.views.charts.test/androidx.compose.ui.tooling.PreviewActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER --es composable me.bytebeats.views.charts.pie.PieChartKt.PieChartPreview
Error while executing: am start -n "me.bytebeats.views.charts.test/androidx.compose.ui.tooling.PreviewActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER --es composable me.bytebeats.views.charts.pie.PieChartKt.PieChartPreview
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=me.bytebeats.views.charts.test/androidx.compose.ui.tooling.PreviewActivity (has extras) }
Error type 3
Error: Activity class {me.bytebeats.views.charts.test/androidx.compose.ui.tooling.PreviewActivity} does not exist.

Error while Launching activity
Failed to launch an application on all devices

From me.bytebeats.views.charts.test/androidx.compose.ui.tooling.PreviewActivity we can see that's because no androidx.compose.ui.tooling.PreviewActivity when debugging.

Actually, if debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" is included into charts/build.gradle, @Preview will work.