Skip to content

Commit

Permalink
Compose material 3 bindings (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
js-bonin authored Oct 18, 2023
1 parent ef0983d commit 84d2154
Show file tree
Hide file tree
Showing 47 changed files with 2,326 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,11 @@ public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/VM
}

public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/VMDCheckboxKt {
public static final fun DisabledToggleCheckboxPreview (Landroidx/compose/runtime/Composer;I)V
public static final fun EnabledToggleCheckboxPreview (Landroidx/compose/runtime/Composer;I)V
public static final fun SimpleTextToggleCheckboxPreview (Landroidx/compose/runtime/Composer;I)V
public static final fun VMDCheckbox (Landroidx/compose/ui/Modifier;Landroidx/compose/ui/Modifier;Lcom/mirego/trikot/viewmodels/declarative/components/VMDToggleViewModel;Landroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/material/CheckboxColors;Landroidx/compose/runtime/Composer;II)V
public static final fun VMDCheckbox (Landroidx/compose/ui/Modifier;Landroidx/compose/ui/Modifier;Lcom/mirego/trikot/viewmodels/declarative/components/VMDToggleViewModel;Lkotlin/jvm/functions/Function4;Landroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/material/CheckboxColors;Landroidx/compose/runtime/Composer;II)V
}

public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/VMDCircularProgressIndicatorKt {
public static final fun DeterminateCircularProgressIndicatorPreview (Landroidx/compose/runtime/Composer;I)V
public static final fun VMDCircularProgressIndicator-DUhRLBM (Landroidx/compose/ui/Modifier;Lcom/mirego/trikot/viewmodels/declarative/components/VMDProgressViewModel;JFJILandroidx/compose/runtime/Composer;II)V
}

Expand Down Expand Up @@ -139,7 +135,6 @@ public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/VM
}

public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/VMDLinearProgressIndicatorKt {
public static final fun DeterminateLinearProgressIndicatorPreview (Landroidx/compose/runtime/Composer;I)V
public static final fun VMDLinearProgressIndicator-eaDK9VM (Landroidx/compose/ui/Modifier;Lcom/mirego/trikot/viewmodels/declarative/components/VMDProgressViewModel;JJLandroidx/compose/runtime/Composer;II)V
}

Expand All @@ -153,9 +148,6 @@ public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/VM
}

public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/VMDSwitchKt {
public static final fun DisabledSwitchPreview (Landroidx/compose/runtime/Composer;I)V
public static final fun EnabledSwitchPreview (Landroidx/compose/runtime/Composer;I)V
public static final fun SimpleTextSwitchPreview (Landroidx/compose/runtime/Composer;I)V
public static final fun VMDSwitch (Landroidx/compose/ui/Modifier;Landroidx/compose/ui/Modifier;Lcom/mirego/trikot/viewmodels/declarative/components/VMDToggleViewModel;Landroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/material/SwitchColors;Landroidx/compose/runtime/Composer;II)V
public static final fun VMDSwitch (Landroidx/compose/ui/Modifier;Landroidx/compose/ui/Modifier;Lcom/mirego/trikot/viewmodels/declarative/components/VMDToggleViewModel;Lkotlin/jvm/functions/Function4;Landroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/material/SwitchColors;Landroidx/compose/runtime/Composer;II)V
}
Expand All @@ -169,6 +161,60 @@ public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/VM
public static final fun VMDText--4IGK_g (Landroidx/compose/ui/Modifier;Lcom/mirego/trikot/viewmodels/declarative/components/VMDTextViewModel;JJLandroidx/compose/ui/text/font/FontStyle;Landroidx/compose/ui/text/font/FontWeight;Landroidx/compose/ui/text/font/FontFamily;JLandroidx/compose/ui/text/style/TextDecoration;Landroidx/compose/ui/text/style/TextAlign;JIZIILkotlin/jvm/functions/Function1;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/runtime/Composer;III)V
}

