├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── app ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── example │ │ └── ssjetpackcomposeswipeableview │ │ └── ui │ │ ├── MainActivity.kt │ │ ├── SwipeAbleViewActivity.kt │ │ └── theme │ │ ├── Color.kt │ │ ├── Shape.kt │ │ ├── Theme.kt │ │ └── Type.kt │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-mdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xxhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xxxhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── values-night │ └── themes.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── themes.xml ├── build.gradle ├── gif ├── banner.png ├── swipeboth.gif ├── swipeleft.gif └── swiperight.gif ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jitpack.yml ├── settings.gradle └── ssjetpackcomposeswipeableview ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src └── main ├── AndroidManifest.xml └── java └── com └── example └── ssjetpackcomposeswipeableview ├── SwipeAbleItemView.kt └── SwipeDirection.kt /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Smartphone (please complete the following information):** 27 | - Device: [e.g. OnePlusNord] 28 | - OS: [e.g. Oreo] 29 | - Version [e.g. 22] 30 | 31 | **Additional context** 32 | Add any other context about the problem here. 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.aar 4 | *.ap_ 5 | *.aab 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | # Uncomment the following line in case you need and you don't have the release build type files in your app 18 | # release/ 19 | 20 | # Gradle files 21 | .gradle/ 22 | build/ 23 | 24 | # Local configuration file (sdk path, etc) 25 | local.properties 26 | 27 | # Proguard folder generated by Eclipse 28 | proguard/ 29 | 30 | # Log Files 31 | *.log 32 | 33 | # Android Studio Navigation editor temp files 34 | .navigation/ 35 | 36 | # Android Studio captures folder 37 | captures/ 38 | 39 | # IntelliJ 40 | *.iml 41 | .idea/workspace.xml 42 | .idea/tasks.xml 43 | .idea/gradle.xml 44 | .idea/assetWizardSettings.xml 45 | .idea/dictionaries 46 | .idea/libraries 47 | # Android Studio 3 in .gitignore file. 48 | .idea/caches 49 | .idea/modules.xml 50 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 51 | .idea/navEditor.xml 52 | 53 | # Keystore files 54 | # Uncomment the following lines if you do not want to check your keystore files in. 55 | #*.jks 56 | #*.keystore 57 | 58 | # External native build folder generated in Android Studio 2.2 and later 59 | .externalNativeBuild 60 | .cxx/ 61 | 62 | # Google Services (e.g. APIs or Firebase) 63 | # google-services.json 64 | 65 | # Freeline 66 | freeline.py 67 | freeline/ 68 | freeline_project_description.json 69 | 70 | # fastlane 71 | fastlane/report.xml 72 | fastlane/Preview.html 73 | fastlane/screenshots 74 | fastlane/test_output 75 | fastlane/readme.md 76 | 77 | # Version control 78 | vcs.xml 79 | 80 | # lint 81 | lint/intermediates/ 82 | lint/generated/ 83 | lint/outputs/ 84 | lint/tmp/ 85 | # lint/reports/ 86 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at mohammed.h@simformsolutions.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Way to contribute 2 | 3 | 1. Fork the repo and create your branch from `main`. 4 | 2. Clone the project to your own machine. (Please have a look at [**Readme.md**](https://github.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeToDelete/blob/main/README.md) to understand how to run this project on your machine) 5 | 3. Commit changes to your own branch 6 | 4. Make sure your code lints. 7 | 5. Push your work back up to your fork. 8 | 6. Issue that pull request! 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Simform Solutions 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](/gif/banner.png) 2 | # SSJetpackComposeSwipeableView 3 | ### SSJetpackComposeSwipeableView is a small library which provides support for the swipeable views. You can use this in your lazyColumns or can add a simple view which contains swipe to edit/delete functionality. 4 | 5 | [![Kotlin Version](https://img.shields.io/badge/Kotlin-v1.6.0-blue.svg)](https://kotlinlang.org) [![Platform](https://img.shields.io/badge/Platform-Android-green.svg?style=flat)](https://www.android.com/) [![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=21) 6 | 7 | # Features 8 | - Simple and easy to use. 9 | - Customize according to your needs. 10 | - Use wherever you want. 11 | - Get proper swipe callback events. 12 | 13 | # 🎬 Preview 14 | 15 | | Swipe Left | Swipe Right | Swipe Left + Right | 16 | | -- | -- | -- | 17 | | | | 18 | 19 | ## Installation 20 | * Add it in your root build.gradle at the end of repositories: 21 | 22 | ```groovy 23 | allprojects { 24 | repositories { 25 | ... 26 | maven { url 'https://jitpack.io' } 27 | } 28 | } 29 | ``` 30 | 31 | * Add the dependency in your app's build.gradle file 32 | 33 | ```groovy 34 | dependencies { 35 | implementation 'com.github.SimformSolutionsPvtLtd:SSJetpackComposeSwipeableView:1.0.1' 36 | } 37 | ``` 38 | 39 | ## How to Use and Customization 40 | 1. Wherever you want to add swipeable view 41 | ```groovy 42 | SwipeAbleItemView( 43 | // Triplet(Icon, TintColor, Id) Pass the icon with the tint color which you want to display in left side view, Id will be used to identify onClick Events. 44 | leftViewIcons = arrayListOf(Pair(Icons.Filled.Edit, "btnEditLeft"), Pair(Icons.Filled.Delete, "btnDeleteLeft")), 45 | // Triplet(Icon, TintColor, Id) Pass the icon with the tint color which you want to display in right side view, Id will be used to identify onClick Events. 46 | rightViewIcons = arrayListOf(Pair(Icons.Filled.Edit, "btnEditRight")), 47 | // Position of the item normally required only when used with lazyColumns to identify the index of the item. 48 | position = 0, 49 | // Swipe direction it can be Left or Right or Both (Left + Right). 50 | swipeDirection = swipeDirection ?: SwipeDirection.BOTH, 51 | // Perform any action when swipeable view is clicked. It provides the position(Index of the item) as well as id to identify which item clicked incase of multiple items. 52 | onClick = { // Pair(Position, Id) 53 | Toast.makeText(context, "${it.second} clicked. Position :- ${it.first}", Toast.LENGTH_SHORT) 54 | .show() 55 | }, 56 | // Width for the left side of the view which will be shown when swiped. 57 | leftViewWidth = 70.dp, 58 | // Width for the right side of the view which will be shown when swiped. 59 | rightViewWidth = 70.dp, 60 | // Height for the swipeable view. 61 | height = 60.dp, 62 | // Background color for left view. 63 | leftViewBackgroundColor = Primary, 64 | // Background color for right view. 65 | rightViewBackgroundColor = Primary, 66 | // Corner radius for swipeable view. 67 | cornerRadius = 4.dp, 68 | // Space between left swipeable view and your main content view. 69 | leftSpace = 10.dp, 70 | // Space between right swipeable view and your main content view. 71 | rightSpace = 10.dp, 72 | // fractionalThreshold for the swipe 73 | fractionalThreshold = 0.3f 74 | ) { 75 | // Your main view comes here. 76 | } 77 | ``` 78 | 79 | ### All Attributes 80 | ------------------------ 81 | 82 | | Attribute | Description | Default | 83 | | --- | --- | --- | 84 | | `leftViewIcons` | Triplet(Icon, TintColor, Id) Pass the icon with the tint color which you want to display in left side view, Id will be used to identify onClick Events. | None | 85 | | `rightViewIcons` | Triplet(Icon, TintColor, Id) Pass the icon with the tint color which you want to display in right side view, Id will be used to identify onClick Events. | None | 86 | | `position` | Position of the item normally required only when used with lazyColumns to identify the index of the item. | `0` | 87 | | `swipeDirection` | Swipe direction it can be Left or Right or Both (Left + Right). | None | 88 | | `onClick` | Perform any action when swipeable view is clicked. It provides a Pair(Position, Id) where the `position` is index of the item and `id` to identify which item clicked incase of multiple items. | None | 89 | | `leftViewWidth` | Width for the left side of the view which will be shown when swiped. | `70.dp` | 90 | | `rightViewWidth` | Width for the right side of the view which will be shown when swiped. | `70.dp` | 91 | | `height` | Height for the swipeable view. | `70.dp` | 92 | | `cornerRadius` | Corner radius to be applied to the button. | `0.dp` | 93 | | `leftSpace` | Space between left swipeable view and your main content view. | `0.dp` | 94 | | `rightSpace` | Space between right swipeable view and your main content view. | `0.dp` | 95 | | `fractionalThreshold` | It is used to resolve the elevation for this button in different. | `0.3f` | 96 | | `content` | Add your actual view here. | none | 97 | 98 | ## Our JetPackCompose Sample 99 | [SSComposeCookBook](https://github.com/SimformSolutionsPvtLtd/SSComposeCookBook) : A Collection of major Jetpack compose UI components which are commonly used. 100 | 101 | ## Our JetPackCompose Libraries 102 | [SSJetPackComposeProgressButton](https://github.com/SimformSolutionsPvtLtd/SSJetPackComposeProgressButton) : SSJetPackComposeProgressButton is an elegant button with a different loading animations which makes your app attractive. 103 | 104 | ## Find this library useful? ❤️ 105 | Support it by joining __[stargazers]__ for this repository.⭐ 106 | 107 | ## How to Contribute🤝 108 | 109 | Whether you're helping us fix bugs, improve the docs, or a feature request, we'd love to have you! 💪 110 | Check out our __[Contributing Guide]__ for ideas on contributing. 111 | 112 | ## Bugs and Feedback 113 | For bugs, feature requests, and discussion please use __[GitHub Issues]__. 114 | 115 | ## Awesome Mobile Libraries 116 | - Check out our other available [awesome mobile libraries](https://github.com/SimformSolutionsPvtLtd/Awesome-Mobile-Libraries) 117 | 118 | ### LICENSE 119 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details 120 | 121 | [//]: # (These are reference links used in the body of this note and get stripped out when the markdown processor does its job. There is no need to format nicely because it shouldn't be seen. Thanks SO - http://stackoverflow.com/questions/4823468/store-comments-in-markdown-syntax) 122 | [stargazers]: 123 | [Contributing Guide]: 124 | [GitHub Issues]: 125 | [LICENSE]: 126 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | } 5 | 6 | android { 7 | compileSdk 31 8 | 9 | defaultConfig { 10 | applicationId "com.example.ssjetpackcomposeswipeableview" 11 | minSdk 21 12 | targetSdk 31 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | vectorDrawables { 18 | useSupportLibrary true 19 | } 20 | } 21 | 22 | buildTypes { 23 | release { 24 | minifyEnabled false 25 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 26 | } 27 | } 28 | compileOptions { 29 | sourceCompatibility JavaVersion.VERSION_1_8 30 | targetCompatibility JavaVersion.VERSION_1_8 31 | } 32 | kotlinOptions { 33 | jvmTarget = '1.8' 34 | useIR = true 35 | } 36 | buildFeatures { 37 | compose true 38 | } 39 | composeOptions { 40 | kotlinCompilerExtensionVersion '1.1.0-rc01' 41 | kotlinCompilerVersion '1.5.31' 42 | } 43 | packagingOptions { 44 | resources { 45 | excludes += '/META-INF/{AL2.0,LGPL2.1}' 46 | } 47 | } 48 | } 49 | 50 | dependencies { 51 | 52 | implementation 'androidx.core:core-ktx:1.7.0' 53 | implementation 'androidx.appcompat:appcompat:1.4.0' 54 | implementation 'com.google.android.material:material:1.4.0' 55 | implementation "androidx.compose.ui:ui:$compose_version" 56 | implementation "androidx.compose.material:material:$compose_version" 57 | implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" 58 | implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0' 59 | implementation 'androidx.activity:activity-compose:1.4.0' 60 | implementation project(path: ':ssjetpackcomposeswipeableview') 61 | testImplementation 'junit:junit:4.+' 62 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 63 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 64 | androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version" 65 | debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" 66 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ssjetpackcomposeswipeableview/ui/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.ssjetpackcomposeswipeableview.ui 2 | 3 | import android.content.Context 4 | import android.content.Intent 5 | import android.os.Bundle 6 | import androidx.activity.ComponentActivity 7 | import androidx.activity.compose.setContent 8 | import androidx.compose.foundation.background 9 | import androidx.compose.foundation.layout.Column 10 | import androidx.compose.foundation.layout.fillMaxHeight 11 | import androidx.compose.foundation.layout.fillMaxWidth 12 | import androidx.compose.foundation.layout.padding 13 | import androidx.compose.foundation.shape.RoundedCornerShape 14 | import androidx.compose.material.Button 15 | import androidx.compose.material.ExperimentalMaterialApi 16 | import androidx.compose.material.MaterialTheme 17 | import androidx.compose.material.Scaffold 18 | import androidx.compose.material.Surface 19 | import androidx.compose.material.Text 20 | import androidx.compose.material.TopAppBar 21 | import androidx.compose.runtime.Composable 22 | import androidx.compose.ui.Modifier 23 | import androidx.compose.ui.graphics.Color 24 | import androidx.compose.ui.platform.LocalContext 25 | import androidx.compose.ui.text.style.TextAlign 26 | import androidx.compose.ui.tooling.preview.Preview 27 | import androidx.compose.ui.unit.dp 28 | import com.example.ssjetpackcomposeswipeableview.SwipeDirection 29 | import com.example.ssjetpackcomposeswipeableview.ui.theme.Background 30 | import com.example.ssjetpackcomposeswipeableview.ui.theme.SSJetpackComposeSwipeAbleViewTheme 31 | 32 | @ExperimentalMaterialApi 33 | class MainActivity : ComponentActivity() { 34 | override fun onCreate(savedInstanceState: Bundle?) { 35 | super.onCreate(savedInstanceState) 36 | setContent { 37 | SSJetpackComposeSwipeAbleViewTheme { 38 | Surface(color = MaterialTheme.colors.background) { 39 | MainContent() 40 | } 41 | } 42 | } 43 | } 44 | 45 | @Preview 46 | @Composable 47 | fun MainContent() { 48 | val context = LocalContext.current 49 | Scaffold(topBar = { 50 | TopAppBar( 51 | title = { Text("SWIPEABLE VIEW") }, 52 | ) 53 | }) { 54 | Column(Modifier.fillMaxHeight().background(Background)) { 55 | Button( 56 | onClick = { 57 | navigateToSwipeAbleViewActivity(context, SwipeDirection.LEFT) 58 | }, modifier = Modifier 59 | .padding(16.dp) 60 | .fillMaxWidth(), shape = RoundedCornerShape(8.dp) 61 | ) { 62 | Text( 63 | modifier = Modifier.padding(8.dp), 64 | text = "Swipe Left", 65 | textAlign = TextAlign.Center, 66 | color = Color.White 67 | ) 68 | } 69 | Button( 70 | onClick = { 71 | navigateToSwipeAbleViewActivity(context, SwipeDirection.RIGHT) 72 | }, modifier = Modifier 73 | .padding(16.dp) 74 | .fillMaxWidth(), shape = RoundedCornerShape(8.dp) 75 | ) { 76 | Text( 77 | modifier = Modifier.padding(8.dp), 78 | text = "Swipe Right", 79 | textAlign = TextAlign.Center, 80 | color = Color.White 81 | ) 82 | } 83 | Button( 84 | onClick = { 85 | navigateToSwipeAbleViewActivity(context, SwipeDirection.BOTH) 86 | }, modifier = Modifier 87 | .padding(16.dp) 88 | .fillMaxWidth(), shape = RoundedCornerShape(8.dp) 89 | ) { 90 | Text( 91 | modifier = Modifier.padding(8.dp), 92 | text = "Swipe Left + Right", 93 | textAlign = TextAlign.Center, 94 | color = Color.White 95 | ) 96 | } 97 | } 98 | } 99 | } 100 | 101 | private fun navigateToSwipeAbleViewActivity(context: Context, swipeDirection: SwipeDirection) { 102 | val intent = Intent(context, SwipeAbleViewActivity::class.java) 103 | intent.putExtra("SwipeDirection", swipeDirection) 104 | startActivity(intent) 105 | } 106 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/ssjetpackcomposeswipeableview/ui/SwipeAbleViewActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.ssjetpackcomposeswipeableview.ui 2 | 3 | import android.content.Context 4 | import android.os.Bundle 5 | import android.widget.Toast 6 | import androidx.activity.ComponentActivity 7 | import androidx.activity.compose.setContent 8 | import androidx.compose.foundation.background 9 | import androidx.compose.foundation.layout.Arrangement 10 | import androidx.compose.foundation.layout.Column 11 | import androidx.compose.foundation.layout.PaddingValues 12 | import androidx.compose.foundation.layout.fillMaxWidth 13 | import androidx.compose.foundation.layout.height 14 | import androidx.compose.foundation.lazy.LazyColumn 15 | import androidx.compose.foundation.shape.RoundedCornerShape 16 | import androidx.compose.material.ExperimentalMaterialApi 17 | import androidx.compose.material.Icon 18 | import androidx.compose.material.IconButton 19 | import androidx.compose.material.Scaffold 20 | import androidx.compose.material.Surface 21 | import androidx.compose.material.Text 22 | import androidx.compose.material.TopAppBar 23 | import androidx.compose.material.icons.Icons 24 | import androidx.compose.material.icons.filled.ArrowBack 25 | import androidx.compose.material.icons.filled.Delete 26 | import androidx.compose.runtime.Composable 27 | import androidx.compose.runtime.mutableStateListOf 28 | import androidx.compose.runtime.remember 29 | import androidx.compose.ui.Alignment 30 | import androidx.compose.ui.Modifier 31 | import androidx.compose.ui.graphics.Color 32 | import androidx.compose.ui.graphics.vector.rememberVectorPainter 33 | import androidx.compose.ui.platform.LocalContext 34 | import androidx.compose.ui.tooling.preview.Preview 35 | import androidx.compose.ui.unit.dp 36 | import com.example.ssjetpackcomposeswipeableview.SwipeAbleItemView 37 | import com.example.ssjetpackcomposeswipeableview.SwipeDirection 38 | import com.example.ssjetpackcomposeswipeableview.ui.theme.Background 39 | import com.example.ssjetpackcomposeswipeableview.ui.theme.Primary 40 | import com.example.ssjetpackcomposeswipeableview.ui.theme.SSJetpackComposeSwipeAbleViewTheme 41 | import com.example.ssjetpackcomposeswipeableview.ui.theme.Secondary 42 | 43 | @ExperimentalMaterialApi 44 | class SwipeAbleViewActivity: ComponentActivity() { 45 | 46 | var swipeDirection: SwipeDirection? = null 47 | 48 | override fun onCreate(savedInstanceState: Bundle?) { 49 | super.onCreate(savedInstanceState) 50 | setContent { 51 | swipeDirection = intent.extras?.get("SwipeDirection") as? SwipeDirection 52 | SSJetpackComposeSwipeAbleViewTheme { 53 | Surface(color = Background) { 54 | MainContent() 55 | } 56 | } 57 | } 58 | } 59 | 60 | @Preview 61 | @Composable 62 | fun MainContent() { 63 | val context = LocalContext.current 64 | val items = remember { mutableStateListOf() } 65 | items.addAll(0..10) 66 | Scaffold(topBar = { 67 | TopAppBar( 68 | title = { 69 | Text("SWIPE ${swipeDirection?.name}") 70 | }, 71 | navigationIcon = { 72 | IconButton(onClick = { onBackPressed() }) { 73 | Icon(Icons.Filled.ArrowBack, contentDescription = null) 74 | } 75 | }, 76 | backgroundColor = Color.White 77 | ) 78 | }) { 79 | Column { 80 | LazyColumn( 81 | contentPadding = PaddingValues(10.dp), 82 | verticalArrangement = Arrangement.spacedBy(10.dp) 83 | ) { 84 | items(items.size) { 85 | CellItem(number = items[it], context) 86 | } 87 | } 88 | } 89 | } 90 | } 91 | 92 | @Composable 93 | fun CellItem(number: Int, context: Context) { 94 | SwipeAbleItemView( 95 | // Pair(Icon, Id) 96 | leftViewIcons = arrayListOf(Triple(rememberVectorPainter(image = Icons.Filled.Delete), Color.White,"btnDeleteLeft")), 97 | rightViewIcons = arrayListOf(Triple((rememberVectorPainter(image = Icons.Filled.Delete)), Color.White,"btnDeleteRight")), 98 | position = number, 99 | swipeDirection = swipeDirection ?: SwipeDirection.BOTH, 100 | onClick = { // Pair(Position, Id) 101 | Toast.makeText(context, "${it.second} clicked. Position :- ${it.first}", Toast.LENGTH_SHORT) 102 | .show() 103 | }, 104 | leftViewWidth = 70.dp, 105 | rightViewWidth = 70.dp, 106 | height = 60.dp, 107 | fractionalThreshold = 0.3f, 108 | leftViewBackgroundColor = Primary, 109 | rightViewBackgroundColor = Primary, 110 | cornerRadius = 4.dp, 111 | leftSpace = 10.dp, 112 | rightSpace = 10.dp 113 | ) { 114 | Column( 115 | modifier = Modifier 116 | .fillMaxWidth() 117 | .height(60.dp) 118 | .background(Secondary, shape = RoundedCornerShape(4.dp)), 119 | verticalArrangement = Arrangement.Center, 120 | horizontalAlignment = Alignment.CenterHorizontally 121 | ) { 122 | Text(text = "Item Number $number", color = Color.Black) 123 | } 124 | } 125 | } 126 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/ssjetpackcomposeswipeableview/ui/theme/Color.kt: -------------------------------------------------------------------------------- 1 | package com.example.ssjetpackcomposeswipeableview.ui.theme 2 | 3 | import androidx.compose.ui.graphics.Color 4 | 5 | val Primary = Color(0xFF5DB989) 6 | val Secondary = Color(0xFFD0F9E5) 7 | val Background = Color(0xFFEAFFF3) -------------------------------------------------------------------------------- /app/src/main/java/com/example/ssjetpackcomposeswipeableview/ui/theme/Shape.kt: -------------------------------------------------------------------------------- 1 | package com.example.ssjetpackcomposeswipeableview.ui.theme 2 | 3 | import androidx.compose.foundation.shape.RoundedCornerShape 4 | import androidx.compose.material.Shapes 5 | import androidx.compose.ui.unit.dp 6 | 7 | val Shapes = Shapes( 8 | small = RoundedCornerShape(4.dp), 9 | medium = RoundedCornerShape(4.dp), 10 | large = RoundedCornerShape(0.dp) 11 | ) -------------------------------------------------------------------------------- /app/src/main/java/com/example/ssjetpackcomposeswipeableview/ui/theme/Theme.kt: -------------------------------------------------------------------------------- 1 | package com.example.ssjetpackcomposeswipeableview.ui.theme 2 | 3 | import androidx.compose.foundation.isSystemInDarkTheme 4 | import androidx.compose.material.MaterialTheme 5 | import androidx.compose.material.darkColors 6 | import androidx.compose.material.lightColors 7 | import androidx.compose.runtime.Composable 8 | import androidx.compose.runtime.remember 9 | 10 | private val DarkColorPalette = darkColors( 11 | primary = Primary, 12 | primaryVariant = Background, 13 | secondary = Secondary 14 | ) 15 | 16 | private val LightColorPalette = lightColors( 17 | primary = Primary, 18 | primaryVariant = Background, 19 | secondary = Secondary 20 | 21 | /* Other default colors to override 22 | background = Color.White, 23 | surface = Color.White, 24 | onPrimary = Color.White, 25 | onSecondary = Color.Black, 26 | onBackground = Color.Black, 27 | onSurface = Color.Black, 28 | */ 29 | ) 30 | 31 | @Composable 32 | fun SSJetpackComposeSwipeAbleViewTheme( 33 | darkTheme: Boolean = isSystemInDarkTheme(), 34 | content: @Composable() () -> Unit 35 | ) { 36 | val colors = if (darkTheme) { 37 | DarkColorPalette 38 | } else { 39 | LightColorPalette 40 | } 41 | 42 | MaterialTheme( 43 | colors = colors, 44 | typography = Typography, 45 | shapes = Shapes, 46 | content = content 47 | ) 48 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/ssjetpackcomposeswipeableview/ui/theme/Type.kt: -------------------------------------------------------------------------------- 1 | package com.example.ssjetpackcomposeswipeableview.ui.theme 2 | 3 | import androidx.compose.material.Typography 4 | import androidx.compose.ui.text.TextStyle 5 | import androidx.compose.ui.text.font.FontFamily 6 | import androidx.compose.ui.text.font.FontWeight 7 | import androidx.compose.ui.unit.sp 8 | 9 | // Set of Material typography styles to start with 10 | val Typography = Typography( 11 | body1 = TextStyle( 12 | fontFamily = FontFamily.Default, 13 | fontWeight = FontWeight.Normal, 14 | fontSize = 16.sp 15 | ) 16 | /* Other default text styles to override 17 | button = TextStyle( 18 | fontFamily = FontFamily.Default, 19 | fontWeight = FontWeight.W500, 20 | fontSize = 14.sp 21 | ), 22 | caption = TextStyle( 23 | fontFamily = FontFamily.Default, 24 | fontWeight = FontWeight.Normal, 25 | fontSize = 12.sp 26 | ) 27 | */ 28 | ) -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeableView/a8d92453a79bacbf690bade958cd6f3d824fc36e/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeableView/a8d92453a79bacbf690bade958cd6f3d824fc36e/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeableView/a8d92453a79bacbf690bade958cd6f3d824fc36e/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeableView/a8d92453a79bacbf690bade958cd6f3d824fc36e/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeableView/a8d92453a79bacbf690bade958cd6f3d824fc36e/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeableView/a8d92453a79bacbf690bade958cd6f3d824fc36e/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeableView/a8d92453a79bacbf690bade958cd6f3d824fc36e/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeableView/a8d92453a79bacbf690bade958cd6f3d824fc36e/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeableView/a8d92453a79bacbf690bade958cd6f3d824fc36e/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeableView/a8d92453a79bacbf690bade958cd6f3d824fc36e/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FF5DB989 4 | #FFD0F9E5 5 | #FFEAFFF3 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SSJetpackComposeSwipeAbleView 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | 14 | 18 | 19 |