Skip to content

Commit

Permalink
names changed to make them more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
MFlisarWork committed Oct 29, 2024
1 parent ece5900 commit 7960e67
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ private fun RowScope.DemoDialogInput1(style: ComposeDialogStyle, icon: (@Composa
DialogInput(
state = state,
title = { Text("Input Dialog") },
input = input,
inputLabel = "Text",
value = input,
label = "Text",
icon = icon,
style = style,
onEvent = {
Expand Down Expand Up @@ -112,8 +112,8 @@ private fun RowScope.DemoDialogInput2(style: ComposeDialogStyle, icon: (@Composa
DialogInput(
state = state,
title = { Text("Input Dialog") },
input = input,
inputLabel = "Numerical Value",
value = input,
label = "Numerical Value",
icon = icon,
style = style,
onEvent = {
Expand Down Expand Up @@ -153,7 +153,7 @@ private fun RowScope.DemoDialogInput3(style: ComposeDialogStyle, icon: (@Composa
state = state,
title = { Text("Input Integer Dialog") },
value = value,
valueLabel = "Integer",
label = "Integer",
icon = icon,
style = style,
onEvent = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ fun main() {
style = style,
title = { Text("Input Dialog") },
state = dialog,
inputLabel = "Enter some text...",
input = input,
label = "Enter some text...",
value = input,
onEvent = {
if (it is DialogEvent.Button && it.button == DialogButtonType.Positive) {
infos.add("Selected input: ${input.value}")
Expand All @@ -240,7 +240,7 @@ fun main() {
style = style,
title = { Text("Number Dialog") },
state = dialog,
valueLabel = "Enter a valid Integer...",
label = "Enter a valid Integer...",
value = input,
onEvent = {
if (it is DialogEvent.Button && it.button == DialogButtonType.Positive) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.michaelflisar.composedialogs.dialogs.date

import com.michaelflisar.composedialogs.core.DialogDefaults
import com.michaelflisar.composedialogs.core.SpecialOptions
import kotlinx.datetime.DayOfWeek
import kotlinx.datetime.LocalDate
import kotlinx.datetime.Month
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.michaelflisar.composedialogs.dialogs.date

import com.michaelflisar.composedialogs.core.DialogDefaults
import com.michaelflisar.composedialogs.core.SpecialOptions
import com.michaelflisar.composedialogs.core.specialOptions
import kotlinx.datetime.DayOfWeek
import kotlinx.datetime.LocalDate
import kotlinx.datetime.Month
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import com.michaelflisar.composedialogs.dialogs.input.composables.DialogInputTex
*
* **Basic Parameters:** all params not described here are derived from [Dialog], check it out for more details
*
* @param input the selected text
* @param inputLabel the optional label of the input field
* @param value the selected text
* @param label the optional label of the input field
* @param inputPlaceholder the placeholder the for the input field
* @param singleLine if true, the input field will only allow a single line
* @param maxLines the max lines for the input field
Expand All @@ -52,8 +52,8 @@ fun DialogInput(
// Base Dialog - State
state: DialogState,
// Custom - Required
input: MutableState<String>,
inputLabel: String = "",
value: MutableState<String>,
label: String = "",
// Custom - Optional
inputPlaceholder: String = "",
singleLine: Boolean = false,
Expand Down Expand Up @@ -85,8 +85,8 @@ fun DialogInput(
}
DialogInputTextField(
modifier,
input,
inputLabel,
value,
label,
inputPlaceholder,
singleLine,
maxLines,
Expand All @@ -108,7 +108,7 @@ fun DialogInput(
/**
* convenient function for [DialogInput]
*
* @param input the initial text for the input field
* @param text the initial text for the input field
*
* @return a state holding the current input value
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import com.michaelflisar.composedialogs.dialogs.input.composables.DialogInputTex
* **Basic Parameters:** all params not described here are derived from [Dialog], check it out for more details
*
* @param value the selected number
* @param valueLabel the optional label of the input field
* @param label the optional label of the input field
* @param inputPlaceholder a placeholder if the input is empty
* @param singleLine if true, the input field will only allow a single line
Expand All @@ -54,7 +54,7 @@ fun <T : Number> DialogInputNumber(
state: DialogState,
// Custom - Required
value: MutableState<T>,
valueLabel: String = "",
label: String = "",
// Custom - Optional
inputPlaceholder: String = "",
singleLine: Boolean = false,
Expand Down Expand Up @@ -98,7 +98,7 @@ fun <T : Number> DialogInputNumber(
DialogInputTextField(
modifier,
stringInput,
valueLabel,
label,
inputPlaceholder,
singleLine,
maxLines,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import com.michaelflisar.composedialogs.dialogs.input.DialogInputValidator
@Composable
fun DialogInputTextField(
modifier: Modifier = Modifier,
state: MutableState<String>,
value: MutableState<String>,
label: String = "",
placeholder: String = "",
singleLine: Boolean = false,
Expand Down Expand Up @@ -62,38 +62,38 @@ fun DialogInputTextField(
var textFieldValueState by remember {
mutableStateOf(
TextFieldValue(
text = state.value,
selection = if (state.value.isEmpty())
text = value.value,
selection = if (value.value.isEmpty())
TextRange.Zero
else {
when (selectionState) {
DialogInput.SelectionState.CursorEnd -> TextRange(
state.value.length,
state.value.length
value.value.length,
value.value.length
)

DialogInput.SelectionState.Default -> TextRange.Zero
DialogInput.SelectionState.SelectAll -> TextRange(0, state.value.length)
DialogInput.SelectionState.SelectAll -> TextRange(0, value.value.length)
is DialogInput.SelectionState.Selection -> TextRange(
selectionState.start.coerceIn(
0,
state.value.length
), selectionState.end.coerceIn(0, state.value.length)
value.value.length
), selectionState.end.coerceIn(0, value.value.length)
)
}
}
)
)
}
val textFieldValue = textFieldValueState.copy(text = state.value)
val textFieldValue = textFieldValueState.copy(text = value.value)
SideEffect {
if (textFieldValue.selection != textFieldValueState.selection ||
textFieldValue.composition != textFieldValueState.composition
) {
textFieldValueState = textFieldValue
}
}
var lastTextValue by remember(state.value) { mutableStateOf(state.value) }
var lastTextValue by remember(value.value) { mutableStateOf(value.value) }

OutlinedTextField(
value = textFieldValue,
Expand All @@ -106,7 +106,7 @@ fun DialogInputTextField(
lastTextValue = it.text
if (changed) {
validator.check(it.text)
state.value = it.text
value.value = it.text
val valid = validator.isValid()
onStateChanged(valid, it.text)
}
Expand All @@ -132,8 +132,8 @@ fun DialogInputTextField(
trailingIcon = if (clearable) {
@Composable {
when {
state.value.isNotEmpty() -> IconButton(onClick = {
state.value = ""
value.value.isNotEmpty() -> IconButton(onClick = {
value.value = ""
validator.check("")
val valid = validator.isValid()
onStateChanged(valid, "")
Expand Down

0 comments on commit 7960e67

Please sign in to comment.