All Projects → rnpy → Shimmerlayout

rnpy / Shimmerlayout

Licence: other
Memory efficient, simple yet highly customizable shimmer effect for Android.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Shimmerlayout

Skeletonview
☠️ An elegant way to show users that something is happening and also prepare them to which contents they are awaiting
Stars: ✭ 10,804 (+13238.27%)
Mutual labels:  placeholder, loading-animations
Rhplaceholder
Show pleasant loading view for your users 😍
Stars: ✭ 238 (+193.83%)
Mutual labels:  placeholder, loading-animations
React Loading Skeleton
Create skeleton screens that automatically adapt to your app!
Stars: ✭ 2,533 (+3027.16%)
Mutual labels:  placeholder, loading-animations
Tabanimated
A skeleton screen framework based on native for iOS. (一个由iOS原生组件映射出骨架屏的框架,包含快速植入,低耦合,兼容复杂视图等特点,提供国内主流骨架屏动画的加载方案,同时支持上拉加载更多、自定制动画。)
Stars: ✭ 2,909 (+3491.36%)
Mutual labels:  placeholder, loading-animations
Ocskeleton
[OCSkeleton] - Make your loading view a little difference.
Stars: ✭ 184 (+127.16%)
Mutual labels:  placeholder, loading-animations
Vue Content Loading
Vue component to easily build (or use presets) SVG loading cards Facebook like.
Stars: ✭ 729 (+800%)
Mutual labels:  placeholder, loading-animations
Superplaceholder.js
⚡Super charge your input placeholders
Stars: ✭ 978 (+1107.41%)
Mutual labels:  placeholder
Babel Plugin Partial Application
[DEPRECATED] Please use https://github.com/citycide/param.macro
Stars: ✭ 60 (-25.93%)
Mutual labels:  placeholder
Three Dots
🔮 CSS loading animations made by single element.
Stars: ✭ 912 (+1025.93%)
Mutual labels:  loading-animations
React Simple Img
🌅 React lazy load images with IntersectionObserver API and Priority Hints
Stars: ✭ 905 (+1017.28%)
Mutual labels:  placeholder
Mocka
Simple, elegant content placeholder
Stars: ✭ 1,205 (+1387.65%)
Mutual labels:  placeholder
Thinkingfaces
Collection of animated spinners and bouncers for iOS 🌠
Stars: ✭ 68 (-16.05%)
Mutual labels:  loading-animations
Wynullview
An easy way to use for view's empty state 一行代码显示空视图,高度自定义
Stars: ✭ 44 (-45.68%)
Mutual labels:  placeholder
React Shimmer
🌠 Async loading, performant Image component for React.js
Stars: ✭ 990 (+1122.22%)
Mutual labels:  placeholder
Placekeanu.com
For when you need a little more Keanu in your life
Stars: ✭ 63 (-22.22%)
Mutual labels:  placeholder
Spinners
A Sass mixin to generate fully customizable, pure CSS3 loading/busy indicators
Stars: ✭ 33 (-59.26%)
Mutual labels:  loading-animations
Chompprogressview
A (semi) realistic chomping progress view that takes bites out of your delicious images! Nom! Nom!
Stars: ✭ 71 (-12.35%)
Mutual labels:  loading-animations
Skeleton Elements
Skeleton elements - UI for improved perceived performance
Stars: ✭ 27 (-66.67%)
Mutual labels:  placeholder
V Img Fallback
Vue Image Fallback
Stars: ✭ 43 (-46.91%)
Mutual labels:  placeholder
Iprogresshud
An elegant, lightweight and responsive progress HUD for iOS app with very simple usage. Available 32 indicators by NVActivityIndicatorView.
Stars: ✭ 66 (-18.52%)
Mutual labels:  loading-animations

ShimmerLayout

Simple, memory efficient and high performance Shimmer Layout for Android.

About

ShimmerLayout can be used to create a shimmer effect to your Android apps loading states (similar to Facebook).

As loading states should be as fast and seamless as possible, this library leaves as much resources as possible for you to do the real work behind, by focusing on:

  • memory efficiency: contrary to other similar libraries that usually work using multiple large bitmaps, this library does not use a single bitmap or large object, making its memory footprint negligible.
  • performance: on top of avoiding large bitmap manipulation, rendering of each shimmer effect frame is done using one single native operation, making its impact on CPU and GPU usage as low as possible.
  • simplicity: View.setVisibility() is all you need to control this layout.
  • lightweight: just over 150 methods and around 20Kb, before proguard does its magic.

ShimmerLayout also offers a unique feature allowing better rendering on complex layouts (especially when used in RecyclerView as a placeholder for each ViewHolder): multiple ShimmerLayout can easily be synchronized together to use the exact same animation.

Despite its simplicity and small size, ShimmerLayout can still be configured for much more complex use cases thanks to a few optional parameters.

Simple use case with default animation, in a RecyclerView allowing scrolling while elements are still loading:

ShimmerLayout

And a more complex loading screen using ShimmerLayout to create a color-changing, rotating shimmer effect on some animated views (in less than 20 lines!):

ShimmerLayout

Originally inspired by Facebook Shimmer for Android and Supercharge ShimmerLayout.

Usage

Use gradle to get latest version from bintray jCenter:

repositories { maven { url "https://jcenter.bintray.com" } }

