Skip to content

mahdi-khosravi-sh/scrolltotop

Repository files navigation

Scroll To Top

ScrollToTop

GitHub repo size GitHub language count GitHub top language GitHub last commit

A simple, fast and beautiful widget for scrolling RecyclerView

Table of Contents
  1. Getting Started
  2. Compatibility
  3. Stats
  4. Contributing
  5. License
  6. Contact

Getting Started

Download

Download the latest AAR from jitpack via Gradle:

  • Gradle

    Project build.gradle

    allprojects {
      repositories {
        ...
        maven { url 'https://jitpack.io' }
      }
    }

    app module build.gradle

    dependencies {
      implementation 'com.github.mahdidev78:scrolltotop:TAG'
    }
  • Maven

    Add the JitPack repository to your build file

    <repositories>
      <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
      </repository>
    </repositories>

    Add the dependency

    <dependency>
      <groupId>com.github.mahdidev78</groupId>
      <artifactId>scrolltotop</artifactId>
      <version>Tag</version>
    </dependency>

Usage

Step 1

Add the ScrollToTop to your layout :

<com.mahdikh.vision.scrolltotop.widget.ScrollToTop
    android:id="@+id/scrollToTop"
    android:layout_width="35dp"
    android:layout_height="35dp"
    android:layout_margin="10dp"
    app:heavyCheckup="true"
    app:minimumPosition="NO_POSITION"
    app:minimumScroll="250dp"
    app:rippleColor="#999999"
    app:shortScroll="true"
    app:smoothScroll="true" />

Step 2

Setup your code :

  • Kotlin
    val scrollToTop:ScrollToTop = findViewById(R.id.scrollToTop)
    scrollToTop.setupWithRecyclerView(recyclerView)    
  • Java
    ScrollToTop scrollToTop = findViewById(R.id.scrollToTop);
    scrollToTop.setupWithRecyclerView(recyclerView);

Advanced Step 3

  • kotlin
    scrollToTop.animator = ScaleAnimator().apply {
      duration = 250
      fromScale = 0.8F
      maxAlpha = 0.8F
      interpolator = FastOutSlowInInterpolator()
    }
  • Java
    ScaleAnimator animator = new ScaleAnimator();    
    animator.setDuration(250);
    animator.setFromScale(0.8F);
    animator.setMaxAlpha(0.8F);
    animator.setInterpolator(new FastOutSlowInInterpolator());
    scrollToTop.setAnimator(animator);

Animators

FadeAnimator, ScaleAnimator, SlideAnimator, FlyAnimator

Attributes

attribute Description Options(examples)
smoothScroll The default value is false true/false
shortScroll The default value is false. If shortScroll is true, smoothScroll must also be true. true/false
heavyCheckup If true, reacts when scrolling list, otherwise react when scrollState changes. true/false
rippleColor oval ripple color. #999999
minimumScroll If the scroll value exceeds this value, ScrollToTop is displayed, otherwise it will be hidden. If the minimumPosition value is anything other than NOPOSITION, this value is ineffective. 250dp
minimumPosition If the minimumPosition value is anything other than NOPOSITION, it means that if this position is scrolled and hidden, scrollToTop will appear. 0, 2, 10 and etc

Compatibility

  • Android KitKat 4.4+

Stats

Contributors Forks Stargazers Issues Apache License

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Copyright 2021, mahdidev78

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Contact

Mahdi Khosravi - mahdi.khosravi.dev78@gmail.com

Project Link: https://github.com/mahdidev78/scrolltotop