Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Add inputType to RichTextEditor to allow auto capitalisation (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinesp authored Nov 20, 2023
1 parent c698b1b commit be02439
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.element.android.wysiwyg.compose

import android.text.InputType
import android.view.View
import androidx.appcompat.widget.AppCompatEditText
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -46,6 +47,7 @@ fun RichTextEditor(
state: RichTextEditorState = rememberRichTextEditorState(),
registerStateUpdates: Boolean = true,
style: RichTextEditorStyle = RichTextEditorDefaults.style(),
inputType: Int = RichTextEditorDefaults.inputType,
resolveMentionDisplay: (text: String, url: String) -> TextDisplay = RichTextEditorDefaults.MentionDisplay,
resolveRoomMentionDisplay: () -> TextDisplay = RichTextEditorDefaults.RoomMentionDisplay,
onError: (Throwable) -> Unit = {},
Expand All @@ -60,6 +62,7 @@ fun RichTextEditor(
registerStateUpdates = registerStateUpdates,
modifier = modifier,
style = style,
inputType = inputType,
onError = onError,
resolveMentionDisplay = resolveMentionDisplay,
resolveRoomMentionDisplay = resolveRoomMentionDisplay
Expand All @@ -73,6 +76,7 @@ private fun RealEditor(
registerStateUpdates: Boolean,
modifier: Modifier = Modifier,
style: RichTextEditorStyle,
inputType: Int,
onError: (Throwable) -> Unit,
resolveMentionDisplay: (text: String, url: String) -> TextDisplay,
resolveRoomMentionDisplay: () -> TextDisplay,
Expand Down Expand Up @@ -175,6 +179,7 @@ private fun RealEditor(
},
update = { view ->
Timber.i("RichTextEditor update() called")
if (inputType != view.inputType) { view.inputType = inputType }
view.applyStyleInCompose(style)
view.typeface = typeface
view.updateStyle(style.toStyleConfig(view.context), mentionDisplayHandler)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.element.android.wysiwyg.compose

import android.text.InputType
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
Expand Down Expand Up @@ -254,4 +255,10 @@ object RichTextEditorDefaults {
),
)
}

const val inputType: Int = InputType.TYPE_CLASS_TEXT or
InputType.TYPE_TEXT_FLAG_MULTI_LINE or
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES or
InputType.TYPE_TEXT_FLAG_AUTO_CORRECT or
InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE
}

0 comments on commit be02439

Please sign in to comment.