From 1023ab91c7d36dc6de4f105b092e0fa2289182cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Leb=C3=A8gue?= Date: Tue, 14 Jan 2025 16:35:50 +0100 Subject: [PATCH] =?UTF-8?q?feat(isReadOnly):=20make=20the=20InputText=20re?= =?UTF-8?q?ad=20only=20if=20needed=20Android=5Fside=E2=80=A6=20(#34)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- .../src/main/java/com/xpeho/xpeho_ui_android/InputText.kt | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 68f4bc9..4a982fc 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,8 @@ InputText( focusRequester = FocusRequester, keyboardAction = ImeAction, onKeyboardAction = () -> Unit, - onInput = (String) -> Unit + onInput = (String) -> Unit, + isReadOnly = Boolean ) ``` diff --git a/xpeho_ui_android/src/main/java/com/xpeho/xpeho_ui_android/InputText.kt b/xpeho_ui_android/src/main/java/com/xpeho/xpeho_ui_android/InputText.kt index ed2bb66..008f51e 100644 --- a/xpeho_ui_android/src/main/java/com/xpeho/xpeho_ui_android/InputText.kt +++ b/xpeho_ui_android/src/main/java/com/xpeho/xpeho_ui_android/InputText.kt @@ -64,7 +64,8 @@ fun InputText( focusRequester: FocusRequester = FocusRequester(), keyboardAction: ImeAction = ImeAction.Next, onKeyboardAction: () -> Unit = {}, - onInput: (String) -> Unit = { input -> println("The input $input is typed") } + onInput: (String) -> Unit = { input -> println("The input $input is typed") }, + isReadOnly : Boolean = false ) { var input by remember { mutableStateOf(defaultInput) } var passwordVisible by remember { mutableStateOf(false) } @@ -123,6 +124,7 @@ fun InputText( fontWeight = FontWeight.Normal, color = inputColor ), + readOnly = isReadOnly, modifier = Modifier .fillMaxWidth() .padding( @@ -132,6 +134,7 @@ fun InputText( .onFocusChanged { isFocused = it.isFocused } .semantics { contentDescription = label } .focusRequester(focusRequester) + ) } @@ -212,7 +215,8 @@ fun InputTextPreview() { defaultInput = "input", labelSize = 14.sp, inputSize = 16.sp, - focusRequester = test2FocusRequester + focusRequester = test2FocusRequester, + isReadOnly = true ) Spacer(modifier = Modifier.height(16.dp)) InputText(