├── .gitignore ├── LICENSE ├── README.md ├── app ├── build.gradle.kts ├── proguard-rules.pro └── src │ ├── androidTest │ └── kotlin │ │ └── tddy │ │ └── ko │ │ └── cardstack │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── kotlin │ │ └── tddy │ │ │ └── ko │ │ │ └── cardstack │ │ │ └── Application.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 │ │ └── strings.xml │ │ └── xml │ │ ├── backup_rules.xml │ │ └── data_extraction_rules.xml │ └── test │ └── kotlin │ └── tddy │ └── ko │ └── cardstack │ └── ExampleUnitTest.kt ├── build-logic ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ └── tddy │ └── ko │ └── cardstack │ └── build_logic │ ├── AndroidApplicationPlugin.kt │ ├── AndroidLibraryPlugin.kt │ ├── ComposeApplicationPlugin.kt │ ├── ComposeLibraryPlugin.kt │ └── extension │ ├── AndroidExtension.kt │ ├── ComposeExtension.kt │ └── Extension.kt ├── build.gradle.kts ├── demo ├── design-system │ ├── build.gradle.kts │ ├── consumer-rules.pro │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── kotlin │ │ │ └── tddy │ │ │ └── ko │ │ │ └── cardstack │ │ │ └── desigh_system │ │ │ └── ExampleInstrumentedTest.kt │ │ ├── main │ │ ├── kotlin │ │ │ └── tddy │ │ │ │ └── ko │ │ │ │ └── cardstack │ │ │ │ └── desigh_system │ │ │ │ └── theme │ │ │ │ ├── Color.kt │ │ │ │ ├── Theme.kt │ │ │ │ └── Type.kt │ │ └── res │ │ │ └── values │ │ │ ├── colors.xml │ │ │ └── themes.xml │ │ └── test │ │ └── kotlin │ │ └── tddy │ │ └── ko │ │ └── cardstack │ │ └── desigh_system │ │ └── ExampleUnitTest.kt └── feature │ ├── build.gradle.kts │ ├── consumer-rules.pro │ ├── proguard-rules.pro │ └── src │ ├── androidTest │ └── kotlin │ │ └── tddy │ │ └── ko │ │ └── cardstack │ │ └── feature │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ ├── img_01.jpg │ │ ├── img_02.jpg │ │ ├── img_03.jpg │ │ ├── img_04.jpg │ │ ├── img_05.jpg │ │ └── img_06.jpg │ └── kotlin │ │ └── tddy │ │ └── ko │ │ └── cardstack │ │ └── feature │ │ ├── Image.kt │ │ └── MainActivity.kt │ └── test │ └── kotlin │ └── tddy │ └── ko │ └── cardstack │ └── feature │ └── ExampleUnitTest.kt ├── gradle.properties ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library └── ui │ ├── build.gradle.kts │ ├── consumer-rules.pro │ ├── proguard-rules.pro │ └── src │ ├── androidTest │ └── kotlin │ │ └── tddy │ │ └── ko │ │ └── cardstack │ │ └── ui │ │ └── ExampleInstrumentedTest.kt │ ├── main │ └── kotlin │ │ └── tddy │ │ └── ko │ │ └── cardstack │ │ └── ui │ │ ├── CardStack.kt │ │ └── CardStackHelper.kt │ └── test │ └── kotlin │ └── tddy │ └── ko │ └── cardstack │ └── ui │ └── ExampleUnitTest.kt └── settings.gradle.kts /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/android,kotlin,androidstudio 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=android,kotlin,androidstudio 3 | 4 | ### Android ### 5 | # Gradle files 6 | .gradle/ 7 | build/ 8 | 9 | # Local configuration file (sdk path, etc) 10 | local.properties 11 | 12 | # Log/OS Files 13 | *.log 14 | 15 | # Android Studio generated files and folders 16 | captures/ 17 | .externalNativeBuild/ 18 | .cxx/ 19 | *.apk 20 | output.json 21 | 22 | # IntelliJ 23 | *.iml 24 | .idea/ 25 | misc.xml 26 | deploymentTargetDropDown.xml 27 | render.experimental.xml 28 | 29 | # Keystore files 30 | *.jks 31 | *.keystore 32 | 33 | # Google Services (e.g. APIs or Firebase) 34 | google-services.json 35 | 36 | # Android Profiling 37 | *.hprof 38 | 39 | ### Android Patch ### 40 | gen-external-apklibs 41 | 42 | # Replacement of .externalNativeBuild directories introduced 43 | # with Android Studio 3.5. 44 | 45 | ### Kotlin ### 46 | # Compiled class file 47 | *.class 48 | 49 | # Log file 50 | 51 | # BlueJ files 52 | *.ctxt 53 | 54 | # Mobile Tools for Java (J2ME) 55 | .mtj.tmp/ 56 | 57 | # Package Files # 58 | *.jar 59 | *.war 60 | *.nar 61 | *.ear 62 | *.zip 63 | *.tar.gz 64 | *.rar 65 | 66 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 67 | hs_err_pid* 68 | replay_pid* 69 | 70 | ### AndroidStudio ### 71 | # Covers files to be ignored for android development using Android Studio. 72 | 73 | # Built application files 74 | *.ap_ 75 | *.aab 76 | 77 | # Files for the ART/Dalvik VM 78 | *.dex 79 | 80 | # Java class files 81 | 82 | # Generated files 83 | bin/ 84 | gen/ 85 | out/ 86 | 87 | # Gradle files 88 | .gradle 89 | 90 | # Signing files 91 | .signing/ 92 | 93 | # Local configuration file (sdk path, etc) 94 | 95 | # Proguard folder generated by Eclipse 96 | proguard/ 97 | 98 | # Log Files 99 | 100 | # Android Studio 101 | /*/build/ 102 | /*/local.properties 103 | /*/out 104 | /*/*/build 105 | /*/*/production 106 | .navigation/ 107 | *.ipr 108 | *~ 109 | *.swp 110 | 111 | # Keystore files 112 | 113 | # Google Services (e.g. APIs or Firebase) 114 | # google-services.json 115 | 116 | # Android Patch 117 | 118 | # External native build folder generated in Android Studio 2.2 and later 119 | .externalNativeBuild 120 | 121 | # NDK 122 | obj/ 123 | 124 | # IntelliJ IDEA 125 | *.iws 126 | /out/ 127 | 128 | # User-specific configurations 129 | .idea/caches/ 130 | .idea/libraries/ 131 | .idea/shelf/ 132 | .idea/workspace.xml 133 | .idea/tasks.xml 134 | .idea/.name 135 | .idea/compiler.xml 136 | .idea/copyright/profiles_settings.xml 137 | .idea/encodings.xml 138 | .idea/misc.xml 139 | .idea/modules.xml 140 | .idea/scopes/scope_settings.xml 141 | .idea/dictionaries 142 | .idea/vcs.xml 143 | .idea/jsLibraryMappings.xml 144 | .idea/datasources.xml 145 | .idea/dataSources.ids 146 | .idea/sqlDataSources.xml 147 | .idea/dynamic.xml 148 | .idea/uiDesigner.xml 149 | .idea/assetWizardSettings.xml 150 | .idea/gradle.xml 151 | .idea/jarRepositories.xml 152 | .idea/navEditor.xml 153 | 154 | # Legacy Eclipse project files 155 | .classpath 156 | .project 157 | .cproject 158 | .settings/ 159 | 160 | # Mobile Tools for Java (J2ME) 161 | 162 | # Package Files # 163 | 164 | # virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml) 165 | 166 | ## Plugin-specific files: 167 | 168 | # mpeltonen/sbt-idea plugin 169 | .idea_modules/ 170 | 171 | # JIRA plugin 172 | atlassian-ide-plugin.xml 173 | 174 | # Mongo Explorer plugin 175 | .idea/mongoSettings.xml 176 | 177 | # Crashlytics plugin (for Android Studio and IntelliJ) 178 | com_crashlytics_export_strings.xml 179 | crashlytics.properties 180 | crashlytics-build.properties 181 | fabric.properties 182 | 183 | ### AndroidStudio Patch ### 184 | 185 | !/gradle/wrapper/gradle-wrapper.jar 186 | 187 | # End of https://www.toptal.com/developers/gitignore/api/android,kotlin,androidstudio 188 | gradle.properties 189 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Draggable Card Stack

