Skip to content

Commit 68c00dc

Browse files
fix(ui): prevent SwipeRefreshLayout from intercepting child touch events (#173)
* Fix accidental rendering of swipe refresh indicator. * Fix scroll up in Files tab. * Update app/src/main/kotlin/org/fossify/filemanager/views/MySwipeRefreshLayout.kt Fix grammar after copy paste. Co-authored-by: Naveen Singh <[email protected]> * docs(changelog): add links --------- Co-authored-by: Naveen Singh <[email protected]> Co-authored-by: Naveen Singh <[email protected]>
1 parent 2fe8b22 commit 68c00dc

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Fixed
1515

16+
- Fixed accidental rendering of pull-to-refresh indicator ([#27])
1617
- Pull-to-refresh setting is now applied as expected ([#136])
1718

1819
## [1.0.1] - 2024-03-17
@@ -40,4 +41,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4041
[1.0.1]: https://github.com/FossifyOrg/File-Manager/compare/1.0.0...1.0.1
4142
[1.0.0]: https://github.com/FossifyOrg/File-Manager/releases/tag/1.0.0
4243

44+
[#27]: https://github.com/FossifyOrg/File-Manager/issues/27
4345
[#136]: https://github.com/FossifyOrg/File-Manager/issues/136
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.fossify.filemanager.views
2+
3+
import android.content.Context
4+
import android.util.AttributeSet
5+
import android.view.MotionEvent
6+
import android.view.View
7+
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
8+
import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
9+
10+
class MySwipeRefreshLayout @JvmOverloads constructor(
11+
context: Context,
12+
attrs: AttributeSet? = null,
13+
) : SwipeRefreshLayout(context, attrs) {
14+
override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
15+
// Setting "isEnabled = false" is recommended for users of this ViewGroup
16+
// who who are not interested in the pull to refresh functionality
17+
// Setting this easily avoids executing code needlessly before the check for "canChildScrollUp".
18+
if (!isEnabled) {
19+
return false
20+
}
21+
return super.onInterceptTouchEvent(ev)
22+
}
23+
24+
override fun onStartNestedScroll(child: View, target: View, nestedScrollAxes: Int): Boolean {
25+
// Ignoring nested scrolls from descendants.
26+
// Allowing descendants to trigger nested scrolls would defeat the purpose of this class
27+
// and result in pull to refresh to happen for all movements on the Y axis
28+
// (even as part of scale/quick scale gestures) while also doubling the throbber with the overscroll shadow.
29+
return if (isEnabled) {
30+
return false
31+
} else {
32+
super.onStartNestedScroll(child, target, nestedScrollAxes)
33+
}
34+
}
35+
36+
override fun canChildScrollUp(): Boolean {
37+
val directChild = getChildAt(0)
38+
return when (directChild) {
39+
is RecyclerViewFastScroller -> {
40+
val innerRecyclerView = directChild.getChildAt(0)
41+
innerRecyclerView?.canScrollVertically(-1) == true
42+
}
43+
else -> super.canChildScrollUp()
44+
}
45+
}
46+
}

app/src/main/res/layout/items_fragment.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
android:textStyle="italic"
6969
android:visibility="gone" />
7070

71-
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
71+
<org.fossify.filemanager.views.MySwipeRefreshLayout
7272
android:id="@+id/items_swipe_refresh"
7373
android:layout_width="match_parent"
7474
android:layout_height="wrap_content"
@@ -90,7 +90,7 @@
9090
app:layoutManager="org.fossify.commons.views.MyGridLayoutManager" />
9191

9292
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller>
93-
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
93+
</org.fossify.filemanager.views.MySwipeRefreshLayout>
9494
</RelativeLayout>
9595

9696
<org.fossify.commons.views.MyFloatingActionButton

app/src/main/res/layout/recents_fragment.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
android:visibility="gone"
2323
tools:visibility="visible" />
2424

25-
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
25+
<org.fossify.filemanager.views.MySwipeRefreshLayout
2626
android:id="@+id/recents_swipe_refresh"
2727
android:layout_width="match_parent"
2828
android:layout_height="wrap_content">
@@ -37,5 +37,5 @@
3737
android:scrollbars="none"
3838
app:layoutManager="org.fossify.commons.views.MyGridLayoutManager" />
3939

40-
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
40+
</org.fossify.filemanager.views.MySwipeRefreshLayout>
4141
</org.fossify.filemanager.fragments.RecentsFragment>

0 commit comments

Comments
 (0)