Skip to content

Commit

Permalink
Merge pull request #18 from sparrow007/ak/b/emptyswipe
Browse files Browse the repository at this point in the history
Fix empty list swipe crash
  • Loading branch information
sparrow007 authored Jan 18, 2022
2 parents f8b60ce + 8641f64 commit 5e12a66
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
Expand All @@ -8,7 +8,7 @@

<com.jackandphantom.carouselrecyclerview.CarouselRecyclerview
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="120dp"
android:id="@+id/recycler"/>

</RelativeLayout>
</FrameLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,12 @@ class CarouselLayoutManager constructor(
* @return Int center position
*/
fun centerPosition(): Int {
var pos = mOffsetAll / getIntervalDistance()
val more = mOffsetAll % getIntervalDistance()
if (abs(more) >= getIntervalDistance() * 0.5f) {
val intervalPosition = getIntervalDistance()
if (intervalPosition == 0) return intervalPosition

var pos = mOffsetAll / intervalPosition
val more = mOffsetAll % intervalPosition
if (abs(more) >= intervalPosition * 0.5f) {
if (more >= 0) pos++
else pos--
}
Expand Down

0 comments on commit 5e12a66

Please sign in to comment.