Skip to content

Commit

Permalink
Add nav_cupcake example (#4826)
Browse files Browse the repository at this point in the history
Move https://github.com/MatkovIvan/nav_cupcake repo to the examples
folder.

This is a Compose Multiplatform adaptation of [Navigate between screens
with
Compose](https://developer.android.com/codelabs/basic-android-kotlin-compose-navigation)
codelab

<img width="2040" alt="multiplatform_screenshot_light"
src="https://github.com/JetBrains/compose-multiplatform/assets/1836384/a579574a-44fe-414c-8a89-1507aaeea250">
<img width="2040" alt="multiplatform_screenshot_dark"
src="https://github.com/JetBrains/compose-multiplatform/assets/1836384/a216841a-958e-4597-a98b-2198a203228e">
  • Loading branch information
MatkovIvan committed May 17, 2024
1 parent 30164c5 commit f9585f5
Show file tree
Hide file tree
Showing 45 changed files with 5,312 additions and 0 deletions.
18 changes: 18 additions & 0 deletions examples/nav_cupcake/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
*.iml
.gradle
.kotlin
**/build/
xcuserdata
!src/**/build/
local.properties
.idea
.DS_Store
captures
.externalNativeBuild
.cxx
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcodeproj/project.xcworkspace/
!*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings
4 changes: 4 additions & 0 deletions examples/nav_cupcake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This is a Compose Multiplatform adaptation of [Navigate between screens with Compose](https://developer.android.com/codelabs/basic-android-kotlin-compose-navigation) codelab

![Multiplatform Screenshot - Light](images/multiplatform_screenshot_light.png)
![Multiplatform Screenshot - Dark](images/multiplatform_screenshot_dark.png)
9 changes: 9 additions & 0 deletions examples/nav_cupcake/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
// this is necessary to avoid the plugins to be loaded multiple times
// in each subproject's classloader
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.composeMultiplatform) apply false
alias(libs.plugins.composeCompiler) apply false
}
149 changes: 149 additions & 0 deletions examples/nav_cupcake/composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig

plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidApplication)
alias(libs.plugins.composeMultiplatform)
alias(libs.plugins.composeCompiler)
}

kotlin {
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
moduleName = "composeApp"
browser {
commonWebpackConfig {
outputFileName = "composeApp.js"
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
static = (static ?: mutableListOf()).apply {
// Serve sources to debug inside browser
add(project.projectDir.path)
}
}
}
}
binaries.executable()
}

androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "11"
}
}
}

jvm("desktop")

listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
iosTarget.binaries.framework {
baseName = "ComposeApp"
isStatic = true
}
}

sourceSets {
all {
languageSettings {
optIn("androidx.compose.material3.ExperimentalMaterial3Api")
optIn("org.jetbrains.compose.resources.ExperimentalResourceApi")
}
}

val commonMain by getting
val jbMain by creating {
dependsOn(commonMain)
}
val desktopMain by getting {
dependsOn(jbMain)
}
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(jbMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}
val wasmJsMain by getting {
dependsOn(jbMain)
}

androidMain.dependencies {
implementation(libs.compose.ui.tooling.preview)
implementation(libs.androidx.activity.compose)
}
commonMain.dependencies {
implementation(libs.kotlinx.datetime)

implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)

implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.androidx.navigation.compose)
}
desktopMain.dependencies {
implementation(compose.desktop.currentOs)
}
}
}

android {
namespace = "org.jetbrains.nav_cupcake"
compileSdk = libs.versions.android.compileSdk.get().toInt()

sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")

defaultConfig {
applicationId = "org.jetbrains.nav_cupcake"
minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
versionCode = 1
versionName = "1.0"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
dependencies {
debugImplementation(libs.compose.ui.tooling)
}
}

compose.desktop {
application {
mainClass = "MainKt"

nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "org.jetbrains.nav_cupcake"
packageVersion = "1.0.0"
}
}
}