implementation 'xyz.peridy.shimmer:shimmerlayout:1.1'

Wrap the layout you want to animate inside a ShimmerLayout. It is recommended to define a layout that looks like the content you're going to display:

<xyz.peridy.shimmerlayout.ShimmerLayout
    android:id="@+id/shimmer_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="16dp">

        <View
            android:layout_width="42dp"
            android:layout_height="42dp"
            android:background="@color/shimmerBackground"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <View
                android:layout_width="152dp"
                android:layout_height="14dp"
                android:layout_marginLeft="8dp"
                android:layout_marginStart="8dp"
                android:background="@color/shimmerBackground"/>

            <View
                android:layout_width="122dp"
                android:layout_height="14dp"
                android:layout_marginLeft="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="4dp"
                android:background="@color/shimmerBackground"/>

        </LinearLayout>

    </LinearLayout>

</xyz.peridy.shimmerlayout.ShimmerLayout>

For the most basic usage, that's all you need. When this layout is visible, it will start animating. It will automatically stop or start again when its visibility change, since it's intended to be a loading placeholder, you're probably already doing this anyway.

ShimmerLayout should work on any view, but remember this is only a loading indicator, and keep things simple. Animated content can also be used in some cases, just make sure to make it as lightweight as possible and use native Android animations (see EvaluatorsDemoActivity):

Customization

Basic configuration

By default, ShimmerLayout will create an effect based those parameters

  • shimmerAngle: shadow angle
  • shimmerWidth: total width of shadow
  • shimmerCenterWidth: width of solid color in the center of shadow
  • shimmerDuration: duration in ms
  • shimmerColor: color

All these can also be set directly in xml layout:

<xyz.peridy.shimmerlayout.ShimmerLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:shimmer_center_width="10dp"
    app:shimmer_width="20dp"
    app:shimmer_angle="30"
    app:shimmer_duration="250"
    app:shimmer_color="#FF0000">

Groups

Groups allow multiple ShimmerLayout to be synchronized with each other. It is highly recommended to use a group when using multiple ShimmerLayout on the same screen.

Without Group, if new ShimmerLayout are added after animation is started (scrolling down a RecyclerView for example), you can end up in cases like this, which would make your designers cry:

Without group

With a group, newly added views are synchronized with any existing one, making designers much happier:

With group

To set a group, simply create a ShimmerGroup object in code, and pass it to all ShimmerLayout you want synchronised:

val myShimmerGroup = ShimmerGroup()

findViewById<ShimmerLayout>(R.id.shimmer_layout_1).shimmerGroup = myShimmerGroup
findViewById<ShimmerLayout>(R.id.shimmer_layout_2).shimmerGroup = myShimmerGroup

For the most common use (in RecyclerView), it is recommended to define the group in the adapter, and pass it to all ViewHolders (see demo app).

TimeInterpolator

A TimeInterpolator can be provided to modify the rate of change of the animation. For example, to have the shimmer accelerate then decelerate, simply use:

shimmerLayout.timeInterpolator = AccelerateDecelerateInterpolator()

Evaluators

ShimmerLayout draws the effect on every frame using one single drawPaint operation. ShimmerLayout provides 3 ways to customize animation though Evaluator classes. Each of these expose a method that is called on each frame to customize the effect, so be mindful of performance when implementing them.

For example, this customizes the effect to use a color-changing radial gradient instead of the default linear gradient, growing and shrinking from the center of the view instead of using a translation from left to right:

matrixEvaluator = null
timeInterpolator = CycleInterpolator(1f)
setShaderEvaluator { fraction ->
    val radius = Math.abs(fraction) * width + 1
    RadialGradient(width / 2f, height / 2f, radius, intArrayOf(Color.BLACK, Color.TRANSPARENT), null, Shader.TileMode.CLAMP)
}
colorEvaluator = object : ShimmerLayout.Evaluator<Int> {
    val evaluator = ArgbEvaluator()
    val colours = arrayOf("#B00000", "#00B000", "#0000B0").map { Color.parseColor(it) }
    val count = colours.size

    override fun evaluate(fraction: Float): Int {
        val localFraction = (1 + fraction) / 2 // CycleInterpolator means fraction ranges from -1 to 1
        val arrayPosition = (localFraction * count).toInt() % count
        val offset = localFraction * count % 1.0f
        return evaluator.evaluate(offset, colours[arrayPosition], colours[(arrayPosition + 1) % count]) as Int
    }
}

And now your designers can cry again with this result:

Radial

Shader Evaluator

The shader is used to create the shadow effect. Providing one allows you to customize the shader to use for each animation frame.

See example above for use of a RadialGradient

Color Evaluator

The color used to tint the shadow effect. By default, ShimmerLayout will use the shimmerColor attribute to tint the effect. Providing an Evaluator allows you to define the color to use for each animation frame.

See example above for use of ArgbEvaluator to alternate between multiple colours.

Matrix Evaluator

Default Matrix uses a translation from left to right, this can be modified by providing a custom Evaluator<Matrix>. For example, this replaces the translation with a rotation (see EvaluatorsDemoActivity for an example using this):

val matrix = Matrix()
setMatrixEvaluator { fraction ->
    matrix.apply {
        setRotate(fraction * 360)
    }
}

License

BSD License

Copyright (c) 2017, Romain Peridy All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].