Coder Social home page Coder Social logo

simpleswipemenulayout-ssml's Introduction

Simple Swipe Menu Layout - SSML

Swipeable layout for Android

0. Preview

Imgur Imgur Imgur

1. Dependency

implementation 'io.sulek.ssml:simpleswipemenulayout:1.0.3'
repositories {
    maven {
        url  "https://dl.bintray.com/sulo61/Android"
    }
}

2. Usage

XML

<app:io.sulek.ssml.SimpleSwipeMenuLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/swipeContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:dynamicMenuWidth="false"
        app:menuSide="Right">

    <LinearLayout
            android:id="@+id/backgroundContainer"
            android:background="#BBBBBB"
            android:layout_width="200dp"
            android:layout_height="0dp">

    <FrameLayout
            android:id="@+id/foregroundContainer"
            android:background="#EEEEEE"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

</app:io.sulek.ssml.SimpleSwipeMenuLayout>

important:

  • all layouts (main SimpleSwipeMenuLayout, foreground container and background container) must have IDs
  • background container should have 0dp height
  • choose menu side: app:menuSide="Left|Right"
  • app:dynamicMenuWidth="true|false"
    • false use for better performance, background container width must be specified (like in example 200dp)
    • true use for dynamic menu width, when background container has wrap_content width

Recycler View

recyclerView.layoutManager = SSMLLinearLayoutManager(context)

Store and restore state

Keep state in model

data class SampleData(..., var isExpanded: Boolean = false)

Listen for changes

itemView.swipeContainer.setOnSwipeListener(object : OnSwipeListener {
    override fun onSwipe(isExpanded: Boolean) {
        sampleData.isExpanded = isExpanded
    }
})

Apply

// at the end of binding data function, this function perform some measurements
itemView.swipeContainer.apply(sampleData.isExpanded)

3. Licence

Copyright 2019 Michał Sułek

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.

simpleswipemenulayout-ssml's People

Contributors

michalsulek avatar sulo61 avatar

Watchers

 avatar  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.