TP-38908 Hide Cursor Handle in OTP Renderer (#155)

This commit is contained in:
Aparna Vadlamani
2023-08-22 17:46:51 +05:30
committed by GitHub
parent 9fd2c6767f
commit 50b20faa1a

View File

@@ -23,11 +23,14 @@ import androidx.compose.ui.unit.dp
import androidx.compose.foundation.layout.*
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
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Color.Companion.Transparent
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.layout.layoutId
import androidx.compose.ui.platform.LocalConfiguration
@@ -287,36 +290,44 @@ class OtpBoxRenderer : Renderer<OtpBoxProperty> {
}
}
val keyboardController = LocalSoftwareKeyboardController.current
BasicTextField(
modifier = modifier,
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),
textAlign = TextAlign.Center
),
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() }
),
visualTransformation = property.visualTransformation?.getVisualTransformation()
?: VisualTransformation.None,
value = inputValue,
onValueChange = onValueChange,
singleLine = true,
enabled = property.isEnabled ?: true,
cursorBrush = SolidColor(
property.cursorColor?.hexToComposeColor ?: Color.Transparent
)
val customTextSelectionColors = TextSelectionColors(
handleColor = Transparent,
backgroundColor = Transparent
)
CompositionLocalProvider(
LocalTextSelectionColors provides customTextSelectionColors,
) {
BasicTextField(
modifier = modifier,
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),
textAlign = TextAlign.Center
),
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() }
),
visualTransformation = property.visualTransformation?.getVisualTransformation()
?: VisualTransformation.None,
value = inputValue,
onValueChange = onValueChange,
singleLine = true,
enabled = property.isEnabled ?: true,
cursorBrush = SolidColor(
property.cursorColor?.hexToComposeColor ?: Color.Transparent
)
)
}
}
}