compose.experimental {
web.application {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.Material.Light.NoActionBar">
<activity
android:exported="true"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.jetbrains.nav_cupcake

import App
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)

setContent {
App()
}
}
}

@Preview
@Composable
fun AppAndroidPreview() {
App()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">Cupcake</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2023 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Cupcake icon for the start fragment -->
<vector android:height="200dp" android:viewportHeight="413.71"
android:viewportWidth="308.15" android:width="148.96909dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#4fc3f7" android:pathData="M34.33,218.79l-27.63,-11.72l-6.7,27.68l34.33,-15.96z"/>
<path android:fillColor="#4fc3f7" android:pathData="M273.75,218.79l27.63,-11.72l6.69,27.68l-34.32,-15.96z"/>
<path android:fillColor="#4fc3f7" android:pathData="M27.22,225.91l20.35,-30.56l29.24,22.58l24.1,-27.94l27.32,24.84l25.84,-26.36l25.85,26.36l27.32,-24.84l24.1,27.94l29.24,-22.58l20.35,30.56"/>
<path android:fillColor="#03a9f4" android:pathData="M280.93,233.84l-20.35,30.57l-29.24,-22.59l-24.1,27.95l-27.32,-24.84l-25.85,26.36l-25.84,-26.36l-27.32,24.84l-24.1,-27.95l-29.24,22.59l-20.35,-30.57"/>
<path android:fillColor="#ffe0b2" android:pathData="M6.72,245.77a147.35,49.81 0,1 0,294.7 0a147.35,49.81 0,1 0,-294.7 0z"/>
<path android:fillColor="#81d4fa" android:pathData="M308.15,234.77 L289.5,219.22l-21.58,31L237.06,228l-25.52,28.14 -28.88,-24.72L155.3,257.8 128,231.41 99.07,256.13 73.54,228 42.68,250.25l-21.58,-31L0,234.75 29.3,380.43C41,424.8 268.46,424.8 281,380.43Z"/>
<path android:fillColor="#4fc3f7" android:pathData="M296.79,290a177.71,177.71 0,0 1,-14.08 22.93c-6.49,8.8 -12.95,17.78 -20.38,25.84 -7.2,7.83 -16.18,14 -24.61,20.32 -26.6,19.82 -63.2,26.79 -95.82,20.47C119.55,377.93 101.2,373 81.14,362c-27.72,-15.16 -49.54,-41.31 -65.72,-67.86 -1.86,-3.05 -3.63,-6.14 -5.34,-9.27L29.3,380.43C41,424.8 268.46,424.8 281,380.43l17.45,-93.7C297.92,287.82 297.36,288.91 296.79,290Z"/>
<path android:fillColor="#29b6f6" android:pathData="M58.88,378.74a2,2 0,0 1,-2 -1.74L42.39,263.14a2,2 0,1 1,4 -0.51L60.87,376.49a2,2 0,0 1,-1.73 2.24Z"/>
<path android:fillColor="#29b6f6" android:pathData="M104.17,385.44a2,2 0,0 1,-2 -1.92l-4.5,-116.09a2,2 0,1 1,4 -0.16l4.51,116.09a2,2 0,0 1,-1.92 2.08Z"/>
<path android:fillColor="#29b6f6" android:pathData="M252.08,378.74h-0.26a2,2 0,0 1,-1.73 -2.24L264.6,262.63a2,2 0,1 1,4 0.51L254.06,377A2,2 0,0 1,252.08 378.74Z"/>
<path android:fillColor="#29b6f6" android:pathData="M206.79,385.44h-0.08a2,2 0,0 1,-1.92 -2.08l4.5,-116.09a2,2 0,0 1,4 0.16l-4.5,116.09A2,2 0,0 1,206.79 385.44Z"/>
<path android:fillColor="#29b6f6" android:pathData="M155.18,388.79a2,2 0,0 1,-2 -2V270.14a2,2 0,0 1,4 0V386.79A2,2 0,0 1,155.18 388.79Z"/>
<path android:fillColor="#f06292" android:pathData="M174.42,0.11S186.94,47.44 104,57.92c0,0 -48.29,5.29 -33.19,37.35a21.64,21.64 0,0 1,-5.47 25.88C47.92,135.74 24.89,164.84 46.08,207a13.44,13.44 0,0 0,7.28 6.57c20.12,7.53 101.54,33.31 201.88,1.32a13.21,13.21 0,0 0,6.3 -4.34c6.57,-8.21 20.38,-31.37 -2.24,-60.91A26.16,26.16 0,0 1,254 135.12c-0.51,-9.9 -4.73,-27.17 -25.88,-39.45a13.57,13.57 0,0 1,-5.69 -16.92c4,-9.75 7.66,-24.1 2,-36.44C214.6,21.28 174.42,0.11 174.42,0.11Z"/>
<path android:fillColor="#ec407a" android:pathData="M256,204.18c-18.82,3.85 -38.66,6.32 -58,5.56a342.08,342.08 0,0 1,-54.75 -7,191.23 191.23,0 0,1 -31,-9 372.7,372.7 0,0 1,-43.43 -19.84c-9.64,-5.25 -19.52,-11.32 -28.07,-18.59 -4.75,14.09 -4.81,31.38 5.4,51.71a13.44,13.44 0,0 0,7.28 6.57c20.12,7.53 101.54,33.31 201.88,1.31a13.12,13.12 0,0 0,6.3 -4.33,48.91 48.91,0 0,0 5.89,-9.43A105.18,105.18 0,0 1,256 204.18Z"/>
<path android:fillColor="#f48fb1" android:pathData="M222.18,89c-28,24.79 -65.43,27.57 -102.41,21.79 -15.62,-2.44 -28.25,-11.48 -42.54,-4.72 -2.93,1.38 -6,4 -5.48,7.19 15.75,0.68 27.44,6.57 42.6,10.88 22.47,6.38 43.32,17.56 65.72,24.18s48,8.13 67.88,-4.07c2.46,-1.51 4.94,-3.39 5.87,-6.13a12.71,12.71 0,0 0,0.06 -6.31c-3.28,-18.77 -15,-33 -31.43,-42.81"/>
<path android:fillColor="#673ab7" android:pathData="M108.057,137.999L141.83,124.422A3.105,3.11 68.099,0 1,145.874 126.143L145.874,126.143A3.105,3.11 68.099,0 1,144.146 130.184L110.373,143.761A3.105,3.11 68.099,0 1,106.329 142.04L106.329,142.04A3.105,3.11 68.099,0 1,108.057 137.999z"/>
<path android:fillColor="#ffee58" android:pathData="M63.656,78.785L63.656,78.785A3.105,3.11 110.731,0 1,67.664 76.982L101.707,89.866A3.105,3.11 110.731,0 1,103.517 93.871L103.517,93.871A3.105,3.11 110.731,0 1,99.509 95.674L65.466,82.79A3.105,3.11 110.731,0 1,63.656 78.785z"/>
<path android:fillColor="#80deea" android:pathData="M223.715,131.605L241.916,99.937A3.121,3.116 119.885,0 1,246.172 98.784L246.172,98.784A3.121,3.116 119.885,0 1,247.318 103.042L229.118,134.71A3.121,3.116 119.885,0 1,224.862 135.864L224.862,135.864A3.121,3.116 119.885,0 1,223.715 131.605z"/>
<path android:fillColor="#8bc34a" android:pathData="M158.163,63.484L158.163,63.484A3.105,3.11 107.861,0 1,162.076 61.482L196.722,72.646A3.105,3.11 107.861,0 1,198.729 76.555L198.729,76.555A3.105,3.11 107.861,0 1,194.817 78.557L160.171,67.393A3.105,3.11 107.861,0 1,158.163 63.484z"/>
<path android:fillColor="#673ab7" android:pathData="M181.372,45.493L201.621,15.246A3.11,3.105 123.799,0 1,205.931 14.389L205.931,14.389A3.11,3.105 123.799,0 1,206.781 18.7L186.532,48.948A3.11,3.105 123.799,0 1,182.222 49.805L182.222,49.805A3.11,3.105 123.799,0 1,181.372 45.493z"/>
<path android:fillColor="#8bc34a" android:pathData="M132.014,205.938L152.263,175.691A3.11,3.105 123.799,0 1,156.574 174.834L156.574,174.834A3.11,3.105 123.799,0 1,157.424 179.145L137.175,209.393A3.11,3.105 123.799,0 1,132.864 210.25L132.864,210.25A3.11,3.105 123.799,0 1,132.014 205.938z"/>
<path android:fillColor="#ffee58" android:pathData="M203.177,166.031L203.177,166.031A3.105,3.11 104.521,0 1,206.966 163.805L242.204,172.931A3.105,3.11 104.521,0 1,244.436 176.716L244.436,176.716A3.105,3.11 104.521,0 1,240.647 178.942L205.409,169.816A3.105,3.11 104.521,0 1,203.177 166.031z"/>
<path android:fillColor="#80deea" android:pathData="M34.294,179.55L56.164,150.453A3.11,3.105 126.929,0 1,60.515 149.832L60.515,149.832A3.11,3.105 126.929,0 1,61.128 154.184L39.258,183.281A3.11,3.105 126.929,0 1,34.907 183.902L34.907,183.902A3.11,3.105 126.929,0 1,34.294 179.55z"/>
<path android:fillColor="#f48fb1" android:pathData="M174.6,0.19c5.85,5.93 5.7,15.41 2.45,23.08a51.17,51.17 0,0 1,-16 20c-22,16.43 -49.79,24.94 -77.21,24.27 -1.61,0 -3.64,-0.43 -4,-2 1.47,-2.29 4.27,-3.29 6.89,-4 12.66,-3.58 26,-5.8 38.46,-10.07C148.61,43.36 169,33.86 174.42,0"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<resources>
<string name="app_name">Cupcake</string>
<string name="order_cupcakes">Order Cupcakes</string>
<string name="one_cupcake">One Cupcake</string>
<string name="six_cupcakes">Six Cupcakes</string>
<string name="twelve_cupcakes">Twelve Cupcakes</string>
<string name="choose_flavor">Choose Flavor</string>
<string name="vanilla">Vanilla</string>
<string name="chocolate">Chocolate</string>
<string name="red_velvet">Red Velvet</string>
<string name="salted_caramel">Salted Caramel</string>
<string name="coffee">Coffee</string>
<string name="special_flavor">Special Flavor</string>
<string name="cancel">Cancel</string>
<string name="next">Next</string>
<string name="choose_pickup_date">Choose Pickup Date</string>
<string name="order_summary">Order Summary</string>
<string name="send">Send Order to Another App</string>
<string name="quantity">Quantity</string>
<string name="flavor">Flavor</string>
<string name="pickup_date">Pickup date</string>
<string name="subtotal_price">Subtotal %1$s</string>
<string name="total_price">Total %1$s</string>
<string name="new_cupcake_order">New Cupcake Order</string>
<string name="order_details">Quantity: %1$s \nFlavor: %2$s \nPickup date: %3$s \nTotal: %4$s \n\nThank you!</string>
<string name="back_button">Back</string>
<string name="cupcakes">%1$d cupcakes</string>
</resources>
10 changes: 10 additions & 0 deletions examples/nav_cupcake/composeApp/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import androidx.compose.runtime.Composable
import org.jetbrains.nav_cupcake.CupcakeApp
import org.jetbrains.nav_cupcake.ui.theme.CupcakeTheme

@Composable
fun App() {
CupcakeTheme {
CupcakeApp()
}
}
Loading

0 comments on commit f9585f5

Please sign in to comment.