Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/st235/swipetoactionlayout

Layout, which provides swipe to reveal behaviour 🎭
https://github.com/st235/swipetoactionlayout

android android-library hacktoberfest hacktoberfest2023 kotlin menu swipe-to-reveal

Last synced: about 2 months ago
JSON representation

Layout, which provides swipe to reveal behaviour 🎭

Awesome Lists containing this project

README

        

# SwipeToActionLayout

![Min Android Sdk](https://img.shields.io/badge/minSdkVersion-16-1976D2.svg)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.st235/swipetoactionlayout.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.github.st235%22%20AND%20a:%22swipetoactionlayout%22)

SwipeToActionLayout is a layout which helps to implement swipe to reveal behaviour. It is really easy to setup and maintain.

First of all, you need to download it, don't you? 🙂

## Download from ...

__Important: library was migrated from JCenter to MavenCentral__

It means that it may be necessary to add __mavenCentral__ repository to your repositories list

```groovy
allprojects {
repositories {
// your repositories

mavenCentral()
}
}
```

- Maven

```text

com.github.st235
swipetoactionlayout
X.X
pom

```

- Gradle

```text
implementation 'com.github.st235:swipetoactionlayout:X.X'
```

- Ivy

```text

```

P.S.: The latest code version is mentioned at the version badge at the top of this page.

## Usage

After you have downloaded the library, you need to integrate it. You should declare layout at your xml.

```xml

... draggable child ...

```

Xml declaration supports the following attributes:

| property | type | description |
| ----- | ----- | ----- |
| **sal_gravity** | enum | gravity of your action menu. could be without rtl support, ie left or right, and with rtl support, ie start and end |
| **sal_isFullActionSupported** | boolean | allows you to add support of quick action, which will be revealed on full swipe |
| **sal_shouldVibrateOnQuickAction** | boolean | when quick action will be applied view can perform haptic feedback. set this flag as true if you want to support it. |
| **sal_items** | reference | reference to your xml menu file |

If you decided to use xml-declared menu then you should create menu file by the next rules:

```xml

```

An item supports the following attributes:

| property | type | description |
| ----- | ----- | ----- |
| **id** | id | an id of your action |
| **title** | text | a supporting text, will be shown under icon |
| **icon** | reference | a reference to drawable |
| **titleTextColor** | color | a color of your title |
| **background** | reference | a reference to your background resource |
| **iconTint** | color | tint to your icon, allows to change color of it |

PS: all these properties are start with `android` prefix, for example `android:background`

Is is also possible to apply actions programmatically

```kotlin
swipeToActionLayout.actions =
listOf(
SwipeAction(0xFFFBDAEE.toInt(), R.drawable.baseline_call_24, getString(R.string.action_call), Color.BLACK, Color.BLACK),
SwipeAction(0xFFFFF7A4.toInt(), R.drawable.baseline_email_24, getString(R.string.action_email), Color.BLACK, Color.BLACK),
SwipeAction(0xFFC0E7F6.toInt(), R.drawable.baseline_duo_24, getString(R.string.action_duo), Color.BLACK, Color.BLACK)
)
```

To listen lifecycle callbacks from `SwipeToActionLayout` you should implement `SwipeMenuListener`

```Kotlin

swipeToActionLayout.menuListener = MenuListener()

private inner class MenuListener: SwipeMenuListener {

override fun onClosed(view: View) {
// empty on purpose
}

override fun onOpened(view: View) {
// empty on purpose
}

override fun onFullyOpened(view: View, quickAction: SwipeAction) {
// empty on purpose
}

override fun onActionClicked(view: View, action: SwipeAction) {
Toast.makeText(this@MainActivity, "On clicked on: ${action.text}", Toast.LENGTH_SHORT).show()
swipeToActionLayout.close()
}
}

```

And that is it. Enjoy it!

### License

```text
MIT License

Copyright (c) 2019 Alexander Dadukin

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