Coder Social home page Coder Social logo

omtodkar / shimmerrecyclerview Goto Github PK

View Code? Open in Web Editor NEW
236.0 1.0 32.0 1.89 MB

A custom Shimmer RecyclerView which adopt to list / grid transition automatically and also supports multiple view types while shimmering.

License: GNU General Public License v3.0

Java 77.34% Kotlin 22.66%
android recyclerview shimmer shimmer-android shimmer-recyclerview shimmer-layout shimmerlayout shimmerrecyclerview

shimmerrecyclerview's Introduction

ShimmerRecyclerView

Build Status Download GitHub API Android Arsenal

ShimmerRecyclerView is an custom RecyclerView library based on Facebook's Shimmer effect for Android library and inspired from Sharish's ShimmerRecyclerView.

There is reason behind creating a separate library for ShimmerRecyclerView, most of libraries doesn't not support runtime switching of LayoutManager or shimmer layout resources. Secondly the other similar library is build upon Supercharge's ShimmerLayout which is I feel very less active in terms of release. So I came up with an alternative.

Demo

Change layout manager in runtime LinearLayoutManager to GridLayoutManager and Shimmer will adopt accordingly. Setup mShimmerRecyclerView.setItemViewType(ShimmerAdapter.ItemViewType) to change view type of Shimmer adapter.

Switching Layouts Multiple Type Demo Grid Demo

Download

To include ShimmerRecyclerView in your project, add the following to your dependencies:

app/build.gradle

dependencies {
   implementation 'com.facebook.shimmer:shimmer:0.5.0'
   implementation 'com.todkars:shimmer-recyclerview:0.4.1'
}

Usage

The following snippet shows how you can use Shimmer RecyclerView in your project.

Layout

<com.todkars.shimmer.ShimmerRecyclerView
    android:id="@+id/shimmer_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
    app:shimmer_recycler_layout="@layout/list_item_shimmer_layout"
    app:shimmer_recycler_item_count="10" />

Activity

public class MainActivity extends Activity {
    
    private ShimmerRecyclerView mShimmerRecyclerView;
    
    //... other variables
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        mShimmerRecyclerView = findViewById(R.id.shimmer_recycler_view);
        
        mShimmerRecyclerView.setLayoutManager(new LinearLayoutManager(this),
            R.layout.list_item_shimmer_layout);
        
        mShimmerRecyclerView.setAdapter(adapter);
        
        // This is optional, use if no attributes are mentioned in layout xml resource.
        // WARNING: Setting Shimmer programmatically will obsolete all shimmer attributes.
        /* mShimmerRecyclerView.setShimmer(mShimmer); */
        
        /* Shimmer layout view type depending on List / Gird */
        mShimmerRecyclerView.setItemViewType((type, position) -> {
            switch (type) {
                case ShimmerRecyclerView.LAYOUT_GRID:
                    return position % 2 == 0
                            ? R.layout.list_item_shimmer_grid
                            : R.layout.list_item_shimmer_grid_alternate;

                default:
                case ShimmerRecyclerView.LAYOUT_LIST:
                    return position == 0 || position % 2 == 0
                            ? R.layout.list_item_shimmer
                            : R.layout.list_item_shimmer_alternate;
            }
        });
        
        mShimmerRecyclerView.showShimmer();     // to start showing shimmer
        
        // To stimulate long running work using android.os.Handler
        mHandler.postDelayed((Runnable) () -> {
            mShimmerRecyclerView.hideShimmer(); // to hide shimmer
        }, 3000);
    }
}

Attributes

Most of the attributes used for ShimmerRecyclerView are same as Facebook's ShimmerFrameLayout below is detail table:

