Skip to content

Commit

Permalink
Merge pull request #60 from rubensousa/develop
Browse files Browse the repository at this point in the history
2.2.0
  • Loading branch information
rubensousa authored Aug 31, 2019
2 parents 9fc5744 + 1f8ce71 commit d8b9d8d
Show file tree
Hide file tree
Showing 46 changed files with 1,605 additions and 955 deletions.
82 changes: 82 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Changelog

## 2.2.0

### New features
- Added Gravity.CENTER support ([#21](https://github.com/rubensousa/GravitySnapHelper/issue/21))
- Added setMaxFlingDistance and setMaxFlingSizeFraction to change the max fling distance allowed ([#29](https://github.com/rubensousa/GravitySnapHelper/issue/29))
- Added setSnapToPadding to allow snapping to the padding set in the RecyclerView. Defaults to false ([#58](https://github.com/rubensousa/GravitySnapHelper/issue/58))
- Added GravitySnapRecyclerView that uses GravitySnapHelper by default
- Added setGravity to change the gravity of GravitySnapHelper
- Added setScrollMsPerInch to change the scroll speed
- Added setSnapListener to allow changing the SnapListener that was set or clearing it
- GravityPagerSnapHelper is now deprecated. Use GravitySnapHelper together with setMaxFlingSizeFraction() to achieve the same behavior
- Added updateSnap to update the snap position if for some reason snapping was stopped

### Improvements

- Improved behavior when smoothScrollToPosition is called. Now the smooth scroller is used
- Added getters to all relevant properties
- getCurrentSnappedPosition now searches for the correct snap view instead of returning the last position that we snapped to
- Added missing NonNull and Nullable annotations

## 2.1.0

- OrientationAwareRecyclerView now doesn't depend on LinearLayoutManager directly
- Fixed SnapListener not being called for the first position sometimes (#57)
- Added getCurrentSnappedPosition to GravitySnapHelper and GravityPagerSnapHelper

## 2.0

### New features:
- Migrated to AndroidX.
- Added smoothScrollToPosition and scrollToPosition methods that'll snap to a certain position.
- Added OrientationAwareRecyclerView that only handles scroll events according to its orientation.

### Bug fixes:
- Fixed snapping not working correctly for RecyclerViews with padding (#49)
- Fixed snapping not considering GridLayoutManager.SpanSizeLookup (#52)

## 1.5

- Fixed reverse layout causing scrolling issues (#40)

## 1.4

- Added Nullable and NonNull annotations
- Updated support library

## 1.3

- Fixed IllegalStateException being thrown when SnapHelper is attached twice to a RecyclerView (#23)
- Bumped min sdk to 14

## 1.2

- Added support for GridLayoutManager

## 1.1

- Added GravityPagerSnapHelper
- Updated support library

## 1.0

- GravitySnapHelper extends from LinearSnapHelper again
- Added SnapListener to listen for snap events


## 0.3

- Extend from SnapHelper until https://code.google.com/p/android/issues/detail?id=223649 gets fixed.

## 0.2

- Added RTL support
- Fixed GravitySnapHelper scrolling too far sometimes (#2)
- Added support to snap last items via enableLastItemSnap(boolean enable)


## 0.1

- Initial release
93 changes: 64 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,87 @@
# RecyclerViewSnap
# GravitySnapHelper

RecyclerView snapping example with SnapHelper
A SnapHelper that snaps a RecyclerView to an edge.

<img src="screens/snap_googleplay.gif" width=300></img> <img src="screens/snap_final.gif" width=300></img>

## Start/Top/End/Bottom Snapping

If you need snapping support to start, top, end or bottom, use GravitySnapHelper.
## Setup

Add this to your build.gradle:

```groovy
// AndroidX
implementation 'com.github.rubensousa:gravitysnaphelper:2.1.0'
implementation 'com.github.rubensousa:gravitysnaphelper:2.2.0'
```

## How to use

You can either create a GravitySnapHelper, or use GravitySnapRecyclerView.

// Old support libraries
implementation 'com.github.rubensousa:gravitysnaphelper-compat:2.0'
If you want to use GravitySnapHelper directly,
you just need to create it and attach it to your RecyclerView:

```kotlin
val snapHelper = GravitySnapHelper(Gravity.START)
snapHelper.attachToRecyclerView(recyclerView)
```

### Snapping start with GravitySnapHelper:
If you want to use GravitySnapRecyclerView, you can use the following xml attributes for customisation:

```java
startRecyclerView.setLayoutManager(new LinearLayoutManager(this,
LinearLayoutManager.HORIZONTAL, false));

new GravitySnapHelper(Gravity.START).attachToRecyclerView(startRecyclerView);
```xml
<attr name="snapGravity" format="enum">
<attr name="snapEnabled" format="boolean" />
<attr name="snapLastItem" format="boolean" />
<attr name="snapToPadding" format="boolean" />
<attr name="snapScrollMsPerInch" format="float" />
<attr name="snapMaxFlingSizeFraction" format="float" />
```

### Snapping top with GravitySnapHelper:
Example:

```java
topRecyclerView.setLayoutManager(new LinearLayoutManager(this));

new GravitySnapHelper(Gravity.TOP).attachToRecyclerView(topRecyclerView);
```xml
<com.github.rubensousa.gravitysnaphelper.GravitySnapRecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:snapGravity="start" />
```

## Center snapping
## Start snapping

```java
new LinearSnapHelper().attachToRecyclerView(recyclerView);
```kotlin
val snapHelper = GravitySnapHelper(Gravity.START)
snapHelper.attachToRecyclerView(recyclerView)
```

## Page snapping
<img src="screens/snap_start.gif" width=350></img>

## Center snapping

```java
new PagerSnapHelper().attachToRecyclerView(recyclerView);
```kotlin
val snapHelper = GravitySnapHelper(Gravity.CENTER)
snapHelper.attachToRecyclerView(recyclerView)
```

<img src="screens/snap_center.gif" width=350></img>

## Limiting fling distance

If you use **setMaxFlingSizeFraction** or **setMaxFlingDistance**
you can change the maximum fling distance allowed.

<img src="screens/snap_fling.gif" width=350></img>


## With decoration

<img src="screens/snap_decoration.gif" width=350></img>

## Features

1. **setMaxFlingDistance** or **setMaxFlingSizeFraction** - changes the max fling distance allowed.
2. **setScrollMsPerInch** - changes the scroll speed.
3. **setGravity** - changes the gravity of the SnapHelper.
4. **setSnapToPadding** - enables snapping to padding (default is false)
5. **smoothScrollToPosition** and **scrollToPosition**
6. RTL support out of the box

## Nested RecyclerViews

Take a look at these blog posts if you're using nested RecyclerViews
Expand All @@ -59,7 +94,7 @@ Take a look at these blog posts if you're using nested RecyclerViews
## License

Copyright 2018 The Android Open Source Project
Copyright 2018 Rúben Sousa
Copyright 2019 Rúben Sousa

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
14 changes: 11 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
applicationId "com.github.rubensousa.recyclerviewsnap"
minSdkVersion rootProject.ext.minSdkVersion
minSdkVersion 19
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}

dependencies {
implementation 'androidx.core:core-ktx:1.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation project(':gravitysnaphelper')
implementation 'com.google.android.material:material:1.1.0-alpha01'
implementation 'com.google.android.material:material:1.1.0-alpha09'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}

This file was deleted.

28 changes: 0 additions & 28 deletions app/src/main/java/com/github/rubensousa/recyclerviewsnap/App.java

This file was deleted.

Loading

0 comments on commit d8b9d8d

Please sign in to comment.