public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/material3/ComposableSingletons$VMDCheckboxKt {
public static final field INSTANCE Lcom/mirego/trikot/viewmodels/declarative/compose/viewmodel/material3/ComposableSingletons$VMDCheckboxKt;
public static field lambda-1 Lkotlin/jvm/functions/Function4;
public static field lambda-2 Lkotlin/jvm/functions/Function4;
public fun <init> ()V
public final fun getLambda-1$compose_flow_release ()Lkotlin/jvm/functions/Function4;
public final fun getLambda-2$compose_flow_release ()Lkotlin/jvm/functions/Function4;
}

public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/material3/ComposableSingletons$VMDSwitchKt {
public static final field INSTANCE Lcom/mirego/trikot/viewmodels/declarative/compose/viewmodel/material3/ComposableSingletons$VMDSwitchKt;
public static field lambda-1 Lkotlin/jvm/functions/Function4;
public static field lambda-2 Lkotlin/jvm/functions/Function4;
public fun <init> ()V
public final fun getLambda-1$compose_flow_release ()Lkotlin/jvm/functions/Function4;
public final fun getLambda-2$compose_flow_release ()Lkotlin/jvm/functions/Function4;
}

public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/material3/VMDBasicTextFieldKt {
public static final fun VMDBasicTextField (Lcom/mirego/trikot/viewmodels/declarative/components/VMDTextFieldViewModel;Landroidx/compose/ui/Modifier;ZLandroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/foundation/text/KeyboardActions;ZIIZLkotlin/jvm/functions/Function1;Landroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/material3/TextFieldColors;Landroidx/compose/ui/graphics/Brush;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/runtime/Composer;III)V
}

public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/material3/VMDCheckboxKt {
public static final fun VMDCheckbox (Landroidx/compose/ui/Modifier;Landroidx/compose/ui/Modifier;Lcom/mirego/trikot/viewmodels/declarative/components/VMDToggleViewModel;Landroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/material3/CheckboxColors;Landroidx/compose/runtime/Composer;II)V
public static final fun VMDCheckbox (Landroidx/compose/ui/Modifier;Landroidx/compose/ui/Modifier;Lcom/mirego/trikot/viewmodels/declarative/components/VMDToggleViewModel;Lkotlin/jvm/functions/Function4;Landroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/material3/CheckboxColors;Landroidx/compose/runtime/Composer;II)V
}

public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/material3/VMDCircularProgressIndicatorKt {
public static final fun VMDCircularProgressIndicator-DUhRLBM (Landroidx/compose/ui/Modifier;Lcom/mirego/trikot/viewmodels/declarative/components/VMDProgressViewModel;JFJILandroidx/compose/runtime/Composer;II)V
}

public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/material3/VMDDropDownMenuKt {
public static final fun VMDDropDownMenu-x0xb5LI (Lcom/mirego/trikot/viewmodels/declarative/components/VMDPickerViewModel;ZLkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;JLandroidx/compose/ui/window/PopupProperties;Lkotlin/jvm/functions/Function5;Landroidx/compose/runtime/Composer;II)V
public static final fun VMDDropDownMenuItem (Lcom/mirego/trikot/viewmodels/declarative/components/VMDPickerViewModel;Lcom/mirego/trikot/viewmodels/declarative/components/VMDPickerItemViewModel;ILandroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function0;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/interaction/MutableInteractionSource;Lkotlin/jvm/functions/Function2;Landroidx/compose/material3/MenuItemColors;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;III)V
}

public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/material3/VMDLinearProgressIndicatorKt {
public static final fun VMDLinearProgressIndicator-eaDK9VM (Landroidx/compose/ui/Modifier;Lcom/mirego/trikot/viewmodels/declarative/components/VMDProgressViewModel;JJLandroidx/compose/runtime/Composer;II)V
}

