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

Commit

Permalink
Hide system keyboard on touch rebound set text field
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkitSuda committed Nov 28, 2022
1 parent cf91c9d commit ab04c05
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@

package com.ankitsuda.rebound.ui.keyboard.field

import android.annotation.SuppressLint
import android.content.Context
import android.text.InputType
import android.view.Gravity
import android.view.View
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputConnection
import android.view.inputmethod.InputMethodManager
import android.widget.TextView
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
Expand All @@ -37,6 +40,9 @@ import com.ankitsuda.base.util.toLegacyInt
import com.ankitsuda.rebound.ui.keyboard.LocalReboundSetKeyboard
import com.ankitsuda.rebound.ui.keyboard.enums.ReboundKeyboardType


@SuppressLint("ClickableViewAccessibility")
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun RowScope.ReboundSetTextField(
layoutWeight: Float = 1.25f,
Expand Down Expand Up @@ -77,7 +83,7 @@ fun RowScope.ReboundSetTextField(
onValueChange?.invoke(newValue)
}
}
setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS)
setRawInputType(inputType or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS)
setTextIsSelectable(true)
val ic = onCreateInputConnection(EditorInfo())

Expand All @@ -88,6 +94,21 @@ fun RowScope.ReboundSetTextField(
keyboard.show()
}

setOnTouchListener { view, motionEvent ->
val imm: InputMethodManager =
context.getSystemService(
Context.INPUT_METHOD_SERVICE
) as InputMethodManager
imm.hideSoftInputFromWindow(
view.windowToken,
InputMethodManager.HIDE_NOT_ALWAYS
)

view.onTouchEvent(motionEvent) // Call native handler

true
}

onFocusChangeListener = View.OnFocusChangeListener { _, p1 ->
if (p1) {
keyboard.setKeyboardType(reboundKeyboardType)
Expand Down

0 comments on commit ab04c05

Please sign in to comment.