Skip to content

Commit 49fd2d6

Browse files
authored
Merge pull request #831 from Team-WSS/fix/820
fix: 텍스트 드래그 안되는 문제 해결
2 parents 76ad429 + b3d123a commit 49fd2d6

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

app/src/main/java/com/into/websoso/ui/createFeed/CreateFeedActivity.kt

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package com.into.websoso.ui.createFeed
33
import android.annotation.SuppressLint
44
import android.content.Context
55
import android.content.Intent
6+
import android.graphics.Rect
67
import android.os.Bundle
7-
import android.text.method.ScrollingMovementMethod
88
import android.view.MotionEvent
99
import android.view.View
1010
import android.view.inputmethod.InputMethodManager
@@ -57,9 +57,22 @@ class CreateFeedActivity : BaseActivity<ActivityCreateFeedBinding>(activity_crea
5757
createFeedImagePickerLauncher()
5858

5959
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
60-
val imm: InputMethodManager =
61-
getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
62-
imm.hideSoftInputFromWindow(currentFocus?.windowToken, 0)
60+
if (ev.action == MotionEvent.ACTION_DOWN) {
61+
val focusView = currentFocus
62+
if (focusView is android.widget.EditText) {
63+
val outRect = Rect()
64+
focusView.getGlobalVisibleRect(outRect)
65+
66+
// 터치한 좌표가 EditText 영역 밖일 경우에만 키보드 숨김 및 포커스 해제
67+
if (!outRect.contains(ev.rawX.toInt(), ev.rawY.toInt())) {
68+
focusView.clearFocus()
69+
val imm: InputMethodManager =
70+
getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
71+
imm.hideSoftInputFromWindow(currentFocus?.windowToken, 0)
72+
}
73+
}
74+
}
75+
6376
return super.dispatchTouchEvent(ev)
6477
}
6578

@@ -99,15 +112,19 @@ class CreateFeedActivity : BaseActivity<ActivityCreateFeedBinding>(activity_crea
99112
@SuppressLint("ClickableViewAccessibility")
100113
private fun setupCustomScroll() {
101114
binding.etCreateFeedContent.setOnTouchListener { view, event ->
102-
if (view.hasFocus()) {
103-
view.parent.requestDisallowInterceptTouchEvent(true)
104-
if ((event.action and MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
115+
when (event.action and MotionEvent.ACTION_MASK) {
116+
MotionEvent.ACTION_DOWN -> {
117+
// 터치 시작 시 부모 개입 차단
118+
view.parent.requestDisallowInterceptTouchEvent(true)
119+
}
120+
121+
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
105122
view.parent.requestDisallowInterceptTouchEvent(false)
106123
}
107124
}
125+
108126
false
109127
}
110-
binding.etCreateFeedContent.movementMethod = ScrollingMovementMethod()
111128
}
112129

113130
private fun onCreateFeedClick() {
@@ -138,8 +155,11 @@ class CreateFeedActivity : BaseActivity<ActivityCreateFeedBinding>(activity_crea
138155

139156
when {
140157
editFeedModel == null -> createFeedViewModel.createFeed()
158+
141159
editFeedModel.feedId == DEFAULT_FEED_ID -> createFeedViewModel.createFeed()
160+
142161
editFeedModel.feedCategory.isEmpty() -> createFeedViewModel.createFeed()
162+
143163
else -> createFeedViewModel.editFeed(
144164
feedId = editFeedModel.feedId,
145165
)

0 commit comments

Comments
 (0)