├── .editorconfig ├── .github └── workflows │ └── test_and_release_snapshot.yml ├── .gitignore ├── LICENSE.txt ├── README.md ├── build.gradle.kts ├── gradle.properties ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jitpack.yml ├── library ├── build.gradle.kts ├── gradle.properties └── src │ ├── commonMain │ └── kotlin │ │ └── com │ │ └── linversion │ │ └── swipe │ │ ├── ActionFinder.kt │ │ ├── SwipeAction.kt │ │ ├── SwipeableActionsBox.kt │ │ ├── SwipeableActionsState.kt │ │ └── defaults.kt │ └── test │ ├── kotlin │ └── me │ │ └── saket │ │ └── swipe │ │ └── SwipeableActionsBoxTest.kt │ └── snapshots │ └── images │ ├── me.saket.swipe_SwipeableActionsBoxTest_empty actions.png │ ├── me.saket.swipe_SwipeableActionsBoxTest_non-empty actions.png │ ├── me.saket.swipe_SwipeableActionsBoxTest_should have extra background when offset is greater than threshold.png │ ├── me.saket.swipe_SwipeableActionsBoxTest_show a each action's background and part of icon when offset is greater than icon offset.png │ └── me.saket.swipe_SwipeableActionsBoxTest_show a each action's background when offset is small.png ├── sample ├── .gitignore ├── build.gradle.kts └── src │ └── main │ ├── AndroidManifest.xml │ ├── kotlin │ └── com │ │ └── linversion │ │ └── swipe │ │ └── sample │ │ ├── SampleActivity.kt │ │ └── theme │ │ └── Theme.kt │ └── res │ ├── drawable │ ├── ic_launcher_background.xml │ └── ic_launcher_foreground.xml │ ├── mipmap-anydpi-v26 │ └── ic_launcher.xml │ └── values │ ├── strings.xml │ └── styles.xml ├── screenshot.gif └── settings.gradle /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | indent_size = 2 3 | insert_final_newline = true 4 | max_line_length = 120 5 | -------------------------------------------------------------------------------- /.github/workflows/test_and_release_snapshot.yml: -------------------------------------------------------------------------------- 1 | name: Run tests and publish snapshot 2 | 3 | on: 4 | push: 5 | branches: [ trunk ] 6 | pull_request: 7 | 8 | jobs: 9 | checks: 10 | name: Run tests 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v3 15 | with: 16 | lfs: true 17 | - uses: gradle/wrapper-validation-action@v1 18 | - uses: actions/setup-java@v3 19 | with: 20 | distribution: 'zulu' 21 | java-version: 17 22 | - uses: gradle/gradle-build-action@v2.4.2 23 | 24 | - name: Run unit tests 25 | run: ./gradlew check 26 | 27 | - name: Run paparazzi screenshot tests 28 | run: ./gradlew verifyPaparazziDebug 29 | 30 | - name: (Fail-only) Upload paparazzi test reports 31 | if: failure() 32 | uses: actions/upload-artifact@v3 33 | with: 34 | name: test-failures 35 | path: | 36 | **/build/reports/tests/*/ 37 | **/out/failures/ 38 | paparazzi/paparazzi-gradle-plugin/src/test/projects/**/build/reports/paparazzi/images/ 39 | 40 | deploy-snapshot: 41 | name: Deploy snapshot 42 | runs-on: ubuntu-latest 43 | timeout-minutes: 10 44 | if: github.repository == 'saket/swipe' && github.ref == 'refs/heads/trunk' 45 | needs: [ checks ] 46 | steps: 47 | - uses: actions/checkout@v3 48 | - uses: gradle/wrapper-validation-action@v1 49 | - uses: actions/setup-java@v3 50 | with: 51 | distribution: 'zulu' 52 | java-version: 17 53 | - uses: gradle/gradle-build-action@v2.4.2 54 | - uses: oNaiPs/secrets-to-env-action@v1 55 | with: 56 | secrets: ${{ toJSON(secrets) }} 57 | 58 | - name: Ensure snapshot version 59 | run: ./gradlew library:throwIfVersionIsNotSnapshot 60 | 61 | - name: Publish snapshot 62 | run: ./gradlew clean publish --no-daemon --no-parallel --no-configuration-cache --stacktrace 63 | env: 64 | ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }} 65 | ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }} 66 | ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_SIGNING_KEY }} 67 | ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_SIGNING_PASSWORD }} 68 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | build/ 16 | 17 | # Gradle files 18 | .gradle/ 19 | build/ 20 | 21 | # Local configuration file (sdk path, etc) 22 | local.properties 23 | 24 | # Log Files 25 | *.log 26 | 27 | # Android Studio stuff 28 | .idea/ 29 | .navigation/ 30 | captures/ 31 | *.iml 32 | 33 | # OS specific ignores 34 | .DS_Store 35 | *~ 36 | *.swp 37 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2019 Saket Narayan 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # swipe-like-ios 2 | 3 | ![](https://github.com/linversion/swipe-like-ios/blob/trunk/screenshot.gif) 4 | 5 | `swipe-like-ios` builds composables that can be swiped left or right for revealing actions 6 | [![](https://jitpack.io/v/linversion/swipe-like-ios.svg)](https://jitpack.io/#linversion/swipe-like-ios) 7 | ```groovy 8 | // settings.gradle.kts 9 | repositories { 10 | maven { setUrl("https://jitpack.io") } 11 | } 12 | 13 | // build.gradle.kts 14 | implementation("com.github.linversion.swipe-like-ios:swipe-like-ios:latest-version") 15 | ``` 16 | 17 | ```kotlin 18 | val archive = SwipeAction( 19 | icon = rememberVectorPainter(Icons.TwoTone.Archive), 20 | background = Color.Green, 21 | onClick = { … } 22 | ) 23 | 24 | val replyAll = SwipeAction( 25 | icon = rememberVectorPainter(Icons.TwoTone.ReplyAll), 26 | background = Color.Perfume, 27 | onClick = { println("Reply swiped") } 28 | ) 29 | 30 | val snooze = SwipeAction( 31 | icon = { Text("Snooze") }, 32 | background = Color.Yellow, 33 | onClick = { … }, 34 | ) 35 | 36 | SwipeableActionsBox( 37 | startActions = listOf(replyAll), 38 | endActions = listOf(snooze, archive), 39 | swipeThreshold = 80.dp, 40 | ) { 41 | // Swipeable content goes here. 42 | } 43 | ``` 44 | 45 | ## License 46 | 47 | ``` 48 | Copyright 2024 linversion. 49 | 50 | Licensed under the Apache License, Version 2.0 (the "License"); 51 | you may not use this file except in compliance with the License. 52 | You may obtain a copy of the License at 53 | 54 | http://www.apache.org/licenses/LICENSE-2.0 55 | 56 | Unless required by applicable law or agreed to in writing, software 57 | distributed under the License is distributed on an "AS IS" BASIS, 58 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 59 | See the License for the specific language governing permissions and 60 | limitations under the License. 61 | ``` 62 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.dsl.JvmTarget 2 | import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile 3 | import com.android.build.gradle.BaseExtension as AndroidBaseExtension 4 | import com.android.build.gradle.BasePlugin as AndroidBasePlugin 5 | 6 | buildscript { 7 | repositories { 8 | google() 9 | mavenCentral() 10 | maven { 11 | url = java.net.URI.create("https://jitpack.io") 12 | } 13 | } 14 | } 15 | 16 | // Lists all plugins used throughout the project without applying them. 17 | plugins { 18 | alias(libs.plugins.android.application) apply false 19 | alias(libs.plugins.android.library) apply false 20 | alias(libs.plugins.kotlin.multiplatform) apply false 21 | alias(libs.plugins.kotlin.android) apply false 22 | alias(libs.plugins.compose.multiplatform) apply false 23 | alias(libs.plugins.paparazzi) apply false 24 | alias(libs.plugins.dokka) apply false 25 | } 26 | 27 | allprojects { 28 | plugins.withType().configureEach { 29 | configure { 30 | compileOptions { 31 | sourceCompatibility = JavaVersion.VERSION_17 32 | targetCompatibility = JavaVersion.VERSION_17 33 | } 34 | } 35 | } 36 | tasks.withType().configureEach { 37 | compilerOptions { 38 | jvmTarget.set(JvmTarget.JVM_17) 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | 19 | android.useAndroidX=true 20 | android.enableJetifier=false 21 | 22 | kotlin.mpp.androidSourceSetLayoutVersion=2 23 | kotlin.mpp.androidGradlePluginCompatibility.nowarn=true 24 | org.jetbrains.compose.experimental.uikit.enabled=true 25 | -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | minSdk = "21" 3 | compileSdk = "34" 4 | kotlin = "1.9.10" 5 | agp = "8.1.0" 6 | androidx-compose-ui = "1.5.1" # https://developer.android.com/jetpack/androidx/releases/compose-ui 7 | androidx-compose-ui-material3 = "1.1.1" 8 | androidx-compose-compiler = "1.5.3" # https://developer.android.com/jetpack/androidx/releases/compose-compiler 9 | compose-multiplatform = "1.5.1" # https://github.com/JetBrains/compose-multiplatform/releases 10 | androidx-appcompat = "1.6.1" 11 | androidx-activity = "1.7.2" # https://developer.android.com/jetpack/androidx/releases/activity 12 | androidx-savedstate = "1.2.1" # https://developer.android.com/jetpack/androidx/releases/savedstate 13 | androidx-lifecycle = "2.6.2" # https://developer.android.com/jetpack/androidx/releases/lifecycle 14 | accompanist = "0.32.0" # https://github.com/google/accompanist/releases 15 | paparazzi = "1.3.1" # https://github.com/cashapp/paparazzi/releases 16 | mavenPublish = "0.25.3" # https://github.com/vanniktech/gradle-maven-publish-plugin/releases 17 | dokka = "1.9.0" # https://github.com/kotlin/dokka/releases 18 | junit = "4.13.2" 19 | android-maven="2.8" 20 | [plugins] 21 | android-application = { id = "com.android.application", version.ref = "agp" } 22 | android-library = { id = "com.android.library", version.ref = "agp" } 23 | paparazzi = { id = "app.cash.paparazzi", version.ref = "paparazzi" } 24 | kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } 25 | kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } 26 | compose-multiplatform = { id = "org.jetbrains.compose", version.ref = "compose-multiplatform" } 27 | dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } 28 | mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" } 29 | 30 | [libraries] 31 | compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "androidx-compose-ui" } 32 | compose-ui = { module = "androidx.compose.ui:ui", version.ref = "androidx-compose-ui" } 33 | compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "androidx-compose-ui-material3" } 34 | compose-materialIcons = { module = "androidx.compose.material:material-icons-extended", version.ref = "androidx-compose-ui" } 35 | 36 | androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" } 37 | androidx-activity = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity"} 38 | androidx-savedstate = { module = "androidx.savedstate:savedstate", version.ref = "androidx-savedstate" } 39 | androidx-lifecycle = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidx-lifecycle"} 40 | 41 | accompanist-systemUi = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanist" } 42 | 43 | junit = { module = "junit:junit", version.ref = "junit" } 44 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linversion/swipe-like-ios/c07532b828134fd7b0550850765c768a655a8f7e/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /jitpack.yml: -------------------------------------------------------------------------------- 1 | jdk: 2 | - openjdk17 3 | - 4 | -------------------------------------------------------------------------------- /library/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | alias(libs.plugins.android.library) 3 | alias(libs.plugins.kotlin.multiplatform) 4 | alias(libs.plugins.compose.multiplatform) 5 | alias(libs.plugins.paparazzi) 6 | id("maven-publish") 7 | } 8 | 9 | kotlin { 10 | @Suppress("OPT_IN_USAGE") 11 | targetHierarchy.default() 12 | 13 | androidTarget() 14 | jvm() 15 | iosX64() 16 | iosArm64() 17 | iosSimulatorArm64() 18 | 19 | sourceSets { 20 | val commonMain by getting { 21 | dependencies { 22 | implementation(compose.ui) 23 | implementation(compose.foundation) 24 | } 25 | } 26 | 27 | val androidUnitTest by getting { 28 | dependencies { 29 | implementation(libs.junit) 30 | implementation(libs.compose.material3) 31 | implementation(libs.compose.materialIcons) 32 | implementation(libs.androidx.savedstate) 33 | implementation(libs.androidx.lifecycle) 34 | } 35 | } 36 | } 37 | } 38 | 39 | android { 40 | namespace = "com.linversion.swipe" 41 | 42 | defaultConfig { 43 | minSdk = libs.versions.minSdk.get().toInt() 44 | compileSdk = libs.versions.compileSdk.get().toInt() 45 | } 46 | buildFeatures { 47 | compose = true 48 | } 49 | composeOptions { 50 | kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get() 51 | } 52 | java { 53 | toolchain.languageVersion.set(JavaLanguageVersion.of(17)) 54 | } 55 | lint { 56 | abortOnError = true 57 | } 58 | 59 | buildTypes { 60 | release { 61 | isMinifyEnabled = false 62 | } 63 | } 64 | 65 | publishing { 66 | singleVariant("release") { 67 | withSourcesJar() 68 | withJavadocJar() 69 | } 70 | } 71 | } 72 | 73 | publishing { 74 | publications { 75 | register("release") { 76 | groupId = "com.linversion.swipe" 77 | artifactId = "swipe-like-ios" 78 | version = "1.0.0" 79 | 80 | afterEvaluate { 81 | from(components["release"]) 82 | } 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /library/gradle.properties: -------------------------------------------------------------------------------- 1 | SONATYPE_HOST=DEFAULT 2 | RELEASE_SIGNING_ENABLED=true 3 | SONATYPE_AUTOMATIC_RELEASE=true 4 | 5 | GROUP=com.linversion.swipe 6 | POM_ARTIFACT_ID=swipe-like-ios 7 | VERSION_NAME=1.0.0-SNAPSHOT 8 | 9 | POM_NAME=swipe 10 | POM_PACKAGING=aar 11 | 12 | POM_DESCRIPTION=swipe-like-ios builds composables that can be swiped left or right for revealing actions like ios 13 | POM_INCEPTION_YEAR=2024 14 | 15 | POM_URL=https://github.com/linversion/swipe-like-ios 16 | POM_SCM_URL=https://github.com/linversion/swipe-like-ios 17 | POM_SCM_CONNECTION=scm:git@github.com:linversion/swipe-like-ios.git 18 | POM_SCM_DEV_CONNECTION=scm:git@github.com:linversion/swipe-like-ios.git 19 | 20 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 21 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 22 | POM_LICENCE_DIST=repo 23 | 24 | POM_DEVELOPER_ID=linversion 25 | POM_DEVELOPER_NAME=linversion 26 | -------------------------------------------------------------------------------- /library/src/commonMain/kotlin/com/linversion/swipe/ActionFinder.kt: -------------------------------------------------------------------------------- 1 | package com.linversion.swipe 2 | 3 | import kotlin.math.abs 4 | 5 | internal data class SwipeActionMeta( 6 | val value: SwipeAction, 7 | val isOnRightSide: Boolean, 8 | ) 9 | 10 | internal data class ActionFinder( 11 | val left: List, 12 | val right: List 13 | ) { 14 | 15 | fun actionAt(offset: Float, totalWidth: Int): SwipeActionMeta? { 16 | if (offset == 0f) { 17 | return null 18 | } 19 | 20 | val isOnRightSide = offset < 0f 21 | val actions = if (isOnRightSide) right else left 22 | 23 | val actionAtOffset = actions.actionAt( 24 | offset = abs(offset).coerceAtMost(totalWidth.toFloat()), 25 | totalWidth = totalWidth 26 | ) 27 | return actionAtOffset?.let { 28 | SwipeActionMeta( 29 | value = actionAtOffset, 30 | isOnRightSide = isOnRightSide 31 | ) 32 | } 33 | } 34 | 35 | private fun List.actionAt(offset: Float, totalWidth: Int): SwipeAction? { 36 | if (isEmpty()) { 37 | return null 38 | } 39 | 40 | val totalWeights = this.sumOf { it.iconSize.value.toInt() } 41 | var offsetSoFar = 0.0 42 | 43 | @Suppress("ReplaceManualRangeWithIndicesCalls") // Avoid allocating an Iterator for every pixel swiped. 44 | for (i in 0 until size) { 45 | val action = this[i] 46 | val actionWidth = (1f / totalWeights) * totalWidth 47 | val actionEndX = offsetSoFar + actionWidth 48 | 49 | if (offset <= actionEndX) { 50 | return action 51 | } 52 | offsetSoFar += actionEndX 53 | } 54 | 55 | // Precision error in the above loop maybe? 56 | error("Couldn't find any swipe action. Width=$totalWidth, offset=$offset, actions=$this") 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /library/src/commonMain/kotlin/com/linversion/swipe/SwipeAction.kt: -------------------------------------------------------------------------------- 1 | package com.linversion.swipe 2 | 3 | import androidx.compose.foundation.Image 4 | import androidx.compose.foundation.layout.size 5 | import androidx.compose.runtime.Composable 6 | import androidx.compose.ui.Modifier 7 | import androidx.compose.ui.graphics.Color 8 | import androidx.compose.ui.graphics.painter.Painter 9 | import androidx.compose.ui.unit.Dp 10 | import androidx.compose.ui.unit.dp 11 | 12 | /** 13 | * Represents an action that can be shown in [SwipeableActionsBox]. 14 | * 15 | * @param background Color used as the background of [SwipeableActionsBox] while 16 | * this action is visible. If this action is swiped, its background color is 17 | * also used for drawing a ripple over the content for providing a visual 18 | * feedback to the user. 19 | * 20 | * @param weight The proportional width to give to this element, as related 21 | * to the total of all weighted siblings. [SwipeableActionsBox] will divide its 22 | * horizontal space and distribute it to actions according to their weight. 23 | * 24 | * @param isUndo Determines the direction in which a ripple is drawn when this 25 | * action is swiped. When false, the ripple grows from this action's position 26 | * to consume the entire composable, and vice versa. This can be used for 27 | * actions that can be toggled on and off. 28 | */ 29 | class SwipeAction( 30 | val onClick: () -> Unit, 31 | val icon: @Composable () -> Unit, 32 | val background: Color, 33 | val iconSize: Dp, 34 | val resetAfterClick: Boolean 35 | ) { 36 | 37 | fun copy( 38 | onClick: () -> Unit = this.onClick, 39 | icon: @Composable () -> Unit = this.icon, 40 | iconSize: Dp = this.iconSize, 41 | background: Color = this.background, 42 | resetAfterClick: Boolean = this.resetAfterClick 43 | ) = SwipeAction( 44 | onClick = onClick, 45 | icon = icon, 46 | iconSize = iconSize, 47 | background = background, 48 | resetAfterClick = resetAfterClick 49 | ) 50 | } 51 | 52 | /** 53 | * See [SwipeAction] for documentation. 54 | */ 55 | fun SwipeAction( 56 | onClick: () -> Unit, 57 | icon: Painter, 58 | iconSize: Dp = 24.dp, 59 | background: Color, 60 | resetAfterClick: Boolean = true 61 | ): SwipeAction { 62 | return SwipeAction( 63 | icon = { 64 | Image( 65 | modifier = Modifier.size(iconSize), 66 | painter = icon, 67 | contentDescription = null 68 | ) 69 | }, 70 | iconSize = iconSize, 71 | background = background, 72 | onClick = onClick, 73 | resetAfterClick = resetAfterClick 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /library/src/commonMain/kotlin/com/linversion/swipe/SwipeableActionsBox.kt: -------------------------------------------------------------------------------- 1 | package com.linversion.swipe 2 | 3 | import androidx.compose.foundation.background 4 | import androidx.compose.foundation.gestures.Orientation.Horizontal 5 | import androidx.compose.foundation.gestures.detectTapGestures 6 | import androidx.compose.foundation.gestures.draggable 7 | import androidx.compose.foundation.layout.Arrangement 8 | import androidx.compose.foundation.layout.Box 9 | import androidx.compose.foundation.layout.BoxScope 10 | import androidx.compose.foundation.layout.BoxWithConstraints 11 | import androidx.compose.foundation.layout.Row 12 | import androidx.compose.foundation.layout.absoluteOffset 13 | import androidx.compose.foundation.layout.fillMaxHeight 14 | import androidx.compose.foundation.layout.width 15 | import androidx.compose.runtime.Composable 16 | import androidx.compose.runtime.remember 17 | import androidx.compose.runtime.rememberCoroutineScope 18 | import androidx.compose.ui.Alignment 19 | import androidx.compose.ui.Modifier 20 | import androidx.compose.ui.draw.clip 21 | import androidx.compose.ui.draw.clipToBounds 22 | import androidx.compose.ui.draw.drawWithContent 23 | import androidx.compose.ui.graphics.RectangleShape 24 | import androidx.compose.ui.graphics.drawscope.DrawScope 25 | import androidx.compose.ui.graphics.graphicsLayer 26 | import androidx.compose.ui.input.pointer.pointerInput 27 | import androidx.compose.ui.platform.LocalDensity 28 | import androidx.compose.ui.platform.LocalLayoutDirection 29 | import androidx.compose.ui.unit.Dp 30 | import androidx.compose.ui.unit.IntOffset 31 | import androidx.compose.ui.unit.LayoutDirection 32 | import androidx.compose.ui.unit.dp 33 | import kotlinx.coroutines.launch 34 | import kotlin.math.abs 35 | import kotlin.math.roundToInt 36 | 37 | /** 38 | * A composable that can be swiped left or right for revealing actions. 39 | * 40 | * @param swipeThreshold Minimum drag distance before any [SwipeAction] is 41 | * activated and can be swiped. 42 | * 43 | * @param backgroundUntilSwipeThreshold Color drawn behind the content until 44 | * [swipeThreshold] is reached. When the threshold is passed, this color is 45 | * replaced by the currently visible [SwipeAction]'s background. 46 | */ 47 | @Composable 48 | fun SwipeableActionsBox( 49 | modifier: Modifier = Modifier, 50 | state: SwipeableActionsState = rememberSwipeableActionsState(), 51 | startActions: List = emptyList(), 52 | endActions: List = emptyList(), 53 | swipeThreshold: Dp = 40.dp, 54 | content: @Composable BoxScope.() -> Unit 55 | ) = BoxWithConstraints(modifier) { 56 | state.also { 57 | it.layoutWidth = constraints.maxWidth 58 | it.swipeThresholdPx = LocalDensity.current.run { swipeThreshold.toPx() } 59 | val isRtl = LocalLayoutDirection.current == LayoutDirection.Rtl 60 | it.actions = remember(endActions, startActions, isRtl) { 61 | ActionFinder( 62 | left = if (isRtl) endActions else startActions, 63 | right = if (isRtl) startActions else endActions, 64 | ) 65 | } 66 | } 67 | 68 | val scope = rememberCoroutineScope() 69 | val offsetX = state.offset.value.roundToInt() 70 | 71 | Box( 72 | modifier = Modifier 73 | .absoluteOffset { IntOffset(x = offsetX, y = 0) } 74 | .draggable( 75 | orientation = Horizontal, 76 | enabled = !state.isResettingOnRelease, 77 | onDragStopped = { 78 | scope.launch { 79 | state.handleOnDragStopped() 80 | } 81 | }, 82 | state = state.draggableState, 83 | ), 84 | content = content 85 | ) 86 | 87 | val actionWidthDp = LocalDensity.current.run { abs(offsetX).toDp() } 88 | 89 | if (state.actions.right.isNotEmpty() && offsetX < 0) { 90 | val rightActionOffset = constraints.maxWidth + offsetX 91 | 92 | Row( 93 | Modifier.absoluteOffset { IntOffset(x = rightActionOffset, y = 0) }.matchParentSize(), 94 | horizontalArrangement = Arrangement.Start 95 | ) { 96 | val actionWidth = actionWidthDp / state.actions.right.size.toFloat() 97 | 98 | for (action in state.actions.right) { 99 | ActionIconBox( 100 | action = action, 101 | actionWidth = actionWidth, 102 | swipeThreshold = swipeThreshold 103 | ) { 104 | if (action.resetAfterClick) { 105 | scope.launch { 106 | state.handleReset() 107 | action.onClick() 108 | } 109 | } 110 | } 111 | } 112 | } 113 | } 114 | 115 | if (state.actions.left.isNotEmpty() && offsetX > 0) { 116 | val leftActionOffset = -constraints.maxWidth + offsetX 117 | 118 | Row( 119 | Modifier.absoluteOffset { IntOffset(x = leftActionOffset, y = 0) }.matchParentSize(), 120 | horizontalArrangement = Arrangement.End 121 | ) { 122 | val actionWidth = actionWidthDp / state.actions.left.size.toFloat() 123 | 124 | for (action in state.actions.left) { 125 | ActionIconBox( 126 | action = action, 127 | actionWidth = actionWidth, 128 | swipeThreshold = swipeThreshold 129 | ) { 130 | if (action.resetAfterClick) { 131 | scope.launch { 132 | state.handleReset() 133 | action.onClick() 134 | } 135 | } 136 | 137 | } 138 | } 139 | } 140 | } 141 | } 142 | 143 | @Composable 144 | private fun ActionIconBox( 145 | action: SwipeAction, 146 | actionWidth: Dp, 147 | swipeThreshold: Dp, 148 | onClick: () -> Unit 149 | ) { 150 | Box( 151 | Modifier.width(actionWidth).fillMaxHeight().background(color = action.background).clip(RectangleShape), 152 | contentAlignment = Alignment.CenterStart 153 | ) { 154 | Box( 155 | modifier = Modifier 156 | .graphicsLayer { 157 | translationX = ((swipeThreshold - action.iconSize) / 2).toPx() 158 | } 159 | .clipToBounds() 160 | .pointerInput(Unit) { 161 | detectTapGestures { 162 | onClick() 163 | } 164 | }, 165 | contentAlignment = Alignment.Center 166 | ) { 167 | action.icon() 168 | } 169 | } 170 | } 171 | 172 | private fun Modifier.drawOverContent(onDraw: DrawScope.() -> Unit): Modifier { 173 | return drawWithContent { 174 | drawContent() 175 | onDraw(this) 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /library/src/commonMain/kotlin/com/linversion/swipe/SwipeableActionsState.kt: -------------------------------------------------------------------------------- 1 | package com.linversion.swipe 2 | 3 | import androidx.compose.animation.core.Animatable 4 | import androidx.compose.animation.core.LinearEasing 5 | import androidx.compose.animation.core.tween 6 | import androidx.compose.foundation.MutatePriority 7 | import androidx.compose.foundation.gestures.DraggableState 8 | import androidx.compose.runtime.Composable 9 | import androidx.compose.runtime.Stable 10 | import androidx.compose.runtime.State 11 | import androidx.compose.runtime.derivedStateOf 12 | import androidx.compose.runtime.getValue 13 | import androidx.compose.runtime.mutableFloatStateOf 14 | import androidx.compose.runtime.mutableIntStateOf 15 | import androidx.compose.runtime.mutableStateOf 16 | import androidx.compose.runtime.remember 17 | import androidx.compose.runtime.setValue 18 | import kotlinx.coroutines.coroutineScope 19 | import kotlinx.coroutines.launch 20 | import kotlin.math.abs 21 | 22 | @Composable 23 | fun rememberSwipeableActionsState(): SwipeableActionsState { 24 | return remember { SwipeableActionsState() } 25 | } 26 | 27 | /** 28 | * The state of a [SwipeableActionsBox]. 29 | */ 30 | @Stable 31 | class SwipeableActionsState internal constructor() { 32 | /** 33 | * The current position (in pixels) of a [SwipeableActionsBox]. 34 | */ 35 | val offset: State get() = offsetState 36 | internal var offsetState = mutableStateOf(0f) 37 | 38 | /** 39 | * Whether [SwipeableActionsBox] is currently animating to reset its offset after it was swiped. 40 | */ 41 | val isResettingOnRelease: Boolean by derivedStateOf { 42 | swipedAction != null 43 | } 44 | private var isAnimating = false 45 | internal var layoutWidth: Int by mutableIntStateOf(0) 46 | internal var swipeThresholdPx: Float by mutableFloatStateOf(0f) 47 | 48 | internal var actions: ActionFinder by mutableStateOf( 49 | ActionFinder(left = emptyList(), right = emptyList()) 50 | ) 51 | 52 | internal var swipedAction: SwipeActionMeta? by mutableStateOf(null) 53 | 54 | internal val draggableState = DraggableState { delta -> 55 | val targetOffset = offsetState.value + delta 56 | 57 | val canSwipeTowardsRight = actions.left.isNotEmpty() 58 | val canSwipeTowardsLeft = actions.right.isNotEmpty() 59 | 60 | val isAllowed = isResettingOnRelease 61 | || targetOffset == 0f 62 | || (targetOffset > 0f && canSwipeTowardsRight) 63 | || (targetOffset < 0f && canSwipeTowardsLeft) 64 | 65 | val isReachLimit = hasCrossedSwipeLimit() 66 | offsetState.value += if ((isAllowed && !isReachLimit) || isAnimating) delta else delta / 10 67 | } 68 | 69 | internal fun hasCrossedSwipeLimit(): Boolean { 70 | return abs(offsetState.value) > (swipeThresholdPx * if (offsetState.value > 0f) actions.left.size else actions.right.size) 71 | } 72 | 73 | internal suspend fun handleOnDragStopped() = coroutineScope { 74 | launch { 75 | draggableState.drag(MutatePriority.PreventUserInput) { 76 | 77 | val limit = (swipeThresholdPx * if (offsetState.value > 0f) actions.left.size else actions.right.size) 78 | val isReachLimit = abs(offsetState.value) > (limit * 2) / 3 // 达到2/3既展开 or 处理过渡滑动 79 | val factor = if (offsetState.value > 0) 1 else -1 80 | isAnimating = true 81 | Animatable(offsetState.value).animateTo( 82 | targetValue = if (isReachLimit) limit * factor else 0f, 83 | animationSpec = tween( 84 | durationMillis = if (isReachLimit) animationLimitMs else animationDurationMs, 85 | easing = LinearEasing 86 | ), 87 | ) { 88 | dragBy(value - offsetState.value) 89 | } 90 | isAnimating = false 91 | } 92 | swipedAction = null 93 | } 94 | } 95 | 96 | internal suspend fun handleReset() = coroutineScope { 97 | launch { 98 | draggableState.drag(MutatePriority.PreventUserInput) { 99 | isAnimating = true 100 | Animatable(offsetState.value).animateTo( 101 | targetValue = 0f, 102 | animationSpec = tween( 103 | durationMillis = animationDurationMs, 104 | easing = LinearEasing 105 | ), 106 | ) { 107 | dragBy(value - offsetState.value) 108 | } 109 | isAnimating = false 110 | } 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /library/src/commonMain/kotlin/com/linversion/swipe/defaults.kt: -------------------------------------------------------------------------------- 1 | package com.linversion.swipe 2 | 3 | internal const val animationDurationMs = 4_00 4 | internal const val animationLimitMs = 2_00 5 | -------------------------------------------------------------------------------- /library/src/test/kotlin/me/saket/swipe/SwipeableActionsBoxTest.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("TestFunctionName") 2 | 3 | package me.saket.swipe 4 | 5 | import androidx.compose.foundation.background 6 | import androidx.compose.foundation.layout.Box 7 | import androidx.compose.foundation.layout.BoxWithConstraints 8 | import androidx.compose.foundation.layout.BoxWithConstraintsScope 9 | import androidx.compose.foundation.layout.Column 10 | import androidx.compose.foundation.layout.Row 11 | import androidx.compose.foundation.layout.fillMaxWidth 12 | import androidx.compose.foundation.layout.padding 13 | import androidx.compose.foundation.layout.size 14 | import androidx.compose.foundation.shape.CircleShape 15 | import androidx.compose.material.icons.Icons 16 | import androidx.compose.material.icons.twotone.ReplyAll 17 | import androidx.compose.material.icons.twotone.Snooze 18 | import androidx.compose.material3.MaterialTheme 19 | import androidx.compose.material3.Text 20 | import androidx.compose.runtime.Composable 21 | import androidx.compose.ui.Alignment 22 | import androidx.compose.ui.Modifier 23 | import androidx.compose.ui.draw.clip 24 | import androidx.compose.ui.draw.shadow 25 | import androidx.compose.ui.graphics.Color 26 | import androidx.compose.ui.graphics.isSpecified 27 | import androidx.compose.ui.graphics.vector.rememberVectorPainter 28 | import androidx.compose.ui.platform.LocalDensity 29 | import androidx.compose.ui.unit.Dp 30 | import androidx.compose.ui.unit.dp 31 | import app.cash.paparazzi.DeviceConfig 32 | import app.cash.paparazzi.Paparazzi 33 | import com.android.ide.common.rendering.api.SessionParams.RenderingMode 34 | import com.linversion.swipe.SwipeAction 35 | import com.linversion.swipe.SwipeableActionsBox 36 | import com.linversion.swipe.SwipeableActionsState 37 | import com.linversion.swipe.rememberSwipeableActionsState 38 | import org.junit.Rule 39 | import org.junit.Test 40 | 41 | class SwipeableActionsBoxTest { 42 | @get:Rule val paparazzi = Paparazzi( 43 | deviceConfig = DeviceConfig.PIXEL_5, 44 | showSystemUi = false, 45 | renderingMode = RenderingMode.SHRINK, 46 | ) 47 | 48 | @Test fun `empty actions`() { 49 | paparazzi.snapshot { 50 | Scaffold { 51 | SwipeableActionsBox { 52 | BatmanIpsumItem() 53 | } 54 | } 55 | } 56 | } 57 | 58 | @Test fun `non-empty actions`() { 59 | paparazzi.snapshot { 60 | Scaffold { 61 | SwipeableActionsBox( 62 | startActions = listOf(replyAll), 63 | endActions = listOf(snooze), 64 | content = { BatmanIpsumItem() }, 65 | ) 66 | } 67 | } 68 | } 69 | 70 | @Test fun `show a each action's background when offset is small`() { 71 | paparazzi.snapshot { 72 | Scaffold { 73 | SwipeableActionsBox( 74 | state = rememberSwipeActionsState(initialOffset = 30.dp), 75 | startActions = listOf(snooze, replyAll), 76 | swipeThreshold = 80.dp, 77 | content = { BatmanIpsumItem(background = Color.Unspecified) } 78 | ) 79 | } 80 | } 81 | } 82 | 83 | @Test fun `show a each action's background and part of icon when offset is greater than icon offset`() { 84 | paparazzi.snapshot { 85 | Scaffold { 86 | SwipeableActionsBox( 87 | state = rememberSwipeActionsState(initialOffset = 80.dp), 88 | startActions = listOf(snooze, replyAll), 89 | swipeThreshold = 80.dp, 90 | content = { BatmanIpsumItem(background = Color.Unspecified) } 91 | ) 92 | } 93 | } 94 | } 95 | 96 | @Test fun `should have extra background when offset is greater than threshold`() { 97 | paparazzi.snapshot { 98 | Scaffold { 99 | SwipeableActionsBox( 100 | state = rememberSwipeActionsState(initialOffset = 180.dp), 101 | startActions = listOf(snooze, replyAll), 102 | swipeThreshold = 80.dp, 103 | content = { BatmanIpsumItem(background = Color.Unspecified) } 104 | ) 105 | } 106 | } 107 | } 108 | 109 | @Composable 110 | private fun Scaffold(content: @Composable BoxWithConstraintsScope.() -> Unit) { 111 | BoxWithConstraints( 112 | modifier = Modifier 113 | .fillMaxWidth() 114 | .background(Color.Whisper), 115 | content = content, 116 | contentAlignment = Alignment.Center 117 | ) 118 | } 119 | 120 | @Composable 121 | private fun BatmanIpsumItem( 122 | modifier: Modifier = Modifier, 123 | background: Color = Color.White 124 | ) { 125 | Row( 126 | modifier 127 | .fillMaxWidth() 128 | .shadow(if (background.isSpecified) 1.dp else 0.dp) 129 | .background(background) 130 | .padding(20.dp) 131 | ) { 132 | Box( 133 | Modifier 134 | .padding(top = 4.dp) 135 | .size(52.dp) 136 | .clip(CircleShape) 137 | .background(Color(0xFF6B4FA9)) 138 | ) 139 | 140 | Column(Modifier.padding(horizontal = 16.dp)) { 141 | Text( 142 | text = "The Batman", 143 | style = MaterialTheme.typography.titleMedium 144 | ) 145 | Text( 146 | modifier = Modifier.padding(top = 2.dp), 147 | text = "Fear is a tool. When that light hits the sky, it’s not just a call. It’s a warning. For them.", 148 | style = MaterialTheme.typography.bodyMedium 149 | ) 150 | } 151 | } 152 | } 153 | 154 | @Composable 155 | fun rememberSwipeActionsState(initialOffset: Dp): SwipeableActionsState { 156 | return rememberSwipeableActionsState().also { 157 | it.offsetState.value = LocalDensity.current.run { initialOffset.toPx() } 158 | } 159 | } 160 | 161 | companion object { 162 | val snooze 163 | @Composable get() = SwipeAction( 164 | icon = rememberVectorPainter(Icons.TwoTone.Snooze), 165 | background = Color.SeaBuckthorn, 166 | onSwipe = {}, 167 | ) 168 | 169 | val replyAll 170 | @Composable get() = SwipeAction( 171 | icon = rememberVectorPainter(Icons.TwoTone.ReplyAll), 172 | background = Color.Perfume, 173 | onSwipe = {}, 174 | ) 175 | } 176 | } 177 | 178 | val Color.Companion.Whisper get() = Color(0XFFF8F5FA) 179 | val Color.Companion.SeaBuckthorn get() = Color(0xFFF9A825) 180 | val Color.Companion.Perfume get() = Color(0xFFD0BCFF) 181 | val Color.Companion.GraySuit get() = Color(0xFFC1BAC9) 182 | -------------------------------------------------------------------------------- /library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_empty actions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linversion/swipe-like-ios/c07532b828134fd7b0550850765c768a655a8f7e/library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_empty actions.png -------------------------------------------------------------------------------- /library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_non-empty actions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linversion/swipe-like-ios/c07532b828134fd7b0550850765c768a655a8f7e/library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_non-empty actions.png -------------------------------------------------------------------------------- /library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_should have extra background when offset is greater than threshold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linversion/swipe-like-ios/c07532b828134fd7b0550850765c768a655a8f7e/library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_should have extra background when offset is greater than threshold.png -------------------------------------------------------------------------------- /library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_show a each action's background and part of icon when offset is greater than icon offset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linversion/swipe-like-ios/c07532b828134fd7b0550850765c768a655a8f7e/library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_show a each action's background and part of icon when offset is greater than icon offset.png -------------------------------------------------------------------------------- /library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_show a each action's background when offset is small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linversion/swipe-like-ios/c07532b828134fd7b0550850765c768a655a8f7e/library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_show a each action's background when offset is small.png -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | alias(libs.plugins.android.application) 3 | alias(libs.plugins.kotlin.android) 4 | } 5 | 6 | android { 7 | namespace = "com.linversion.swipe.sample" 8 | 9 | defaultConfig { 10 | applicationId = namespace 11 | minSdk = libs.versions.minSdk.get().toInt() 12 | compileSdk = libs.versions.compileSdk.get().toInt() 13 | versionCode = 1 14 | versionName = "1.0" 15 | } 16 | buildFeatures { 17 | compose = true 18 | } 19 | composeOptions { 20 | kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get() 21 | } 22 | java { 23 | toolchain.languageVersion.set(JavaLanguageVersion.of(17)) 24 | } 25 | lint { 26 | abortOnError = true 27 | } 28 | } 29 | 30 | dependencies { 31 | implementation(projects.library) 32 | implementation(libs.androidx.appcompat) 33 | implementation(libs.androidx.activity) 34 | implementation(libs.compose.foundation) 35 | implementation(libs.compose.ui) 36 | implementation(libs.compose.material3) 37 | implementation(libs.compose.materialIcons) 38 | implementation(libs.accompanist.systemUi) 39 | } 40 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/linversion/swipe/sample/SampleActivity.kt: -------------------------------------------------------------------------------- 1 | package com.linversion.swipe.sample 2 | 3 | import android.os.Build 4 | import android.os.Bundle 5 | import androidx.activity.compose.setContent 6 | import androidx.appcompat.app.AppCompatActivity 7 | import androidx.compose.foundation.background 8 | import androidx.compose.foundation.isSystemInDarkTheme 9 | import androidx.compose.foundation.layout.Box 10 | import androidx.compose.foundation.layout.Column 11 | import androidx.compose.foundation.layout.Row 12 | import androidx.compose.foundation.layout.fillMaxWidth 13 | import androidx.compose.foundation.layout.padding 14 | import androidx.compose.foundation.layout.size 15 | import androidx.compose.foundation.shape.CircleShape 16 | import androidx.compose.foundation.shape.RoundedCornerShape 17 | import androidx.compose.material.icons.Icons 18 | import androidx.compose.material.icons.rounded.Delete 19 | import androidx.compose.material.icons.twotone.Archive 20 | import androidx.compose.material.icons.twotone.ReplyAll 21 | import androidx.compose.material.icons.twotone.Snooze 22 | import androidx.compose.material3.ExperimentalMaterial3Api 23 | import androidx.compose.material3.MaterialTheme 24 | import androidx.compose.material3.Scaffold 25 | import androidx.compose.material3.Text 26 | import androidx.compose.material3.TopAppBar 27 | import androidx.compose.material3.dynamicDarkColorScheme 28 | import androidx.compose.material3.dynamicLightColorScheme 29 | import androidx.compose.material3.surfaceColorAtElevation 30 | import androidx.compose.runtime.Composable 31 | import androidx.compose.runtime.LaunchedEffect 32 | import androidx.compose.runtime.getValue 33 | import androidx.compose.runtime.mutableStateOf 34 | import androidx.compose.runtime.saveable.rememberSaveable 35 | import androidx.compose.runtime.setValue 36 | import androidx.compose.ui.Modifier 37 | import androidx.compose.ui.draw.shadow 38 | import androidx.compose.ui.graphics.Color 39 | import androidx.compose.ui.graphics.vector.rememberVectorPainter 40 | import androidx.compose.ui.res.stringResource 41 | import androidx.compose.ui.unit.dp 42 | import androidx.core.view.WindowCompat 43 | import com.google.accompanist.systemuicontroller.rememberSystemUiController 44 | import com.linversion.swipe.SwipeAction 45 | import com.linversion.swipe.SwipeableActionsBox 46 | import com.linversion.swipe.sample.theme.DarkTheme 47 | import com.linversion.swipe.sample.theme.LightTheme 48 | 49 | @OptIn(ExperimentalMaterial3Api::class) 50 | class SampleActivity : AppCompatActivity() { 51 | override fun onCreate(savedInstanceState: Bundle?) { 52 | super.onCreate(savedInstanceState) 53 | 54 | setContent { 55 | val uiController = rememberSystemUiController() 56 | val systemInDarkTheme = isSystemInDarkTheme() 57 | LaunchedEffect(Unit) { 58 | WindowCompat.setDecorFitsSystemWindows(window, false) 59 | uiController.setSystemBarsColor(Color.Transparent, darkIcons = !systemInDarkTheme) 60 | uiController.setNavigationBarColor(Color.Transparent) 61 | } 62 | 63 | val colors = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { 64 | if (systemInDarkTheme) dynamicDarkColorScheme(this) else dynamicLightColorScheme(this) 65 | } else { 66 | if (systemInDarkTheme) DarkTheme else LightTheme 67 | } 68 | 69 | MaterialTheme(colors) { 70 | Scaffold( 71 | topBar = { 72 | TopAppBar(title = { Text(stringResource(R.string.app_name)) }) 73 | } 74 | ) { contentPadding -> 75 | SwipeableBoxPreview( 76 | Modifier.padding(contentPadding) 77 | ) 78 | } 79 | } 80 | } 81 | } 82 | } 83 | 84 | @Composable 85 | private fun SwipeableBoxPreview(modifier: Modifier = Modifier) { 86 | var isSnoozed by rememberSaveable { mutableStateOf(false) } 87 | var isArchived by rememberSaveable { mutableStateOf(false) } 88 | 89 | val replyAll = SwipeAction( 90 | icon = rememberVectorPainter(Icons.TwoTone.ReplyAll), 91 | background = Color.Perfume, 92 | onClick = { println("Reply swiped") } 93 | ) 94 | val delete = SwipeAction( 95 | icon = rememberVectorPainter(Icons.Rounded.Delete), 96 | background = Color.Red, 97 | onClick = {println("Delete swiped") } 98 | ) 99 | val snooze = SwipeAction( 100 | icon = rememberVectorPainter(Icons.TwoTone.Snooze), 101 | background = Color.SeaBuckthorn, 102 | onClick = { isSnoozed = !isSnoozed } 103 | ) 104 | val archive = SwipeAction( 105 | icon = rememberVectorPainter(Icons.TwoTone.Archive), 106 | background = Color.Fern, 107 | onClick = { isArchived = !isArchived } 108 | ) 109 | 110 | SwipeableActionsBox( 111 | modifier = modifier, 112 | startActions = listOf(delete, replyAll), 113 | endActions = listOf(snooze, archive), 114 | swipeThreshold = 80.dp, 115 | ) { 116 | BatmanIpsumItem( 117 | isSnoozed = isSnoozed 118 | ) 119 | } 120 | } 121 | 122 | @Composable 123 | private fun BatmanIpsumItem( 124 | modifier: Modifier = Modifier, 125 | isSnoozed: Boolean 126 | ) { 127 | Row( 128 | modifier 129 | .fillMaxWidth() 130 | .shadow(1.dp) 131 | .background(MaterialTheme.colorScheme.surfaceColorAtElevation(8.dp)) 132 | .padding(vertical = 16.dp, horizontal = 20.dp) 133 | ) { 134 | Box( 135 | Modifier 136 | .padding(top = 2.dp) 137 | .size(52.dp) 138 | .background(MaterialTheme.colorScheme.primary, CircleShape) 139 | ) 140 | 141 | Column(Modifier.padding(horizontal = 16.dp)) { 142 | Text( 143 | text = "The Batman", 144 | style = MaterialTheme.typography.titleMedium 145 | ) 146 | Text( 147 | modifier = Modifier.padding(top = 4.dp), 148 | text = "Fear is a tool. When that light hits the sky, it’s not just a call. It’s a warning. For them.", 149 | style = MaterialTheme.typography.bodyMedium 150 | ) 151 | 152 | if (isSnoozed) { 153 | Text( 154 | modifier = Modifier 155 | .padding(top = 16.dp) 156 | .background(Color.SeaBuckthorn.copy(alpha = 0.4f), RoundedCornerShape(4.dp)) 157 | .padding(horizontal = 8.dp, vertical = 4.dp), 158 | text = "Snoozed until tomorrow", 159 | style = MaterialTheme.typography.labelLarge 160 | ) 161 | } 162 | } 163 | } 164 | } 165 | 166 | val Color.Companion.SeaBuckthorn get() = Color(0xFFF9A825) 167 | val Color.Companion.Fern get() = Color(0xFF66BB6A) 168 | val Color.Companion.Perfume get() = Color(0xFFD0BCFF) 169 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/linversion/swipe/sample/theme/Theme.kt: -------------------------------------------------------------------------------- 1 | package com.linversion.swipe.sample.theme 2 | 3 | import androidx.compose.material3.darkColorScheme 4 | import androidx.compose.material3.lightColorScheme 5 | import androidx.compose.ui.graphics.Color 6 | 7 | val LightTheme = lightColorScheme( 8 | primary = Color(0xFF007AFF), 9 | background = Color(0xFFCACACF), 10 | surface = Color(0xFFCACACF) 11 | ) 12 | 13 | val DarkTheme = darkColorScheme( 14 | primary = Color(0xFF64A0E5), 15 | background = Color(0xFF121212), 16 | surface = Color(0xFF121212) 17 | ) 18 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 9 | 10 | 16 | 19 | 22 | 23 | 24 | 25 | 31 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Swipe 3 | 4 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | #356859 3 | #356859 4 | #B5D2C3 5 | 6 | 13 | 14 | -------------------------------------------------------------------------------- /screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linversion/swipe-like-ios/c07532b828134fd7b0550850765c768a655a8f7e/screenshot.gif -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | maven { 4 | url 'https://maven.aliyun.com/repository/google' 5 | } 6 | maven { 7 | url 'https://maven.aliyun.com/repository/public' 8 | } 9 | google() 10 | mavenCentral() 11 | gradlePluginPortal() 12 | } 13 | } 14 | 15 | dependencyResolutionManagement { 16 | repositories { 17 | maven { 18 | url 'https://maven.aliyun.com/repository/google' 19 | } 20 | maven { 21 | url 'https://maven.aliyun.com/repository/public' 22 | } 23 | google() 24 | mavenCentral() 25 | } 26 | } 27 | 28 | include ':library' 29 | include ':sample' 30 | 31 | rootProject.name = "swipe" 32 | enableFeaturePreview('TYPESAFE_PROJECT_ACCESSORS') 33 | --------------------------------------------------------------------------------