2 | 3 |

4 | MavenCentral 5 | API 6 | License 7 |

8 |

9 | A Jetpack Compose library for customizable draggable card stacks with smooth animations. 10 |

11 | 12 |

13 | 14 |

15 | 16 | ## Features 17 | 18 | - 🎯 Smooth spring-based animations 19 | - 🔄 Vertical and horizontal swiping 20 | - 📱 Responsive design 21 | - 🎨 Customizable card alignment & spacing 22 | - 💫 Dynamic elevation & scale animations 23 | - ⚡ Velocity-based swipe detection 24 | - 🔄 Automatic card reordering 25 | 26 | ## Installation 27 | ```kotlin 28 | dependencies { 29 | implementation("io.github.teddko:cardstack:1.0.1") 30 | } 31 | ``` 32 | 33 | ## Basic Usage 34 | ```kotlin 35 | @Composable 36 | fun CardStackDemo() { 37 | val items = remember { listOf("Card 1", "Card 2", "Card 3") } 38 | 39 | DraggableCardStack( 40 | initialItems = items, 41 | height = 200.dp, 42 | cardSpacingRatio = 0.1f, 43 | cardAlignment = CardAlignment.BOTTOM, 44 | dragAlignment = DragAlignment.HORIZONTAL 45 | ) { item -> 46 | Card( 47 | modifier = Modifier 48 | .fillMaxSize() 49 | .padding(16.dp) 50 | ) { 51 | Text( 52 | text = item, 53 | modifier = Modifier.padding(16.dp) 54 | ) 55 | } 56 | } 57 | } 58 | ``` 59 | 60 | ## Advanced Usage 61 | ```kotlin 62 | data class CardItem( 63 | val title: String, 64 | val description: String, 65 | val imageUrl: String 66 | ) 67 | 68 | @Composable 69 | fun AdvancedCardStack() { 70 | val items = remember { 71 | listOf( 72 | CardItem("Title 1", "Description 1", "url1"), 73 | CardItem("Title 2", "Description 2", "url2"), 74 | CardItem("Title 3", "Description 3", "url3") 75 | ) 76 | } 77 | 78 | DraggableCardStack( 79 | initialItems = items, 80 | height = 200.dp, 81 | cardSpacingRatio = 0.1f, 82 | cardAlignment = CardAlignment.BOTTOM, 83 | dragAlignment = DragAlignment.HORIZONTAL 84 | ) { item -> 85 | Card(modifier = Modifier.fillMaxSize()) { 86 | Row( 87 | modifier = Modifier 88 | .fillMaxSize() 89 | .padding(16.dp), 90 | horizontalArrangement = Arrangement.spacedBy(16.dp), 91 | verticalAlignment = Alignment.CenterVertically 92 | ) { 93 | AsyncImage( 94 | modifier = Modifier 95 | .size(100.dp) 96 | .clip(CircleShape), 97 | model = item.imageUrl, 98 | contentDescription = item.description, 99 | contentScale = ContentScale.Crop, 100 | ) 101 | Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { 102 | Text(text = item.title) 103 | Text(text = item.description) 104 | } 105 | } 106 | } 107 | } 108 | } 109 | ``` 110 | 111 | ## Customization 112 | ### Card Alignment 113 | ```kotlin 114 | CardAlignment.BOTTOM // Bottom center 115 | CardAlignment.BOTTOM_START // Bottom left 116 | CardAlignment.BOTTOM_END // Bottom right 117 | CardAlignment.TOP // Top center 118 | CardAlignment.TOP_START // Top left 119 | CardAlignment.TOP_END // Top right 120 | CardAlignment.START // Center left 121 | CardAlignment.END // Center right 122 | ``` 123 | 124 | ### Drag Alignment 125 | ```kotlin 126 | DragAlignment.VERTICAL // Vertical only 127 | DragAlignment.HORIZONTAL // Horizontal only 128 | DragAlignment.NONE // All directions 129 | ``` 130 | -------------------------------------------------------------------------------- /app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | alias(libs.plugins.tddy.ko.android.application) 3 | alias(libs.plugins.tddy.ko.compose.application) 4 | } 5 | 6 | android { 7 | namespace = "tddy.ko.cardstack" 8 | 9 | defaultConfig { 10 | applicationId = "tddy.ko.cardstack" 11 | versionCode = 1 12 | versionName = "1.0" 13 | 14 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 15 | } 16 | 17 | buildTypes { 18 | release { 19 | isMinifyEnabled = false 20 | proguardFiles( 21 | getDefaultProguardFile("proguard-android-optimize.txt"), 22 | "proguard-rules.pro" 23 | ) 24 | } 25 | } 26 | } 27 | 28 | dependencies { 29 | implementation(projects.library.ui) 30 | implementation(projects.demo.designSystem) 31 | implementation(projects.demo.feature) 32 | } -------------------------------------------------------------------------------- /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/androidTest/kotlin/tddy/ko/cardstack/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("tddy.ko.cardstack", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/kotlin/tddy/ko/cardstack/Application.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack 2 | 3 | import android.app.Application 4 | 5 | class Application : Application() -------------------------------------------------------------------------------- /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 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CardStack 3 | -------------------------------------------------------------------------------- /app/src/main/res/xml/backup_rules.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/xml/data_extraction_rules.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 12 | 13 | 19 | -------------------------------------------------------------------------------- /app/src/test/kotlin/tddy/ko/cardstack/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /build-logic/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | `kotlin-dsl-precompiled-script-plugins` 4 | } 5 | 6 | dependencies { 7 | implementation(libs.android.gradlePlugin) 8 | implementation(libs.kotlin.gradlePlugin) 9 | implementation(libs.ksp.gradlePlugin) 10 | compileOnly(libs.compose.gradlePlugin) 11 | } 12 | 13 | gradlePlugin { 14 | plugins { 15 | register("AndroidApplication") { 16 | id = "tddy.ko.cardstack.application" 17 | implementationClass = "AndroidApplicationPlugin" 18 | } 19 | 20 | register("AndroidLibrary") { 21 | id = "tddy.ko.cardstack.library" 22 | implementationClass = "AndroidLibraryPlugin" 23 | } 24 | 25 | register("ComposeApplication") { 26 | id = "tddy.ko.cardstack.compose.application" 27 | implementationClass = "ComposeApplicationPlugin" 28 | } 29 | 30 | register("ComposeLibrary") { 31 | id = "tddy.ko.cardstack.compose.library" 32 | implementationClass = "ComposeLibraryPlugin" 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /build-logic/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") 2 | @Suppress("UnstableApiUsage") 3 | dependencyResolutionManagement { 4 | repositories { 5 | google() 6 | mavenCentral() 7 | } 8 | versionCatalogs { 9 | create("libs") { 10 | from(files("../gradle/libs.versions.toml")) 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /build-logic/src/main/kotlin/tddy/ko/cardstack/build_logic/AndroidApplicationPlugin.kt: -------------------------------------------------------------------------------- 1 | import org.gradle.api.Plugin 2 | import org.gradle.api.Project 3 | import tddy.ko.cardstack.build_logic.extension.applicationExtension 4 | import tddy.ko.cardstack.build_logic.extension.configureAndroidExtension 5 | import tddy.ko.cardstack.build_logic.extension.libs 6 | import tddy.ko.cardstack.build_logic.extension.plugin 7 | 8 | class AndroidApplicationPlugin : Plugin { 9 | override fun apply(target: Project) { 10 | with(target) { 11 | pluginManager.apply { 12 | apply(libs.plugin("android-application").pluginId) 13 | apply(libs.plugin("kotlin-android").pluginId) 14 | } 15 | applicationExtension.apply { 16 | configureAndroidExtension(this) 17 | defaultConfig.targetSdk = 35 18 | } 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /build-logic/src/main/kotlin/tddy/ko/cardstack/build_logic/AndroidLibraryPlugin.kt: -------------------------------------------------------------------------------- 1 | import org.gradle.api.Plugin 2 | import org.gradle.api.Project 3 | import org.gradle.kotlin.dsl.dependencies 4 | import tddy.ko.cardstack.build_logic.extension.configureAndroidExtension 5 | import tddy.ko.cardstack.build_logic.extension.library 6 | import tddy.ko.cardstack.build_logic.extension.libraryExtension 7 | import tddy.ko.cardstack.build_logic.extension.libs 8 | import tddy.ko.cardstack.build_logic.extension.plugin 9 | 10 | class AndroidLibraryPlugin : Plugin { 11 | override fun apply(target: Project) { 12 | with(target) { 13 | pluginManager.apply { 14 | apply(libs.plugin("android-library").pluginId) 15 | apply(libs.plugin("kotlin-android").pluginId) 16 | } 17 | 18 | dependencies { 19 | add("implementation", libs.library("androidx-core-ktx")) 20 | add("implementation", libs.library("androidx-appcompat")) 21 | } 22 | 23 | @Suppress("UnstableApiUsage") 24 | libraryExtension.apply { 25 | configureAndroidExtension(this) 26 | testOptions.targetSdk = 35 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /build-logic/src/main/kotlin/tddy/ko/cardstack/build_logic/ComposeApplicationPlugin.kt: -------------------------------------------------------------------------------- 1 | import org.gradle.api.Plugin 2 | import org.gradle.api.Project 3 | import tddy.ko.cardstack.build_logic.extension.applicationExtension 4 | import tddy.ko.cardstack.build_logic.extension.configureComposeExtension 5 | import tddy.ko.cardstack.build_logic.extension.libs 6 | import tddy.ko.cardstack.build_logic.extension.plugin 7 | 8 | class ComposeApplicationPlugin : Plugin { 9 | override fun apply(target: Project) { 10 | with(target) { 11 | pluginManager.apply { 12 | apply(libs.plugin("android-application").pluginId) 13 | apply(libs.plugin("compose-compiler").pluginId) 14 | } 15 | configureComposeExtension(commonExtension = applicationExtension) 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /build-logic/src/main/kotlin/tddy/ko/cardstack/build_logic/ComposeLibraryPlugin.kt: -------------------------------------------------------------------------------- 1 | import org.gradle.api.Plugin 2 | import org.gradle.api.Project 3 | import org.gradle.kotlin.dsl.dependencies 4 | import tddy.ko.cardstack.build_logic.extension.configureComposeExtension 5 | import tddy.ko.cardstack.build_logic.extension.library 6 | import tddy.ko.cardstack.build_logic.extension.libraryExtension 7 | import tddy.ko.cardstack.build_logic.extension.libs 8 | import tddy.ko.cardstack.build_logic.extension.plugin 9 | 10 | class ComposeLibraryPlugin : Plugin { 11 | override fun apply(target: Project) { 12 | with(target) { 13 | pluginManager.apply { 14 | apply(libs.plugin("android-library").pluginId) 15 | apply(libs.plugin("compose-compiler").pluginId) 16 | } 17 | 18 | configureComposeExtension(commonExtension = libraryExtension) 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /build-logic/src/main/kotlin/tddy/ko/cardstack/build_logic/extension/AndroidExtension.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack.build_logic.extension 2 | 3 | import com.android.build.api.dsl.CommonExtension 4 | import org.gradle.api.JavaVersion 5 | import org.gradle.api.Project 6 | import org.gradle.kotlin.dsl.dependencies 7 | import org.gradle.kotlin.dsl.provideDelegate 8 | import org.gradle.kotlin.dsl.withType 9 | import org.jetbrains.kotlin.gradle.dsl.JvmTarget 10 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile 11 | 12 | internal fun Project.configureAndroidExtension(commonExtension: CommonExtension<*, *, *, *, *, *>) { 13 | commonExtension.apply { 14 | compileSdk = 35 15 | defaultConfig { minSdk = 23 } 16 | 17 | dependencies { 18 | add("coreLibraryDesugaring", libs.library("android-desugarJdkLibs")) 19 | } 20 | 21 | compileOptions { 22 | sourceCompatibility = JavaVersion.VERSION_17 23 | targetCompatibility = JavaVersion.VERSION_17 24 | isCoreLibraryDesugaringEnabled = true 25 | } 26 | 27 | tasks.withType().configureEach { 28 | compilerOptions { 29 | jvmTarget.set(JvmTarget.JVM_17) 30 | val warningsAsErrors: String? by project 31 | allWarningsAsErrors.set(warningsAsErrors.toBoolean()) 32 | freeCompilerArgs.addAll( 33 | "-opt-in=kotlin.RequiresOptIn", 34 | "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", 35 | "-opt-in=kotlinx.coroutines.FlowPreview", 36 | ) 37 | } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /build-logic/src/main/kotlin/tddy/ko/cardstack/build_logic/extension/ComposeExtension.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack.build_logic.extension 2 | 3 | import com.android.build.api.dsl.CommonExtension 4 | import org.gradle.api.Project 5 | import org.gradle.kotlin.dsl.dependencies 6 | import org.gradle.kotlin.dsl.getByType 7 | import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension 8 | 9 | internal fun Project.configureComposeExtension(commonExtension: CommonExtension<*, *, *, *, *, *>) { 10 | commonExtension.apply { 11 | buildFeatures.compose = true 12 | dependencies { 13 | add("implementation", libs.library("androidx-compose-ui-graphics")) 14 | add("implementation", libs.library("androidx-compose-ui-tooling-preview")) 15 | add("implementation", libs.library("androidx-compose-material3")) 16 | add("implementation", libs.library("androidx-compose-activity")) 17 | add("debugImplementation", libs.library("androidx-compose-ui-tooling")) 18 | } 19 | extensions.getByType().apply { 20 | enableStrongSkippingMode.set(true) 21 | includeSourceInformation.set(true) 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /build-logic/src/main/kotlin/tddy/ko/cardstack/build_logic/extension/Extension.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack.build_logic.extension 2 | 3 | import com.android.build.api.dsl.ApplicationExtension 4 | import com.android.build.api.dsl.LibraryExtension 5 | import org.gradle.api.Project 6 | import org.gradle.api.artifacts.MinimalExternalModuleDependency 7 | import org.gradle.api.artifacts.VersionCatalog 8 | import org.gradle.api.artifacts.VersionCatalogsExtension 9 | import org.gradle.api.plugins.ExtensionContainer 10 | import org.gradle.kotlin.dsl.getByType 11 | import org.gradle.plugin.use.PluginDependency 12 | 13 | internal val Project.applicationExtension get() = extensions.getByType() 14 | 15 | internal val Project.libraryExtension get() = extensions.getByType() 16 | 17 | private val ExtensionContainer.libs: VersionCatalog 18 | get() = getByType().named("libs") 19 | 20 | internal val Project.libs get() = extensions.libs 21 | 22 | internal fun VersionCatalog.library(name: String): MinimalExternalModuleDependency { 23 | return findLibrary(name).get().get() 24 | } 25 | 26 | internal fun VersionCatalog.plugin(name: String): PluginDependency { 27 | return findPlugin(name).get().get() 28 | } -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile 2 | 3 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 4 | plugins { 5 | alias(libs.plugins.android.application) apply false 6 | alias(libs.plugins.android.library) apply false 7 | alias(libs.plugins.kotlin.android) apply false 8 | alias(libs.plugins.kotlin.jvm) apply false 9 | alias(libs.plugins.kotlin.ksp) apply false 10 | alias(libs.plugins.compose.compiler) apply false 11 | } 12 | 13 | tasks { 14 | register("clean", Delete::class) { 15 | delete(rootProject.layout.buildDirectory) 16 | } 17 | withType(KotlinCompile::class) { 18 | compilerOptions.allWarningsAsErrors = true 19 | } 20 | } -------------------------------------------------------------------------------- /demo/design-system/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | alias(libs.plugins.tddy.ko.android.library) 3 | alias(libs.plugins.tddy.ko.compose.library) 4 | } 5 | 6 | android { 7 | namespace = "tddy.ko.cardstack.desigh_system" 8 | } -------------------------------------------------------------------------------- /demo/design-system/consumer-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/demo/design-system/consumer-rules.pro -------------------------------------------------------------------------------- /demo/design-system/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 -------------------------------------------------------------------------------- /demo/design-system/src/androidTest/kotlin/tddy/ko/cardstack/desigh_system/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack.desigh_system 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("tddy.ko.cardstack.desigh_system.test", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /demo/design-system/src/main/kotlin/tddy/ko/cardstack/desigh_system/theme/Color.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack.desigh_system.theme 2 | 3 | import androidx.compose.material3.lightColorScheme 4 | import androidx.compose.ui.graphics.Color 5 | 6 | internal val purple200 = Color(0xFFBB86FC) 7 | internal val purple500 = Color(0xFF6200EE) 8 | internal val purple700 = Color(0xFF3700B3) 9 | internal val teal200 = Color(0xFF03DAC5) 10 | internal val teal700 = Color(0xFF018786) 11 | 12 | internal val LightColorScheme = lightColorScheme( 13 | primary = purple200, 14 | secondary = purple500, 15 | tertiary = purple700, 16 | surface = Color.White 17 | ) -------------------------------------------------------------------------------- /demo/design-system/src/main/kotlin/tddy/ko/cardstack/desigh_system/theme/Theme.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack.desigh_system.theme 2 | 3 | import android.app.Activity 4 | import androidx.compose.foundation.isSystemInDarkTheme 5 | import androidx.compose.material3.MaterialTheme 6 | import androidx.compose.material3.Surface 7 | import androidx.compose.runtime.Composable 8 | import androidx.compose.ui.platform.LocalView 9 | import androidx.core.view.WindowCompat 10 | 11 | @Composable 12 | fun CardStackTheme( 13 | darkTheme: Boolean = isSystemInDarkTheme(), 14 | content: @Composable () -> Unit 15 | ) { 16 | 17 | val view = LocalView.current 18 | val window = (view.context as Activity).window 19 | 20 | WindowCompat 21 | .getInsetsController(window, view) 22 | .apply { 23 | isAppearanceLightStatusBars = true 24 | isAppearanceLightNavigationBars = true 25 | } 26 | 27 | MaterialTheme( 28 | colorScheme = LightColorScheme, 29 | typography = Typography 30 | ) { 31 | Surface(content = content) 32 | } 33 | } -------------------------------------------------------------------------------- /demo/design-system/src/main/kotlin/tddy/ko/cardstack/desigh_system/theme/Type.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack.desigh_system.theme 2 | 3 | import androidx.compose.material3.Typography 4 | import androidx.compose.ui.text.TextStyle 5 | import androidx.compose.ui.text.font.FontWeight 6 | import androidx.compose.ui.unit.sp 7 | 8 | val Typography = Typography( 9 | titleLarge = TextStyle( 10 | fontWeight = FontWeight.Medium, 11 | fontSize = 26.sp, 12 | lineHeight = 26.sp 13 | ), 14 | titleMedium = TextStyle( 15 | fontWeight = FontWeight.Medium, 16 | fontSize = 20.sp, 17 | lineHeight = 26.sp 18 | ), 19 | titleSmall = TextStyle( 20 | fontWeight = FontWeight.Bold, 21 | fontSize = 14.sp, 22 | lineHeight = 26.sp 23 | ), 24 | bodyLarge = TextStyle( 25 | fontWeight = FontWeight.Bold, 26 | fontSize = 18.sp, 27 | lineHeight = 28.8.sp 28 | ), 29 | bodyMedium = TextStyle( 30 | fontWeight = FontWeight.Medium, 31 | fontSize = 16.sp, 32 | lineHeight = 28.8.sp 33 | ), 34 | bodySmall = TextStyle( 35 | fontWeight = FontWeight.Medium, 36 | fontSize = 14.sp, 37 | lineHeight = 28.8.sp 38 | ), 39 | labelLarge = TextStyle( 40 | fontWeight = FontWeight.Medium, 41 | fontSize = 12.sp, 42 | lineHeight = 15.4.sp 43 | ), 44 | labelMedium = TextStyle( 45 | fontWeight = FontWeight.Medium, 46 | fontSize = 11.sp, 47 | lineHeight = 15.4.sp 48 | ), 49 | labelSmall = TextStyle( 50 | fontWeight = FontWeight.Light, 51 | fontSize = 10.sp, 52 | lineHeight = 15.4.sp 53 | ) 54 | ) -------------------------------------------------------------------------------- /demo/design-system/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /demo/design-system/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /demo/design-system/src/test/kotlin/tddy/ko/cardstack/desigh_system/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack.desigh_system 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /demo/feature/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | alias(libs.plugins.tddy.ko.android.library) 3 | alias(libs.plugins.tddy.ko.compose.library) 4 | } 5 | 6 | android { 7 | namespace = "tddy.ko.cardstack.feature" 8 | } 9 | 10 | dependencies { 11 | implementation(projects.demo.designSystem) 12 | implementation(projects.library.ui) 13 | implementation(libs.coil) 14 | } -------------------------------------------------------------------------------- /demo/feature/consumer-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/demo/feature/consumer-rules.pro -------------------------------------------------------------------------------- /demo/feature/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 -------------------------------------------------------------------------------- /demo/feature/src/androidTest/kotlin/tddy/ko/cardstack/feature/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack.feature 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("tddy.ko.cardstack.feature.test", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /demo/feature/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /demo/feature/src/main/assets/img_01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/demo/feature/src/main/assets/img_01.jpg -------------------------------------------------------------------------------- /demo/feature/src/main/assets/img_02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/demo/feature/src/main/assets/img_02.jpg -------------------------------------------------------------------------------- /demo/feature/src/main/assets/img_03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/demo/feature/src/main/assets/img_03.jpg -------------------------------------------------------------------------------- /demo/feature/src/main/assets/img_04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/demo/feature/src/main/assets/img_04.jpg -------------------------------------------------------------------------------- /demo/feature/src/main/assets/img_05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/demo/feature/src/main/assets/img_05.jpg -------------------------------------------------------------------------------- /demo/feature/src/main/assets/img_06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/demo/feature/src/main/assets/img_06.jpg -------------------------------------------------------------------------------- /demo/feature/src/main/kotlin/tddy/ko/cardstack/feature/Image.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack.feature 2 | 3 | data class Image( 4 | val asset: String, 5 | val description: String 6 | ) 7 | 8 | val images = listOf( 9 | Image(asset = "file:///android_asset/img_01.jpg", description = "Image 1"), 10 | Image(asset = "file:///android_asset/img_02.jpg", description = "Image 2"), 11 | Image(asset = "file:///android_asset/img_03.jpg", description = "Image 3"), 12 | Image(asset = "file:///android_asset/img_04.jpg", description = "Image 4"), 13 | Image(asset = "file:///android_asset/img_05.jpg", description = "Image 5"), 14 | Image(asset = "file:///android_asset/img_06.jpg", description = "Image 6") 15 | ) 16 | -------------------------------------------------------------------------------- /demo/feature/src/main/kotlin/tddy/ko/cardstack/feature/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack.feature 2 | 3 | import android.os.Bundle 4 | import androidx.activity.ComponentActivity 5 | import androidx.activity.compose.setContent 6 | import androidx.compose.foundation.layout.Arrangement 7 | import androidx.compose.foundation.layout.Column 8 | import androidx.compose.foundation.layout.fillMaxSize 9 | import androidx.compose.foundation.layout.imePadding 10 | import androidx.compose.foundation.layout.navigationBarsPadding 11 | import androidx.compose.foundation.layout.padding 12 | import androidx.compose.foundation.layout.statusBarsPadding 13 | import androidx.compose.foundation.shape.RoundedCornerShape 14 | import androidx.compose.material3.Text 15 | import androidx.compose.ui.Alignment 16 | import androidx.compose.ui.Modifier 17 | import androidx.compose.ui.draw.clip 18 | import androidx.compose.ui.graphics.Color 19 | import androidx.compose.ui.layout.ContentScale 20 | import androidx.compose.ui.unit.dp 21 | import androidx.core.view.WindowCompat 22 | import coil3.compose.AsyncImage 23 | import tddy.ko.cardstack.desigh_system.theme.CardStackTheme 24 | import tddy.ko.cardstack.ui.CardAlignment 25 | import tddy.ko.cardstack.ui.DragAlignment 26 | import tddy.ko.cardstack.ui.DraggableCardStack 27 | 28 | class MainActivity : ComponentActivity() { 29 | override fun onCreate(savedInstanceState: Bundle?) { 30 | super.onCreate(savedInstanceState) 31 | WindowCompat.setDecorFitsSystemWindows(window, false) 32 | setContent { 33 | CardStackTheme { 34 | Column( 35 | modifier = Modifier 36 | .fillMaxSize() 37 | .statusBarsPadding() 38 | .navigationBarsPadding() 39 | .imePadding(), 40 | verticalArrangement = Arrangement.Center, 41 | horizontalAlignment = Alignment.CenterHorizontally 42 | ) { 43 | DraggableCardStack( 44 | initialItems = images, 45 | height = 300.dp, 46 | cardSpacingRatio = .1f, 47 | cardAlignment = CardAlignment.BOTTOM, 48 | dragAlignment = DragAlignment.NONE 49 | ) { 50 | AsyncImage( 51 | modifier = Modifier 52 | .fillMaxSize() 53 | .clip(shape = RoundedCornerShape(8.dp)), 54 | model = it.asset, 55 | contentDescription = it.description, 56 | contentScale = ContentScale.Crop 57 | ) 58 | Text( 59 | modifier = Modifier 60 | .align(Alignment.BottomEnd) 61 | .padding(bottom = 16.dp, end = 16.dp), 62 | text = it.description, 63 | color = Color.White 64 | ) 65 | } 66 | } 67 | } 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /demo/feature/src/test/kotlin/tddy/ko/cardstack/feature/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack.feature 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /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. For more details, visit 12 | # https://developer.android.com/r/tools/gradle-multi-project-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 | # Kotlin code style for this project: "official" or "obsolete": 19 | kotlin.code.style=official 20 | # Enables namespacing of each library's R class so that its R class includes only the 21 | # resources declared in the library itself and none from the library's dependencies, 22 | # thereby reducing the size of the R class for that library 23 | android.nonTransitiveRClass=true -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | androidGradlePlugin = "8.7.1" 3 | jetbrainsKotlinJvm = "1.9.24" 4 | kotlin = "2.0.10" 5 | ksp = "2.0.10-1.0.24" 6 | androidDesugarJdkLibs = "2.1.2" 7 | 8 | vankiktechMaven = "0.30.0" 9 | 10 | androidxCompose = "1.7.5" 11 | androidxCoreKtx = "1.15.0" 12 | androidxAppcompat = "1.7.0" 13 | androidxActivityCompose = "1.9.3" 14 | 15 | junit = "4.13.2" 16 | junitVersion = "1.2.1" 17 | espressoCore = "3.6.1" 18 | 19 | material = "1.12.0" 20 | 21 | coil = "3.0.0-rc01" 22 | 23 | [libraries] 24 | android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" } 25 | kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } 26 | compose-gradlePlugin = { module = "org.jetbrains.kotlin:compose-compiler-gradle-plugin", version.ref = "kotlin" } 27 | ksp-gradlePlugin = { group = "com.google.devtools.ksp", name = "com.google.devtools.ksp.gradle.plugin", version.ref = "ksp" } 28 | 29 | android-desugarJdkLibs = { group = "com.android.tools", name = "desugar_jdk_libs", version.ref = "androidDesugarJdkLibs" } 30 | 31 | androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "androidxCoreKtx" } 32 | androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidxAppcompat" } 33 | 34 | androidx-compose-activity = { group = "androidx.activity", name = "activity-compose", version.ref = "androidxActivityCompose" } 35 | androidx-compose-ui = { group = "androidx.compose.ui", name = "ui", version.ref = "androidxCompose" } 36 | androidx-compose-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics", version.ref = "androidxCompose" } 37 | androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "androidxCompose" } 38 | androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview", version.ref = "androidxCompose" } 39 | androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version = "1.3.0" } 40 | 41 | junit = { group = "junit", name = "junit", version.ref = "junit" } 42 | androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } 43 | androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } 44 | 45 | material = { group = "com.google.android.material", name = "material", version.ref = "material" } 46 | coil = { group = "io.coil-kt.coil3", name = "coil-compose", version.ref = "coil" } 47 | 48 | [plugins] 49 | tddy-ko-android-application = { id = "tddy.ko.cardstack.application", version = "unspecified" } 50 | tddy-ko-android-library = { id = "tddy.ko.cardstack.library", version = "unspecified" } 51 | tddy-ko-compose-application = { id = "tddy.ko.cardstack.compose.application", version = "unspecified" } 52 | tddy-ko-compose-library = { id = "tddy.ko.cardstack.compose.library", version = "unspecified" } 53 | 54 | kotlin-ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } 55 | kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "jetbrainsKotlinJvm" } 56 | kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } 57 | 58 | android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" } 59 | android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" } 60 | 61 | compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } 62 | vanniktech-maven = { id = "com.vanniktech.maven.publish", version.ref = "vankiktechMaven" } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Oct 25 16:41:34 KST 2024 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 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 | -------------------------------------------------------------------------------- /library/ui/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.vanniktech.maven.publish.SonatypeHost 2 | 3 | plugins { 4 | alias(libs.plugins.tddy.ko.android.library) 5 | alias(libs.plugins.tddy.ko.compose.library) 6 | alias(libs.plugins.vanniktech.maven) 7 | } 8 | 9 | android { 10 | namespace = "tddy.ko.cardstack.ui" 11 | } 12 | 13 | mavenPublishing { 14 | publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) 15 | 16 | signAllPublications() 17 | 18 | coordinates("io.github.teddko", "cardstack", "1.0.0") 19 | 20 | pom { 21 | name.set("CardStack") 22 | description.set("Jetpack Compose CardStack Library") 23 | url.set("https://github.com/TeddKo/CardStack") 24 | inceptionYear.set("2024") 25 | 26 | licenses { 27 | license { 28 | name.set("The Apache License, Version 2.0") 29 | url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") 30 | distribution.set("http://www.apache.org/licenses/LICENSE-2.0.txt") 31 | } 32 | } 33 | 34 | developers { 35 | developer { 36 | id.set("TeddKo") 37 | name.set("Tedd Ko") 38 | email.set("tddy.ko@kakao.com") 39 | url.set("https://github.com/TeddKo") 40 | } 41 | } 42 | 43 | scm { 44 | url.set("https://github.com/TeddKo/CardStack") 45 | connection.set("scm:git:git://github.com/TeddKo/CardStack.git") 46 | developerConnection.set("scm:git:git://github.com/TeddKo/CardStack.git") 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /library/ui/consumer-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeddKo/DraggableCardStack/e0ba0a979ab41c2e98812c03d4a7ed928246420d/library/ui/consumer-rules.pro -------------------------------------------------------------------------------- /library/ui/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 -------------------------------------------------------------------------------- /library/ui/src/androidTest/kotlin/tddy/ko/cardstack/ui/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack.ui 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("tddy.ko.cardstack.ui.test", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /library/ui/src/main/kotlin/tddy/ko/cardstack/ui/CardStack.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack.ui 2 | 3 | import androidx.compose.animation.core.Spring 4 | import androidx.compose.animation.core.animateFloat 5 | import androidx.compose.animation.core.animateFloatAsState 6 | import androidx.compose.animation.core.animateOffset 7 | import androidx.compose.animation.core.spring 8 | import androidx.compose.animation.core.tween 9 | import androidx.compose.animation.core.updateTransition 10 | import androidx.compose.foundation.gestures.detectDragGestures 11 | import androidx.compose.foundation.layout.Box 12 | import androidx.compose.foundation.layout.BoxScope 13 | import androidx.compose.foundation.layout.fillMaxWidth 14 | import androidx.compose.foundation.layout.height 15 | import androidx.compose.foundation.layout.padding 16 | import androidx.compose.foundation.shape.RoundedCornerShape 17 | import androidx.compose.runtime.Composable 18 | import androidx.compose.runtime.LaunchedEffect 19 | import androidx.compose.runtime.derivedStateOf 20 | import androidx.compose.runtime.getValue 21 | import androidx.compose.runtime.key 22 | import androidx.compose.runtime.mutableFloatStateOf 23 | import androidx.compose.runtime.mutableStateOf 24 | import androidx.compose.runtime.remember 25 | import androidx.compose.runtime.rememberCoroutineScope 26 | import androidx.compose.runtime.rememberUpdatedState 27 | import androidx.compose.runtime.setValue 28 | import androidx.compose.ui.Alignment 29 | import androidx.compose.ui.Modifier 30 | import androidx.compose.ui.draw.shadow 31 | import androidx.compose.ui.geometry.Offset 32 | import androidx.compose.ui.graphics.graphicsLayer 33 | import androidx.compose.ui.input.pointer.pointerInput 34 | import androidx.compose.ui.input.pointer.util.VelocityTracker 35 | import androidx.compose.ui.platform.LocalConfiguration 36 | import androidx.compose.ui.platform.LocalDensity 37 | import androidx.compose.ui.unit.Density 38 | import androidx.compose.ui.unit.Dp 39 | import androidx.compose.ui.unit.dp 40 | import androidx.compose.ui.zIndex 41 | import kotlinx.coroutines.delay 42 | import kotlinx.coroutines.launch 43 | 44 | /** 45 | * DraggableCardStack is a customizable composable that implements a stack of draggable cards 46 | * with smooth animations and gestures. It supports both vertical and horizontal swiping with 47 | * customizable alignment and spacing. 48 | * 49 | * @param initialItems The initial list of items to display in the card stack 50 | * @param height The height of each card in the stack 51 | * @param cardSpacingRatio The ratio that determines spacing between cards relative to screen height 52 | * @param cardAlignment The alignment of cards in the stack (TOP, BOTTOM, START, END, etc.) 53 | * @param dragAlignment The direction in which cards can be dragged (VERTICAL, HORIZONTAL, NONE) 54 | * @param cardContent The composable content for each card 55 | * 56 | * Features: 57 | * - Smooth card animations with spring physics 58 | * - Customizable card alignment and spacing 59 | * - Support for both vertical and horizontal swiping 60 | * - Velocity-based swipe detection 61 | * - Automatic card reordering after swipe 62 | * - Elevation and scale animations 63 | * 64 | * Example usage: 65 | * ``` 66 | * DraggableCardStack( 67 | * initialItems = listOf("Card 1", "Card 2", "Card 3"), 68 | * height = 200.dp, 69 | * cardSpacingRatio = 0.1f, 70 | * cardAlignment = CardAlignment.BOTTOM, 71 | * dragAlignment = DragAlignment.HORIZONTAL 72 | * ) { item -> 73 | * // Card content 74 | * Text(text = item) 75 | * } 76 | * ``` 77 | * 78 | * Notes: 79 | * - The card stack automatically handles device rotation and screen size changes 80 | * - Cards can be swiped when velocity exceeds the threshold or drag distance is sufficient 81 | * - Each card maintains its own state and animation properties 82 | * - The stack supports dynamic updates to the item list 83 | * 84 | * @see CardAlignment for available card alignment options 85 | * @see DragAlignment for available drag direction options 86 | **/ 87 | @Composable 88 | fun DraggableCardStack( 89 | initialItems: List, 90 | height: Dp, 91 | cardSpacingRatio: Float, 92 | cardAlignment: CardAlignment, 93 | dragAlignment: DragAlignment, 94 | cardContent: @Composable BoxScope.(T) -> Unit 95 | ) { 96 | var items by remember { mutableStateOf(initialItems) } 97 | val density = LocalDensity.current 98 | val configuration = LocalConfiguration.current 99 | val screenWidth = configuration.screenWidthDp.dp 100 | val screenHeight = configuration.screenHeightDp.dp 101 | 102 | val cardSpacing = remember(screenHeight) { screenHeight * (cardSpacingRatio * .1f) } 103 | val velocityThreshold = 104 | remember(screenWidth, screenHeight) { minOf(screenWidth, screenHeight) * 0.6f } 105 | 106 | val stackedHeight by remember(items.size, cardSpacing, cardAlignment) { 107 | derivedStateOf { 108 | when (cardAlignment) { 109 | CardAlignment.BOTTOM, CardAlignment.BOTTOM_START, CardAlignment.BOTTOM_END, 110 | CardAlignment.TOP, CardAlignment.TOP_START, CardAlignment.TOP_END -> 111 | height + (cardSpacing * (items.size - 1)) 112 | 113 | CardAlignment.START, CardAlignment.END -> height 114 | } 115 | } 116 | } 117 | 118 | val contentAlignment = remember(cardAlignment) { 119 | when (cardAlignment) { 120 | CardAlignment.BOTTOM -> Alignment.BottomCenter 121 | CardAlignment.BOTTOM_START -> Alignment.BottomStart 122 | CardAlignment.BOTTOM_END -> Alignment.BottomEnd 123 | CardAlignment.TOP -> Alignment.TopCenter 124 | CardAlignment.TOP_START -> Alignment.TopStart 125 | CardAlignment.TOP_END -> Alignment.TopEnd 126 | CardAlignment.START, CardAlignment.END -> Alignment.Center 127 | } 128 | } 129 | 130 | val (stackDragProgress, onDrag) = remember { mutableFloatStateOf(0f) } 131 | 132 | Box( 133 | modifier = Modifier 134 | .fillMaxWidth() 135 | .height(height = stackedHeight), 136 | contentAlignment = contentAlignment 137 | ) { 138 | items 139 | .asReversed() 140 | .forEachIndexed { index, item -> 141 | key(item) { 142 | DraggableCard( 143 | density = density, 144 | height = height, 145 | cardSpacing = cardSpacing, 146 | velocityThreshold = velocityThreshold, 147 | itemCount = items.size, 148 | index = items.size - 1 - index, 149 | cardAlignment = cardAlignment, 150 | dragAlignment = dragAlignment, 151 | stackDragProgress = stackDragProgress, 152 | onDrag = onDrag, 153 | onSwipe = { direction -> 154 | items = when (direction) { 155 | DragDirection.LEFT, DragDirection.DOWN -> items 156 | .toMutableList() 157 | .apply { 158 | remove(items.last()) 159 | add(0, items.last()) 160 | } 161 | 162 | DragDirection.RIGHT, DragDirection.UP -> items 163 | .toMutableList() 164 | .apply { 165 | remove(items.first()) 166 | add(items.first()) 167 | } 168 | } 169 | }, 170 | content = { cardContent(item) } 171 | ) 172 | } 173 | } 174 | } 175 | } 176 | 177 | /** 178 | * 179 | * A composable component that represents a draggable card within the card stack. 180 | * Handles individual card animations, gestures, and state management. 181 | * 182 | * @param density The current display density 183 | * @param height Height of the card 184 | * @param cardSpacing Spacing between cards in the stack 185 | * @param velocityThreshold Threshold for swipe velocity to trigger card actions 186 | * @param itemCount Total number of cards in the stack 187 | * @param index Position of this card in the stack (0 is top card) 188 | * @param cardAlignment Alignment of cards in the stack 189 | * @param dragAlignment Allowed drag directions 190 | * @param stackDragProgress Current drag progress of the stack (-1 to 1) 191 | * @param onDrag Callback invoked during drag with progress value 192 | * @param onSwipe Callback invoked when card is swiped with direction 193 | * @param content Composable content to be displayed in the card 194 | * 195 | * Features: 196 | * - Spring-based animations for smooth transitions 197 | * - Gesture detection with velocity tracking 198 | * - Dynamic elevation changes during interaction 199 | * - Scale animations based on stack position 200 | * - Support for both vertical and horizontal swiping 201 | * - Automatic card repositioning after swipe 202 | * 203 | * Internal behavior: 204 | * - Tracks drag offset and animation state 205 | * - Calculates swipe velocity and direction 206 | * - Manages elevation changes during drag 207 | * - Handles scale transitions 208 | * - Applies position adjustments based on alignment 209 | * 210 | * Animation specifications: 211 | * - Uses spring animation for offset changes (low bounce, low stiffness) 212 | * - Animates elevation from 4dp to 8dp during interaction 213 | * - Scale factor decreases for each card in the stack 214 | * - Smooth transitions for all transform properties 215 | * 216 | * Gesture handling: 217 | * - Only top card (index 0) responds to gestures 218 | * - Tracks velocity for swipe detection 219 | * - Supports configurable velocity thresholds 220 | * - Handles drag cancellation and completion 221 | * 222 | * Note: This component is designed to be used within DraggableCardStack 223 | * and should not be used independently. 224 | */ 225 | @Composable 226 | private fun DraggableCard( 227 | density: Density, 228 | height: Dp, 229 | cardSpacing: Dp, 230 | velocityThreshold: Dp, 231 | itemCount: Int, 232 | index: Int, 233 | cardAlignment: CardAlignment, 234 | dragAlignment: DragAlignment, 235 | stackDragProgress: Float, 236 | onDrag: (Float) -> Unit, 237 | onSwipe: (DragDirection) -> Unit, 238 | content: @Composable BoxScope.() -> Unit 239 | ) { 240 | val coroutineScope = rememberCoroutineScope() 241 | var offset by remember { mutableStateOf(Offset.Zero) } 242 | var isAnimating by remember { mutableStateOf(false) } 243 | 244 | val velocityThresholdPx = with(density) { velocityThreshold.toPx() } 245 | val spacingPx = with(density) { cardSpacing.toPx() } 246 | 247 | val swipeProgress = calculateSwipeProgress(offset, velocityThresholdPx) 248 | 249 | val updatedOnDrag by rememberUpdatedState(onDrag) 250 | val updatedOnSwipe by rememberUpdatedState(onSwipe) 251 | 252 | val transition = updateTransition(targetState = offset, label = "cardTransition") 253 | 254 | val animatedOffset by transition.animateOffset( 255 | label = "offsetAnimation", 256 | transitionSpec = { 257 | spring(dampingRatio = Spring.DampingRatioLowBouncy, stiffness = Spring.StiffnessLow) 258 | }, 259 | targetValueByState = { it } 260 | ) 261 | val animatedElevation by animateFloatAsState( 262 | targetValue = if (isAnimating) 8f else 4f, 263 | animationSpec = tween(durationMillis = 200), 264 | label = "animatedElevation" 265 | ) 266 | 267 | 268 | val targetScale = calculateScales(index, itemCount, stackDragProgress) 269 | val animatedScale by transition.animateFloat( 270 | label = "scaleAnimation", 271 | transitionSpec = { 272 | spring(dampingRatio = Spring.DampingRatioLowBouncy, stiffness = Spring.StiffnessLow) 273 | }, 274 | targetValueByState = { targetScale } 275 | ) 276 | 277 | val lastOffset = calculateLastOffset(cardAlignment, index, spacingPx) 278 | val dragBasedOffset = 279 | calculateDragBasedOffset(stackDragProgress, index, spacingPx, itemCount, cardAlignment) 280 | 281 | LaunchedEffect(swipeProgress) { updatedOnDrag(swipeProgress) } 282 | 283 | Box( 284 | modifier = Modifier 285 | .fillMaxWidth() 286 | .height(height) 287 | .padding(horizontal = 12.dp) 288 | .zIndex(itemCount.toFloat() - index) 289 | .graphicsLayer { 290 | scaleX = animatedScale 291 | scaleY = animatedScale 292 | translationX = animatedOffset.x + lastOffset.x + dragBasedOffset.x 293 | translationY = animatedOffset.y + lastOffset.y + dragBasedOffset.y 294 | applyAlignmentAdjustment(cardAlignment, animatedScale, size) 295 | } 296 | .shadow(elevation = animatedElevation.dp, shape = RoundedCornerShape(12.dp)) 297 | .then( 298 | if (!isAnimating) { 299 | Modifier.pointerInput(Unit) { 300 | val velocityTracker = VelocityTracker() 301 | detectDragGestures( 302 | onDragStart = { velocityTracker.resetTracking() }, 303 | onDrag = { change, dragAmount -> 304 | change.consume() 305 | offset += when (dragAlignment) { 306 | DragAlignment.VERTICAL -> Offset(x = 0f, y = dragAmount.y) 307 | DragAlignment.HORIZONTAL -> Offset(x = dragAmount.x, 0f) 308 | DragAlignment.NONE -> Offset(x = dragAmount.x, y = dragAmount.y) 309 | } 310 | velocityTracker.addPosition(change.uptimeMillis, change.position) 311 | }, 312 | onDragEnd = { 313 | val velocity = velocityTracker.calculateVelocity() 314 | val direction = 315 | determineSwipeDirection(velocity = velocity, offset = offset) 316 | 317 | val shouldSwipe = direction != null && isSwipeVelocityExceeded( 318 | velocity = velocity, 319 | velocityThresholdPx = velocityThresholdPx 320 | ) 321 | 322 | coroutineScope.launch { 323 | isAnimating = true 324 | if (shouldSwipe && direction != null) { 325 | val targetOffset = calculateTargetOffset( 326 | direction = direction, 327 | size = size, 328 | offset = offset, 329 | cardAlignment = cardAlignment 330 | ) 331 | offset = targetOffset 332 | delay(10) 333 | updatedOnSwipe(direction) 334 | } 335 | offset = Offset.Zero 336 | delay(10) 337 | isAnimating = false 338 | } 339 | } 340 | ) 341 | } 342 | } else Modifier 343 | ), 344 | contentAlignment = Alignment.Center, 345 | content = content 346 | ) 347 | } -------------------------------------------------------------------------------- /library/ui/src/main/kotlin/tddy/ko/cardstack/ui/CardStackHelper.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack.ui 2 | 3 | import androidx.compose.ui.geometry.Offset 4 | import androidx.compose.ui.geometry.Size 5 | import androidx.compose.ui.graphics.GraphicsLayerScope 6 | import androidx.compose.ui.unit.IntSize 7 | import androidx.compose.ui.unit.Velocity 8 | import kotlin.math.absoluteValue 9 | import kotlin.math.pow 10 | 11 | /** 12 | * Represents the possible directions for card swiping gestures. 13 | * Used to determine and handle the direction of card movement during swipe animations. 14 | **/ 15 | enum class DragDirection { LEFT, RIGHT, UP, DOWN } 16 | 17 | /** 18 | * Defines the alignment options for cards within the stack. 19 | * Controls how cards are positioned and stacked relative to each other. 20 | **/ 21 | enum class CardAlignment { BOTTOM, BOTTOM_START, BOTTOM_END, TOP, TOP_START, TOP_END, START, END } 22 | 23 | /** 24 | * Specifies the allowed drag directions for card interactions. 25 | * Controls how users can interact with and drag cards in the stack. 26 | **/ 27 | enum class DragAlignment { VERTICAL, HORIZONTAL, NONE } 28 | 29 | /** 30 | * Determines the swipe direction based on velocity and offset. 31 | * 32 | * @param velocity The velocity of the drag gesture 33 | * @param offset The current offset of the drag 34 | * @return The determined DragDirection or null if not exceeding thresholds 35 | **/ 36 | internal fun determineSwipeDirection(velocity: Velocity, offset: Offset): DragDirection? { 37 | val isHorizontal = velocity.x.absoluteValue > velocity.y.absoluteValue 38 | return when { 39 | isHorizontal && velocity.x > 0 && offset.x > 0 -> DragDirection.RIGHT 40 | isHorizontal && velocity.x < 0 && offset.x < 0 -> DragDirection.LEFT 41 | !isHorizontal && velocity.y > 0 && offset.y > 0 -> DragDirection.DOWN 42 | !isHorizontal && velocity.y < 0 && offset.y < 0 -> DragDirection.UP 43 | else -> null 44 | } 45 | } 46 | 47 | /** 48 | * Checks if the swipe velocity exceeds the defined threshold. 49 | * 50 | * @param velocity The velocity of the drag gesture 51 | * @param velocityThresholdPx The threshold value in pixels 52 | * @return True if the velocity exceeds the threshold 53 | **/ 54 | internal fun isSwipeVelocityExceeded(velocity: Velocity, velocityThresholdPx: Float): Boolean = 55 | velocity.x.absoluteValue > velocityThresholdPx || velocity.y.absoluteValue > velocityThresholdPx 56 | 57 | /** 58 | * Calculates the target offset for card animation based on swipe direction. 59 | * 60 | * @param direction The direction of the swipe 61 | * @param size The size of the card 62 | * @param offset The current offset 63 | * @param cardAlignment The alignment of cards in the stack 64 | * @return The target offset for the animation 65 | **/ 66 | internal fun calculateTargetOffset( 67 | direction: DragDirection, 68 | size: IntSize, 69 | offset: Offset, 70 | cardAlignment: CardAlignment 71 | ): Offset = when (direction) { 72 | DragDirection.LEFT -> Offset(-size.width.toFloat() * 1.5f, offset.y) 73 | DragDirection.RIGHT -> Offset(size.width.toFloat() * 1.5f, offset.y) 74 | DragDirection.UP -> Offset(offset.x, calculateVerticalOffset(cardAlignment, size, offset)) 75 | DragDirection.DOWN -> Offset(offset.x, size.height.toFloat() * 1.5f) 76 | } 77 | 78 | /** 79 | * Calculates the vertical offset for card animation based on alignment. 80 | * 81 | * @param cardAlignment The alignment of cards in the stack 82 | * @param size The size of the card 83 | * @param offset The current offset 84 | * @return The calculated vertical offset 85 | **/ 86 | internal fun calculateVerticalOffset( 87 | cardAlignment: CardAlignment, 88 | size: IntSize, 89 | offset: Offset 90 | ): Float = when (cardAlignment) { 91 | CardAlignment.BOTTOM, CardAlignment.BOTTOM_START, CardAlignment.BOTTOM_END -> -size.height.toFloat() * 1.5f 92 | else -> offset.y 93 | } 94 | 95 | /** 96 | * Calculates the swipe progress as a normalized value between -1 and 1. 97 | * 98 | * @param offset The current drag offset 99 | * @param velocityThresholdPx The velocity threshold in pixels 100 | * @return The normalized swipe progress 101 | **/ 102 | internal fun calculateSwipeProgress(offset: Offset, velocityThresholdPx: Float): Float { 103 | val xProgress = offset.x / velocityThresholdPx 104 | val yProgress = offset.y / velocityThresholdPx 105 | return when { 106 | xProgress.absoluteValue > yProgress.absoluteValue -> xProgress.coerceIn(-1f, 1f) 107 | else -> -yProgress.coerceIn(-1f, 1f) 108 | } 109 | } 110 | 111 | /** 112 | * Calculates the scale factor for each card in the stack. 113 | * 114 | * @param index The index of the card in the stack 115 | * @return The calculated scale factor 116 | **/ 117 | internal fun calculateScales(index: Int, itemCount: Int, stackDragProgress: Float): Float { 118 | val baseScale = 1f - (index * 0.05f) 119 | val scaleIncrement = 0.05f * stackDragProgress 120 | return when { 121 | index > 0 -> baseScale + (scaleIncrement * (itemCount - index - 1)) 122 | .coerceAtMost(.05f) 123 | 124 | else -> baseScale 125 | } 126 | } 127 | 128 | /** 129 | * Calculates the initial offset for each card based on its position in the stack. 130 | * 131 | * @param cardAlignment The alignment of cards in the stack 132 | * @param index The index of the card 133 | * @param spacingPx The spacing between cards in pixels 134 | * @return The calculated offset 135 | **/ 136 | internal fun calculateLastOffset( 137 | cardAlignment: CardAlignment, 138 | index: Int, 139 | spacingPx: Float 140 | ): Offset = when (cardAlignment) { 141 | CardAlignment.TOP -> Offset(0f, spacingPx * index) 142 | CardAlignment.TOP_START -> Offset(-spacingPx * index, spacingPx * index) 143 | CardAlignment.TOP_END -> Offset(spacingPx * index, spacingPx * index) 144 | CardAlignment.BOTTOM -> Offset(0f, -spacingPx * index) 145 | CardAlignment.BOTTOM_START -> Offset(-spacingPx * index, -spacingPx * index) 146 | CardAlignment.BOTTOM_END -> Offset(spacingPx * index, -spacingPx * index) 147 | CardAlignment.START -> Offset(-spacingPx * index, 0f) 148 | CardAlignment.END -> Offset(spacingPx * index, 0f) 149 | } 150 | 151 | /** 152 | * Calculates the offset during drag operations based on stack configuration. 153 | * 154 | * @param stackDragProgress The current drag progress 155 | * @param index Card index in the stack 156 | * @param spacingPx Spacing between cards 157 | * @param itemCount Total number of cards 158 | * @param cardAlignment Stack alignment 159 | * @return The calculated drag-based offset 160 | **/ 161 | internal fun calculateDragBasedOffset( 162 | stackDragProgress: Float, 163 | index: Int, 164 | spacingPx: Float, 165 | itemCount: Int, 166 | cardAlignment: CardAlignment 167 | ): Offset { 168 | val progress = if (index == itemCount - 1 && stackDragProgress < 0f) { 169 | (-stackDragProgress).coerceIn(0f, 1f) 170 | } else { 171 | (stackDragProgress * (1f - (index.toFloat() / itemCount))).coerceIn(-1f, 1f) 172 | } 173 | 174 | val easedProgress = progress * progress * (3 - 2 * progress) 175 | 176 | return when (cardAlignment) { 177 | CardAlignment.TOP -> Offset( 178 | 0f, 179 | spacingPx * easedProgress * if (index == itemCount - 1 && stackDragProgress < 0f) 1f else -1f 180 | ) 181 | CardAlignment.BOTTOM -> Offset(0f, spacingPx * easedProgress) 182 | CardAlignment.TOP_START -> Offset( 183 | spacingPx * easedProgress, 184 | -spacingPx * easedProgress 185 | ) 186 | CardAlignment.BOTTOM_START -> Offset( 187 | spacingPx * easedProgress, 188 | spacingPx * easedProgress 189 | ) 190 | CardAlignment.TOP_END -> Offset( 191 | -spacingPx * easedProgress, 192 | -spacingPx * easedProgress 193 | ) 194 | CardAlignment.BOTTOM_END -> Offset( 195 | -spacingPx * easedProgress, 196 | spacingPx * easedProgress 197 | ) 198 | CardAlignment.START -> Offset(spacingPx * easedProgress, 0f) 199 | CardAlignment.END -> Offset(-spacingPx * easedProgress, 0f) 200 | } 201 | } 202 | 203 | /** 204 | * Applies alignment-based adjustments to card transformation. 205 | * Adjusts the card position based on its scale and alignment to maintain proper positioning. 206 | * 207 | * @param cardAlignment The alignment of cards in the stack 208 | * @param animatedScale The current scale value of the card 209 | * @param size The size of the card 210 | **/ 211 | internal fun GraphicsLayerScope.applyAlignmentAdjustment( 212 | cardAlignment: CardAlignment, 213 | animatedScale: Float, 214 | size: Size 215 | ) { 216 | val widthAdjustment = (size.width * (1f - animatedScale)) / 2f 217 | val heightAdjustment = (size.height * (1f - animatedScale)) / 2f 218 | 219 | when (cardAlignment) { 220 | CardAlignment.TOP -> translationY += heightAdjustment 221 | CardAlignment.TOP_START -> { 222 | translationY += heightAdjustment 223 | translationX -= widthAdjustment 224 | } 225 | 226 | CardAlignment.TOP_END -> { 227 | translationY += heightAdjustment 228 | translationX += widthAdjustment 229 | } 230 | 231 | CardAlignment.BOTTOM -> translationY -= heightAdjustment 232 | CardAlignment.BOTTOM_START -> { 233 | translationY -= heightAdjustment 234 | translationX -= widthAdjustment 235 | } 236 | 237 | CardAlignment.BOTTOM_END -> { 238 | translationY -= heightAdjustment 239 | translationX += widthAdjustment 240 | } 241 | 242 | CardAlignment.START -> translationX -= widthAdjustment 243 | CardAlignment.END -> translationX += widthAdjustment 244 | } 245 | } -------------------------------------------------------------------------------- /library/ui/src/test/kotlin/tddy/ko/cardstack/ui/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package tddy.ko.cardstack.ui 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | includeBuild("build-logic") 3 | repositories { 4 | google { 5 | content { 6 | includeGroupByRegex("com\\.android.*") 7 | includeGroupByRegex("com\\.google.*") 8 | includeGroupByRegex("androidx.*") 9 | } 10 | } 11 | mavenCentral() 12 | gradlePluginPortal() 13 | } 14 | } 15 | 16 | @Suppress("UnstableApiUsage") 17 | dependencyResolutionManagement { 18 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 19 | repositories { 20 | google() 21 | mavenCentral() 22 | } 23 | } 24 | 25 | rootProject.name = "CardStack" 26 | include(":app") 27 | 28 | include(":library:ui") 29 | include( 30 | ":demo:feature", 31 | ":demo:design-system" 32 | ) --------------------------------------------------------------------------------