Name Attribute Description
Shimmer Layout shimmer_recycler_layout Layout reference used for as shimmer base.
Shimmer Item Count shimmer_recycler_item_count Number of shimmers to be shown in list, default is 9.
Clip to Children shimmer_recycler_clip_to_children Whether to clip the shimmering effect to the children, or to opaquely draw the shimmer on top of the children. Use this if your overall layout contains transparency.
Colored shimmer_recycler_colored Whether you want the shimmer to affect just the alpha or draw colors on-top of the children.
Base Color shimmer_recycler_base_color If colored is specified, the base color of the content.
Highlight Color shimmer_recycler_highlight_color If colored is specified, the shimmer's highlight color.
Base Alpha shimmer_recycler_base_alpha If colored is not specified, the alpha used to render the base view i.e. the unhighlighted view over which the highlight is drawn.
Highlight Alpha shimmer_recycler_highlight_alpha If colored is not specified, the alpha of the shimmer highlight.
Auto Start shimmer_recycler_auto_start Whether to automatically start the animation when the view is shown, or not.
Duration shimmer_recycler_duration Time it takes for the highlight to move from one end of the layout to the other.
Repeat Count shimmer_recycler_repeat_count Number of times of the current animation will repeat.
Repeat Delay shimmer_recycler_repeat_delay Delay after which the current animation will repeat.
Repeat Mode shimmer_recycler_repeat_mode What the animation should do after reaching the end, either restart from the beginning or reverse back towards it.
Direction shimmer_recycler_direction The travel direction of the shimmer highlight: left to right, top to bottom, right to left or bottom to top.
Dropoff shimmer_recycler_dropoff Controls the size of the fading edge of the highlight.
Intensity shimmer_recycler_intensity Controls the brightness of the highlight at the center
Shape shimmer_recycler_shape Shape of the highlight mask, either with a linear or a circular gradient.
Tilt shimmer_recycler_tilt Angle at which the highlight is tilted, measured in degrees.
Fixed Width or Height shimmer_recycler_fixed_width or shimmer_recycler_fixed_height Fixed sized highlight mask, if set, overrides the relative size value.
Width or Height Ratio shimmer_recycler_width_ratio or shimmer_recycler_height_ratio Size of the highlight mask, relative to the layout it is applied to.
    ShimmerRecyclerView a custom RecyclerView library
    Copyright (C) 2019  Omkar Todkar <[email protected]>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see https://www.gnu.org/licenses/gpl.txt

Facebook Shimmer is published under BSD License

shimmerrecyclerview's People

Contributors

hamzaahmedkhan avatar omtodkar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

shimmerrecyclerview's Issues

Gradle is not able to resolve the 'implementation 'com.todkars:shimmer-recyclerview:0.4.1'.It is perfectly resolving the facebook shimmer effect.

Describe the bug
Gradle is not able to resolve the 'implementation 'com.todkars:shimmer-recyclerview:0.4.1'.It is perfectly resolving the facebook shimmer effect .
In the xml file I can use Shimmer frame layout but not able to use shimmer recycler view.
To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'

  2. Click on '....'

  3. Scroll down to '....'

  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
Screenshot (3)
Screenshot (2)

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Shimmer effect not working black screen is there

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Scroll listner is not working

Describe the bug
when registering a scroll listener (endless scroll listener part of this library: https://github.com/mikepenz/FastAdapter), it does not receive the events, when changing ShimmerRecyclerView to android RecyclerView (changed only in layout file, code is always same), it works fine.

To Reproduce
Steps to reproduce the behavior:
by Using EndlessRecyclerOnScrollListener of FasterAdapter (https://github.com/mikepenz/FastAdapter)

       //...
        appsAdapter = ItemAdapter() 
        fastAdapter = FastAdapter.with(appsAdapter)
  
        footerAdapter = items()

        val endlessRecyclerOnScrollListener =
            object : EndlessRecyclerOnScrollListener(footerAdapter) {
                override fun onLoadMore(currentPage: Int) {
                   Timber.d("load more items")
                   //....
                }
            }
 
        binding.recyclerView.apply {
            layoutManager =    LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
            adapter = fastAdapter 
            addOnScrollListener(endlessRecyclerOnScrollListener) 
        }

Expected behavior
The onLoadMore function of EndlessRecyclerOnScrollListener should be called when scrolling the bottom of recycler view

Smartphone :
Android api 29

Constraint Layout not supported

Shimmer layouts made in constrait layout fails to match the width of the parent.
the width is somehow smaller than the width of the parent.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.