-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/worldline/learning-kotlin
- Loading branch information
Showing
215 changed files
with
8,655 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
build/ | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
iosApp/Podfile.lock | ||
iosApp/Pods/* | ||
iosApp/iosApp.xcworkspace/* | ||
iosApp/iosApp.xcodeproj/* | ||
!iosApp/iosApp.xcodeproj/project.pbxproj | ||
shared/shared.podspec |
23 changes: 23 additions & 0 deletions
23
material/app-compose-multiplatform-with-web/.run/desktopApp.run.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="desktopApp" type="GradleRunConfiguration" factoryName="Gradle"> | ||
<ExternalSystemSettings> | ||
<option name="executionName" /> | ||
<option name="externalProjectPath" value="$PROJECT_DIR$/desktopApp" /> | ||
<option name="externalSystemIdString" value="GRADLE" /> | ||
<option name="scriptParameters" value="" /> | ||
<option name="taskDescriptions"> | ||
<list /> | ||
</option> | ||
<option name="taskNames"> | ||
<list> | ||
<option value="run" /> | ||
</list> | ||
</option> | ||
<option name="vmOptions" value="" /> | ||
</ExternalSystemSettings> | ||
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess> | ||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess> | ||
<DebugAllEnabled>false</DebugAllEnabled> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Compose Multiplatform for Web | ||
|
||
> **Note** | ||
> Web support is Experimental and may be changed at any time. Use it only for evaluation purposes. | ||
> We would appreciate your feedback on it in the public Slack channel [#compose-web](https://slack-chats.kotlinlang.org/c/compose-web). | ||
> If you face any issues, please report them on [GitHub](https://github.com/JetBrains/compose-multiplatform/issues). | ||
You can experiment with sharing your mobile or desktop UIs with the web. Compose for Web is based on [Kotlin/Wasm](https://kotl.in/wasm), | ||
the newest target for Kotlin Multiplatform projects. It allows Kotlin developers to run their code in the browser with | ||
all the benefits that WebAssembly has to offer, such as good and predictable performance for your applications. | ||
|
||
# Image Viewer | ||
|
||
Web version of an image gallery for remote server image viewing built with Compose Multiplatform. | ||
|
||
![](screenshots/imageviewer.png) | ||
|
||
## Build and run | ||
|
||
Check out the repo, navigate to the project folder, and use the following commands: | ||
|
||
### Run Web version via Gradle | ||
|
||
`./gradlew :webApp:wasmRun` | ||
|
||
### Run Desktop version via Gradle | ||
|
||
`./gradlew :desktopApp:run` | ||
|
||
### Install Android application via Gradle | ||
|
||
`./gradlew :androidApp:installDebug` | ||
|
||
## Setup Environment | ||
|
||
>**Note** | ||
> Using experimental Kotlin/Wasm may require enabling experimental features in the target environment. | ||
- **Chrome** 110 or newer: enable **WebAssembly Garbage Collection** at [chrome://flags/#enable-webassembly-garbage-collection](chrome://flags/#enable-webassembly-garbage-collection) or with Chrome 109 or newer, run the program with the `--js-flags=--experimental-wasm-gc` command line argument. | ||
- **Firefox Nightly** 112 or newer: enable **javascript.options.wasm_function_references** and **javascript.options.wasm_gc** at [about:config](about:config). | ||
- **Edge** 109 or newer: run the program with the `--js-flags=--experimental-wasm-gc` command line argument. | ||
|
||
For more information see https://kotl.in/wasm_help/. | ||
|
||
## IDE | ||
|
||
We recommend using [IntelliJ IDEA 2023.1 or newer](https://www.jetbrains.com/idea/) to work with the project. | ||
|
||
# Feedback & Questions | ||
|
||
Give it a try, and share your feedback and ask questions in the Kotlin Slack [#compose-web](https://slack-chats.kotlinlang.org/c/compose-web) channel (if you’re not a member, [apply here](https://kotl.in/slack)) or on Twitter to [@bashorov](https://twitter.com/bashorov). | ||
|
||
# Learn more | ||
|
||
* [Compose Multiplatform](https://github.com/JetBrains/compose-multiplatform/#compose-multiplatform) | ||
* [Kotlin/Wasm](https://kotl.in/wasm/) | ||
* [Other examples](../../../#examples) |
37 changes: 37 additions & 0 deletions
37
material/app-compose-multiplatform-with-web/androidApp/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
plugins { | ||
kotlin("multiplatform") | ||
id("com.android.application") | ||
id("org.jetbrains.compose") | ||
} | ||
|
||
kotlin { | ||
android() | ||
sourceSets { | ||
val androidMain by getting { | ||
dependencies { | ||
implementation(project(":shared")) | ||
} | ||
} | ||
} | ||
} | ||
|
||
android { | ||
compileSdk = 33 | ||
defaultConfig { | ||
applicationId = "org.jetbrains.Imageviewer" | ||
minSdk = 26 | ||
targetSdk = 33 | ||
versionCode = 1 | ||
versionName = "1.0" | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
} | ||
} | ||
|
||
|
||
compose { | ||
val composeVersion = project.property("compose.wasm.version") as String | ||
kotlinCompilerPlugin.set(composeVersion) | ||
} |
27 changes: 27 additions & 0 deletions
27
material/app-compose-multiplatform-with-web/androidApp/src/androidMain/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="example.imageviewer"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_imageviewer" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_imageviewer_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.AppCompat.Light.NoActionBar"> | ||
<activity | ||
android:exported="true" | ||
android:name="example.imageviewer.MainActivity" | ||
> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
15 changes: 15 additions & 0 deletions
15
...tiplatform-with-web/androidApp/src/androidMain/kotlin/example/imageviewer/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package example.imageviewer | ||
|
||
import android.os.Bundle | ||
import androidx.activity.compose.setContent | ||
import androidx.appcompat.app.AppCompatActivity | ||
import example.imageviewer.view.ImageViewerAndroid | ||
|
||
class MainActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContent { | ||
ImageViewerAndroid() | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
material/app-compose-multiplatform-with-web/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
plugins { | ||
// this is necessary to avoid the plugins to be loaded multiple times | ||
// in each subproject's classloader | ||
kotlin("jvm") apply false | ||
kotlin("multiplatform") apply false | ||
kotlin("android") apply false | ||
id("com.android.application") apply false | ||
id("com.android.library") apply false | ||
id("org.jetbrains.compose") apply false | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
google() | ||
mavenCentral() | ||
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") | ||
mavenLocal() | ||
maven("https://maven.pkg.jetbrains.space/kotlin/p/wasm/experimental") | ||
} | ||
|
||
configurations.all { | ||
val conf = this | ||
// Currently it's necessary to make the android build work properly | ||
conf.resolutionStrategy.eachDependency { | ||
val isWasm = conf.name.contains("wasm", true) | ||
val isJs = conf.name.contains("js", true) | ||
val isComposeGroup = requested.module.group.startsWith("org.jetbrains.compose") | ||
val isComposeCompiler = requested.module.group.startsWith("org.jetbrains.compose.compiler") | ||
if (isComposeGroup && !isComposeCompiler && !isWasm && !isJs) { | ||
val composeVersion = project.property("compose.version") as String | ||
useVersion(composeVersion) | ||
} | ||
if (requested.module.name.startsWith("kotlin-stdlib")) { | ||
val kotlinVersion = project.property("kotlin.version") as String | ||
useVersion(kotlinVersion) | ||
} | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
material/app-compose-multiplatform-with-web/desktopApp/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import org.jetbrains.compose.desktop.application.dsl.TargetFormat | ||
|
||
plugins { | ||
kotlin("multiplatform") | ||
id("org.jetbrains.compose") | ||
} | ||
|
||
kotlin { | ||
jvm { | ||
withJava() | ||
} | ||
sourceSets { | ||
val jvmMain by getting { | ||
dependencies { | ||
implementation(compose.desktop.currentOs) | ||
implementation(project(":shared")) | ||
} | ||
} | ||
} | ||
} | ||
|
||
compose.desktop { | ||
application { | ||
mainClass = "example.imageviewer.MainKt" | ||
|
||
nativeDistributions { | ||
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) | ||
packageName = "ImageViewer" | ||
packageVersion = "1.0.0" | ||
|
||
val iconsRoot = project.file("../common/src/desktopMain/resources/images") | ||
macOS { | ||
iconFile.set(iconsRoot.resolve("icon-mac.icns")) | ||
} | ||
windows { | ||
iconFile.set(iconsRoot.resolve("icon-windows.ico")) | ||
menuGroup = "Compose Examples" | ||
// see https://wixtoolset.org/documentation/manual/v3/howtos/general/generate_guids.html | ||
upgradeUuid = "18159995-d967-4CD2-8885-77BFA97CFA9F" | ||
} | ||
linux { | ||
iconFile.set(iconsRoot.resolve("icon-linux.png")) | ||
} | ||
} | ||
} | ||
} | ||
|
||
compose { | ||
val composeVersion = project.property("compose.wasm.version") as String | ||
kotlinCompilerPlugin.set(composeVersion) | ||
} |
12 changes: 12 additions & 0 deletions
12
material/app-compose-multiplatform-with-web/desktopApp/rules.pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Ktor | ||
-keep class io.ktor.** { *; } | ||
-keepclassmembers class io.ktor.** { volatile <fields>; } | ||
-keep class io.ktor.client.engine.cio.** { *; } | ||
-keep class kotlinx.coroutines.** { *; } | ||
-dontwarn kotlinx.atomicfu.** | ||
-dontwarn io.netty.** | ||
-dontwarn com.typesafe.** | ||
-dontwarn org.slf4j.** | ||
|
||
# Obfuscation breaks coroutines/ktor for some reason | ||
-dontobfuscate |
8 changes: 8 additions & 0 deletions
8
...-compose-multiplatform-with-web/desktopApp/src/jvmMain/kotlin/example/imageviewer/Main.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package example.imageviewer | ||
|
||
import androidx.compose.ui.window.application | ||
import example.imageviewer.view.ImageViewerDesktop | ||
|
||
fun main() = application { | ||
ImageViewerDesktop() | ||
} |
19 changes: 19 additions & 0 deletions
19
material/app-compose-multiplatform-with-web/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
kotlin.code.style=official | ||
xcodeproj=iosApp | ||
kotlin.native.cocoapods.generate.wrapper=true | ||
android.useAndroidX=true | ||
org.gradle.jvmargs=-Xmx3g | ||
org.jetbrains.compose.experimental.jscanvas.enabled=true | ||
org.jetbrains.compose.experimental.macos.enabled=true | ||
org.jetbrains.compose.experimental.uikit.enabled=true | ||
kotlin.native.cacheKind=none | ||
kotlin.mpp.androidSourceSetLayoutVersion=2 | ||
kotlin.native.useEmbeddableCompilerJar=true | ||
# Enable kotlin/native experimental memory model | ||
kotlin.native.binary.memoryModel=experimental | ||
agp.version=7.1.3 | ||
ktor.version=2.2.1 | ||
kotlin.js.ir.output.granularity=whole-program | ||
compose.version=1.4.0 | ||
compose.wasm.version=1.4.0-dev-wasm09 | ||
kotlin.version=1.9.0 |
6 changes: 6 additions & 0 deletions
6
material/app-compose-multiplatform-with-web/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip | ||
networkTimeout=10000 | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.