11package com.richtextinput
22
33import android.R.attr.htmlDescription
4+ import android.app.Activity
45import android.graphics.Typeface
56import android.text.Spannable
67import android.text.style.StrikethroughSpan
78import android.text.style.StyleSpan
89import android.text.style.UnderlineSpan
10+ import android.view.inputmethod.InputMethodManager
911import android.widget.EditText
1012import androidx.core.text.HtmlCompat
1113import androidx.core.text.toHtml
@@ -68,6 +70,12 @@ class RichTextInputViewManager : SimpleViewManager<EditText>() {
6870 Assertions .assertNotNull(root)
6971
7072 when (commandId) {
73+ " focus" -> {
74+ focus(root)
75+ }
76+ " blur" -> {
77+ blur(root)
78+ }
7179 " toggleBold" -> {
7280 toggleBold(root)
7381 }
@@ -92,6 +100,20 @@ class RichTextInputViewManager : SimpleViewManager<EditText>() {
92100 super .receiveCommand(root, commandId, args)
93101 }
94102
103+ fun focus (editText : EditText ) {
104+ editText.requestFocus()
105+
106+ val inputMethodManager = editText.context.getSystemService(Activity .INPUT_METHOD_SERVICE ) as InputMethodManager
107+ inputMethodManager.showSoftInput(editText, 0 )
108+ }
109+
110+ fun blur (editText : EditText ) {
111+ editText.clearFocus()
112+
113+ val inputMethodManager = editText.context.getSystemService(Activity .INPUT_METHOD_SERVICE ) as InputMethodManager
114+ inputMethodManager.hideSoftInputFromWindow(editText.windowToken, 0 )
115+ }
116+
95117 fun insertText (editText : EditText , text : String ) {
96118 val spannedText = HtmlCompat .fromHtml(text, HtmlCompat .FROM_HTML_MODE_LEGACY )
97119 val trimmedText = spannedText.toString().trim()
0 commit comments