├── .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 | 
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 | [](https://kotlinlang.org) [](https://www.android.com/) [](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 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | ext {
4 | compose_version = '1.0.5'
5 | }
6 | repositories {
7 | google()
8 | mavenCentral()
9 | }
10 | dependencies {
11 | classpath "com.android.tools.build:gradle:7.0.3"
12 | classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0'
13 |
14 | // NOTE: Do not place your application dependencies here; they belong
15 | // in the individual module build.gradle files
16 | }
17 | }
18 |
19 | task clean(type: Delete) {
20 | delete rootProject.buildDir
21 | }
--------------------------------------------------------------------------------
/gif/banner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeableView/a8d92453a79bacbf690bade958cd6f3d824fc36e/gif/banner.png
--------------------------------------------------------------------------------
/gif/swipeboth.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeableView/a8d92453a79bacbf690bade958cd6f3d824fc36e/gif/swipeboth.gif
--------------------------------------------------------------------------------
/gif/swipeleft.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeableView/a8d92453a79bacbf690bade958cd6f3d824fc36e/gif/swipeleft.gif
--------------------------------------------------------------------------------
/gif/swiperight.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeableView/a8d92453a79bacbf690bade958cd6f3d824fc36e/gif/swiperight.gif
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeableView/a8d92453a79bacbf690bade958cd6f3d824fc36e/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Dec 16 12:38:01 IST 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/jitpack.yml:
--------------------------------------------------------------------------------
1 | jdk:
2 | - openjdk11
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | dependencyResolutionManagement {
2 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
3 | repositories {
4 | google()
5 | mavenCentral()
6 | jcenter() // Warning: this repository is going to shut down soon
7 | }
8 | }
9 | rootProject.name = "SSJetpackComposeSwipeAbleView"
10 | include ':app'
11 | include ':ssjetpackcomposeswipeableview'
12 |
--------------------------------------------------------------------------------
/ssjetpackcomposeswipeableview/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | id 'kotlin-android'
4 | id 'maven-publish'
5 | }
6 |
7 | afterEvaluate {
8 | publishing {
9 | publications {
10 | // Creates a Maven publication called "release".
11 | release(MavenPublication) {
12 | from components.release
13 | groupId = 'com.simform.ssjetpackcomposeswipeableview'
14 | artifactId = 'ssjetpackcomposeswipeableview'
15 | version = '1.0.1'
16 | }
17 | }
18 | }
19 | }
20 |
21 | android {
22 | compileSdk 31
23 |
24 | defaultConfig {
25 | minSdk 21
26 | targetSdk 31
27 | versionCode 1
28 | versionName "1.0"
29 |
30 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
31 | consumerProguardFiles "consumer-rules.pro"
32 | }
33 |
34 | buildTypes {
35 | release {
36 | minifyEnabled false
37 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
38 | }
39 | }
40 | buildFeatures {
41 | compose true
42 | }
43 | composeOptions {
44 | kotlinCompilerExtensionVersion '1.1.0-rc01'
45 | kotlinCompilerVersion '1.5.31'
46 | }
47 | compileOptions {
48 | sourceCompatibility JavaVersion.VERSION_1_8
49 | targetCompatibility JavaVersion.VERSION_1_8
50 | }
51 | kotlinOptions {
52 | jvmTarget = '1.8'
53 | }
54 | }
55 |
56 | dependencies {
57 |
58 | implementation 'androidx.core:core-ktx:1.7.0'
59 | implementation 'androidx.appcompat:appcompat:1.4.0'
60 | implementation 'com.google.android.material:material:1.4.0'
61 | implementation "androidx.compose.ui:ui:$compose_version"
62 | implementation "androidx.compose.material:material:$compose_version"
63 | implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
64 | testImplementation 'junit:junit:4.+'
65 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
66 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
67 | }
--------------------------------------------------------------------------------
/ssjetpackcomposeswipeableview/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SimformSolutionsPvtLtd/SSJetpackComposeSwipeableView/a8d92453a79bacbf690bade958cd6f3d824fc36e/ssjetpackcomposeswipeableview/consumer-rules.pro
--------------------------------------------------------------------------------
/ssjetpackcomposeswipeableview/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
--------------------------------------------------------------------------------
/ssjetpackcomposeswipeableview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/ssjetpackcomposeswipeableview/src/main/java/com/example/ssjetpackcomposeswipeableview/SwipeAbleItemView.kt:
--------------------------------------------------------------------------------
1 | package com.example.ssjetpackcomposeswipeableview
2 |
3 | import androidx.compose.foundation.background
4 | import androidx.compose.foundation.gestures.Orientation
5 | import androidx.compose.foundation.layout.Arrangement
6 | import androidx.compose.foundation.layout.Box
7 | import androidx.compose.foundation.layout.Column
8 | import androidx.compose.foundation.layout.Row
9 | import androidx.compose.foundation.layout.fillMaxHeight
10 | import androidx.compose.foundation.layout.fillMaxWidth
11 | import androidx.compose.foundation.layout.height
12 | import androidx.compose.foundation.layout.offset
13 | import androidx.compose.foundation.layout.width
14 | import androidx.compose.foundation.shape.RoundedCornerShape
15 | import androidx.compose.material.ExperimentalMaterialApi
16 | import androidx.compose.material.FractionalThreshold
17 | import androidx.compose.material.Icon
18 | import androidx.compose.material.IconButton
19 | import androidx.compose.material.rememberSwipeableState
20 | import androidx.compose.material.swipeable
21 | import androidx.compose.runtime.Composable
22 | import androidx.compose.ui.Alignment
23 | import androidx.compose.ui.Modifier
24 | import androidx.compose.ui.graphics.Color
25 | import androidx.compose.ui.graphics.painter.Painter
26 | import androidx.compose.ui.platform.LocalDensity
27 | import androidx.compose.ui.unit.Dp
28 | import androidx.compose.ui.unit.IntOffset
29 | import androidx.compose.ui.unit.dp
30 | import kotlin.math.roundToInt
31 |
32 | @ExperimentalMaterialApi
33 | @Composable
34 |
35 | /**
36 | * @param leftViewIcons Icons which needs to be shown on the left side of the screen requires a Triplet of Icon, tint color and Id of the view Triplet(Icon, TintColor, Id).
37 | * @param rightViewIcons Icons which needs to be shown on the right side of the screen requires a Pair of Icon, tint color and Id of the view Pair(Icon, TintColor, Id).
38 | * @param position Position of the cell.
39 | * @param onClick OnClick event of the swipeable view returns a Pair of Position(Int) and Id(String) of the view Pair(Position, Id).
40 | * @param height Height of the swipeable view.
41 | * @param leftViewBackgroundColor Background color of swipeable view of left side.
42 | * @param rightViewBackgroundColor Background color of swipeable view of right side.
43 | * @param cornerRadius Corner radius of the swipeable views.
44 | * @param leftSpace Space between left side swipeable view and content view
45 | * @param rightSpace Space between right side swipeable view and content view
46 | * @param fractionalThreshold The fraction (between 0 and 1) that the threshold will be at.
47 | * @param content Pass the content of your view.
48 | **/
49 | fun SwipeAbleItemView(
50 | leftViewIcons: ArrayList>,
51 | rightViewIcons: ArrayList>,
52 | position: Int = 0,
53 | onClick: (Pair) -> (Unit),
54 | swipeDirection: SwipeDirection,
55 | leftViewWidth: Dp = 70.dp,
56 | rightViewWidth: Dp = 70.dp,
57 | height: Dp = 70.dp,
58 | leftViewBackgroundColor: Color,
59 | rightViewBackgroundColor: Color,
60 | cornerRadius: Dp = 0.dp,
61 | leftSpace: Dp = 0.dp,
62 | rightSpace: Dp = 0.dp,
63 | fractionalThreshold: Float = 0.3f,
64 | content: @Composable () -> Unit
65 | ) {
66 |
67 | val swipeAbleState = rememberSwipeableState(initialValue = 0)
68 | val anchors = when (swipeDirection) {
69 | SwipeDirection.LEFT -> mapOf(
70 | 0f to 0,
71 | -(with(LocalDensity.current) { rightViewWidth.toPx() }) to 1
72 | )
73 | SwipeDirection.RIGHT -> mapOf(
74 | 0f to 0,
75 | (with(LocalDensity.current) { leftViewWidth.toPx() }) to 1
76 | )
77 | else -> mapOf(
78 | 0f to 0,
79 | ((with(LocalDensity.current) { leftViewWidth.toPx() })) to 1,
80 | -(with(LocalDensity.current) { rightViewWidth.toPx() }) to 2
81 | )
82 | }
83 |
84 | Column(
85 | modifier = Modifier
86 | .fillMaxWidth()
87 | .height(height)
88 | ) {
89 | Column(
90 | verticalArrangement = Arrangement.Center,
91 | horizontalAlignment = Alignment.CenterHorizontally
92 | ) {
93 | Box(
94 | modifier = Modifier
95 | .fillMaxWidth()
96 | .background(Color.Transparent)
97 | .swipeable(
98 | state = swipeAbleState,
99 | anchors = anchors,
100 | thresholds = { _, _ ->
101 | FractionalThreshold(fractionalThreshold)
102 | },
103 | orientation = Orientation.Horizontal
104 | ),
105 | ) {
106 | Row(
107 | modifier = Modifier
108 | .fillMaxWidth()
109 | .height(height),
110 | horizontalArrangement = when (swipeDirection) {
111 | SwipeDirection.BOTH -> Arrangement.SpaceBetween
112 | SwipeDirection.LEFT -> Arrangement.End
113 | else -> Arrangement.Start
114 | },
115 | verticalAlignment = Alignment.CenterVertically
116 | ) {
117 | // When user Swipes to right the left side of the view which is visible
118 | if (swipeDirection == SwipeDirection.RIGHT || swipeDirection == SwipeDirection.BOTH) {
119 | Row(modifier = Modifier
120 | .fillMaxHeight()
121 | .width(leftViewWidth - leftSpace)
122 | .background(
123 | leftViewBackgroundColor,
124 | shape = RoundedCornerShape(cornerRadius)
125 | ),
126 | verticalAlignment = Alignment.CenterVertically,
127 | horizontalArrangement = Arrangement.Center) {
128 | leftViewIcons.forEachIndexed { index, triplet ->
129 | IconButton(
130 | onClick = {
131 | // Pair(Position, Id)
132 | onClick(Pair(position, triplet.third))
133 | }
134 | ) {
135 | // Triplet(Icon, TintColor, Id)
136 | Icon(painter = triplet.first, contentDescription = triplet.third, tint = triplet.second)
137 | }
138 | }
139 | }
140 | }
141 | // When user Swipes to left the right side of the view which is visible
142 | if (swipeDirection == SwipeDirection.LEFT || swipeDirection == SwipeDirection.BOTH) {
143 | Row(
144 | modifier = Modifier
145 | .fillMaxHeight()
146 | .width(rightViewWidth - rightSpace)
147 | .background(
148 | rightViewBackgroundColor,
149 | shape = RoundedCornerShape(cornerRadius)
150 | ),
151 | verticalAlignment = Alignment.CenterVertically,
152 | horizontalArrangement = Arrangement.Center
153 | ) {
154 | rightViewIcons.forEachIndexed { index, triplet ->
155 | IconButton(
156 | onClick = {
157 | // Pair(Position, Id)
158 | onClick(Pair(position, triplet.third))
159 | }
160 | ) {
161 | // Triplet(Icon, TintColor, Id)
162 | Icon(painter = triplet.first, contentDescription = triplet.third, tint = triplet.second)
163 | }
164 | }
165 | }
166 | }
167 | }
168 | // Main content view of the cell
169 | Box(
170 | modifier = Modifier
171 | .offset {
172 | IntOffset(
173 | swipeAbleState.offset.value.roundToInt(), 0
174 | )
175 | }
176 | .fillMaxWidth()
177 | ) {
178 | content()
179 | }
180 | }
181 | }
182 | }
183 | }
--------------------------------------------------------------------------------
/ssjetpackcomposeswipeableview/src/main/java/com/example/ssjetpackcomposeswipeableview/SwipeDirection.kt:
--------------------------------------------------------------------------------
1 | package com.example.ssjetpackcomposeswipeableview
2 |
3 | /**
4 | * Swipe Directions :-
5 | * Left :- If you want to swipe left
6 | * Right :- If you want to swipe right
7 | * Both :- If you want to swipe left + right both
8 | **/
9 | enum class SwipeDirection {
10 | LEFT, RIGHT, BOTH
11 | }
--------------------------------------------------------------------------------