├── .gitignore ├── LICENSE.txt ├── README.md ├── androidApp ├── build.gradle.kts └── src │ └── androidMain │ ├── AndroidManifest.xml │ ├── ic_launcher-playstore.png │ ├── kotlin │ └── com │ │ └── myapplication │ │ └── MainActivity.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_foreground.webp │ └── ic_launcher_round.webp │ ├── mipmap-mdpi │ ├── ic_launcher.webp │ ├── ic_launcher_foreground.webp │ └── ic_launcher_round.webp │ ├── mipmap-xhdpi │ ├── ic_launcher.webp │ ├── ic_launcher_foreground.webp │ └── ic_launcher_round.webp │ ├── mipmap-xxhdpi │ ├── ic_launcher.webp │ ├── ic_launcher_foreground.webp │ └── ic_launcher_round.webp │ ├── mipmap-xxxhdpi │ ├── ic_launcher.webp │ ├── ic_launcher_foreground.webp │ └── ic_launcher_round.webp │ └── values │ ├── ic_launcher_background.xml │ └── strings.xml ├── build.gradle.kts ├── cleanup.sh ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── iosApp ├── Configuration │ └── Config.xcconfig ├── Podfile ├── iosApp.xcodeproj │ └── project.pbxproj └── iosApp │ ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ └── app-icon-1024.png │ └── Contents.json │ ├── ContentView.swift │ ├── Info.plist │ ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json │ └── iOSApp.swift ├── readme_images ├── android_app_running.png ├── banner.png ├── edit_run_config.png ├── hello_world_ios.png ├── open_project_view.png ├── run_on_android.png ├── target_device.png └── text_field_added.png ├── settings.gradle.kts └── shared ├── build.gradle.kts └── src ├── androidMain ├── AndroidManifest.xml └── kotlin │ └── main.android.kt ├── commonMain ├── kotlin │ ├── App.kt │ ├── extensions │ │ ├── LongExtensions.kt │ │ ├── ModifierExtensions.kt │ │ └── StringExtensions.kt │ ├── model │ │ ├── CourseProgresse.kt │ │ ├── Guide.kt │ │ └── Profile.kt │ └── ui │ │ ├── home │ │ ├── HomeScreen.kt │ │ ├── HomeViewModel.kt │ │ └── LoginScreen.kt │ │ └── tabs │ │ ├── CourseProgressesScreen.kt │ │ ├── GuidesScreen.kt │ │ └── TabScreen.kt └── resources │ └── compose-multiplatform.xml └── iosMain └── kotlin └── main.ios.kt /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | build/ 7 | /captures 8 | .externalNativeBuild 9 | .cxx 10 | iosApp/Podfile.lock 11 | iosApp/Pods/* 12 | iosApp/iosApp.xcworkspace/* 13 | iosApp/iosApp.xcodeproj/* 14 | !iosApp/iosApp.xcodeproj/project.pbxproj 15 | shared/shared.podspec 16 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2020-2021 JetBrains s.r.o. and and respective authors and developers. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KMP Sensors 2 | ![thumb](https://github.com/git-jr/KMPSensors/assets/35709152/8f39bf63-53b1-4af3-aaad-934dd3074de9) 3 | 4 | 5 | > **Nota** 6 | > A base deste repositório foi gerada através do [JetBrains Compose Multiplatform iOS Android template](https://github.com/JetBrains/compose-multiplatform-ios-android-template), que é uma versão limpa do projeto, quase 100% pronta para rodar no Android e iOS. Você só precisa realizar algumas configurações, conforme descritas abaixo na seção "Compose Multiplatform mobile application", e começar a criar coisas incríveis com um único código para as duas plataformas. 7 | 8 | Esse projeto consome a [API Dashboard da Alura](https://suporte.alura.com.br/support/solutions/articles/72000565226-api-do-dashboard-para-alunos-e-alunas) para exibir uma lista de cursos e guias de estudo em progresso de uma conta de usuário específica (ou uma API mock que eu criei para facilitar as coisas hehe), junto de algumas animações criadas com Jetpack Compose e o melhor, o mesmo código rodando tanto no Android, quanto no iOS para iPhone. 9 | A versão do Android ainda utiliza alguns sensores do dispositivo para criar animações em tela conforme o celular é movimentado. 10 | 11 | ### 🎨 Preview Android - IOS 12 | 13 | 14 | 15 | 16 | https://github.com/git-jr/KMPSensors/assets/35709152/ce306d47-025d-44c9-a24e-770daf5e513a 17 | 18 | 19 | 20 | ### 💻 Algumas tecnologias em uso no momento 21 | - UI e Animações: Jetpack Compose 22 | - MVVM: Através de ViewModels no Compose com a lib [Moko mvvm](https://github.com/icerockdev/moko-mvvm) 23 | - Rest API: Através da lib [Ktor](https://ktor.io/docs/welcome.html) para requisições, em conjunto com [Kotlinx Serialization](https://github.com/Kotlin/kotlinx.serialization) para lidar com jsons. 24 | - Carregamento de imagens: [Kamel](https://github.com/Kamel-Media/Kamel) 25 | - Formatação de datas: [Kotlinx Datetime](https://github.com/Kotlin/kotlinx-datetime) 26 | ‎‎‎‎‎‎‎‎ㅤ 27 | 28 | ㅤㅤ 29 | ㅤ 30 | ㅤ 31 | 32 | ##### Segue o readme original para quem tiver interesse: 33 | # [Compose Multiplatform](https://github.com/JetBrains/compose-multiplatform) mobile application 34 | 35 | > **Note** 36 | > Compose Multiplatform for iOS is in Alpha. It may change incompatibly and require manual migration in the future. 37 | > We would appreciate your feedback on it in the public Slack channel [#compose-ios](https://kotlinlang.slack.com/archives/C0346LWVBJ4/p1678888063176359). 38 | > If you have any issues, please report them on [GitHub](https://github.com/JetBrains/compose-multiplatform/issues). 39 | 40 | You can use this template to start developing your own [Compose Multiplatform](https://github.com/JetBrains/compose-multiplatform#readme) mobile application targeting Android and iOS. 41 | Follow our tutorial below to get your first Compose Multiplatform app up and running. 42 | The result will be a [Kotlin Multiplatform](https://kotlinlang.org/docs/multiplatform.html) project that uses the Compose Multiplatform UI framework. 43 | 44 | ![](readme_images/banner.png) 45 | 46 | If you want to create an application targeting desktop platforms – Windows, macOS, or Linux – 47 | use the [Compose Multiplatform desktop application template](https://github.com/JetBrains/compose-multiplatform-desktop-template#readme). 48 | 49 | ## Set up the environment 50 | 51 | > **Warning** 52 | > You need a Mac with macOS to write and run iOS-specific code on simulated or real devices. 53 | > This is an Apple requirement. 54 | 55 | To work with this template, you need the following: 56 | 57 | * A machine running a recent version of macOS 58 | * [Xcode](https://apps.apple.com/us/app/xcode/id497799835) 59 | * [Android Studio](https://developer.android.com/studio) 60 | * The [Kotlin Multiplatform Mobile plugin](https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform-mobile) 61 | * The [CocoaPods dependency manager](https://kotlinlang.org/docs/native-cocoapods.html) 62 | 63 | ### Check your environment 64 | 65 | Before you start, use the [KDoctor](https://github.com/Kotlin/kdoctor) tool to ensure that your development environment is configured correctly: 66 | 67 | 1. Install KDoctor with [Homebrew](https://brew.sh/): 68 | 69 | ```text 70 | brew install kdoctor 71 | ``` 72 | 73 | 2. Run KDoctor in your terminal: 74 | 75 | ```text 76 | kdoctor 77 | ``` 78 | 79 | If everything is set up correctly, you'll see valid output: 80 | 81 | ```text 82 | Environment diagnose (to see all details, use -v option): 83 | [✓] Operation System 84 | [✓] Java 85 | [✓] Android Studio 86 | [✓] Xcode 87 | [✓] Cocoapods 88 | 89 | Conclusion: 90 | ✓ Your system is ready for Kotlin Multiplatform Mobile development! 91 | ``` 92 | 93 | Otherwise, KDoctor will highlight which parts of your setup still need to be configured and will suggest a way to fix them. 94 | 95 | ## Examine the project structure 96 | 97 | Open the project in Android Studio and switch the view from **Android** to **Project** to see all the files and targets belonging to the project: 98 | 99 | 100 | 101 | Your Compose Multiplatform project includes 3 modules: 102 | 103 | ### shared 104 | 105 | This is a Kotlin module that contains the logic common for both Android and iOS applications, that is, the code you share between platforms. 106 | 107 | This `shared` module is also where you’ll write your Compose Multiplatform code. 108 | In `shared/src/commonMain/kotlin/App.kt`, you can find the shared root `@Composable` function for your app. 109 | 110 | It uses Gradle as the build system. You can add dependencies and change settings in `shared/build.gradle.kts`. 111 | The `shared` module builds into an Android library and an iOS framework. 112 | 113 | ### androidApp 114 | 115 | This is a Kotlin module that builds into an Android application. It uses Gradle as the build system. 116 | The `androidApp` module depends on and uses the `shared` module as a regular Android library. 117 | 118 | ### iosApp 119 | 120 | This is an Xcode project that builds into an iOS application. 121 | It depends on and uses the `shared` module as a CocoaPods dependency. 122 | 123 | ## Run your application 124 | 125 | ### On Android 126 | 127 | To run your application on an Android emulator: 128 | 129 | 1. Ensure you have an Android virtual device available. Otherwise, [create one](https://developer.android.com/studio/run/managing-avds#createavd). 130 | 2. In the list of run configurations, select `androidApp`. 131 | 3. Choose your virtual device and click **Run**: 132 | 133 | 134 | 135 | 136 | 137 |
138 | Alternatively, use Gradle 139 | 140 | To install an Android application on a real Android device or an emulator, run `./gradlew installDebug` in the terminal. 141 | 142 |
143 | 144 | ### On iOS 145 | 146 | #### Running on a simulator 147 | 148 | To run your application on an iOS simulator in Android Studio, modify the `iosApp` run configuration: 149 | 150 | 1. In the list of run configurations, select **Edit Configurations**: 151 | 152 | 153 | 154 | 2. Navigate to **iOS Application** | **iosApp**. 155 | 3. In the **Execution target** list, select your target device. Click **OK**: 156 | 157 | 158 | 159 | 4. The `iosApp` run configuration is now available. Click **Run** next to your virtual device: 160 | 161 | 162 | 163 | #### Running on a real device 164 | 165 | You can run your Compose Multiplatform application on a real iOS device for free. 166 | To do so, you'll need the following: 167 | 168 | * The `TEAM_ID` associated with your [Apple ID](https://support.apple.com/en-us/HT204316) 169 | * The iOS device registered in Xcode 170 | 171 | > **Note** 172 | > Before you continue, we suggest creating a simple "Hello, world!" project in Xcode to ensure you can successfully run apps on your device. 173 | > You can follow the instructions below or watch this [Stanford CS193P lecture recording](https://youtu.be/bqu6BquVi2M?start=716&end=1399). 174 | 175 |
176 | How to create and run a simple project in Xcode 177 | 178 | 1. On the Xcode welcome screen, select **Create a new project in Xcode**. 179 | 2. On the **iOS** tab, choose the **App** template. Click **Next**. 180 | 3. Specify the product name and keep other settings default. Click **Next**. 181 | 4. Select where to store the project on your computer and click **Create**. You'll see an app that displays "Hello, world!" on the device screen. 182 | 5. At the top of your Xcode screen, click on the device name near the **Run** button. 183 | 6. Plug your device into the computer. You'll see this device in the list of run options. 184 | 7. Choose your device and click **Run**. 185 | 186 |
187 | 188 | ##### Finding your Team ID 189 | 190 | In the terminal, run `kdoctor --team-ids` to find your Team ID. 191 | KDoctor will list all Team IDs currently configured on your system, for example: 192 | 193 | ```text 194 | 3ABC246XYZ (Max Sample) 195 | ZABCW6SXYZ (SampleTech Inc.) 196 | ``` 197 | 198 |
199 | Alternative way to find your Team ID 200 | 201 | If KDoctor doesn't work for you, try this alternative method: 202 | 203 | 1. In Android Studio, run the `iosApp` configuration with the selected real device. The build should fail. 204 | 2. Go to Xcode and select **Open a project or file**. 205 | 3. Navigate to the `iosApp/iosApp.xcworkspace` file of your project. 206 | 4. In the left-hand menu, select `iosApp`. 207 | 5. Navigate to **Signing & Capabilities**. 208 | 6. In the **Team** list, select your team. 209 | 210 | If you haven't set up your team yet, use the **Add account** option and follow the steps. 211 | 212 |
213 | 214 | To run the application, set the `TEAM_ID`: 215 | 216 | 1. In the template, navigate to the `iosApp/Configuration/Config.xcconfig` file. 217 | 2. Set your `TEAM_ID`. 218 | 3. Re-open the project in Android Studio. It should show the registered iOS device in the `iosApp` run configuration. 219 | 220 | ## Make your first changes 221 | 222 | You can now make some changes in the code and check that they are visible in both the iOS and Android applications at the same time: 223 | 224 | 1. In Android Studio, navigate to the `shared/src/commonMain/kotlin/App.kt` file. 225 | This is the common entry point for your Compose Multiplatform app. 226 | 227 | Here, you see the code responsible for rendering the "Hello, World!" button and the animated Compose Multiplatform logo: 228 | 229 | ```kotlin 230 | @OptIn(ExperimentalResourceApi::class) 231 | @Composable 232 | fun App() { 233 | MaterialTheme { 234 | var greetingText by remember { mutableStateOf("Hello, World!") } 235 | var showImage by remember { mutableStateOf(false) } 236 | Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) { 237 | Button(onClick = { 238 | greetingText = "Hello, ${getPlatformName()}" 239 | showImage = !showImage 240 | }) { 241 | Text(greetingText) 242 | } 243 | AnimatedVisibility(showImage) { 244 | Image( 245 | painterResource("compose-multiplatform.xml"), 246 | null 247 | ) 248 | } 249 | } 250 | } 251 | } 252 | ``` 253 | 254 | 2. Update the shared code by adding a text field that will update the name displayed on the button: 255 | 256 | ```diff 257 | @OptIn(ExperimentalResourceApi::class) 258 | @Composable 259 | fun App() { 260 | MaterialTheme { 261 | var greetingText by remember { mutableStateOf("Hello, World!") } 262 | var showImage by remember { mutableStateOf(false) } 263 | Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) { 264 | Button(onClick = { 265 | greetingText = "Hello, ${getPlatformName()}" 266 | showImage = !showImage 267 | }) { 268 | Text(greetingText) 269 | } 270 | + TextField(greetingText, onValueChange = { greetingText = it }) 271 | AnimatedVisibility(showImage) { 272 | Image( 273 | painterResource("compose-multiplatform.xml"), 274 | null 275 | ) 276 | } 277 | } 278 | } 279 | } 280 | ``` 281 | 282 | 3. Re-run both the `androidApp` and `iosApp` configurations. You'll see this change reflected in both the Android and iOS apps: 283 | 284 | 285 | 286 | ## How to configure the iOS application 287 | 288 | To get a better understanding of this template's setup and learn how to configure the basic properties of your iOS app without Xcode, 289 | open the `iosApp/Configuration/Config.xcconfig` file in Android Studio. The configuration file contains: 290 | 291 | * `APP_NAME`, a target executable and an application bundle name. 292 | * `BUNDLE_ID`, which [uniquely identifies the app throughout the system](https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleidentifier#discussion). 293 | * `TEAM_ID`, [a unique identifier generated by Apple that's assigned to your team](https://developer.apple.com/help/account/manage-your-team/locate-your-team-id/#:~:text=A%20Team%20ID%20is%20a,developer%20in%20App%20Store%20Connect). 294 | 295 | To configure the `APP_NAME` option, open `Config.xcconfig` in any text editor *before opening* the project in Android Studio, and then set the desired name. 296 | 297 | If you need to change this option after you open the project in Android Studio, do the following: 298 | 299 | 1. Close the project in Android Studio. 300 | 2. Run `./cleanup.sh` in your terminal. 301 | 3. Change the setting. 302 | 4. Open the project in Android Studio again. 303 | 304 | To configure advanced settings, use Xcode. After opening the project in Android Studio, 305 | open the `iosApp/iosApp.xcworkspace` file in Xcode and make changes there. 306 | 307 | ## Next steps 308 | 309 | We encourage you to explore Compose Multiplatform further and try out more projects: 310 | 311 | * [Learn about other cases for using the Compose Multiplatform UI framework](https://github.com/JetBrains/compose-multiplatform#readme) 312 | * [Create an application targeting Windows, macOS, and Linux with Compose Multiplatform for Desktop](https://github.com/JetBrains/compose-multiplatform-desktop-template#readme) 313 | * [Complete more Compose Multiplatform tutorials](https://github.com/JetBrains/compose-multiplatform/blob/master/tutorials/README.md) 314 | * [Explore some more advanced Compose Multiplatform example projects](https://github.com/JetBrains/compose-multiplatform/blob/master/examples/README.md) 315 | -------------------------------------------------------------------------------- /androidApp/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("multiplatform") 3 | id("com.android.application") 4 | id("org.jetbrains.compose") 5 | } 6 | 7 | kotlin { 8 | androidTarget() 9 | sourceSets { 10 | val androidMain by getting { 11 | dependencies { 12 | implementation(project(":shared")) 13 | } 14 | } 15 | } 16 | } 17 | 18 | android { 19 | compileSdk = (findProperty("android.compileSdk") as String).toInt() 20 | namespace = "com.myapplication" 21 | 22 | sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") 23 | 24 | defaultConfig { 25 | applicationId = "com.myapplication.MyApplication" 26 | minSdk = (findProperty("android.minSdk") as String).toInt() 27 | targetSdk = (findProperty("android.targetSdk") as String).toInt() 28 | versionCode = 1 29 | versionName = "1.0" 30 | } 31 | compileOptions { 32 | sourceCompatibility = JavaVersion.VERSION_11 33 | targetCompatibility = JavaVersion.VERSION_11 34 | } 35 | kotlin { 36 | jvmToolchain(11) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /androidApp/src/androidMain/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 14 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /androidApp/src/androidMain/ic_launcher-playstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/androidApp/src/androidMain/ic_launcher-playstore.png -------------------------------------------------------------------------------- /androidApp/src/androidMain/kotlin/com/myapplication/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.myapplication 2 | 3 | import MainView 4 | import android.content.Context 5 | import android.hardware.Sensor 6 | import android.hardware.SensorEvent 7 | import android.hardware.SensorEventListener 8 | import android.hardware.SensorManager 9 | import android.os.Bundle 10 | import androidx.activity.compose.setContent 11 | import androidx.appcompat.app.AppCompatActivity 12 | import androidx.compose.animation.core.Spring 13 | import androidx.compose.animation.core.animateFloatAsState 14 | import androidx.compose.animation.core.spring 15 | import androidx.compose.foundation.layout.Box 16 | import androidx.compose.foundation.layout.fillMaxSize 17 | import androidx.compose.runtime.getValue 18 | import androidx.compose.runtime.mutableStateOf 19 | import androidx.compose.runtime.setValue 20 | import androidx.compose.ui.Modifier 21 | import androidx.compose.ui.draw.rotate 22 | import kotlin.math.PI 23 | 24 | 25 | class MainActivity : AppCompatActivity(), SensorEventListener { 26 | 27 | private lateinit var sensorManager: SensorManager 28 | private var accelerometer: Sensor? = null 29 | private var magnetometer: Sensor? = null 30 | private var gravity: FloatArray? = null 31 | private var geomagnetic: FloatArray? = null 32 | 33 | private var rotate by mutableStateOf(0f) 34 | 35 | override fun onCreate(savedInstanceState: Bundle?) { 36 | super.onCreate(savedInstanceState) 37 | initSensors() 38 | 39 | setContent { 40 | val animatedRotate by animateFloatAsState( 41 | targetValue = rotate, 42 | animationSpec = spring( 43 | dampingRatio = Spring.DampingRatioHighBouncy, 44 | stiffness = Spring.StiffnessVeryLow 45 | ) 46 | ) 47 | MainView(animatedMainRotate = animatedRotate) 48 | } 49 | } 50 | 51 | 52 | private fun initSensors() { 53 | sensorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager 54 | accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) 55 | magnetometer = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) 56 | 57 | val sensorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager 58 | 59 | val accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY) 60 | val magnetometer = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) 61 | 62 | sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI) 63 | sensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_UI) 64 | } 65 | 66 | override fun onSensorChanged(event: SensorEvent?) { 67 | if (event?.sensor?.type == Sensor.TYPE_GRAVITY) 68 | gravity = event.values 69 | 70 | if (event?.sensor?.type == Sensor.TYPE_MAGNETIC_FIELD) 71 | geomagnetic = event.values 72 | 73 | if (gravity != null && geomagnetic != null) { 74 | val firstArrayOfRotation = FloatArray(9) 75 | val seconArrayOfRotation = FloatArray(9) 76 | val success = SensorManager.getRotationMatrix( 77 | firstArrayOfRotation, 78 | seconArrayOfRotation, 79 | gravity, 80 | geomagnetic 81 | ) 82 | if (success) { 83 | val orientation = FloatArray(3) 84 | SensorManager.getOrientation(firstArrayOfRotation, orientation) 85 | 86 | val pitchInDegrees = (orientation[2] * (180.0 / PI)).toFloat() 87 | 88 | rotate = pitchInDegrees / 10 89 | } 90 | } 91 | } 92 | 93 | 94 | override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) { 95 | // TODO Auto-generated method 96 | } 97 | 98 | } -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /androidApp/src/androidMain/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 | -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/androidApp/src/androidMain/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-hdpi/ic_launcher_foreground.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/androidApp/src/androidMain/res/mipmap-hdpi/ic_launcher_foreground.webp -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/androidApp/src/androidMain/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/androidApp/src/androidMain/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-mdpi/ic_launcher_foreground.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/androidApp/src/androidMain/res/mipmap-mdpi/ic_launcher_foreground.webp -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/androidApp/src/androidMain/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/androidApp/src/androidMain/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-xhdpi/ic_launcher_foreground.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/androidApp/src/androidMain/res/mipmap-xhdpi/ic_launcher_foreground.webp -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/androidApp/src/androidMain/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/androidApp/src/androidMain/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-xxhdpi/ic_launcher_foreground.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/androidApp/src/androidMain/res/mipmap-xxhdpi/ic_launcher_foreground.webp -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/androidApp/src/androidMain/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/androidApp/src/androidMain/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_foreground.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/androidApp/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_foreground.webp -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/androidApp/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/values/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #4285F4 4 | -------------------------------------------------------------------------------- /androidApp/src/androidMain/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | My application 3 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | // this is necessary to avoid the plugins to be loaded multiple times 3 | // in each subproject's classloader 4 | kotlin("multiplatform").apply(false) 5 | id("com.android.application").apply(false) 6 | id("com.android.library").apply(false) 7 | id("org.jetbrains.compose").apply(false) 8 | } 9 | -------------------------------------------------------------------------------- /cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | rm -rf .idea 3 | ./gradlew clean 4 | rm -rf .gradle 5 | rm -rf build 6 | rm -rf */build 7 | rm -rf iosApp/iosApp.xcworkspace 8 | rm -rf iosApp/Pods 9 | rm -rf iosApp/iosApp.xcodeproj/project.xcworkspace 10 | rm -rf iosApp/iosApp.xcodeproj/xcuserdata 11 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | #Gradle 2 | org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M" 3 | 4 | #Kotlin 5 | kotlin.code.style=official 6 | 7 | #MPP 8 | kotlin.mpp.stability.nowarn=true 9 | kotlin.mpp.enableCInteropCommonization=true 10 | kotlin.mpp.androidSourceSetLayoutVersion=2 11 | 12 | #Compose 13 | org.jetbrains.compose.experimental.uikit.enabled=true 14 | kotlin.native.cacheKind=none 15 | 16 | #Android 17 | android.useAndroidX=true 18 | android.compileSdk=33 19 | android.targetSdk=33 20 | android.minSdk=24 21 | 22 | #Versions 23 | kotlin.version=1.9.0 24 | agp.version=7.4.2 25 | compose.version=1.4.3 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original 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 POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Stop when "xargs" is not available. 209 | if ! command -v xargs >/dev/null 2>&1 210 | then 211 | die "xargs is not available" 212 | fi 213 | 214 | # Use "xargs" to parse quoted args. 215 | # 216 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 217 | # 218 | # In Bash we could simply go: 219 | # 220 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 221 | # set -- "${ARGS[@]}" "$@" 222 | # 223 | # but POSIX shell has neither arrays nor command substitution, so instead we 224 | # post-process each arg (as a line of input to sed) to backslash-escape any 225 | # character that might be a shell metacharacter, then use eval to reverse 226 | # that process (while maintaining the separation between arguments), and wrap 227 | # the whole thing up as a single "set" statement. 228 | # 229 | # This will of course break if any of these variables contains a newline or 230 | # an unmatched quote. 231 | # 232 | 233 | eval "set -- $( 234 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 235 | xargs -n1 | 236 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 237 | tr '\n' ' ' 238 | )" '"$@"' 239 | 240 | exec "$JAVACMD" "$@" 241 | -------------------------------------------------------------------------------- /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% equ 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% equ 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 | set EXIT_CODE=%ERRORLEVEL% 84 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 85 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 86 | exit /b %EXIT_CODE% 87 | 88 | :mainEnd 89 | if "%OS%"=="Windows_NT" endlocal 90 | 91 | :omega 92 | -------------------------------------------------------------------------------- /iosApp/Configuration/Config.xcconfig: -------------------------------------------------------------------------------- 1 | TEAM_ID= 2 | BUNDLE_ID=com.myapplication.MyApplication 3 | APP_NAME=My application 4 | -------------------------------------------------------------------------------- /iosApp/Podfile: -------------------------------------------------------------------------------- 1 | target 'iosApp' do 2 | use_frameworks! 3 | platform :ios, '14.1' 4 | pod 'shared', :path => '../shared' 5 | end -------------------------------------------------------------------------------- /iosApp/iosApp.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 51; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557BA273AAA24004C7B11 /* Assets.xcassets */; }; 11 | 058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */; }; 12 | 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iOSApp.swift */; }; 13 | 7555FF83242A565900829871 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* ContentView.swift */; }; 14 | CFDB58B53BB94DE262B13C24 /* Pods_iosApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B1049432C0C2B312090ABF6 /* Pods_iosApp.framework */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | 058557BA273AAA24004C7B11 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 19 | 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 20 | 2152FB032600AC8F00CF470E /* iOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSApp.swift; sourceTree = ""; }; 21 | 4FF3202A603A284706412EDC /* Pods-iosApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iosApp.debug.xcconfig"; path = "Target Support Files/Pods-iosApp/Pods-iosApp.debug.xcconfig"; sourceTree = ""; }; 22 | 6B1049432C0C2B312090ABF6 /* Pods_iosApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_iosApp.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | 7555FF7B242A565900829871 /* My application.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "My application.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 7555FF82242A565900829871 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 25 | 7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | AB3632DC29227652001CCB65 /* Config.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = ""; }; 27 | FF8CA3F5360CEAB49D74065F /* Pods-iosApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iosApp.release.xcconfig"; path = "Target Support Files/Pods-iosApp/Pods-iosApp.release.xcconfig"; sourceTree = ""; }; 28 | /* End PBXFileReference section */ 29 | 30 | /* Begin PBXFrameworksBuildPhase section */ 31 | F85CB1118929364A9C6EFABC /* Frameworks */ = { 32 | isa = PBXFrameworksBuildPhase; 33 | buildActionMask = 2147483647; 34 | files = ( 35 | CFDB58B53BB94DE262B13C24 /* Pods_iosApp.framework in Frameworks */, 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 058557D7273AAEEB004C7B11 /* Preview Content */ = { 43 | isa = PBXGroup; 44 | children = ( 45 | 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */, 46 | ); 47 | path = "Preview Content"; 48 | sourceTree = ""; 49 | }; 50 | 42799AB246E5F90AF97AA0EF /* Frameworks */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 6B1049432C0C2B312090ABF6 /* Pods_iosApp.framework */, 54 | ); 55 | name = Frameworks; 56 | sourceTree = ""; 57 | }; 58 | 7555FF72242A565900829871 = { 59 | isa = PBXGroup; 60 | children = ( 61 | AB1DB47929225F7C00F7AF9C /* Configuration */, 62 | 7555FF7D242A565900829871 /* iosApp */, 63 | 7555FF7C242A565900829871 /* Products */, 64 | FEFF387C0A8D172AA4D59CAE /* Pods */, 65 | 42799AB246E5F90AF97AA0EF /* Frameworks */, 66 | ); 67 | sourceTree = ""; 68 | }; 69 | 7555FF7C242A565900829871 /* Products */ = { 70 | isa = PBXGroup; 71 | children = ( 72 | 7555FF7B242A565900829871 /* My application.app */, 73 | ); 74 | name = Products; 75 | sourceTree = ""; 76 | }; 77 | 7555FF7D242A565900829871 /* iosApp */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | 058557BA273AAA24004C7B11 /* Assets.xcassets */, 81 | 7555FF82242A565900829871 /* ContentView.swift */, 82 | 7555FF8C242A565B00829871 /* Info.plist */, 83 | 2152FB032600AC8F00CF470E /* iOSApp.swift */, 84 | 058557D7273AAEEB004C7B11 /* Preview Content */, 85 | ); 86 | path = iosApp; 87 | sourceTree = ""; 88 | }; 89 | AB1DB47929225F7C00F7AF9C /* Configuration */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | AB3632DC29227652001CCB65 /* Config.xcconfig */, 93 | ); 94 | path = Configuration; 95 | sourceTree = ""; 96 | }; 97 | FEFF387C0A8D172AA4D59CAE /* Pods */ = { 98 | isa = PBXGroup; 99 | children = ( 100 | 4FF3202A603A284706412EDC /* Pods-iosApp.debug.xcconfig */, 101 | FF8CA3F5360CEAB49D74065F /* Pods-iosApp.release.xcconfig */, 102 | ); 103 | path = Pods; 104 | sourceTree = ""; 105 | }; 106 | /* End PBXGroup section */ 107 | 108 | /* Begin PBXNativeTarget section */ 109 | 7555FF7A242A565900829871 /* iosApp */ = { 110 | isa = PBXNativeTarget; 111 | buildConfigurationList = 7555FFA5242A565B00829871 /* Build configuration list for PBXNativeTarget "iosApp" */; 112 | buildPhases = ( 113 | 98D614C51D2DA07C614CC46E /* [CP] Check Pods Manifest.lock */, 114 | 7555FF77242A565900829871 /* Sources */, 115 | 7555FF79242A565900829871 /* Resources */, 116 | F85CB1118929364A9C6EFABC /* Frameworks */, 117 | 2134C13603D0B299603D9F49 /* [CP] Copy Pods Resources */, 118 | ); 119 | buildRules = ( 120 | ); 121 | dependencies = ( 122 | ); 123 | name = iosApp; 124 | productName = iosApp; 125 | productReference = 7555FF7B242A565900829871 /* My application.app */; 126 | productType = "com.apple.product-type.application"; 127 | }; 128 | /* End PBXNativeTarget section */ 129 | 130 | /* Begin PBXProject section */ 131 | 7555FF73242A565900829871 /* Project object */ = { 132 | isa = PBXProject; 133 | attributes = { 134 | LastSwiftUpdateCheck = 1130; 135 | LastUpgradeCheck = 1130; 136 | ORGANIZATIONNAME = orgName; 137 | TargetAttributes = { 138 | 7555FF7A242A565900829871 = { 139 | CreatedOnToolsVersion = 11.3.1; 140 | }; 141 | }; 142 | }; 143 | buildConfigurationList = 7555FF76242A565900829871 /* Build configuration list for PBXProject "iosApp" */; 144 | compatibilityVersion = "Xcode 9.3"; 145 | developmentRegion = en; 146 | hasScannedForEncodings = 0; 147 | knownRegions = ( 148 | en, 149 | Base, 150 | ); 151 | mainGroup = 7555FF72242A565900829871; 152 | productRefGroup = 7555FF7C242A565900829871 /* Products */; 153 | projectDirPath = ""; 154 | projectRoot = ""; 155 | targets = ( 156 | 7555FF7A242A565900829871 /* iosApp */, 157 | ); 158 | }; 159 | /* End PBXProject section */ 160 | 161 | /* Begin PBXResourcesBuildPhase section */ 162 | 7555FF79242A565900829871 /* Resources */ = { 163 | isa = PBXResourcesBuildPhase; 164 | buildActionMask = 2147483647; 165 | files = ( 166 | 058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */, 167 | 058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */, 168 | ); 169 | runOnlyForDeploymentPostprocessing = 0; 170 | }; 171 | /* End PBXResourcesBuildPhase section */ 172 | 173 | /* Begin PBXShellScriptBuildPhase section */ 174 | 2134C13603D0B299603D9F49 /* [CP] Copy Pods Resources */ = { 175 | isa = PBXShellScriptBuildPhase; 176 | buildActionMask = 2147483647; 177 | files = ( 178 | ); 179 | inputFileListPaths = ( 180 | "${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-input-files.xcfilelist", 181 | ); 182 | name = "[CP] Copy Pods Resources"; 183 | outputFileListPaths = ( 184 | "${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-output-files.xcfilelist", 185 | ); 186 | runOnlyForDeploymentPostprocessing = 0; 187 | shellPath = /bin/sh; 188 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources.sh\"\n"; 189 | showEnvVarsInLog = 0; 190 | }; 191 | 98D614C51D2DA07C614CC46E /* [CP] Check Pods Manifest.lock */ = { 192 | isa = PBXShellScriptBuildPhase; 193 | buildActionMask = 2147483647; 194 | files = ( 195 | ); 196 | inputFileListPaths = ( 197 | ); 198 | inputPaths = ( 199 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 200 | "${PODS_ROOT}/Manifest.lock", 201 | ); 202 | name = "[CP] Check Pods Manifest.lock"; 203 | outputFileListPaths = ( 204 | ); 205 | outputPaths = ( 206 | "$(DERIVED_FILE_DIR)/Pods-iosApp-checkManifestLockResult.txt", 207 | ); 208 | runOnlyForDeploymentPostprocessing = 0; 209 | shellPath = /bin/sh; 210 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 211 | showEnvVarsInLog = 0; 212 | }; 213 | /* End PBXShellScriptBuildPhase section */ 214 | 215 | /* Begin PBXSourcesBuildPhase section */ 216 | 7555FF77242A565900829871 /* Sources */ = { 217 | isa = PBXSourcesBuildPhase; 218 | buildActionMask = 2147483647; 219 | files = ( 220 | 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */, 221 | 7555FF83242A565900829871 /* ContentView.swift in Sources */, 222 | ); 223 | runOnlyForDeploymentPostprocessing = 0; 224 | }; 225 | /* End PBXSourcesBuildPhase section */ 226 | 227 | /* Begin XCBuildConfiguration section */ 228 | 7555FFA3242A565B00829871 /* Debug */ = { 229 | isa = XCBuildConfiguration; 230 | baseConfigurationReference = AB3632DC29227652001CCB65 /* Config.xcconfig */; 231 | buildSettings = { 232 | ALWAYS_SEARCH_USER_PATHS = NO; 233 | CLANG_ANALYZER_NONNULL = YES; 234 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 235 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 236 | CLANG_CXX_LIBRARY = "libc++"; 237 | CLANG_ENABLE_MODULES = YES; 238 | CLANG_ENABLE_OBJC_ARC = YES; 239 | CLANG_ENABLE_OBJC_WEAK = YES; 240 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 241 | CLANG_WARN_BOOL_CONVERSION = YES; 242 | CLANG_WARN_COMMA = YES; 243 | CLANG_WARN_CONSTANT_CONVERSION = YES; 244 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 245 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 246 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 247 | CLANG_WARN_EMPTY_BODY = YES; 248 | CLANG_WARN_ENUM_CONVERSION = YES; 249 | CLANG_WARN_INFINITE_RECURSION = YES; 250 | CLANG_WARN_INT_CONVERSION = YES; 251 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 252 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 253 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 254 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 255 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 256 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 257 | CLANG_WARN_STRICT_PROTOTYPES = YES; 258 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 259 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 260 | CLANG_WARN_UNREACHABLE_CODE = YES; 261 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 262 | COPY_PHASE_STRIP = NO; 263 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 264 | ENABLE_STRICT_OBJC_MSGSEND = YES; 265 | ENABLE_TESTABILITY = YES; 266 | GCC_C_LANGUAGE_STANDARD = gnu11; 267 | GCC_DYNAMIC_NO_PIC = NO; 268 | GCC_NO_COMMON_BLOCKS = YES; 269 | GCC_OPTIMIZATION_LEVEL = 0; 270 | GCC_PREPROCESSOR_DEFINITIONS = ( 271 | "DEBUG=1", 272 | "$(inherited)", 273 | ); 274 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 275 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 276 | GCC_WARN_UNDECLARED_SELECTOR = YES; 277 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 278 | GCC_WARN_UNUSED_FUNCTION = YES; 279 | GCC_WARN_UNUSED_VARIABLE = YES; 280 | IPHONEOS_DEPLOYMENT_TARGET = 14.1; 281 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 282 | MTL_FAST_MATH = YES; 283 | ONLY_ACTIVE_ARCH = YES; 284 | SDKROOT = iphoneos; 285 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 286 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 287 | }; 288 | name = Debug; 289 | }; 290 | 7555FFA4242A565B00829871 /* Release */ = { 291 | isa = XCBuildConfiguration; 292 | baseConfigurationReference = AB3632DC29227652001CCB65 /* Config.xcconfig */; 293 | buildSettings = { 294 | ALWAYS_SEARCH_USER_PATHS = NO; 295 | CLANG_ANALYZER_NONNULL = YES; 296 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 297 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 298 | CLANG_CXX_LIBRARY = "libc++"; 299 | CLANG_ENABLE_MODULES = YES; 300 | CLANG_ENABLE_OBJC_ARC = YES; 301 | CLANG_ENABLE_OBJC_WEAK = YES; 302 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 303 | CLANG_WARN_BOOL_CONVERSION = YES; 304 | CLANG_WARN_COMMA = YES; 305 | CLANG_WARN_CONSTANT_CONVERSION = YES; 306 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 307 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 308 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 309 | CLANG_WARN_EMPTY_BODY = YES; 310 | CLANG_WARN_ENUM_CONVERSION = YES; 311 | CLANG_WARN_INFINITE_RECURSION = YES; 312 | CLANG_WARN_INT_CONVERSION = YES; 313 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 314 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 315 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 316 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 317 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 318 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 319 | CLANG_WARN_STRICT_PROTOTYPES = YES; 320 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 321 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 322 | CLANG_WARN_UNREACHABLE_CODE = YES; 323 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 324 | COPY_PHASE_STRIP = NO; 325 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 326 | ENABLE_NS_ASSERTIONS = NO; 327 | ENABLE_STRICT_OBJC_MSGSEND = YES; 328 | GCC_C_LANGUAGE_STANDARD = gnu11; 329 | GCC_NO_COMMON_BLOCKS = YES; 330 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 331 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 332 | GCC_WARN_UNDECLARED_SELECTOR = YES; 333 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 334 | GCC_WARN_UNUSED_FUNCTION = YES; 335 | GCC_WARN_UNUSED_VARIABLE = YES; 336 | IPHONEOS_DEPLOYMENT_TARGET = 14.1; 337 | MTL_ENABLE_DEBUG_INFO = NO; 338 | MTL_FAST_MATH = YES; 339 | SDKROOT = iphoneos; 340 | SWIFT_COMPILATION_MODE = wholemodule; 341 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 342 | VALIDATE_PRODUCT = YES; 343 | }; 344 | name = Release; 345 | }; 346 | 7555FFA6242A565B00829871 /* Debug */ = { 347 | isa = XCBuildConfiguration; 348 | baseConfigurationReference = 4FF3202A603A284706412EDC /* Pods-iosApp.debug.xcconfig */; 349 | buildSettings = { 350 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 351 | CODE_SIGN_IDENTITY = "Apple Development"; 352 | CODE_SIGN_STYLE = Automatic; 353 | DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\""; 354 | DEVELOPMENT_TEAM = D2APWWKF9L; 355 | ENABLE_PREVIEWS = YES; 356 | INFOPLIST_FILE = iosApp/Info.plist; 357 | IPHONEOS_DEPLOYMENT_TARGET = 14.1; 358 | LD_RUNPATH_SEARCH_PATHS = ( 359 | "$(inherited)", 360 | "@executable_path/Frameworks", 361 | ); 362 | PRODUCT_BUNDLE_IDENTIFIER = com.kmpsensors; 363 | PRODUCT_NAME = "${APP_NAME}"; 364 | PROVISIONING_PROFILE_SPECIFIER = ""; 365 | SWIFT_VERSION = 5.0; 366 | TARGETED_DEVICE_FAMILY = "1,2"; 367 | }; 368 | name = Debug; 369 | }; 370 | 7555FFA7242A565B00829871 /* Release */ = { 371 | isa = XCBuildConfiguration; 372 | baseConfigurationReference = FF8CA3F5360CEAB49D74065F /* Pods-iosApp.release.xcconfig */; 373 | buildSettings = { 374 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 375 | CODE_SIGN_IDENTITY = "Apple Development"; 376 | CODE_SIGN_STYLE = Automatic; 377 | DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\""; 378 | DEVELOPMENT_TEAM = D2APWWKF9L; 379 | ENABLE_PREVIEWS = YES; 380 | INFOPLIST_FILE = iosApp/Info.plist; 381 | IPHONEOS_DEPLOYMENT_TARGET = 14.1; 382 | LD_RUNPATH_SEARCH_PATHS = ( 383 | "$(inherited)", 384 | "@executable_path/Frameworks", 385 | ); 386 | PRODUCT_BUNDLE_IDENTIFIER = com.kmpsensors; 387 | PRODUCT_NAME = "${APP_NAME}"; 388 | PROVISIONING_PROFILE_SPECIFIER = ""; 389 | SWIFT_VERSION = 5.0; 390 | TARGETED_DEVICE_FAMILY = "1,2"; 391 | }; 392 | name = Release; 393 | }; 394 | /* End XCBuildConfiguration section */ 395 | 396 | /* Begin XCConfigurationList section */ 397 | 7555FF76242A565900829871 /* Build configuration list for PBXProject "iosApp" */ = { 398 | isa = XCConfigurationList; 399 | buildConfigurations = ( 400 | 7555FFA3242A565B00829871 /* Debug */, 401 | 7555FFA4242A565B00829871 /* Release */, 402 | ); 403 | defaultConfigurationIsVisible = 0; 404 | defaultConfigurationName = Release; 405 | }; 406 | 7555FFA5242A565B00829871 /* Build configuration list for PBXNativeTarget "iosApp" */ = { 407 | isa = XCConfigurationList; 408 | buildConfigurations = ( 409 | 7555FFA6242A565B00829871 /* Debug */, 410 | 7555FFA7242A565B00829871 /* Release */, 411 | ); 412 | defaultConfigurationIsVisible = 0; 413 | defaultConfigurationName = Release; 414 | }; 415 | /* End XCConfigurationList section */ 416 | }; 417 | rootObject = 7555FF73242A565900829871 /* Project object */; 418 | } 419 | -------------------------------------------------------------------------------- /iosApp/iosApp/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } -------------------------------------------------------------------------------- /iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "app-icon-1024.png", 5 | "idiom" : "universal", 6 | "platform" : "ios", 7 | "size" : "1024x1024" 8 | } 9 | ], 10 | "info" : { 11 | "author" : "xcode", 12 | "version" : 1 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/app-icon-1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/app-icon-1024.png -------------------------------------------------------------------------------- /iosApp/iosApp/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /iosApp/iosApp/ContentView.swift: -------------------------------------------------------------------------------- 1 | 2 | import SwiftUI 3 | import shared 4 | import CoreMotion 5 | import Combine 6 | 7 | 8 | 9 | struct ComposeView: UIViewControllerRepresentable { 10 | 11 | func makeUIViewController(context: Context) -> UIViewController { 12 | let mainViewController = Main_iosKt.MainViewController() 13 | 14 | let motionManager = MotionManager() 15 | motionManager.startUpdates() 16 | return mainViewController 17 | } 18 | 19 | func updateUIViewController(_ uiViewController: UIViewController, context: Context) {} 20 | } 21 | 22 | struct ContentView: View { 23 | var body: some View { 24 | ComposeView() 25 | .ignoresSafeArea(.all, edges: .bottom) // Compose has own keyboard handler 26 | } 27 | } 28 | 29 | 30 | 31 | class MotionManager: ObservableObject { 32 | private let motionManager = CMMotionManager() 33 | private var cancellables: Set = [] 34 | 35 | @Published var motionData: (acceleration: CMAcceleration, rotationRate: CMRotationRate) = (.init(x: 0, y: 0, z: 0), .init(x: 0, y: 0, z: 0)) 36 | 37 | @Published var rollAngle: Double = 0.0 38 | @Published var pitchAngle: Double = 0.0 39 | 40 | init() { 41 | motionPublisher 42 | .receive(on: DispatchQueue.main) 43 | .assign(to: \.motionData, on: self) 44 | .store(in: &cancellables) 45 | } 46 | 47 | func startUpdates() { 48 | motionManager.startAccelerometerUpdates() 49 | motionManager.startGyroUpdates() 50 | 51 | Timer.publish(every: 0.1, on: .main, in: .default) 52 | .autoconnect() 53 | .sink { [weak self] _ in 54 | guard let self = self else { return } 55 | 56 | if let accelerometerData = self.motionManager.accelerometerData { 57 | let acceleration = accelerometerData.acceleration 58 | if let gyroData = self.motionManager.gyroData { 59 | let rotationRate = gyroData.rotationRate 60 | let motionData = (acceleration: acceleration, rotationRate: rotationRate) 61 | self.motionPublisher.send(motionData) 62 | 63 | let rollAngle = atan2(acceleration.x, acceleration.z) 64 | self.rollAngle = rollAngle * 180 / .pi // Converter to degrees 65 | // print("rollAngle: \(self.rollAngle)") 66 | 67 | if self.rollAngle > 20.0 { 68 | print("Celular foi virado para a direita") 69 | } else if self.rollAngle < -20.0 { 70 | print("Celular foi virado para a esquerda") 71 | } 72 | 73 | let pitchAngle = atan2(acceleration.y, acceleration.z) 74 | self.pitchAngle = pitchAngle * 180 / .pi // Converter to degrees 75 | // print("pitchAngle: \(self.pitchAngle)") 76 | } 77 | } 78 | } 79 | .store(in: &cancellables) 80 | } 81 | 82 | func stopUpdates() { 83 | motionManager.stopAccelerometerUpdates() 84 | motionManager.stopGyroUpdates() 85 | cancellables.forEach { $0.cancel() } 86 | } 87 | 88 | var motionPublisher: PassthroughSubject<(acceleration: CMAcceleration, rotationRate: CMRotationRate), Never> = PassthroughSubject() 89 | } -------------------------------------------------------------------------------- /iosApp/iosApp/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CADisableMinimumFrameDurationOnPhone 6 | 7 | CFBundleDevelopmentRegion 8 | $(DEVELOPMENT_LANGUAGE) 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UIApplicationSceneManifest 26 | 27 | UIApplicationSupportsMultipleScenes 28 | 29 | 30 | UILaunchScreen 31 | 32 | UIRequiredDeviceCapabilities 33 | 34 | armv7 35 | 36 | UISupportedInterfaceOrientations 37 | 38 | UIInterfaceOrientationPortrait 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UISupportedInterfaceOrientations~ipad 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationPortraitUpsideDown 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /iosApp/iosApp/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } -------------------------------------------------------------------------------- /iosApp/iosApp/iOSApp.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | @main 4 | struct iOSApp: App { 5 | var body: some Scene { 6 | WindowGroup { 7 | ZStack { 8 | Color.white.ignoresSafeArea(.all) // status bar color 9 | ContentView() 10 | }.preferredColorScheme(.light) 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /readme_images/android_app_running.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/readme_images/android_app_running.png -------------------------------------------------------------------------------- /readme_images/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/readme_images/banner.png -------------------------------------------------------------------------------- /readme_images/edit_run_config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/readme_images/edit_run_config.png -------------------------------------------------------------------------------- /readme_images/hello_world_ios.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/readme_images/hello_world_ios.png -------------------------------------------------------------------------------- /readme_images/open_project_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/readme_images/open_project_view.png -------------------------------------------------------------------------------- /readme_images/run_on_android.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/readme_images/run_on_android.png -------------------------------------------------------------------------------- /readme_images/target_device.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/readme_images/target_device.png -------------------------------------------------------------------------------- /readme_images/text_field_added.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-jr/KMPSensors/21601f80537723a7da7225603241bf0a4eb3b159/readme_images/text_field_added.png -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "ComposeSensors" 2 | 3 | include(":androidApp") 4 | include(":shared") 5 | 6 | pluginManagement { 7 | repositories { 8 | gradlePluginPortal() 9 | maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") 10 | google() 11 | } 12 | 13 | plugins { 14 | val kotlinVersion = extra["kotlin.version"] as String 15 | val agpVersion = extra["agp.version"] as String 16 | val composeVersion = extra["compose.version"] as String 17 | 18 | kotlin("jvm").version(kotlinVersion) 19 | kotlin("multiplatform").version(kotlinVersion) 20 | kotlin("android").version(kotlinVersion) 21 | 22 | id("com.android.application").version(agpVersion) 23 | id("com.android.library").version(agpVersion) 24 | 25 | id("org.jetbrains.compose").version(composeVersion) 26 | } 27 | } 28 | 29 | dependencyResolutionManagement { 30 | repositories { 31 | google() 32 | mavenCentral() 33 | maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /shared/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("multiplatform") 3 | kotlin("native.cocoapods") 4 | id("com.android.library") 5 | id("org.jetbrains.compose") 6 | kotlin("plugin.serialization") version "1.9.0" 7 | } 8 | 9 | kotlin { 10 | androidTarget() 11 | 12 | iosX64() 13 | iosArm64() 14 | iosSimulatorArm64() 15 | 16 | cocoapods { 17 | version = "1.0.0" 18 | summary = "Some description for the Shared Module" 19 | homepage = "Link to the Shared Module homepage" 20 | ios.deploymentTarget = "14.1" 21 | podfile = project.file("../iosApp/Podfile") 22 | framework { 23 | baseName = "shared" 24 | isStatic = true 25 | } 26 | extraSpecAttributes["resources"] = 27 | "['src/commonMain/resources/**', 'src/iosMain/resources/**']" 28 | } 29 | 30 | sourceSets { 31 | val ktorVersion = "2.3.3" 32 | 33 | val commonMain by getting { 34 | dependencies { 35 | implementation(compose.runtime) 36 | implementation(compose.foundation) 37 | implementation(compose.material) 38 | implementation(compose.material3) 39 | @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class) 40 | implementation(compose.components.resources) 41 | implementation("media.kamel:kamel-image:0.7.1") 42 | implementation("io.ktor:ktor-client-core:$ktorVersion") 43 | implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion") 44 | implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion") 45 | implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1") 46 | api("dev.icerock.moko:mvvm-core:0.16.1") // only ViewModel, EventsDispatcher, Dispatchers.UI 47 | api("dev.icerock.moko:mvvm-compose:0.16.1") // api mvvm-core, getViewModel for Compose Multiplatfrom 48 | implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0") 49 | } 50 | } 51 | val androidMain by getting { 52 | dependencies { 53 | api("androidx.activity:activity-compose:1.7.2") 54 | api("androidx.appcompat:appcompat:1.6.1") 55 | api("androidx.core:core-ktx:1.10.1") 56 | // if foudation is updated to 1.5.0, then the app crashes 57 | api("androidx.compose.foundation:foundation:1.4.3") 58 | 59 | implementation("io.ktor:ktor-client-android:$ktorVersion") 60 | } 61 | } 62 | val iosX64Main by getting 63 | val iosArm64Main by getting 64 | val iosSimulatorArm64Main by getting 65 | val iosMain by creating { 66 | dependsOn(commonMain) 67 | iosX64Main.dependsOn(this) 68 | iosArm64Main.dependsOn(this) 69 | iosSimulatorArm64Main.dependsOn(this) 70 | 71 | dependencies { 72 | implementation("io.ktor:ktor-client-darwin:$ktorVersion") 73 | } 74 | } 75 | } 76 | } 77 | 78 | android { 79 | compileSdk = (findProperty("android.compileSdk") as String).toInt() 80 | namespace = "com.myapplication.common" 81 | 82 | sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") 83 | sourceSets["main"].res.srcDirs("src/androidMain/res") 84 | sourceSets["main"].resources.srcDirs("src/commonMain/resources") 85 | 86 | defaultConfig { 87 | minSdk = (findProperty("android.minSdk") as String).toInt() 88 | targetSdk = (findProperty("android.targetSdk") as String).toInt() 89 | } 90 | compileOptions { 91 | sourceCompatibility = JavaVersion.VERSION_18 92 | targetCompatibility = JavaVersion.VERSION_18 93 | } 94 | kotlin { 95 | jvmToolchain(18) 96 | } 97 | } -------------------------------------------------------------------------------- /shared/src/androidMain/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /shared/src/androidMain/kotlin/main.android.kt: -------------------------------------------------------------------------------- 1 | import androidx.compose.runtime.Composable 2 | 3 | actual fun getPlatformName(): String = "Android" 4 | 5 | @Composable 6 | fun MainView(animatedMainRotate: Float) = App(animatedMainRotate) 7 | -------------------------------------------------------------------------------- /shared/src/commonMain/kotlin/App.kt: -------------------------------------------------------------------------------- 1 | import androidx.compose.material.MaterialTheme 2 | import androidx.compose.runtime.Composable 3 | import androidx.compose.runtime.collectAsState 4 | import androidx.compose.runtime.getValue 5 | import dev.icerock.moko.mvvm.compose.getViewModel 6 | import dev.icerock.moko.mvvm.compose.viewModelFactory 7 | import ui.home.HomeScreen 8 | import ui.home.LoginScreen 9 | import ui.home.ViewModel 10 | 11 | 12 | @Composable 13 | fun App(animatedMainRotate: Float = 0f) { 14 | MaterialTheme { 15 | val viewModel = getViewModel(Unit, viewModelFactory { ViewModel() }) 16 | val state by viewModel.profileUiState.collectAsState() 17 | 18 | if (state.apiUrl.isNotEmpty()) { 19 | HomeScreen(viewModel, animatedMainRotate = animatedMainRotate) 20 | } else { 21 | LoginScreen(onLogin = { apiUrl -> 22 | viewModel.updateApiUrl(apiUrl) 23 | }) 24 | } 25 | } 26 | } 27 | 28 | 29 | expect fun getPlatformName(): String -------------------------------------------------------------------------------- /shared/src/commonMain/kotlin/extensions/LongExtensions.kt: -------------------------------------------------------------------------------- 1 | package extensions 2 | 3 | import kotlinx.datetime.Instant 4 | import kotlinx.datetime.TimeZone 5 | import kotlinx.datetime.toLocalDateTime 6 | 7 | fun Long.timestampToDisplayDate(): String { 8 | 9 | // coverting a data like "1629780000000" (alura api pattern) to "23/08/2021 às 16:00" 10 | val dateTime = 11 | Instant.fromEpochMilliseconds(this).toLocalDateTime(TimeZone.currentSystemDefault()) 12 | return "${dateTime.dayOfMonth.toString().padStart(2, '0')}/${ 13 | dateTime.monthNumber.toString().padStart(2, '0') 14 | }/${dateTime.year} às ${dateTime.hour.toString().padStart(2, '0')}:${ 15 | dateTime.minute.toString().padStart(2, '0') 16 | }" 17 | } -------------------------------------------------------------------------------- /shared/src/commonMain/kotlin/extensions/ModifierExtensions.kt: -------------------------------------------------------------------------------- 1 | package extensions 2 | 3 | import androidx.compose.foundation.clickable 4 | import androidx.compose.foundation.interaction.MutableInteractionSource 5 | import androidx.compose.runtime.remember 6 | import androidx.compose.ui.Modifier 7 | import androidx.compose.ui.composed 8 | 9 | fun Modifier.noRippleClickable(onClick: () -> Unit): Modifier = composed { 10 | clickable(indication = null, 11 | interactionSource = remember { MutableInteractionSource() }) { 12 | onClick() 13 | } 14 | } -------------------------------------------------------------------------------- /shared/src/commonMain/kotlin/extensions/StringExtensions.kt: -------------------------------------------------------------------------------- 1 | package extensions 2 | 3 | import androidx.compose.ui.graphics.Color 4 | 5 | fun String.hexToRgbColor(): Color { 6 | require(this[0] == '#') { "A valid color value starts with a '#'" } 7 | 8 | if (length != 7 || this[0] != '#') { 9 | return Color.Black.copy(0.5f) 10 | } 11 | 12 | val r = substring(1, 3).toInt(16) 13 | val g = substring(3, 5).toInt(16) 14 | val b = substring(5, 7).toInt(16) 15 | 16 | return Color(r, g, b) 17 | } -------------------------------------------------------------------------------- /shared/src/commonMain/kotlin/model/CourseProgresse.kt: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | @Serializable 6 | data class CourseProgresse( 7 | val finished: Boolean, 8 | val id: Int, 9 | val lastAccessTime: Long, 10 | val name: String, 11 | val progress: Int, 12 | val readyToFinish: Boolean, 13 | val slug: String 14 | ) -------------------------------------------------------------------------------- /shared/src/commonMain/kotlin/model/Guide.kt: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | @Serializable 6 | data class Guide( 7 | val author: String, 8 | val code: String, 9 | val color: String, 10 | val finishedCourses: Int, 11 | val finishedSteps: Int, 12 | val id: Int, 13 | val kind: String, 14 | val lastAccessTime: Long, 15 | val name: String, 16 | val totalCourses: Int, 17 | val totalSteps: Int, 18 | val url: String 19 | ) -------------------------------------------------------------------------------- /shared/src/commonMain/kotlin/model/Profile.kt: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | @Serializable 6 | data class Profile( 7 | val courseProgresses: List = emptyList(), 8 | val guides: List = emptyList(), 9 | val id: Int = 0, 10 | ) -------------------------------------------------------------------------------- /shared/src/commonMain/kotlin/ui/home/HomeScreen.kt: -------------------------------------------------------------------------------- 1 | package ui.home 2 | 3 | import androidx.compose.animation.core.Spring 4 | import androidx.compose.animation.core.animateFloatAsState 5 | import androidx.compose.animation.core.spring 6 | import androidx.compose.foundation.Canvas 7 | import androidx.compose.foundation.layout.Arrangement 8 | import androidx.compose.foundation.layout.Box 9 | import androidx.compose.foundation.layout.Column 10 | import androidx.compose.foundation.layout.fillMaxSize 11 | import androidx.compose.foundation.layout.offset 12 | import androidx.compose.foundation.layout.size 13 | import androidx.compose.runtime.Composable 14 | import androidx.compose.runtime.LaunchedEffect 15 | import androidx.compose.runtime.collectAsState 16 | import androidx.compose.runtime.getValue 17 | import androidx.compose.runtime.mutableStateOf 18 | import androidx.compose.runtime.remember 19 | import androidx.compose.runtime.rememberCoroutineScope 20 | import androidx.compose.runtime.setValue 21 | import androidx.compose.ui.Alignment 22 | import androidx.compose.ui.Modifier 23 | import androidx.compose.ui.draw.alpha 24 | import androidx.compose.ui.draw.rotate 25 | import androidx.compose.ui.graphics.Color 26 | import androidx.compose.ui.graphics.Path 27 | import androidx.compose.ui.graphics.drawscope.Fill 28 | import androidx.compose.ui.unit.dp 29 | import kotlinx.coroutines.delay 30 | import kotlinx.coroutines.launch 31 | import ui.tabs.TabScreen 32 | 33 | private var horizontalPagerInAction by mutableStateOf(false) 34 | private var valueToBeChangedOnTheLeft by mutableStateOf(3f) 35 | private var valueToBeChangedOnTheRight by mutableStateOf(3f) 36 | private var rotate by mutableStateOf(0f) 37 | 38 | 39 | @Composable 40 | fun HomeScreen( 41 | viewModel: ViewModel, 42 | animatedMainRotate: Float = 0f 43 | ) { 44 | val state by viewModel.profileUiState.collectAsState() 45 | val scope = rememberCoroutineScope() 46 | 47 | Box( 48 | Modifier 49 | .fillMaxSize(), 50 | contentAlignment = Alignment.BottomCenter 51 | ) { 52 | var offsetWave by remember { mutableStateOf(0f) } 53 | 54 | LaunchedEffect(offsetWave) { 55 | // using "when" instead of "if" because can be util to add more animations 56 | when (offsetWave) { 57 | 0f -> { 58 | // when offset is 0 (list is in its ideal point), give a little move on the wave 59 | rotate += 2 60 | delay(800) 61 | rotate = 0f 62 | } 63 | } 64 | } 65 | 66 | Wave( 67 | modifier = Modifier 68 | .alpha(0.5f) 69 | .offset(y = -(offsetWave.dp) / 10) // smooth slide with paralax effect on the wave 70 | ) 71 | 72 | TabScreen( 73 | modifier = Modifier, 74 | state = state, 75 | animatedMainRotate = animatedMainRotate, 76 | onScroll = { 77 | offsetWave = it.toFloat() 78 | }, 79 | hasMovedToLeft = { 80 | horizontalPagerInAction = true 81 | scope.launch { 82 | val originalValeuLeft = valueToBeChangedOnTheLeft 83 | val originalValeuRight = valueToBeChangedOnTheRight 84 | val targetValeuLeft = originalValeuLeft * 4f 85 | val targetValeuRight = originalValeuRight / 2f 86 | 87 | valueToBeChangedOnTheLeft = targetValeuLeft 88 | valueToBeChangedOnTheRight = targetValeuRight 89 | 90 | delay(700) 91 | valueToBeChangedOnTheLeft = originalValeuLeft 92 | valueToBeChangedOnTheRight = originalValeuRight 93 | delay(700) 94 | horizontalPagerInAction = false 95 | } 96 | }, 97 | hasMovedToRight = { 98 | horizontalPagerInAction = true 99 | scope.launch { 100 | val originalValeuLeft = valueToBeChangedOnTheLeft 101 | val targetValeuLeft = originalValeuLeft / 2f 102 | 103 | val originalValeuRight = valueToBeChangedOnTheRight 104 | val targetValeuRight = originalValeuRight * 4f 105 | 106 | valueToBeChangedOnTheLeft = targetValeuLeft 107 | valueToBeChangedOnTheRight = targetValeuRight 108 | delay(700) 109 | valueToBeChangedOnTheLeft = originalValeuLeft 110 | valueToBeChangedOnTheRight = originalValeuRight 111 | delay(700) 112 | horizontalPagerInAction = false 113 | } 114 | } 115 | ) 116 | } 117 | } 118 | 119 | @Composable 120 | fun Wave( 121 | modifier: Modifier = Modifier 122 | ) { 123 | Column( 124 | modifier = modifier 125 | .fillMaxSize(), 126 | horizontalAlignment = Alignment.CenterHorizontally, 127 | verticalArrangement = Arrangement.Bottom 128 | ) { 129 | Box( 130 | modifier = Modifier 131 | .weight(2f) 132 | .fillMaxSize(), 133 | contentAlignment = Alignment.Center 134 | ) { 135 | var width: Float 136 | var height = 1080f 137 | 138 | val animatedOffset by animateFloatAsState( 139 | targetValue = rotate, 140 | animationSpec = spring( 141 | dampingRatio = Spring.DampingRatioHighBouncy, 142 | stiffness = Spring.StiffnessVeryLow 143 | ) 144 | ) 145 | 146 | val startHeight by animateFloatAsState( 147 | targetValue = height / valueToBeChangedOnTheLeft, 148 | animationSpec = spring( 149 | dampingRatio = Spring.DampingRatioHighBouncy, 150 | stiffness = Spring.StiffnessVeryLow 151 | ) 152 | ) 153 | 154 | val endHeight by animateFloatAsState( 155 | targetValue = height / valueToBeChangedOnTheRight, 156 | animationSpec = spring( 157 | dampingRatio = Spring.DampingRatioHighBouncy, 158 | stiffness = Spring.StiffnessVeryLow 159 | ) 160 | ) 161 | 162 | Canvas( 163 | modifier = Modifier 164 | .size(800.dp) 165 | .rotate(animatedOffset) 166 | ) { 167 | width = size.width 168 | height = size.height 169 | 170 | val peakHeight = height * 0.2f 171 | val dipHeight = height * 0.2f 172 | 173 | val path = Path().apply { 174 | moveTo(-50f, startHeight + 100) 175 | cubicTo( 176 | width * 0.33f, peakHeight, 177 | width * 0.66f, dipHeight, 178 | width + 50, endHeight + 100 179 | ) 180 | lineTo( 181 | width + 50, 182 | height + 1000 183 | ) 184 | lineTo( 185 | -50f, 186 | height + 1000 187 | ) 188 | close() 189 | } 190 | drawPath(path, color = Color(1, 8, 14), style = Fill) // wave color 191 | } 192 | } 193 | } 194 | } -------------------------------------------------------------------------------- /shared/src/commonMain/kotlin/ui/home/HomeViewModel.kt: -------------------------------------------------------------------------------- 1 | package ui.home 2 | 3 | import dev.icerock.moko.mvvm.viewmodel.ViewModel 4 | import io.ktor.client.HttpClient 5 | import io.ktor.client.call.body 6 | import io.ktor.client.plugins.contentnegotiation.ContentNegotiation 7 | import io.ktor.client.request.get 8 | import io.ktor.serialization.kotlinx.json.json 9 | import kotlinx.coroutines.flow.MutableStateFlow 10 | import kotlinx.coroutines.flow.StateFlow 11 | import kotlinx.coroutines.flow.asStateFlow 12 | import kotlinx.coroutines.flow.update 13 | import kotlinx.coroutines.launch 14 | import model.Profile 15 | 16 | class ViewModel : ViewModel() { 17 | private val _profileUiState = MutableStateFlow(ProfileUiState(profile = Profile())) 18 | val profileUiState: StateFlow = _profileUiState.asStateFlow() 19 | 20 | override fun onCleared() { 21 | httpClient.close() 22 | } 23 | 24 | private val httpClient = HttpClient { 25 | install(ContentNegotiation) { 26 | json() 27 | } 28 | } 29 | 30 | fun updateProfile() { 31 | viewModelScope.launch { 32 | val profile = getProfile() 33 | _profileUiState.update { 34 | it.copy(profile = profile) 35 | } 36 | } 37 | } 38 | 39 | private suspend fun getProfile(): Profile { 40 | val profile = httpClient 41 | .get(profileUiState.value.apiUrl) 42 | .body() 43 | return profile 44 | } 45 | 46 | fun updateApiUrl(url: String?) { 47 | val apiUrl = url ?: "https://git-jr.github.io/mock-apis/alura-api.json" 48 | _profileUiState.update { 49 | it.copy(apiUrl = apiUrl) 50 | } 51 | updateProfile() 52 | } 53 | } 54 | 55 | data class ProfileUiState( 56 | val profile: Profile, 57 | val apiUrl: String = "" 58 | ) 59 | -------------------------------------------------------------------------------- /shared/src/commonMain/kotlin/ui/home/LoginScreen.kt: -------------------------------------------------------------------------------- 1 | package ui.home 2 | 3 | import androidx.compose.foundation.background 4 | import androidx.compose.foundation.border 5 | import androidx.compose.foundation.layout.Arrangement 6 | import androidx.compose.foundation.layout.Box 7 | import androidx.compose.foundation.layout.Column 8 | import androidx.compose.foundation.layout.Row 9 | import androidx.compose.foundation.layout.Spacer 10 | import androidx.compose.foundation.layout.fillMaxSize 11 | import androidx.compose.foundation.layout.fillMaxWidth 12 | import androidx.compose.foundation.layout.padding 13 | import androidx.compose.foundation.shape.RoundedCornerShape 14 | import androidx.compose.material.OutlinedTextField 15 | import androidx.compose.material.Text 16 | import androidx.compose.material.TextButton 17 | import androidx.compose.material.TextFieldDefaults 18 | import androidx.compose.runtime.Composable 19 | import androidx.compose.runtime.getValue 20 | import androidx.compose.runtime.mutableStateOf 21 | import androidx.compose.runtime.remember 22 | import androidx.compose.runtime.setValue 23 | import androidx.compose.ui.Alignment 24 | import androidx.compose.ui.Modifier 25 | import androidx.compose.ui.graphics.Brush 26 | import androidx.compose.ui.graphics.Color 27 | import androidx.compose.ui.text.font.FontWeight 28 | import androidx.compose.ui.text.style.TextAlign 29 | import androidx.compose.ui.unit.dp 30 | import androidx.compose.ui.unit.sp 31 | import extensions.noRippleClickable 32 | 33 | @Composable 34 | fun LoginScreen(onLogin: (String?) -> Unit) { 35 | val gradientBackgroundColor = 36 | Brush.verticalGradient(listOf(Color(52, 122, 255), Color(1, 8, 11))) 37 | Box( 38 | Modifier.background(gradientBackgroundColor), 39 | ) { 40 | Box( 41 | modifier = Modifier 42 | .fillMaxSize(), 43 | ) { 44 | Column( 45 | modifier = Modifier 46 | .padding(16.dp) 47 | .fillMaxSize(), 48 | horizontalAlignment = Alignment.CenterHorizontally, 49 | verticalArrangement = Arrangement.Center 50 | ) { 51 | var urlTextState by remember { mutableStateOf("") } 52 | Text( 53 | text = "Digite a url da API do seu perfil ou use a de teste", 54 | textAlign = TextAlign.Center, 55 | color = Color.White, 56 | fontSize = 18.sp, 57 | fontWeight = FontWeight.Bold, 58 | ) 59 | 60 | Spacer(modifier = Modifier.padding(32.dp)) 61 | 62 | OutlinedTextField( 63 | value = urlTextState, 64 | onValueChange = { urlTextState = it }, 65 | modifier = Modifier.fillMaxWidth(), 66 | colors = TextFieldDefaults.outlinedTextFieldColors( 67 | focusedBorderColor = Color.White, 68 | unfocusedBorderColor = Color.White, 69 | cursorColor = Color.White, 70 | textColor = Color.White, 71 | ), 72 | ) 73 | 74 | 75 | Spacer(modifier = Modifier.padding(8.dp)) 76 | 77 | Row( 78 | modifier = Modifier 79 | .background( 80 | Color(2, 17, 24).copy(0.2f), 81 | shape = RoundedCornerShape(20) 82 | ) 83 | .border( 84 | 1.dp, 85 | Color.Black.copy(0.5f), 86 | shape = RoundedCornerShape(20) 87 | ) 88 | .padding(16.dp) 89 | .fillMaxWidth(), 90 | ) { 91 | Text( 92 | text = "Mergulhar", 93 | textAlign = TextAlign.Center, 94 | color = Color.White, 95 | modifier = Modifier 96 | .fillMaxWidth() 97 | .noRippleClickable { 98 | if (urlTextState.isNotEmpty()) onLogin(urlTextState) 99 | } 100 | ) 101 | } 102 | 103 | Spacer(modifier = Modifier.padding(24.dp)) 104 | 105 | TextButton( 106 | onClick = { onLogin(null) }, 107 | modifier = Modifier 108 | .fillMaxWidth() 109 | ) { 110 | Text( 111 | text = "Usar url de teste", 112 | textAlign = TextAlign.Center, 113 | color = Color.White, 114 | ) 115 | } 116 | } 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /shared/src/commonMain/kotlin/ui/tabs/CourseProgressesScreen.kt: -------------------------------------------------------------------------------- 1 | package ui.tabs 2 | 3 | import androidx.compose.animation.AnimatedVisibility 4 | import androidx.compose.animation.fadeIn 5 | import androidx.compose.animation.fadeOut 6 | import androidx.compose.foundation.background 7 | import androidx.compose.foundation.border 8 | import androidx.compose.foundation.layout.Arrangement 9 | import androidx.compose.foundation.layout.Box 10 | import androidx.compose.foundation.layout.Column 11 | import androidx.compose.foundation.layout.IntrinsicSize 12 | import androidx.compose.foundation.layout.Row 13 | import androidx.compose.foundation.layout.Spacer 14 | import androidx.compose.foundation.layout.fillMaxHeight 15 | import androidx.compose.foundation.layout.fillMaxSize 16 | import androidx.compose.foundation.layout.fillMaxWidth 17 | import androidx.compose.foundation.layout.height 18 | import androidx.compose.foundation.layout.padding 19 | import androidx.compose.foundation.layout.size 20 | import androidx.compose.foundation.rememberScrollState 21 | import androidx.compose.foundation.shape.CircleShape 22 | import androidx.compose.foundation.shape.RoundedCornerShape 23 | import androidx.compose.foundation.verticalScroll 24 | import androidx.compose.material3.Text 25 | import androidx.compose.runtime.Composable 26 | import androidx.compose.runtime.LaunchedEffect 27 | import androidx.compose.ui.Alignment 28 | import androidx.compose.ui.Modifier 29 | import androidx.compose.ui.draw.rotate 30 | import androidx.compose.ui.graphics.Brush 31 | import androidx.compose.ui.graphics.Color 32 | import androidx.compose.ui.text.font.FontWeight 33 | import androidx.compose.ui.text.style.TextAlign 34 | import androidx.compose.ui.unit.dp 35 | import androidx.compose.ui.unit.sp 36 | import extensions.timestampToDisplayDate 37 | import io.kamel.image.KamelImage 38 | import io.kamel.image.asyncPainterResource 39 | import io.ktor.http.Url 40 | import model.CourseProgresse 41 | 42 | @Composable 43 | fun CourseProgressesScreen( 44 | state: List, 45 | onScroll: (Int) -> Unit = {}, 46 | animatedMainRotate: Float 47 | ) { 48 | val gradientBackgroundColor = 49 | Brush.verticalGradient(listOf(Color.Blue.copy(0.4f), Color(1, 8, 14))) 50 | 51 | AnimatedVisibility( 52 | state.isEmpty(), 53 | exit = fadeOut() 54 | ) { 55 | Column( 56 | modifier = Modifier 57 | .background(gradientBackgroundColor) 58 | .fillMaxSize(), 59 | horizontalAlignment = Alignment.CenterHorizontally, 60 | verticalArrangement = Arrangement.Center 61 | ) { 62 | Text( 63 | text = "Nenhum curso em progresso no momento", 64 | textAlign = TextAlign.Center, 65 | color = Color.White, 66 | fontSize = 16.sp, 67 | ) 68 | } 69 | } 70 | AnimatedVisibility( 71 | state.isNotEmpty(), 72 | enter = fadeIn() 73 | ) { 74 | val scrollState = rememberScrollState() 75 | 76 | LaunchedEffect(scrollState.value) { 77 | onScroll(scrollState.value) 78 | } 79 | Column( 80 | modifier = Modifier 81 | .verticalScroll(scrollState) 82 | .background(gradientBackgroundColor) 83 | .fillMaxSize(), 84 | horizontalAlignment = Alignment.CenterHorizontally, 85 | ) { 86 | Row( 87 | modifier = Modifier 88 | .height(150.dp) 89 | .fillMaxWidth(), 90 | horizontalArrangement = Arrangement.Center, 91 | verticalAlignment = Alignment.CenterVertically 92 | ) { 93 | Row( 94 | modifier = Modifier 95 | .background(Color(2, 17, 24).copy(0.2f), shape = CircleShape) 96 | .border(1.dp, Color.Black.copy(0.5f), shape = CircleShape) 97 | .padding(16.dp), 98 | ) { 99 | Text( 100 | "Cursos em progresso", 101 | textAlign = TextAlign.Center, 102 | color = Color.White, 103 | fontSize = 16.sp, 104 | ) 105 | } 106 | } 107 | 108 | state.forEach { courseProgresse -> 109 | CourseItem( 110 | course = courseProgresse, 111 | modifier = Modifier 112 | .rotate(animatedMainRotate) 113 | ) 114 | } 115 | } 116 | } 117 | } 118 | 119 | @Composable 120 | fun CourseItem(modifier: Modifier, course: CourseProgresse) { 121 | 122 | val linearColors = Brush.linearGradient( 123 | listOf( 124 | Color.Gray.copy(0.2f), 125 | Color.White.copy(0.1f), 126 | Color.Gray.copy(0.2f) 127 | ) 128 | ) 129 | 130 | Box( 131 | modifier = modifier 132 | .height(IntrinsicSize.Max) 133 | ) { 134 | Row( 135 | modifier = Modifier 136 | .padding(horizontal = 16.dp, vertical = 8.dp) 137 | .background(linearColors, shape = RoundedCornerShape(16.dp)) 138 | .fillMaxHeight() 139 | .fillMaxWidth(), 140 | verticalAlignment = Alignment.CenterVertically 141 | ) { 142 | Spacer(modifier = Modifier.height(8.dp)) 143 | } 144 | 145 | Row( 146 | modifier = Modifier 147 | .padding(16.dp) 148 | .fillMaxWidth(), 149 | verticalAlignment = Alignment.CenterVertically 150 | ) { 151 | Box( 152 | modifier = Modifier 153 | .weight(2f), 154 | contentAlignment = Alignment.Center 155 | ) { 156 | KamelImage( 157 | asyncPainterResource(Url("https://www.alura.com.br/assets/api/cursos/${course.slug}.svg")), 158 | contentDescription = "Logo curso ${course.name}", 159 | modifier = Modifier 160 | .size(50.dp), 161 | ) 162 | } 163 | Column( 164 | modifier = Modifier 165 | .weight(8f) 166 | .padding(top = 8.dp, bottom = 8.dp, end = 8.dp), 167 | verticalArrangement = Arrangement.Center 168 | ) { 169 | Text( 170 | text = course.name, 171 | fontSize = 14.sp, 172 | fontWeight = FontWeight.Bold, 173 | color = Color.White, 174 | ) 175 | 176 | Text( 177 | "Progresso: ${course.progress}%", 178 | fontSize = 12.sp, 179 | fontWeight = FontWeight.Bold, 180 | color = Color.White, 181 | ) 182 | Text( 183 | "Último acesso: ${course.lastAccessTime.timestampToDisplayDate()}", 184 | fontSize = 12.sp, 185 | fontWeight = FontWeight.Bold, 186 | color = Color.White, 187 | ) 188 | } 189 | } 190 | } 191 | } 192 | 193 | 194 | -------------------------------------------------------------------------------- /shared/src/commonMain/kotlin/ui/tabs/GuidesScreen.kt: -------------------------------------------------------------------------------- 1 | package ui.tabs 2 | 3 | import androidx.compose.animation.AnimatedVisibility 4 | import androidx.compose.animation.fadeIn 5 | import androidx.compose.animation.fadeOut 6 | import androidx.compose.foundation.background 7 | import androidx.compose.foundation.border 8 | import androidx.compose.foundation.layout.Arrangement 9 | import androidx.compose.foundation.layout.Box 10 | import androidx.compose.foundation.layout.Column 11 | import androidx.compose.foundation.layout.IntrinsicSize 12 | import androidx.compose.foundation.layout.Row 13 | import androidx.compose.foundation.layout.Spacer 14 | import androidx.compose.foundation.layout.fillMaxHeight 15 | import androidx.compose.foundation.layout.fillMaxSize 16 | import androidx.compose.foundation.layout.fillMaxWidth 17 | import androidx.compose.foundation.layout.height 18 | import androidx.compose.foundation.layout.padding 19 | import androidx.compose.foundation.layout.size 20 | import androidx.compose.foundation.rememberScrollState 21 | import androidx.compose.foundation.shape.CircleShape 22 | import androidx.compose.foundation.shape.RoundedCornerShape 23 | import androidx.compose.foundation.verticalScroll 24 | import androidx.compose.material3.Text 25 | import androidx.compose.runtime.Composable 26 | import androidx.compose.runtime.LaunchedEffect 27 | import androidx.compose.ui.Alignment 28 | import androidx.compose.ui.Modifier 29 | import androidx.compose.ui.graphics.Brush 30 | import androidx.compose.ui.graphics.Color 31 | import androidx.compose.ui.text.font.FontWeight 32 | import androidx.compose.ui.text.style.TextAlign 33 | import androidx.compose.ui.unit.dp 34 | import androidx.compose.ui.unit.sp 35 | import extensions.hexToRgbColor 36 | import extensions.timestampToDisplayDate 37 | import model.Guide 38 | 39 | 40 | @Composable 41 | fun GuidesScreen( 42 | state: List, 43 | onScroll: (Int) -> Unit = {} 44 | ) { 45 | val gradientBackgroundColor = 46 | Brush.verticalGradient(listOf(Color.Blue.copy(0.4f), Color(1, 8, 14))) 47 | 48 | AnimatedVisibility( 49 | state.isEmpty(), 50 | exit = fadeOut() 51 | ) { 52 | Column( 53 | modifier = Modifier 54 | .background(gradientBackgroundColor) 55 | .fillMaxSize(), 56 | horizontalAlignment = Alignment.CenterHorizontally, 57 | verticalArrangement = Arrangement.Center 58 | ) { 59 | Text( 60 | text = "Nenhum guia em progresso no momento", 61 | textAlign = TextAlign.Center, 62 | modifier = Modifier.fillMaxSize() 63 | ) 64 | } 65 | } 66 | AnimatedVisibility( 67 | state.isNotEmpty(), 68 | enter = fadeIn() 69 | ) { 70 | val scrollState = rememberScrollState() 71 | 72 | LaunchedEffect(scrollState.value) { 73 | onScroll(scrollState.value) 74 | } 75 | Column( 76 | modifier = Modifier 77 | .verticalScroll(scrollState) 78 | .background(gradientBackgroundColor) 79 | .fillMaxSize(), 80 | horizontalAlignment = Alignment.CenterHorizontally, 81 | ) { 82 | Row( 83 | modifier = Modifier 84 | .height(150.dp) 85 | .fillMaxWidth(), 86 | horizontalArrangement = Arrangement.Center, 87 | verticalAlignment = Alignment.CenterVertically 88 | ) { 89 | Row( 90 | modifier = Modifier 91 | .background(Color(2, 17, 24).copy(0.2f), shape = CircleShape) 92 | .border(1.dp, Color.Black.copy(0.5f), shape = CircleShape) 93 | .padding(16.dp), 94 | ) { 95 | Text( 96 | "Guias de estudo", 97 | textAlign = TextAlign.Center, 98 | color = Color.White, 99 | fontSize = 16.sp, 100 | ) 101 | } 102 | } 103 | 104 | state.forEach { guide -> 105 | GuideItem(guide) 106 | } 107 | } 108 | } 109 | } 110 | 111 | @Composable 112 | fun GuideItem(guide: Guide) { 113 | 114 | val linearColors = Brush.linearGradient( 115 | listOf( 116 | Color.Gray.copy(0.2f), 117 | Color.White.copy(0.1f), 118 | Color.Gray.copy(0.2f) 119 | ) 120 | ) 121 | 122 | Box(modifier = Modifier.height(IntrinsicSize.Max)) { 123 | Row( 124 | modifier = Modifier 125 | .padding(horizontal = 16.dp, vertical = 8.dp) 126 | .background(linearColors, shape = RoundedCornerShape(16.dp)) 127 | .fillMaxHeight() 128 | .fillMaxWidth(), 129 | verticalAlignment = Alignment.CenterVertically 130 | ) { 131 | Spacer(modifier = Modifier.height(8.dp)) 132 | } 133 | 134 | Row( 135 | modifier = Modifier 136 | .padding(16.dp) 137 | .fillMaxWidth(), 138 | verticalAlignment = Alignment.CenterVertically 139 | ) { 140 | Box( 141 | modifier = Modifier 142 | .weight(2f), 143 | contentAlignment = Alignment.Center 144 | ) { 145 | Box( 146 | modifier = Modifier 147 | .size(50.dp) 148 | .padding(4.dp) 149 | .background(guide.color.hexToRgbColor(), shape = CircleShape) 150 | ) 151 | } 152 | Column( 153 | modifier = Modifier 154 | .weight(8f) 155 | .padding(top = 8.dp, bottom = 8.dp, end = 8.dp), 156 | verticalArrangement = Arrangement.Center 157 | ) { 158 | Text( 159 | text = guide.name, 160 | fontSize = 14.sp, 161 | fontWeight = FontWeight.Bold, 162 | color = Color.White, 163 | ) 164 | Text( 165 | "Último acesso: ${guide.lastAccessTime.timestampToDisplayDate()}", 166 | fontSize = 12.sp, 167 | fontWeight = FontWeight.Bold, 168 | color = Color.White, 169 | ) 170 | 171 | Text( 172 | "Passos concluidos: ${guide.finishedSteps} de ${guide.totalSteps}", 173 | fontSize = 12.sp, 174 | fontWeight = FontWeight.Bold, 175 | color = Color.White, 176 | ) 177 | } 178 | } 179 | } 180 | } 181 | 182 | -------------------------------------------------------------------------------- /shared/src/commonMain/kotlin/ui/tabs/TabScreen.kt: -------------------------------------------------------------------------------- 1 | package ui.tabs 2 | 3 | import androidx.compose.foundation.ExperimentalFoundationApi 4 | import androidx.compose.foundation.layout.Box 5 | import androidx.compose.foundation.layout.fillMaxSize 6 | import androidx.compose.foundation.pager.HorizontalPager 7 | import androidx.compose.foundation.pager.rememberPagerState 8 | import androidx.compose.runtime.Composable 9 | import androidx.compose.runtime.LaunchedEffect 10 | import androidx.compose.ui.Alignment 11 | import androidx.compose.ui.Modifier 12 | import ui.home.ProfileUiState 13 | 14 | @OptIn(ExperimentalFoundationApi::class) 15 | @Composable 16 | fun TabScreen( 17 | modifier: Modifier = Modifier, 18 | state: ProfileUiState, 19 | hasMovedToLeft: () -> Unit = {}, 20 | hasMovedToRight: () -> Unit = {}, 21 | onScroll: (Int) -> Unit = {}, 22 | animatedMainRotate: Float 23 | ) { 24 | val textTabs = listOf("Cursos em progresso", "Guias de estudo") 25 | val pagerState = rememberPagerState() 26 | 27 | LaunchedEffect(pagerState.currentPage) { 28 | when (pagerState.currentPage) { 29 | 0 -> hasMovedToLeft() 30 | 1 -> hasMovedToRight() 31 | } 32 | } 33 | 34 | HorizontalPager(state = pagerState, pageCount = textTabs.size) { page -> 35 | Box( 36 | modifier = modifier 37 | .fillMaxSize(), 38 | contentAlignment = Alignment.Center 39 | ) { 40 | if (page == 0) { 41 | CourseProgressesScreen( 42 | state = state.profile.courseProgresses, 43 | animatedMainRotate = animatedMainRotate, 44 | onScroll = { 45 | onScroll(it) 46 | } 47 | ) 48 | } else { 49 | GuidesScreen( 50 | state = state.profile.guides, 51 | onScroll = { 52 | onScroll(it) 53 | } 54 | ) 55 | } 56 | } 57 | } 58 | } 59 | 60 | 61 | -------------------------------------------------------------------------------- /shared/src/commonMain/resources/compose-multiplatform.xml: -------------------------------------------------------------------------------- 1 | 6 | 10 | 14 | 18 | 24 | 30 | 36 | 37 | -------------------------------------------------------------------------------- /shared/src/iosMain/kotlin/main.ios.kt: -------------------------------------------------------------------------------- 1 | import androidx.compose.ui.window.ComposeUIViewController 2 | 3 | actual fun getPlatformName(): String = "iOS" 4 | 5 | fun MainViewController() = ComposeUIViewController { App() } --------------------------------------------------------------------------------