TP-43540 | Added support for cursor handle and cursor background colo… (#197)
This commit is contained in:
committed by
GitHub
parent
7afc667357
commit
04727e9522
@@ -24,7 +24,9 @@ data class CustomTextFieldProperty(
|
||||
var colors: OutlinedTextFieldColors? = null,
|
||||
var arrangementData: ArrangementData? = null,
|
||||
var invalidCharRegex: String? = null,
|
||||
var showKeyboardOnRender : Boolean? = null
|
||||
var showKeyboardOnRender : Boolean? = null,
|
||||
var cursorHandleColor: String? = null,
|
||||
var cursorBackgroundColor: String? = null
|
||||
) : BaseProperty() {
|
||||
|
||||
override fun copyNonNullFrom(property: BaseProperty?) {
|
||||
@@ -50,6 +52,8 @@ data class CustomTextFieldProperty(
|
||||
customTextFieldProperty?.arrangementData?.let { arrangementData = it }
|
||||
customTextFieldProperty?.invalidCharRegex?.let { invalidCharRegex = it }
|
||||
customTextFieldProperty?.showKeyboardOnRender?.let { showKeyboardOnRender = it }
|
||||
customTextFieldProperty?.cursorHandleColor?.let { cursorHandleColor = it }
|
||||
customTextFieldProperty?.cursorBackgroundColor?.let { cursorBackgroundColor = it }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.text.selection.LocalTextSelectionColors
|
||||
import androidx.compose.foundation.text.selection.TextSelectionColors
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -28,6 +30,7 @@ import com.navi.uitron.model.data.UiTronData
|
||||
import com.navi.uitron.model.ui.*
|
||||
import com.navi.uitron.utils.CUSTOM_TEXT_FIELD_DATA
|
||||
import com.navi.uitron.utils.CUSTOM_TEXT_FIELD_PROPERTY
|
||||
import com.navi.uitron.utils.EMPTY
|
||||
import com.navi.uitron.utils.ShapeUtil
|
||||
import com.navi.uitron.utils.UI_TRON_VM
|
||||
import com.navi.uitron.viewmodel.UiTronViewModel
|
||||
@@ -54,6 +57,9 @@ class CustomTextFieldRenderer(
|
||||
private val uiTronRenderer: UiTronRenderer
|
||||
) : Renderer<CustomTextFieldProperty> {
|
||||
|
||||
private val colorPurple = "#1F002A"
|
||||
private val alpha = 0.4f
|
||||
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
override fun Render(
|
||||
@@ -103,6 +109,13 @@ class CustomTextFieldRenderer(
|
||||
mutableStateOf(property.colors?.unfocusedBorderColor)
|
||||
}
|
||||
val keyboardController = LocalSoftwareKeyboardController.current
|
||||
|
||||
val customTextSelectionColors by remember(property?.cursorBackgroundColor,property?.cursorHandleColor) {
|
||||
mutableStateOf(
|
||||
getCustomTextSelectionColor(property)
|
||||
)
|
||||
}
|
||||
|
||||
if (property.visible.orTrue()) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@@ -162,69 +175,73 @@ class CustomTextFieldRenderer(
|
||||
.wrapContentHeight()
|
||||
.layoutId(property.layoutId.orEmpty())
|
||||
) {
|
||||
BasicTextField(
|
||||
modifier = Modifier
|
||||
.onFocusChanged {
|
||||
isFocused = it.isFocused
|
||||
if (customTextFieldData?.hasError
|
||||
.orFalse()
|
||||
.not()
|
||||
) {
|
||||
if (it.isFocused) {
|
||||
borderColor = property.colors?.focusedBorderColor
|
||||
uiTronViewModel.handleActions(customTextFieldData?.onFocusAction)
|
||||
} else {
|
||||
borderColor = property.colors?.unfocusedBorderColor
|
||||
uiTronViewModel.handleActions(customTextFieldData?.onDeFocusAction)
|
||||
CompositionLocalProvider(
|
||||
LocalTextSelectionColors provides customTextSelectionColors
|
||||
) {
|
||||
BasicTextField(
|
||||
modifier = Modifier
|
||||
.onFocusChanged {
|
||||
isFocused = it.isFocused
|
||||
if (customTextFieldData?.hasError
|
||||
.orFalse()
|
||||
.not()
|
||||
) {
|
||||
if (it.isFocused) {
|
||||
borderColor = property.colors?.focusedBorderColor
|
||||
uiTronViewModel.handleActions(customTextFieldData?.onFocusAction)
|
||||
} else {
|
||||
borderColor = property.colors?.unfocusedBorderColor
|
||||
uiTronViewModel.handleActions(customTextFieldData?.onDeFocusAction)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.setPadding(property.inputTextProperty?.padding)
|
||||
.align(
|
||||
getContentAlignment(
|
||||
property.inputTextProperty?.alignment
|
||||
?: ContentAlignmentType.CenterStart.name
|
||||
.setPadding(property.inputTextProperty?.padding)
|
||||
.align(
|
||||
getContentAlignment(
|
||||
property.inputTextProperty?.alignment
|
||||
?: ContentAlignmentType.CenterStart.name
|
||||
)
|
||||
)
|
||||
.fillMaxWidth(),
|
||||
textStyle = TextStyle(
|
||||
fontSize = property.inputTextProperty?.textStyle?.fontSize?.sp
|
||||
?: 14.sp,
|
||||
color = property.inputTextProperty?.textStyle?.color?.hexToComposeColor
|
||||
?: Color.Black,
|
||||
fontFamily = UiTronSdkManager.getDependencyProvider()
|
||||
.getFontFamily(property.inputTextProperty?.textStyle?.fontFamily),
|
||||
fontWeight = UiTronSdkManager.getDependencyProvider()
|
||||
.getFontWeight(property.inputTextProperty?.textStyle?.fontWeight)
|
||||
),
|
||||
keyboardOptions = KeyboardOptions(
|
||||
capitalization = KeyboardUtil.getKeyboardCapitalization(property.keyboardOptions?.capitalization),
|
||||
keyboardType = KeyboardUtil.getKeyboardType(property.keyboardOptions?.keyboardType),
|
||||
imeAction = KeyboardUtil.getImeAction(property.keyboardOptions?.imeAction)
|
||||
),
|
||||
keyboardActions = KeyboardActions(
|
||||
onDone = { keyboardController?.hide() }
|
||||
),
|
||||
value = inputValue,
|
||||
onValueChange = { input ->
|
||||
val editedInput = onInputValueChange(
|
||||
input = input,
|
||||
property = property,
|
||||
customTextFieldData = customTextFieldData,
|
||||
uiTronViewModel = uiTronViewModel,
|
||||
isTextTransformedValueUpdated = mutableStateOf(false)
|
||||
)
|
||||
isTextTransformedValueEdited.value = true
|
||||
inputValue = editedInput
|
||||
},
|
||||
singleLine = property.singleLine ?: false,
|
||||
visualTransformation = property.visualTransformation?.getVisualTransformation()
|
||||
?: VisualTransformation.None,
|
||||
enabled = property.isEnabled ?: true,
|
||||
cursorBrush = SolidColor(
|
||||
property.cursorColor?.hexToComposeColor ?: Color.Gray
|
||||
)
|
||||
.fillMaxWidth(),
|
||||
textStyle = TextStyle(
|
||||
fontSize = property.inputTextProperty?.textStyle?.fontSize?.sp
|
||||
?: 14.sp,
|
||||
color = property.inputTextProperty?.textStyle?.color?.hexToComposeColor
|
||||
?: Color.Black,
|
||||
fontFamily = UiTronSdkManager.getDependencyProvider()
|
||||
.getFontFamily(property.inputTextProperty?.textStyle?.fontFamily),
|
||||
fontWeight = UiTronSdkManager.getDependencyProvider()
|
||||
.getFontWeight(property.inputTextProperty?.textStyle?.fontWeight)
|
||||
),
|
||||
keyboardOptions = KeyboardOptions(
|
||||
capitalization = KeyboardUtil.getKeyboardCapitalization(property.keyboardOptions?.capitalization),
|
||||
keyboardType = KeyboardUtil.getKeyboardType(property.keyboardOptions?.keyboardType),
|
||||
imeAction = KeyboardUtil.getImeAction(property.keyboardOptions?.imeAction)
|
||||
),
|
||||
keyboardActions = KeyboardActions(
|
||||
onDone = { keyboardController?.hide() }
|
||||
),
|
||||
value = inputValue,
|
||||
onValueChange = { input ->
|
||||
val editedInput = onInputValueChange(
|
||||
input = input,
|
||||
property = property,
|
||||
customTextFieldData = customTextFieldData,
|
||||
uiTronViewModel = uiTronViewModel,
|
||||
isTextTransformedValueUpdated = mutableStateOf(false)
|
||||
)
|
||||
isTextTransformedValueEdited.value = true
|
||||
inputValue = editedInput
|
||||
},
|
||||
singleLine = property.singleLine ?: false,
|
||||
visualTransformation = property.visualTransformation?.getVisualTransformation()
|
||||
?: VisualTransformation.None,
|
||||
enabled = property.isEnabled ?: true,
|
||||
cursorBrush = SolidColor(
|
||||
property.cursorColor?.hexToComposeColor ?: Color.Gray
|
||||
)
|
||||
)
|
||||
}
|
||||
if (inputValue.isEmpty()) {
|
||||
property.hintStyle?.let {
|
||||
TextRenderer().Render(
|
||||
@@ -347,4 +364,27 @@ class CustomTextFieldRenderer(
|
||||
}
|
||||
return inputValue
|
||||
}
|
||||
|
||||
private fun getCustomTextSelectionColor(property: CustomTextFieldProperty): TextSelectionColors {
|
||||
|
||||
if (property.cursorBackgroundColor.isNullOrEmpty())
|
||||
property.cursorBackgroundColor = null
|
||||
|
||||
if (property.cursorHandleColor.isNullOrEmpty())
|
||||
property.cursorHandleColor = null
|
||||
|
||||
val cursorHandleColor =
|
||||
property.cursorHandleColor?.hexToComposeColor ?: colorPurple.hexToComposeColor
|
||||
|
||||
val cursorBackgroundColor = property.cursorBackgroundColor?.hexToComposeColor
|
||||
?: (
|
||||
property.cursorHandleColor?.hexToComposeColor?.copy(alpha = alpha)
|
||||
?: colorPurple.hexToComposeColor.copy(alpha = alpha)
|
||||
)
|
||||
|
||||
return TextSelectionColors(
|
||||
handleColor = cursorHandleColor,
|
||||
backgroundColor = cursorBackgroundColor
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user