public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/material3/VMDSwitchKt {
public static final fun VMDSwitch (Landroidx/compose/ui/Modifier;Landroidx/compose/ui/Modifier;Lcom/mirego/trikot/viewmodels/declarative/components/VMDToggleViewModel;Landroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/material3/SwitchColors;Landroidx/compose/runtime/Composer;II)V
public static final fun VMDSwitch (Landroidx/compose/ui/Modifier;Landroidx/compose/ui/Modifier;Lcom/mirego/trikot/viewmodels/declarative/components/VMDToggleViewModel;Lkotlin/jvm/functions/Function4;Landroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/material3/SwitchColors;Landroidx/compose/runtime/Composer;II)V
}

public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/material3/VMDTextFieldKt {
public static final fun VMDTextField (Landroidx/compose/ui/Modifier;Lcom/mirego/trikot/viewmodels/declarative/components/VMDTextFieldViewModel;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Landroidx/compose/foundation/text/KeyboardActions;ZZIILandroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/ui/graphics/Shape;Landroidx/compose/material3/TextFieldColors;Landroidx/compose/runtime/Composer;III)V
public static final fun buildKeyboardActions (Lcom/mirego/trikot/viewmodels/declarative/components/VMDTextFieldViewModel;Landroidx/compose/foundation/text/KeyboardActions;)Landroidx/compose/foundation/text/KeyboardActions;
}

public final class com/mirego/trikot/viewmodels/declarative/compose/viewmodel/material3/VMDTextKt {
public static final fun VMDText--4IGK_g (Landroidx/compose/ui/Modifier;Lcom/mirego/trikot/viewmodels/declarative/components/VMDTextViewModel;JJLandroidx/compose/ui/text/font/FontStyle;Landroidx/compose/ui/text/font/FontWeight;Landroidx/compose/ui/text/font/FontFamily;JLandroidx/compose/ui/text/style/TextDecoration;Landroidx/compose/ui/text/style/TextAlign;JIZIILkotlin/jvm/functions/Function1;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/runtime/Composer;III)V
}

