Skip to content

Commit

Permalink
Update to compose 1.4.0-beta02 (#148)
Browse files Browse the repository at this point in the history
Description
Update to compose 1.4.0-beta02
Add missing parameters in VMD components
The one we were interrested in is minLines but while at it, I decided to make a pass for other missing ones.
  • Loading branch information
npresseault authored Mar 6, 2023
1 parent ff9756c commit f635530
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 46 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Kotlin `1.8.10`
- Jetpack Compose Compiler to `1.4.3`
- Jetpack Compose Runtime to `1.3.3`
- Jetpack Compose UI to `1.3.1`
- Jetpack Compose UI to `1.4.0-beta02`
- Jetpack Compose Material 3 to `1.1.0-alpha07`
- Ktlint to `11.2.0`
- Androidx Lifecycle to `2.6.0-rc01`
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object Versions {
const val JETPACK_COMPOSE_RUNTIME = "1.3.3"
const val JETPACK_COMPOSE_FOUNDATION = "1.3.1"
const val JETPACK_COMPOSE_UI_TOOLING = "1.3.3"
const val JETPACK_COMPOSE_MATERIAL = "1.3.1"
const val JETPACK_COMPOSE_MATERIAL = "1.4.0-beta02"
const val JETPACK_COMPOSE_MATERIAL_3 = "1.1.0-alpha07"
const val COIL = "2.0.0-rc03"
const val KTLINT = "11.2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fun VMDBasicTextField(
keyboardActions: KeyboardActions = KeyboardActions(),
singleLine: Boolean = false,
maxLines: Int = Int.MAX_VALUE,
minLines: Int = 1,
isError: Boolean = false,
onTextLayout: (TextLayoutResult) -> Unit = {},
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
Expand Down Expand Up @@ -71,6 +72,7 @@ fun VMDBasicTextField(
),
keyboardActions = keyboardActionsDelegate,
maxLines = maxLines,
minLines = minLines,
singleLine = singleLine,
visualTransformation = visualTransformation,
onTextLayout = onTextLayout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fun <C : VMDContent> VMDButton(
modifier: Modifier = Modifier,
viewModel: VMDButtonViewModel<C>,
contentAlignment: Alignment = Alignment.Center,
propagateMinConstraints: Boolean = false,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
indication: Indication? = rememberRipple(),
content: @Composable (BoxScope.(field: C) -> Unit)
Expand All @@ -39,6 +40,7 @@ fun <C : VMDContent> VMDButton(
indication = indication
),
contentAlignment = contentAlignment,
propagateMinConstraints = propagateMinConstraints,
content = { content(buttonViewModel.content) }
)
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.mirego.trikot.viewmodels.declarative.compose.viewmodel

import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.RowScope
import androidx.compose.material.Checkbox
import androidx.compose.material.CheckboxColors
import androidx.compose.material.CheckboxDefaults
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.mirego.trikot.viewmodels.declarative.components.VMDToggleViewModel
Expand All @@ -23,13 +25,15 @@ fun VMDCheckbox(
modifier: Modifier = Modifier,
componentModifier: Modifier = Modifier,
viewModel: VMDToggleViewModel<VMDNoContent>,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
colors: CheckboxColors = CheckboxDefaults.colors()
) {
VMDCheckbox(
modifier = modifier,
componentModifier = componentModifier,
viewModel = viewModel,
label = {},
interactionSource = interactionSource,
colors = colors
)
}
Expand All @@ -40,6 +44,7 @@ fun <C : VMDContent> VMDCheckbox(
componentModifier: Modifier = Modifier,
viewModel: VMDToggleViewModel<C>,
label: @Composable (RowScope.(field: C) -> Unit),
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
colors: CheckboxColors = CheckboxDefaults.colors()
) {
val toggleViewModel: VMDToggleViewModel<C> by viewModel.observeAsState(excludedProperties = if (modifier.isOverridingAlpha()) listOf(viewModel::isHidden) else emptyList())
Expand All @@ -51,11 +56,12 @@ fun <C : VMDContent> VMDCheckbox(
label = { label(toggleViewModel.label) },
content = {
Checkbox(
onCheckedChange = { checked -> viewModel.onValueChange(checked) },
modifier = componentModifier,
enabled = toggleViewModel.isEnabled,
checked = toggleViewModel.isOn,
colors = colors,
onCheckedChange = { checked -> viewModel.onValueChange(checked) },
interactionSource = interactionSource,
colors = colors
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import com.mirego.trikot.viewmodels.declarative.components.VMDProgressViewModel
Expand All @@ -22,7 +23,9 @@ fun VMDCircularProgressIndicator(
modifier: Modifier = Modifier,
viewModel: VMDProgressViewModel,
color: Color = MaterialTheme.colors.primary,
strokeWidth: Dp = ProgressIndicatorDefaults.StrokeWidth
strokeWidth: Dp = ProgressIndicatorDefaults.StrokeWidth,
backgroundColor: Color = Color.Transparent,
strokeCap: StrokeCap = StrokeCap.Square,
) {
val progressViewModel: VMDProgressViewModel by viewModel.observeAsState(excludedProperties = if (modifier.isOverridingAlpha()) listOf(viewModel::isHidden) else emptyList())
val animatedProgress by animateFloatAsState(targetValue = progressViewModel.determination?.progressRatio ?: 0f)
Expand All @@ -35,14 +38,18 @@ fun VMDCircularProgressIndicator(
CircularProgressIndicator(
modifier = newModifier,
color = color,
strokeWidth = strokeWidth
strokeWidth = strokeWidth,
backgroundColor = backgroundColor,
strokeCap = strokeCap
)
} else {
CircularProgressIndicator(
modifier = newModifier,
progress = animatedProgress,
color = color,
strokeWidth = strokeWidth
strokeWidth = strokeWidth,
backgroundColor = backgroundColor,
strokeCap = strokeCap
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.mirego.trikot.viewmodels.declarative.compose.viewmodel

import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.RowScope
import androidx.compose.material.Switch
import androidx.compose.material.SwitchColors
import androidx.compose.material.SwitchDefaults
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.mirego.trikot.viewmodels.declarative.components.VMDToggleViewModel
Expand All @@ -23,6 +25,7 @@ fun VMDSwitch(
modifier: Modifier = Modifier,
componentModifier: Modifier = Modifier,
viewModel: VMDToggleViewModel<VMDNoContent>,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
colors: SwitchColors = SwitchDefaults.colors()
) {
VMDSwitch(
Expand All @@ -40,6 +43,7 @@ fun <C : VMDContent> VMDSwitch(
componentModifier: Modifier = Modifier,
viewModel: VMDToggleViewModel<C>,
label: @Composable (RowScope.(field: C) -> Unit),
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
colors: SwitchColors = SwitchDefaults.colors()
) {
val toggleViewModel: VMDToggleViewModel<C> by viewModel.observeAsState(excludedProperties = if (modifier.isOverridingAlpha()) listOf(viewModel::isHidden) else emptyList())
Expand All @@ -55,6 +59,7 @@ fun <C : VMDContent> VMDSwitch(
enabled = toggleViewModel.isEnabled,
checked = toggleViewModel.isOn,
colors = colors,
interactionSource = interactionSource,
onCheckedChange = { checked -> viewModel.onValueChange(checked) },
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fun VMDText(
overflow: TextOverflow = TextOverflow.Clip,
softWrap: Boolean = true,
maxLines: Int = Int.MAX_VALUE,
minLines: Int = 1,
onTextLayout: (TextLayoutResult) -> Unit = {},
style: TextStyle = LocalTextStyle.current
) {
Expand All @@ -58,6 +59,7 @@ fun VMDText(
overflow = overflow,
softWrap = softWrap,
maxLines = maxLines,
minLines = minLines,
onTextLayout = onTextLayout,
style = style
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.mirego.trikot.viewmodels.declarative.compose.viewmodel

import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.shape.ZeroCornerSize
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.LocalTextStyle
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.material.TextFieldColors
import androidx.compose.material.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.OffsetMapping
Expand All @@ -28,11 +33,17 @@ fun VMDTextField(
viewModel: VMDTextFieldViewModel,
textStyle: TextStyle = LocalTextStyle.current,
placeHolderStyle: TextStyle = LocalTextStyle.current,
label: @Composable (() -> Unit)? = null,
placeholder: @Composable (() -> Unit)? = null,
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
keyboardActions: KeyboardActions = KeyboardActions(),
singleLine: Boolean = true,
isError: Boolean = false,
singleLine: Boolean = false,
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
minLines: Int = 1,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
shape: Shape = MaterialTheme.shapes.small.copy(bottomEnd = ZeroCornerSize, bottomStart = ZeroCornerSize),
textFieldColors: TextFieldColors = TextFieldDefaults.textFieldColors()
) {
val textFieldViewModel: VMDTextFieldViewModel by viewModel.observeAsState(excludedProperties = if (modifier.isOverridingAlpha()) listOf(viewModel::isHidden) else emptyList())
Expand All @@ -47,6 +58,7 @@ fun VMDTextField(
viewModel.onValueChange(value)
},
enabled = textFieldViewModel.isEnabled,
label = label,
placeholder = {
Text(
text = textFieldViewModel.placeholder,
Expand All @@ -55,17 +67,21 @@ fun VMDTextField(
},
leadingIcon = leadingIcon,
trailingIcon = trailingIcon,
colors = textFieldColors,
textStyle = textStyle,
isError = isError,
visualTransformation = FormattedVisualTransformation(viewModel.formatText),
keyboardActions = keyboardActionsDelegate,
keyboardOptions = KeyboardOptions(
keyboardType = textFieldViewModel.keyboardType.composeValue,
capitalization = textFieldViewModel.autoCapitalization.composeValue,
imeAction = textFieldViewModel.keyboardReturnKeyType.composeValue
),
singleLine = singleLine,
isError = isError,
visualTransformation = FormattedVisualTransformation(viewModel.formatText)
maxLines = maxLines,
minLines = minLines,
interactionSource = interactionSource,
shape = shape,
colors = textFieldColors
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fun <C : VMDContent> VMDButton(
modifier: Modifier = Modifier,
viewModel: VMDButtonViewModel<C>,
contentAlignment: Alignment = Alignment.Center,
propagateMinConstraints: Boolean = false,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
indication: Indication? = rememberRipple(),
content: @Composable (BoxScope.(field: C) -> Unit)
Expand All @@ -39,6 +40,7 @@ fun <C : VMDContent> VMDButton(
indication = indication
),
contentAlignment = contentAlignment,
propagateMinConstraints = propagateMinConstraints,
content = { content(buttonViewModel.content) }
)
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.mirego.trikot.viewmodels.declarative.compose.viewmodel

import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.RowScope
import androidx.compose.material.Checkbox
import androidx.compose.material.CheckboxColors
import androidx.compose.material.CheckboxDefaults
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.mirego.trikot.streams.cancellable.CancellableManager
Expand All @@ -23,13 +25,15 @@ fun VMDCheckbox(
modifier: Modifier = Modifier,
componentModifier: Modifier = Modifier,
viewModel: VMDToggleViewModel<VMDNoContent>,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
colors: CheckboxColors = CheckboxDefaults.colors()
) {
VMDCheckbox(
modifier = modifier,
componentModifier = componentModifier,
viewModel = viewModel,
label = {},
interactionSource = interactionSource,
colors = colors
)
}
Expand All @@ -40,6 +44,7 @@ fun <C : VMDContent> VMDCheckbox(
componentModifier: Modifier = Modifier,
viewModel: VMDToggleViewModel<C>,
label: @Composable (RowScope.(field: C) -> Unit),
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
colors: CheckboxColors = CheckboxDefaults.colors()
) {
val toggleViewModel: VMDToggleViewModel<C> by viewModel.observeAsState(excludedProperties = if (modifier.isOverridingAlpha()) listOf(viewModel::isHidden) else emptyList())
Expand All @@ -51,11 +56,12 @@ fun <C : VMDContent> VMDCheckbox(
label = { label(toggleViewModel.label) },
content = {
Checkbox(
onCheckedChange = { checked -> viewModel.onValueChange(checked) },
modifier = componentModifier,
enabled = toggleViewModel.isEnabled,
checked = toggleViewModel.isOn,
colors = colors,
onCheckedChange = { checked -> viewModel.onValueChange(checked) },
interactionSource = interactionSource,
colors = colors
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import com.mirego.trikot.streams.cancellable.CancellableManager
Expand All @@ -22,7 +23,9 @@ fun VMDCircularProgressIndicator(
modifier: Modifier = Modifier,
viewModel: VMDProgressViewModel,
color: Color = MaterialTheme.colors.primary,
strokeWidth: Dp = ProgressIndicatorDefaults.StrokeWidth
strokeWidth: Dp = ProgressIndicatorDefaults.StrokeWidth,
backgroundColor: Color = Color.Transparent,
strokeCap: StrokeCap = StrokeCap.Square,
) {
val progressViewModel: VMDProgressViewModel by viewModel.observeAsState(excludedProperties = if (modifier.isOverridingAlpha()) listOf(viewModel::isHidden) else emptyList())
val animatedProgress by animateFloatAsState(targetValue = progressViewModel.determination?.progressRatio ?: 0f)
Expand All @@ -35,14 +38,18 @@ fun VMDCircularProgressIndicator(
CircularProgressIndicator(
modifier = newModifier,
color = color,
strokeWidth = strokeWidth
strokeWidth = strokeWidth,
backgroundColor = backgroundColor,
strokeCap = strokeCap
)
} else {
CircularProgressIndicator(
modifier = newModifier,
progress = animatedProgress,
color = color,
strokeWidth = strokeWidth
strokeWidth = strokeWidth,
backgroundColor = backgroundColor,
strokeCap = strokeCap
)
}
}
Expand Down
Loading

0 comments on commit f635530

Please sign in to comment.