Skip to content

Commit

Permalink
feat: 키보드 이벤트 감지 기능 수정 (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaehyuns authored and ChooSeoyeon committed Oct 11, 2024
1 parent e05eaae commit 26b1807
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.net.Uri
import android.os.Bundle
import android.view.MotionEvent
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -214,8 +215,19 @@ class CommentDetailActivity : AppCompatActivity(), OnUpdateStatusClickListener {
}

override fun dispatchTouchEvent(motionEvent: MotionEvent): Boolean {
(getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager).apply {
this.hideSoftInputFromWindow(currentFocus?.windowToken, 0)
val view = currentFocus
if (view != null && (view is EditText || view.id == R.id.iv_send_comment)) {
val screenCoords = IntArray(2)
view.getLocationOnScreen(screenCoords)
val x = motionEvent.rawX + view.left - screenCoords[0]
val y = motionEvent.rawY + view.top - screenCoords[1]

if (motionEvent.action == MotionEvent.ACTION_UP &&
(x < view.left || x >= view.right || y < view.top || y > view.bottom)
) {
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(view.windowToken, 0)
}
}
return super.dispatchTouchEvent(motionEvent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_20"
android:layout_marginEnd="@dimen/margin_20"
android:layout_marginEnd="@dimen/size_23"
android:layout_marginBottom="@dimen/margin_30"
android:background="@drawable/bg_gray100_radius_16dp"
android:fontFamily="@font/suit_medium"
Expand Down

0 comments on commit 26b1807

Please sign in to comment.