public final class com/mirego/trikot/viewmodels/declarative/configuration/DefaultImageProvider : com/mirego/trikot/viewmodels/declarative/configuration/VMDImageProvider {
public static final field $stable I
public fun <init> ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,21 @@ fun <C : VMDContent> VMDCheckbox(

@Preview
@Composable
fun EnabledToggleCheckboxPreview() {
private fun EnabledToggleCheckboxPreview() {
val toggleViewModel = VMDComponents.Toggle.withState(true, MainScope())
VMDCheckbox(viewModel = toggleViewModel)
}

@Preview
@Composable
fun DisabledToggleCheckboxPreview() {
private fun DisabledToggleCheckboxPreview() {
val toggleViewModel = VMDComponents.Toggle.withState(false, MainScope())
VMDCheckbox(viewModel = toggleViewModel)
}

@Preview
@Composable
fun SimpleTextToggleCheckboxPreview() {
private fun SimpleTextToggleCheckboxPreview() {
val toggleViewModel = VMDComponents.Toggle.withText("Label", true, MainScope())
VMDCheckbox(viewModel = toggleViewModel, label = { Text(it.text) })
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fun VMDCircularProgressIndicator(

@Preview
@Composable
fun DeterminateCircularProgressIndicatorPreview() {
private fun DeterminateCircularProgressIndicatorPreview() {
val progressViewModel = VMDComponents.Progress.determinate(0.25f, MainScope())
VMDCircularProgressIndicator(
viewModel = progressViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fun VMDLinearProgressIndicator(

@Preview
@Composable
fun DeterminateLinearProgressIndicatorPreview() {
private fun DeterminateLinearProgressIndicatorPreview() {
val progressViewModel = VMDComponents.Progress.determinate(0.25f, MainScope())
VMDLinearProgressIndicator(
modifier = Modifier.fillMaxWidth(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@ fun <C : VMDContent> VMDSwitch(

@Preview
@Composable
fun EnabledSwitchPreview() {
private fun EnabledSwitchPreview() {
val toggleViewModel =
VMDComponents.Toggle.withState(true, MainScope())
VMDSwitch(viewModel = toggleViewModel)
}

@Preview
@Composable
fun DisabledSwitchPreview() {
private fun DisabledSwitchPreview() {
val toggleViewModel =
VMDComponents.Toggle.withState(false, MainScope())
VMDSwitch(viewModel = toggleViewModel)
}

@Preview
@Composable
fun SimpleTextSwitchPreview() {
private fun SimpleTextSwitchPreview() {
val toggleViewModel =
VMDComponents.Toggle.withText("Label", true, MainScope())
VMDSwitch(viewModel = toggleViewModel, label = { Text(it.text) })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.mirego.trikot.viewmodels.declarative.compose.viewmodel.material3

import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.Text
import androidx.compose.material3.TextFieldColors
import androidx.compose.material3.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.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.TextStyle
import com.mirego.trikot.viewmodels.declarative.components.VMDTextFieldViewModel
import com.mirego.trikot.viewmodels.declarative.compose.extensions.composeValue
import com.mirego.trikot.viewmodels.declarative.compose.extensions.isOverridingAlpha
import com.mirego.trikot.viewmodels.declarative.compose.extensions.observeAsState
import com.mirego.trikot.viewmodels.declarative.compose.extensions.vmdModifier
import com.mirego.trikot.viewmodels.declarative.compose.viewmodel.internal.FormattedVisualTransformation

@ExperimentalMaterial3Api
@Composable
fun VMDBasicTextField(
viewModel: VMDTextFieldViewModel,
modifier: Modifier = Modifier,
readOnly: Boolean = false,
textStyle: TextStyle = TextStyle.Default,
placeHolderStyle: TextStyle = LocalTextStyle.current,
keyboardActions: KeyboardActions = KeyboardActions(),
singleLine: Boolean = false,
maxLines: Int = Int.MAX_VALUE,
minLines: Int = 1,
isError: Boolean = false,
onTextLayout: (TextLayoutResult) -> Unit = {},
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
colors: TextFieldColors = TextFieldDefaults.colors(),
cursorBrush: Brush = SolidColor(Color.Black),
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
contentPadding: PaddingValues = TextFieldDefaults.contentPaddingWithoutLabel()
) {
val textFieldViewModel: VMDTextFieldViewModel by viewModel.observeAsState(excludedProperties = if (modifier.isOverridingAlpha()) listOf(viewModel::isHidden) else emptyList())
val keyboardActionsDelegate = buildKeyboardActions(viewModel, keyboardActions)

val textColor = textStyle.color
val mergedTextStyle = textStyle.merge(TextStyle(color = textColor))
val visualTransformation = FormattedVisualTransformation(viewModel.formatText)

BasicTextField(
value = viewModel.text,
onValueChange = { value: String ->
viewModel.onValueChange(value)
},
modifier = modifier.vmdModifier(viewModel),
enabled = textFieldViewModel.isEnabled,
readOnly = readOnly,
textStyle = mergedTextStyle,
keyboardOptions = KeyboardOptions(
keyboardType = textFieldViewModel.keyboardType.composeValue,
capitalization = textFieldViewModel.autoCapitalization.composeValue,
imeAction = textFieldViewModel.keyboardReturnKeyType.composeValue
),
keyboardActions = keyboardActionsDelegate,
maxLines = maxLines,
minLines = minLines,
singleLine = singleLine,
visualTransformation = visualTransformation,
onTextLayout = onTextLayout,
interactionSource = interactionSource,
cursorBrush = cursorBrush,
decorationBox = @Composable { innerTextField ->
TextFieldDefaults.DecorationBox(
value = viewModel.text,
visualTransformation = visualTransformation,
innerTextField = innerTextField,
placeholder = {
Text(
text = textFieldViewModel.placeholder,
style = placeHolderStyle
)
},
singleLine = singleLine,
enabled = viewModel.isEnabled,
isError = isError,
interactionSource = interactionSource,
colors = colors,
contentPadding = contentPadding,
leadingIcon = leadingIcon,
trailingIcon = trailingIcon
)
}
)
}
Loading

0 comments on commit 84d2154

Please sign in to comment.