diff --git a/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/customview/OrientationAwareRecyclerView.kt b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/customview/OrientationAwareRecyclerView.kt new file mode 100644 index 000000000..6cadf13f8 --- /dev/null +++ b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/customview/OrientationAwareRecyclerView.kt @@ -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) + } +} diff --git a/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/home/festivallist/FestivalListFragment.kt b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/home/festivallist/FestivalListFragment.kt index 38213de80..47ebe1b2d 100644 --- a/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/home/festivallist/FestivalListFragment.kt +++ b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/home/festivallist/FestivalListFragment.kt @@ -78,6 +78,7 @@ class FestivalListFragment : Fragment() { vm.initFestivalList() binding.srlFestivalList.isRefreshing = false } + binding.srlFestivalList.setDistanceToTriggerSync(400) binding.ivSearch.setOnClickListener { // 임시 연결 showSchoolDetail() } diff --git a/android/festago/presentation/src/main/res/layout/fragment_festival_list.xml b/android/festago/presentation/src/main/res/layout/fragment_festival_list.xml index 2020f8f84..70e55fb23 100644 --- a/android/festago/presentation/src/main/res/layout/fragment_festival_list.xml +++ b/android/festago/presentation/src/main/res/layout/fragment_festival_list.xml @@ -69,7 +69,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/containerAppBarFestivalList"> - + tools:text="연세대 아카라카 연세대 아카라카 연세대 아카라카" /> + +