Skip to content

Commit

Permalink
Migrate on material3
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-ananiev committed Mar 24, 2023
1 parent 2c1f6f4 commit 55c3737
Show file tree
Hide file tree
Showing 27 changed files with 332 additions and 383 deletions.
3 changes: 1 addition & 2 deletions YChartsLib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ dependencies {
implementation(co.ycharts.dependency.YChartDependency.CORE_KTX)
implementation(co.ycharts.dependency.YChartDependency.APPCOMPAT)
implementation(co.ycharts.dependency.YChartDependency.MATERIAL)
implementation(co.ycharts.dependency.YChartDependency.MATERIAL_3)
implementation(co.ycharts.dependency.YChartDependency.COMPOSE_UI)
implementation(co.ycharts.dependency.YChartDependency.COMPOSE_ACTIVITY)
implementation(co.ycharts.dependency.YChartDependency.COMPOSE_MATERIAL)
implementation(co.ycharts.dependency.YChartDependency.MATERIAL_3)
implementation(co.ycharts.dependency.YChartDependency.COMPOSE_TOOLING_PREVIEW)
//implementation(co.ycharts.dependency.YChartDependency.RUNTIME_LIVEDATA)
testImplementation(co.ycharts.dependency.YChartDependency.JUNIT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package co.yml.charts.common.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.material.Text
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package co.yml.charts.common.components.accessibility

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
Expand All @@ -16,49 +16,48 @@ import kotlinx.coroutines.launch
/**
* Bottom sheet to show items in vertical list view with a close button at top
*/
@ExperimentalMaterialApi
@Composable
fun AccessibilityBottomSheetDialog(
content: @Composable ColumnScope.() -> Unit,
modifier: Modifier = Modifier,
backgroundColor: Color,
popUpTopRightButtonTitle: String,
popUpTopRightButtonDescription: String,
sheetState: ModalBottomSheetState
) {
val composeScope = rememberCoroutineScope()
ModalBottomSheetLayout(
sheetContent = {
Box(
modifier = modifier
.background(backgroundColor)
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = modifier.fillMaxWidth()
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp),
horizontalArrangement = Arrangement.End
) {
Button(onClick = {
composeScope.launch { sheetState.hide() }
}) {
Text(
text = popUpTopRightButtonTitle,
modifier = Modifier.semantics {
contentDescription = popUpTopRightButtonDescription
})
}
}
content()
}
}
},
sheetState = sheetState,
sheetBackgroundColor = Color.White,
sheetElevation = 0.dp
) {}
}
//@Composable
//fun AccessibilityBottomSheetDialog(
// content: @Composable ColumnScope.() -> Unit,
// modifier: Modifier = Modifier,
// backgroundColor: Color,
// popUpTopRightButtonTitle: String,
// popUpTopRightButtonDescription: String,
// sheetState: ModalBottomSheetState
//) {
// val composeScope = rememberCoroutineScope()
// ModalBottomSheetLayout(
// sheetContent = {
// Box(
// modifier = modifier
// .background(backgroundColor)
// ) {
// Column(
// horizontalAlignment = Alignment.CenterHorizontally,
// modifier = modifier.fillMaxWidth()
// ) {
// Row(
// modifier = Modifier
// .fillMaxWidth()
// .padding(10.dp),
// horizontalArrangement = Arrangement.End
// ) {
// Button(onClick = {
// composeScope.launch { sheetState.hide() }
// }) {
// Text(
// text = popUpTopRightButtonTitle,
// modifier = Modifier.semantics {
// contentDescription = popUpTopRightButtonDescription
// })
// }
// }
// content()
// }
// }
// },
// sheetState = sheetState,
// sheetBackgroundColor = Color.White,
// sheetElevation = 0.dp
// ) {}
//}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package co.yml.charts.common.components.accessibility
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package co.yml.charts.common.components.accessibility
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package co.yml.charts.common.components.accessibility
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package co.yml.charts.common.components.accessibility
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down
90 changes: 42 additions & 48 deletions YChartsLib/src/main/java/co/yml/charts/ui/barchart/BarChart.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package co.yml.charts.ui.barchart


import androidx.activity.compose.BackHandler
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -30,9 +28,6 @@ import co.yml.charts.ui.barchart.models.BarChartData
import co.yml.charts.ui.barchart.models.BarData
import co.yml.charts.ui.barchart.models.BarStyle
import co.yml.charts.ui.barchart.models.SelectionHighlightData
import co.yml.charts.common.components.ItemDivider
import co.yml.charts.common.components.accessibility.AccessibilityBottomSheetDialog
import co.yml.charts.common.components.accessibility.BarInfo
import co.yml.charts.common.extensions.RowClip
import co.yml.charts.common.extensions.collectIsTalkbackEnabledAsState
import co.yml.charts.common.extensions.getMaxElementInYAxis
Expand All @@ -51,23 +46,22 @@ import kotlinx.coroutines.launch
* @param barChartData : All data needed to Bar Chart
* @see [BarChartData] Data class to save all params related to Bar Chart
*/
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun BarChart(modifier: Modifier, barChartData: BarChartData) {
val accessibilitySheetState =
rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden)
// val accessibilitySheetState =
// rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden)
val scope = rememberCoroutineScope()
val isTalkBackEnabled by LocalContext.current.collectIsTalkbackEnabledAsState()

if (accessibilitySheetState.isVisible && isTalkBackEnabled
&& barChartData.accessibilityConfig.shouldHandleBackWhenTalkBackPopUpShown
) {
BackHandler {
scope.launch {
accessibilitySheetState.hide()
}
}
}
// if (accessibilitySheetState.isVisible && isTalkBackEnabled
// && barChartData.accessibilityConfig.shouldHandleBackWhenTalkBackPopUpShown
// ) {
// BackHandler {
// scope.launch {
// accessibilitySheetState.hide()
// }
// }
// }
Surface(modifier) {
with(barChartData) {
var barHighlightVisibility by remember { mutableStateOf(false) }
Expand All @@ -80,7 +74,7 @@ fun BarChart(modifier: Modifier, barChartData: BarChartData) {
var rowHeight by remember { mutableStateOf(0f) }
val paddingRight = paddingEnd
val points = chartData.map { it.point }
val bgColor = MaterialTheme.colors.surface
val bgColor = MaterialTheme.colorScheme.surface

val (xMin, xMax) = getXMaxAndMinPoints(points)
val (_, yMax) = getYMaxAndMinPoints(points)
Expand All @@ -105,7 +99,7 @@ fun BarChart(modifier: Modifier, barChartData: BarChartData) {
// accessibilitySheetState.animateTo(
// ModalBottomSheetValue.Expanded
// )
accessibilitySheetState.show()
// accessibilitySheetState.show()
}
}
},
Expand Down Expand Up @@ -212,34 +206,34 @@ fun BarChart(modifier: Modifier, barChartData: BarChartData) {
}
if (isTalkBackEnabled) {
with(barChartData) {
AccessibilityBottomSheetDialog(
modifier = Modifier.fillMaxSize(),
backgroundColor = Color.White,
content = {
LazyColumn {
items(chartData.size) { index ->
Column {
BarInfo(
xAxisData.axisLabelDescription(
xAxisData.labelData(
index
)
),
chartData[index].description,
chartData[index].color
)
ItemDivider(
thickness = accessibilityConfig.dividerThickness,
dividerColor = accessibilityConfig.dividerColor
)
}
}
}
},
popUpTopRightButtonTitle = accessibilityConfig.popUpTopRightButtonTitle,
popUpTopRightButtonDescription = accessibilityConfig.popUpTopRightButtonDescription,
sheetState = accessibilitySheetState
)
// AccessibilityBottomSheetDialog(
// modifier = Modifier.fillMaxSize(),
// backgroundColor = Color.White,
// content = {
// LazyColumn {
// items(chartData.size) { index ->
// Column {
// BarInfo(
// xAxisData.axisLabelDescription(
// xAxisData.labelData(
// index
// )
// ),
// chartData[index].description,
// chartData[index].color
// )
// ItemDivider(
// thickness = accessibilityConfig.dividerThickness,
// dividerColor = accessibilityConfig.dividerColor
// )
// }
// }
// }
// },
// popUpTopRightButtonTitle = accessibilityConfig.popUpTopRightButtonTitle,
// popUpTopRightButtonDescription = accessibilityConfig.popUpTopRightButtonDescription,
// sheetState = accessibilitySheetState
// )
}
}
}
Expand Down
Loading

0 comments on commit 55c3737

Please sign in to comment.