Skip to content

Silvannaight/Material-backdrop

 
 

Repository files navigation

Backdrop

Download

What is it?

This library makes it easy to implement a Backdrop pattern with a CoordinatorLayout

Download

JCenter (Recommended):

For support library:

dependencies {
    implementation 'ru.semper-viventem.backdrop:backdrop:0.1.5'
}

For Android X:

dependencies {
    implementation 'ru.semper-viventem.backdrop:backdrop:0.1.5_x'
}

JitPack:

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

dependencies {
    implementation 'com.github.Semper-Viventem:BackdropView:0.1.5'
}

How to use it?

You need to add a layout Toolbar, back container and foreground container

Add BackdropBehavior to the Foreground View Container:

XML

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <LinearLayout
        android:id="@+id/backContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        
        <!-- anything -->
    </LinearLayout>

    <!-- Add BackdropBehavior to this view -->
    <android.support.design.card.MaterialCardView
        android:id="@+id/foregroundContainer"
        app:layout_behavior="ru.semper_viventem.backdrop.BackdropBehavior"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        
        <!-- anything -->
    </android.support.design.card.MaterialCardView>

</android.support.design.widget.CoordinatorLayout>

Kotlin

I used this extension to search for behavior:

fun <T : CoordinatorLayout.Behavior<*>> View.findBehavior(): T = layoutParams.run {
    if (this !is CoordinatorLayout.LayoutParams) throw IllegalArgumentException("View's layout params should be CoordinatorLayout.LayoutParams")

    (layoutParams as CoordinatorLayout.LayoutParams).behavior as? T
            ?: throw IllegalArgumentException("Layout's behavior is not current behavior")
}
...

val backdropBehavior: BackdropBehavior = foregroundContainer.findBehavior() // find behavior

with(backdropBehavior) {
        attachBackContainer(R.id.backContainer) // set back container
        attachToolbar(R.id.toolbar) // set toolbar
        
        // set navigation icons for toolbar
        setClosedIcon(R.drawable.ic_menu)
        setOpenedIcon(R.drawable.ic_close)
        
        // add listener
        addOnDropListener(object : BackdropBehavior.OnDropListener {
            override fun onDrop(dropState: BackdropBehavior.DropState, fromUser: Boolean) {
                // TODO: handle listener            
            }
        })
}

...

License


MIT License

Copyright (c) 2018 Konstantin Kulikov ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

A simple solution for implementing backdrop for Android

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 100.0%