TP-40579 add on max char reached and on click action in custom text f… (#170)
This commit is contained in:
@@ -47,16 +47,18 @@ fun PlayGroundScreen() {
|
||||
.fillMaxSize()
|
||||
) {
|
||||
if (fieldValue.value.isEmpty().not()) {
|
||||
var errorMessage = "Error In Config"
|
||||
val uiTronResponse: UiTronResponse? = try {
|
||||
stringToUiTronResponse(rawString = fieldValue.value)
|
||||
} catch (e: Exception) {
|
||||
errorMessage = e.toString()
|
||||
null
|
||||
}
|
||||
uiTronResponse?.let {
|
||||
UiTronRenderer(uiTronResponse.data, uiTronViewModel = UiTronViewModel())
|
||||
.Render(composeViews = uiTronResponse.parentComposeView.orEmpty())
|
||||
} ?: kotlin.run {
|
||||
Text(text = "Error In Config", color = Color.Red)
|
||||
Text(text = errorMessage, color = Color.Red)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ data class CustomTextFieldData(
|
||||
var hint: String? = null,
|
||||
var onValueChangeAction: UiTronActionData? = null,
|
||||
var onInputValueChangeAction: UiTronActionData? = null,
|
||||
var onMaxCharReachedAction: UiTronActionData? = null,
|
||||
var inputText: String? = null,
|
||||
var hasError: Boolean? = null,
|
||||
var errorMessage: String? = null,
|
||||
@@ -15,6 +16,7 @@ data class CustomTextFieldData(
|
||||
hint = data?.hint ?: hint
|
||||
onValueChangeAction = data?.onValueChangeAction ?: onValueChangeAction
|
||||
onInputValueChangeAction = data?.onInputValueChangeAction ?: onInputValueChangeAction
|
||||
onMaxCharReachedAction = data?.onMaxCharReachedAction ?: onMaxCharReachedAction
|
||||
inputText = data?.inputText ?: inputText
|
||||
hasError = data?.hasError ?: hasError
|
||||
errorMessage = data?.errorMessage ?: errorMessage
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.navi.uitron.model.data.UiTronData
|
||||
import com.navi.uitron.model.ui.*
|
||||
import com.navi.uitron.utils.ShapeUtil
|
||||
import com.navi.uitron.viewmodel.UiTronViewModel
|
||||
import customClickable
|
||||
import getContentAlignment
|
||||
import getDataId
|
||||
import getInputId
|
||||
@@ -74,15 +75,22 @@ class CustomTextFieldRenderer(
|
||||
customTextFieldData =
|
||||
customTextFieldData?.copyNonNull(dataState.value) ?: dataState.value
|
||||
}
|
||||
var inputValue by remember {
|
||||
mutableStateOf(customTextFieldData?.inputText.orEmpty())
|
||||
val isTextTransformedValueUpdated = remember {
|
||||
mutableStateOf(false)
|
||||
}
|
||||
var inputValue by remember(customTextFieldData?.inputText) {
|
||||
val input = onInputValueChange(
|
||||
input = customTextFieldData?.inputText.orEmpty(),
|
||||
property = property,
|
||||
customTextFieldData = customTextFieldData,
|
||||
uiTronViewModel = uiTronViewModel,
|
||||
isTextTransformedValueUpdated = isTextTransformedValueUpdated
|
||||
)
|
||||
mutableStateOf(input)
|
||||
}
|
||||
var isFocused by remember {
|
||||
mutableStateOf(false)
|
||||
}
|
||||
LaunchedEffect(Unit) {
|
||||
uiTronViewModel.handle[property.layoutId.getInputId()] = inputValue
|
||||
}
|
||||
var borderColor by remember {
|
||||
mutableStateOf(property.colors?.unfocusedBorderColor)
|
||||
}
|
||||
@@ -120,7 +128,14 @@ class CustomTextFieldRenderer(
|
||||
shape = ShapeUtil.getShape(shape = property.rowProperty?.borderStrokeData?.shape)
|
||||
)
|
||||
.setPadding(property.rowProperty?.padding ?: ComposePadding(10, 10, 10, 10))
|
||||
.alpha(property.alpha ?: 1.0f),
|
||||
.alpha(property.alpha ?: 1.0f)
|
||||
.customClickable(
|
||||
{
|
||||
uiTronViewModel.handleActions(customTextFieldData?.onClick)
|
||||
},
|
||||
actions = customTextFieldData?.onClick?.actions,
|
||||
property = property
|
||||
),
|
||||
verticalAlignment = getVerticalAlignment(
|
||||
property.rowProperty?.verticalAlignment
|
||||
?: VerticalAlignmentType.CenterVertically.name
|
||||
@@ -184,44 +199,19 @@ class CustomTextFieldRenderer(
|
||||
),
|
||||
value = inputValue,
|
||||
onValueChange = { input ->
|
||||
val updatedInput = if (property.singleLine.orFalse()) {
|
||||
input.replace("\n"," ")
|
||||
} else {
|
||||
input
|
||||
}
|
||||
if (!updatedInput.isInvalidInput(property.invalidCharRegex)) {
|
||||
property.maxChar?.let { maxChar ->
|
||||
if (maxChar >= updatedInput.length) {
|
||||
inputValue = updatedInput
|
||||
val transformedText = transformInput(
|
||||
property.valueTransformation,
|
||||
updatedInput
|
||||
)
|
||||
customTextFieldData?.inputText = transformedText
|
||||
uiTronViewModel.handle[property.layoutId.getInputId()] =
|
||||
transformedText
|
||||
if (property.applyValidationOnValueChange.orFalse() || customTextFieldData?.hasError == true) {
|
||||
uiTronViewModel.handleActions(customTextFieldData?.onValueChangeAction)
|
||||
}
|
||||
}
|
||||
} ?: run {
|
||||
inputValue = updatedInput
|
||||
val transformedText = transformInput(
|
||||
property.valueTransformation,
|
||||
updatedInput
|
||||
)
|
||||
customTextFieldData?.inputText = transformedText
|
||||
uiTronViewModel.handle[property.layoutId.getInputId()] =
|
||||
transformedText
|
||||
if (property.applyValidationOnValueChange.orFalse() || customTextFieldData?.hasError == true) {
|
||||
uiTronViewModel.handleActions(customTextFieldData?.onValueChangeAction)
|
||||
}
|
||||
}
|
||||
uiTronViewModel.handleActions(customTextFieldData?.onInputValueChangeAction)
|
||||
}
|
||||
val editedInput = onInputValueChange(
|
||||
input = input,
|
||||
property = property,
|
||||
customTextFieldData = customTextFieldData,
|
||||
uiTronViewModel = uiTronViewModel,
|
||||
isTextTransformedValueUpdated = mutableStateOf(false)
|
||||
)
|
||||
isTextTransformedValueUpdated.value = true
|
||||
inputValue = editedInput
|
||||
},
|
||||
singleLine = property.singleLine ?: false,
|
||||
visualTransformation = property.visualTransformation?.getVisualTransformation() ?: VisualTransformation.None,
|
||||
visualTransformation = property.visualTransformation?.getVisualTransformation()
|
||||
?: VisualTransformation.None,
|
||||
enabled = property.isEnabled ?: true,
|
||||
cursorBrush = SolidColor(
|
||||
property.cursorColor?.hexToComposeColor ?: Color.Gray
|
||||
@@ -258,6 +248,8 @@ class CustomTextFieldRenderer(
|
||||
} else if (inputValue.isNotNullAndNotEmpty()) {
|
||||
if (isFocused) {
|
||||
borderColor = property.colors?.focusedBorderColor
|
||||
} else {
|
||||
borderColor = property.colors?.unfocusedBorderColor
|
||||
}
|
||||
val successText = getTransformedText(
|
||||
property.successTextTransformation,
|
||||
@@ -277,4 +269,59 @@ class CustomTextFieldRenderer(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun onInputValueChange(
|
||||
input: String,
|
||||
property: CustomTextFieldProperty,
|
||||
customTextFieldData: CustomTextFieldData?,
|
||||
uiTronViewModel: UiTronViewModel,
|
||||
isTextTransformedValueUpdated: MutableState<Boolean>
|
||||
): String {
|
||||
if (isTextTransformedValueUpdated.value && input == customTextFieldData?.inputText) {
|
||||
isTextTransformedValueUpdated.value = false
|
||||
return customTextFieldData.inputText.orEmpty()
|
||||
}
|
||||
val updatedInput = if (property.singleLine.orFalse()) {
|
||||
input.replace("\n", " ")
|
||||
} else {
|
||||
input
|
||||
}
|
||||
var inputValue = updatedInput
|
||||
if (!updatedInput.isInvalidInput(property.invalidCharRegex)) {
|
||||
property.maxChar?.let { maxChar ->
|
||||
if (maxChar >= updatedInput.length) {
|
||||
inputValue = updatedInput
|
||||
val transformedText = transformInput(
|
||||
property.valueTransformation,
|
||||
updatedInput
|
||||
)
|
||||
customTextFieldData?.inputText = transformedText
|
||||
uiTronViewModel.handle[property.layoutId.getInputId()] =
|
||||
transformedText
|
||||
if (property.applyValidationOnValueChange.orFalse() || customTextFieldData?.hasError == true) {
|
||||
uiTronViewModel.handleActions(customTextFieldData?.onValueChangeAction)
|
||||
}
|
||||
if (maxChar == updatedInput.length) {
|
||||
uiTronViewModel.handleActions(customTextFieldData?.onMaxCharReachedAction)
|
||||
}
|
||||
} else {
|
||||
return customTextFieldData?.inputText.orEmpty()
|
||||
}
|
||||
} ?: run {
|
||||
inputValue = updatedInput
|
||||
val transformedText = transformInput(
|
||||
property.valueTransformation,
|
||||
updatedInput
|
||||
)
|
||||
customTextFieldData?.inputText = transformedText
|
||||
uiTronViewModel.handle[property.layoutId.getInputId()] =
|
||||
transformedText
|
||||
if (property.applyValidationOnValueChange.orFalse() || customTextFieldData?.hasError == true) {
|
||||
uiTronViewModel.handleActions(customTextFieldData?.onValueChangeAction)
|
||||
}
|
||||
}
|
||||
uiTronViewModel.handleActions(customTextFieldData?.onInputValueChangeAction)
|
||||
}
|
||||
return inputValue
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user