yusufpats / backdrop

BackdropLayout - An easy to implement Layout based on the Backdrop component from Material Design

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Backdrop Layout

Download License Apache 2.0 Android min SDK

An easy to implement Layout based on the Backdrop component from Material Design

Setup

Add this dependency to your app build.gradle:

implementation 'com.yusufpats.backdroplayout:backdropLayout:<latest-version>'

How to use?

XML

Add the BackdropLayout to your activity .xml file:

<?xml version="1.0" encoding="utf-8"?>
<com.yusufpats.backdroplayout.BackdropLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/backdrop_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary">

    <!-- APPBAR LAYOUT -->
    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:elevation="0dp">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            app:title="Backdrop"
            app:titleTextColor="@color/white" />
    </com.google.android.material.appbar.AppBarLayout>

    <!-- BACK LAYER -->
    <FrameLayout
        android:id="@+id/back_layer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?actionBarSize" />

    <!-- FRONT LAYER -->
    <androidx.cardview.widget.CardView
        android:id="@+id/front_layer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?actionBarSize"
        app:cardBackgroundColor="#FAF8ED"
        app:cardCornerRadius="16dp"
        app:cardElevation="16dp" />
</com.yusufpats.backdroplayout.BackdropLayout>

Code (Kotlin)

// let BackdropLayout know about the front layer
backdropLayout.frontSheet = frontLayer
        
// The triggerView can be any view that should trigger the backdrop toggle()
// Toggle backdrop on trigger view click
triggerView.setOnClickListener {
    backdropLayout.toggleBackdrop()
}

Aditional customizations (Kotlin)

Function Description
frontSheet (Required) set the front layer of the BackdropLayout
duration duration of toggle animation
revealHeight height of the frontSheet that should be visible when backdrop is open
peakHeight height of the BackLayer that should be visible when backdrop is open
interpolator animation interpolator
(NOTE: If Reveal height and Peak Height both are set, the reveal height will take precedence)

You can also set the trigger ImageView and let the backdrop layout do the magic for you

// `openIcon` - Icon to be used for the trigger view when backdrop is not open
// `closeIcon` - Icon to be used for the trigger view when backdrop is open

fun setTriggerView(triggerView: ImageView, openIcon: Drawable, closeIcon: Drawable);

Author   GitHub followers

Yusuf I Patrawala (yusufpats@gmail.com)
Github - @yusufpats

License

Copyright 2019 Yusuf Patrawala

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.

About

BackdropLayout - An easy to implement Layout based on the Backdrop component from Material Design

License:Apache License 2.0


Languages

Language:Kotlin 100.0%