Git Product home page Git Product logo

statelayout's Introduction

StateLayout

A custom layout that can easily switch different states(like empty,error,progress,content) with animations.

Source


This library has been inspired by lufficc/iShuiHui

fade demofade_scale demo

Integration

From Source

  1. For using StateLayout module in sample app, include the source code and add the below dependencies in entry/build.gradle to generate hap/support.har.
    implementation project(path: ':stateLayout')
  2. For using StateLayout module in separate application using har file, add the har file in the entry/libs folder and add the dependencies in entry/build.gradle file.
    implementation fileTree(dir: 'libs', include: ['*.har'])
    

Usage


Add StateLayout to your layout file

Remember ,StateLayout can only hold one direct child

<?xml version="1.0" encoding="utf-8"?>
<com.lufficc.statelayout.StateLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:id="$+id:stateLayout"
    ohos:height="match_parent"
    ohos:width="match_parent" >
    <DirectionalLayout
        ohos:height="match_parent"
        ohos:width="match_parent"
        ohos:alignment="center">

        <Image
            ohos:height="match_content"
            ohos:width="match_content"
            ohos:image_src="$media:avatar"
            ohos:layout_alignment="horizontal_center"/>

        <Text
            ohos:height="match_content"
            ohos:width="match_content"
            ohos:multiple_lines="true"
            ohos:text="Hello World! I am content view."
            ohos:text_size="$float:text_size"
            />
    </DirectionalLayout>
</com.lufficc.statelayout.StateLayout>

operation in java

stateLayout.showErrorView(); //switch to error view
stateLayout.showErrorView(msg); //switch to error view with a message

stateLayout.showEmptyView();  //switch to empty view
stateLayout.showEmptyView(msg);  //switch to empty view with a message

stateLayout.showProgressView();  //switch to progress view
stateLayout.showProgressView(msg);  //switch to progress view with a message

stateLayout.showContentView();  //switch to your content view

Custom Animation

you can custom your own animation by implements ViewAnimProvider interface, by default,there are two simple animations, FadeViewAnimProvider and FadeScaleViewAnimProvider

public interface ViewAnimProvider {
    AnimatorProperty showAnimation();

    AnimatorProperty hideAnimation();
}

//or

stateLayout.setHideAnimation(yourAnimation);
stateLayout.setShowAnimation(yourAnimation);

stateLayout.setViewSwitchAnimProvider(new FadeViewAnimProvider()); //user it

attrs

attr for
app:errorDrawable custom the error drawable
app:emptyDrawable custom the empty drawable

listener

setErrorAction(ClickedListener onErrorButtonClickedListener ); // set a callback called where error view is clicked,
// you can retry, load data,for example

setEmptyAction(ClickedListener onEmptyClickedListener ); // set a callback called where empty view is clicked

Take a look at the sample project for more information.

License

Check the LICENSE file

statelayout's People

Contributors

gleelakrishna avatar prasanta352 avatar

Watchers

 avatar

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.