-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AN/USER] feat: 축제 목록 화면 스크롤 민감도를 줄인다(#�764) (#765)
* feat(customView): 가로 스크롤 시 세로 스크롤과 중첩되지 않는 커스텀 리사이클러뷰 작성 * feat(FestivalList): 축제 목록 리사이클러뷰의 민감도를 줄인다 * feat(FestivalList): 스와이프 새로고침의 민감도를 줄인다 * feat(FestivalList): 축제 목록 tab 디자인 수정 * feat(FestivalList): 축제 이름에서 대학교 이름을 뺀다
- Loading branch information
1 parent
0bcd8d7
commit 1f3cf51
Showing
5 changed files
with
70 additions
and
5 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
.../main/java/com/festago/festago/presentation/ui/customview/OrientationAwareRecyclerView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.festago.festago.presentation.ui.customview | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.MotionEvent | ||
import androidx.recyclerview.widget.RecyclerView | ||
|
||
/** | ||
* A RecyclerView that only handles scroll events with the same orientation of its LayoutManager. | ||
* Avoids situations where nested recyclerviews don't receive touch events properly: | ||
*/ | ||
class OrientationAwareRecyclerView @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet, | ||
defStyleAttr: Int = 0, | ||
) : RecyclerView(context, attrs, defStyleAttr) { | ||
|
||
private var lastX = 0.0f | ||
private var lastY = 0.0f | ||
private var scrolling = false | ||
|
||
init { | ||
addOnScrollListener(object : OnScrollListener() { | ||
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { | ||
super.onScrollStateChanged(recyclerView, newState) | ||
scrolling = newState != SCROLL_STATE_IDLE | ||
} | ||
}) | ||
} | ||
|
||
override fun onInterceptTouchEvent(e: MotionEvent): Boolean { | ||
val lm = layoutManager ?: return super.onInterceptTouchEvent(e) | ||
var allowScroll = true | ||
when (e.actionMasked) { | ||
MotionEvent.ACTION_DOWN -> { | ||
lastX = e.x | ||
lastY = e.y | ||
// If we were scrolling, stop now by faking a touch release | ||
if (scrolling) { | ||
val newEvent = MotionEvent.obtain(e) | ||
newEvent.action = MotionEvent.ACTION_UP | ||
return super.onInterceptTouchEvent(newEvent) | ||
} | ||
} | ||
|
||
MotionEvent.ACTION_MOVE -> { | ||
// We're moving, so check if we're trying | ||
// to scroll vertically or horizontally so we don't intercept the wrong event. | ||
val currentX = e.x | ||
val currentY = e.y | ||
val dx = Math.abs(currentX - lastX) | ||
val dy = Math.abs(currentY - lastY) | ||
allowScroll = if (dy > dx) lm.canScrollVertically() else lm.canScrollHorizontally() | ||
} | ||
} | ||
if (!allowScroll) return false | ||
return super.onInterceptTouchEvent(e) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters