diff --git a/.gitignore b/.gitignore index 088e0f189e..a99e625403 100644 --- a/.gitignore +++ b/.gitignore @@ -4,13 +4,7 @@ out *.iml .gradle /local.properties -/.idea -/.idea/caches -/.idea/libraries -/.idea/modules.xml -/.idea/workspace.xml -/.idea/navEditor.xml -/.idea/assetWizardSettings.xml +.idea/ .DS_Store build/ /captures diff --git a/CHANGELOG.md b/CHANGELOG.md index 05e0571420..cfe50545de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,84 @@ +# 1.2.0 (October 2022) +## Common + +### Features +* [Allow to use Compose on multiple Kotlin versions](https://github.com/JetBrains/compose-jb/pull/2366) +* [`import org.jetbrains.compose.compose` is no longer needed in build.gradle.kts](https://github.com/JetBrains/compose-jb/pull/2215) +* [Allow to use a custom Compose Compiler](https://github.com/JetBrains/compose-jb/pull/2347) + +## Desktop + +### Features +* [Support Kotlin 1.7.20](https://github.com/JetBrains/compose-jb/pull/2357) +* [ProGuard integration for packaging](https://github.com/JetBrains/compose-jb/pull/2313) +* [New experimental event API (onClick, onDrag, WindowInfo.keyboardModifiers)](https://github.com/JetBrains/compose-jb/tree/master/tutorials/Mouse_Events#new-experimental-onclick-handlers-only-for-desktop-jvm-platform) +* Focus + * [Make clickable, mouseClickable, toggleable request focus onClick](https://github.com/JetBrains/androidx/pull/257) + * [Toggle a toggleable component on Space key](https://github.com/JetBrains/androidx/pull/262) + * [Make Slider change the value with onKeyEvent for: all arrows, PgDn, PdUp, Home, End buttons](https://github.com/JetBrains/androidx/pull/254) + * [Navigate drop down menu items using up and down arrows](https://github.com/JetBrains/androidx/pull/259) +* [Ability to override text context menu globally](https://github.com/JetBrains/compose-jb/tree/master/tutorials/Context_Menu#custom-text-context-menu) +* [Context menu implementation for integrating into Swing applications](https://github.com/JetBrains/compose-jb/tree/master/tutorials/Context_Menu#swing-interoperability) +* [Animated image component](https://github.com/JetBrains/compose-jb/pull/2015) +* [Show a new window/dialog on the same display](https://github.com/JetBrains/androidx/pull/312) +* [Change default Font on MacOs to San Francisco](https://github.com/JetBrains/androidx/pull/296) +* Support [performKeyInput](https://github.com/JetBrains/androidx/pull/278), [performMouseInput, performTextInput](https://github.com/JetBrains/androidx/pull/260) in tests. +* Focus switches seamlessly between Swing and Compose components using [SwingPanel](https://github.com/JetBrains/androidx/pull/229) or [ComposePanel](https://github.com/JetBrains/androidx/pull/228) +* [Documentation for how to package apps using Conveyor](https://github.com/JetBrains/compose-jb/tree/master/tutorials/Native_distributions_and_local_execution#available-tools) + +### Fixes +* [Fix IDEA plugin compatability](https://github.com/JetBrains/compose-jb/pull/2318) +* Fixes for Right-to-Left languages support + * [LayoutDirection is detected from the system settings](https://github.com/JetBrains/androidx/pull/264) + * [Fix RTL selection in a multiline text](https://github.com/JetBrains/androidx/pull/285) + * [Fix cursor visual position at BiDi transition](https://github.com/JetBrains/androidx/pull/286) + * [Fix the cursor position after the '\n' character in RTL](https://github.com/JetBrains/androidx/pull/268) + * [In placeAutoMirrored for RTL, calculate the placement position using the placeable width respecting the constraints](https://github.com/JetBrains/androidx/pull/267) + * [Placing the root content properly for RTL layout](https://github.com/JetBrains/androidx/pull/265) +* TextField + * [Fix the cursor position when clicking at a position after a line-break](https://github.com/JetBrains/androidx/pull/284) + * [Fix selection with End, Home](https://github.com/JetBrains/androidx/pull/279) + * [Fix the cursor height on a new empty line](https://github.com/JetBrains/androidx/pull/277) +* [Fix DesktopMenu and DesktopAlertDialog to invoke dismiss callback once](https://github.com/JetBrains/androidx/pull/256) +* [Fix a large icon in macOs menu](https://github.com/JetBrains/androidx/pull/248) +* [Fix hover in LazyColumn](https://github.com/JetBrains/androidx/pull/249) +* [Fix pointerHoverIcon: update icon when it's changed conditionally](https://github.com/JetBrains/androidx/pull/231) +* [Fix focusable parameter for Window and Dialog](https://github.com/JetBrains/androidx/pull/225) +* [Fix 2 SplitPanel minor bugs](https://github.com/JetBrains/compose-jb/pull/2175) +* [Fix `java.lang.IllegalStateException: cannot open system clipboard` crash](https://github.com/JetBrains/skiko/pull/586) +* [Fix `System.setProperty("skiko.renderApi", "SOFTWARE"` on macOS](https://github.com/JetBrains/skiko/pull/599) + +### API changes +* [Deprecate experimental pointerMoveFilter in favor of onPointerEvent](https://github.com/JetBrains/androidx/pull/247) +* [Deprecate experimental Modifier.mouseClickable in favor of Modifier.onClick](https://github.com/JetBrains/androidx/pull/243) + +## Web + +### Features +* Support Kotlin 1.7.10 +* [Add support for transition in CSS api](https://github.com/JetBrains/compose-jb/pull/2228) +* [Add missing `background-blend-mode` property](https://github.com/JetBrains/compose-jb/pull/2128) +* [SVG: Publish custom attr functions](https://github.com/JetBrains/compose-jb/pull/2127) +* [Add list overload for `classes`](https://github.com/JetBrains/compose-jb/pull/2094) +* [Add support of dl, dt and dd](https://github.com/JetBrains/compose-jb/pull/1922) + +### Fixes +* [Add pom information and license to Web artifacts](https://github.com/JetBrains/compose-jb/pull/2195) + +### API changes +* [Deprecate 3 overloads of StyleScope.borderWidth with wrong parameter names](https://github.com/JetBrains/compose-jb/pull/2297) +* [Remove deprecated compose.web.web-widgets from the source code](https://github.com/JetBrains/compose-jb/pull/2294) +* [Remove unnecessary parameter for `required` attribute](https://github.com/JetBrains/compose-jb/pull/1988) + +## Updated dependencies +This version of Compose Multiplatform is based on the next Jetpack Compose libraries: +* [Compiler 1.3.2](https://developer.android.com/jetpack/androidx/releases/compose-compiler#1.3.2) +* [Runtime 1.2.1](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.2.1) +* [UI 1.2.1](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.1) +* [Foundation 1.2.1](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.2.1) +* [Material 1.2.1](https://developer.android.com/jetpack/androidx/releases/compose-material#1.2.1) +* [Material3 1.0.0-alpha14](https://developer.android.com/jetpack/androidx/releases/compose-material3#1.0.0-alpha14) + # 1.1.1 (Mar 2022) ## Desktop @@ -42,7 +123,6 @@ fun main() = application { - [Implement experimental accessibility support for Windows](https://github.com/JetBrains/compose-jb/tree/master/tutorials/Accessibility) - [Implement accessibility focus tracking by Tab](https://github.com/JetBrains/compose-jb/issues/1772) - All bugfixes/features between Jetpack Compose 1.1.0-beta02 and 1.1.0 (see the release notes for each module [here](https://developer.android.com/jetpack/androidx/releases/compose)) -- Android target depends on Jetpack Compose 1.1.0. ### Fixes - Fixes for TextField ([1](https://github.com/JetBrains/compose-jb/issues/1834), [2](https://github.com/JetBrains/compose-jb/issues/1615), [3](https://github.com/JetBrains/compose-jb/issues/1781), [4](https://github.com/JetBrains/compose-jb/issues/1670)) @@ -77,6 +157,15 @@ fun main() = singleWindowApplication { ``` - [`PointerEvent.awtEvent`, `KeyEvent.awtEvent` are deprecated](https://github.com/JetBrains/androidx/pull/198), use `PointerEvent.awtEventOrNull`, `KeyEvent.awtEventOrNull` instead. The event can be null, if it isn't sent by AWT (for example, Compose can send synthetic Move events on relayout) +## Updated dependencies +This version of Compose Multiplatform is based on the next Jetpack Compose libraries: +* [Compiler 1.1.0](https://developer.android.com/jetpack/androidx/releases/compose-compiler#1.1.0) +* [Runtime 1.1.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.1.0) +* [UI 1.1.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.1.0) +* [Foundation 1.1.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.1.0) +* [Material 1.1.0](https://developer.android.com/jetpack/androidx/releases/compose-material#1.1.0) +* [Material3 1.0.0-alpha05](https://developer.android.com/jetpack/androidx/releases/compose-material3#1.0.0-alpha05) + # 1.0.1 (Dec 2021) This is basically 1.0.0 that works with Kotlin 1.6.10 @@ -103,6 +192,15 @@ This is basically 1.0.0 that works with Kotlin 1.6.10 - [Some functions were made internal (either not related to compose-web or not intended for usage in apps): buildCSS , StylePropertyList.nativeEquals , variableValue , buildCSSStyleRule , buildKeyframes , jsObject , CSSKeyframesRule.appendRule](https://github.com/JetBrains/compose-jb/pull/1509/files) - CSSMediaRule: functions feature and combine were made extensions functions on GenericStyleSheetBuilder. This makes them consistent with the rest of functions which create CSSMediaQuery.MediaFeature instances +## Updated dependencies +This version of Compose Multiplatform is based on the next Jetpack Compose libraries: +* [Compiler 1.1.0-beta02](https://developer.android.com/jetpack/androidx/releases/compose-compiler#1.1.0-beta02) +* [Runtime 1.1.0-beta02](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.1.0-beta02) +* [UI 1.1.0-beta02](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.1.0-beta02) +* [Foundation 1.1.0-beta02](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.1.0-beta02) +* [Material 1.1.0-beta02](https://developer.android.com/jetpack/androidx/releases/compose-material#1.1.0-beta02) +* [Material3 1.0.0-alpha03](https://developer.android.com/jetpack/androidx/releases/compose-material3#1.0.0-alpha03) + # 1.0.0-beta (Oct 2021) ## Common - no Android artifacts are published anymore. Google-published artifacts are referenced instead. This approach eliminates compatibility issues. diff --git a/README.md b/README.md index b727723062..176c912f11 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ Note that when you use Compose Multiplatform, you setup your project differently * [components](components) - custom components of Compose Multiplatform * [Split Pane](components/SplitPane) * [experimental](experimental) - experimental components and examples + * [examples](experimental/examples) - examples that use new experimental functionality * [cef](experimental/cef) - CEF integration in Jetpack Compose (somewhat outdated) * [Video Player](experimental/components/VideoPlayer) * [LWJGL integration](experimental/lwjgl-integration) - An example showing how to integrate Compose with [LWJGL](https://www.lwjgl.org) diff --git a/ci/compose-uber-jar/gradle.properties b/ci/compose-uber-jar/gradle.properties index 03b9d463c9..c40ccc968d 100644 --- a/ci/compose-uber-jar/gradle.properties +++ b/ci/compose-uber-jar/gradle.properties @@ -1,2 +1,2 @@ -compose.version=1.1.0 +compose.version=1.2.0 kotlin.code.style=official diff --git a/components/gradle.properties b/components/gradle.properties index 8fb205f495..e3465edb66 100644 --- a/components/gradle.properties +++ b/components/gradle.properties @@ -3,6 +3,6 @@ android.useAndroidX=true android.enableJetifier=true kotlin.code.style=official # __KOTLIN_COMPOSE_VERSION__ -kotlin.version=1.6.10 +kotlin.version=1.7.20 # __LATEST_COMPOSE_RELEASE_VERSION__ -compose.version=1.1.0 +compose.version=1.2.0 diff --git a/examples/codeviewer/README.md b/examples/codeviewer/README.md index 0fdefed7ad..172adda0ce 100644 --- a/examples/codeviewer/README.md +++ b/examples/codeviewer/README.md @@ -1,13 +1,14 @@ MPP Code Viewer example for desktop/android written in Multiplatform Compose library. ### Running desktop application -``` -./gradlew :desktop:run -``` + +* To run, launch command: `./gradlew :desktop:run` +* Or choose **desktop** configuration in IDE and run it. + ![desktop-run-configuration.png](screenshots/desktop-run-configuration.png) ### Building native desktop distribution ``` -./gradlew :desktop:package +./gradlew :desktop:packageDistributionForCurrentOS # outputs are written to desktop/build/compose/binaries ``` diff --git a/examples/codeviewer/android/build.gradle.kts b/examples/codeviewer/android/build.gradle.kts index 1a03c22b9f..13073d45fb 100644 --- a/examples/codeviewer/android/build.gradle.kts +++ b/examples/codeviewer/android/build.gradle.kts @@ -5,11 +5,11 @@ plugins { } android { - compileSdkVersion(31) + compileSdk = 32 defaultConfig { - minSdkVersion(26) - targetSdkVersion(31) + minSdk = 26 + targetSdk = 32 versionCode = 1 versionName = "1.0" } @@ -22,5 +22,5 @@ android { dependencies { implementation(project(":common")) - implementation("androidx.activity:activity-compose:1.4.0") + implementation("androidx.activity:activity-compose:1.5.0") } \ No newline at end of file diff --git a/examples/codeviewer/android/src/main/AndroidManifest.xml b/examples/codeviewer/android/src/main/AndroidManifest.xml index 64ddd4d7c6..308d3a79b5 100644 --- a/examples/codeviewer/android/src/main/AndroidManifest.xml +++ b/examples/codeviewer/android/src/main/AndroidManifest.xml @@ -12,7 +12,7 @@ + > diff --git a/examples/codeviewer/build.gradle.kts b/examples/codeviewer/build.gradle.kts index 59387d208b..bf95fe23b1 100644 --- a/examples/codeviewer/build.gradle.kts +++ b/examples/codeviewer/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // this is necessary to avoid the plugins to be loaded multiple times // in each subproject's classloader @@ -17,10 +15,4 @@ subprojects { mavenCentral() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") } - - plugins.withId("org.jetbrains.kotlin.multiplatform") { - tasks.withType { - kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn" - } - } } diff --git a/examples/codeviewer/common/build.gradle.kts b/examples/codeviewer/common/build.gradle.kts index 08fb9990fa..1b8e451301 100644 --- a/examples/codeviewer/common/build.gradle.kts +++ b/examples/codeviewer/common/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.compose.compose - plugins { id("com.android.library") kotlin("multiplatform") @@ -22,8 +20,8 @@ kotlin { named("androidMain") { kotlin.srcDirs("src/jvmMain/kotlin") dependencies { - api("androidx.appcompat:appcompat:1.4.1") - api("androidx.core:core-ktx:1.7.0") + api("androidx.appcompat:appcompat:1.5.1") + api("androidx.core:core-ktx:1.8.0") } } named("desktopMain") { @@ -36,16 +34,11 @@ kotlin { } android { - compileSdkVersion(31) + compileSdk = 32 defaultConfig { - minSdkVersion(21) - targetSdkVersion(31) - } - - compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 + minSdk = 26 + targetSdk = 32 } sourceSets { diff --git a/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt b/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt index d35c300295..4095a8bf60 100644 --- a/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt +++ b/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt @@ -3,10 +3,4 @@ package org.jetbrains.codeviewer.platform import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset -actual fun Modifier.pointerMoveFilter( - onEnter: () -> Boolean, - onExit: () -> Boolean, - onMove: (Offset) -> Boolean -): Modifier = this - actual fun Modifier.cursorForHorizontalResize() = this \ No newline at end of file diff --git a/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt b/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt index f08c93a6cc..ad049b6045 100644 --- a/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt +++ b/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt @@ -1,13 +1,15 @@ package org.jetbrains.codeviewer.platform +import android.annotation.SuppressLint import androidx.compose.runtime.Composable import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.font.Font import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight +@SuppressLint("DiscouragedApi") @Composable -actual fun Font(name: String, res: String, weight: FontWeight, style: FontStyle): Font { +actual fun font(name: String, res: String, weight: FontWeight, style: FontStyle): Font { val context = LocalContext.current val id = context.resources.getIdentifier(res, "font", context.packageName) return Font(id, weight, style) diff --git a/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt b/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt index 52c58a9dc3..8832527ae0 100644 --- a/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt +++ b/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt @@ -4,7 +4,6 @@ import androidx.compose.foundation.ScrollState import androidx.compose.foundation.lazy.LazyListState import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import androidx.compose.ui.unit.Dp @Composable actual fun VerticalScrollbar( diff --git a/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt b/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt index 4ce937e23c..28a5c3dec9 100644 --- a/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt +++ b/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt @@ -1,12 +1,5 @@ package org.jetbrains.codeviewer.platform import androidx.compose.ui.Modifier -import androidx.compose.ui.geometry.Offset - -expect fun Modifier.pointerMoveFilter( - onEnter: () -> Boolean = { true }, - onExit: () -> Boolean = { true }, - onMove: (Offset) -> Boolean = { true } -): Modifier expect fun Modifier.cursorForHorizontalResize(): Modifier \ No newline at end of file diff --git a/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt b/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt index 00fa6102a2..d22698e61b 100644 --- a/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt +++ b/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt @@ -6,4 +6,4 @@ import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight @Composable -expect fun Font(name: String, res: String, weight: FontWeight, style: FontStyle): Font \ No newline at end of file +expect fun font(name: String, res: String, weight: FontWeight, style: FontStyle): Font \ No newline at end of file diff --git a/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Fonts.kt b/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Fonts.kt index 09a81d77f3..70461d77e5 100644 --- a/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Fonts.kt +++ b/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Fonts.kt @@ -4,57 +4,57 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight -import org.jetbrains.codeviewer.platform.Font +import org.jetbrains.codeviewer.platform.font object Fonts { @Composable fun jetbrainsMono() = FontFamily( - Font( + font( "JetBrains Mono", "jetbrainsmono_regular", FontWeight.Normal, FontStyle.Normal ), - Font( + font( "JetBrains Mono", "jetbrainsmono_italic", FontWeight.Normal, FontStyle.Italic ), - Font( + font( "JetBrains Mono", "jetbrainsmono_bold", FontWeight.Bold, FontStyle.Normal ), - Font( + font( "JetBrains Mono", "jetbrainsmono_bold_italic", FontWeight.Bold, FontStyle.Italic ), - Font( + font( "JetBrains Mono", "jetbrainsmono_extrabold", FontWeight.ExtraBold, FontStyle.Normal ), - Font( + font( "JetBrains Mono", "jetbrainsmono_extrabold_italic", FontWeight.ExtraBold, FontStyle.Italic ), - Font( + font( "JetBrains Mono", "jetbrainsmono_medium", FontWeight.Medium, FontStyle.Normal ), - Font( + font( "JetBrains Mono", "jetbrainsmono_medium_italic", FontWeight.Medium, diff --git a/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTreeView.kt b/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTreeView.kt index e570279036..9bc690a7a5 100644 --- a/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTreeView.kt +++ b/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTreeView.kt @@ -1,6 +1,9 @@ package org.jetbrains.codeviewer.ui.filetree import androidx.compose.foundation.clickable +import androidx.compose.foundation.hoverable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsHoveredAsState import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.rememberLazyListState @@ -11,6 +14,7 @@ import androidx.compose.material.Text import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.* import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Alignment @@ -24,7 +28,6 @@ import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import org.jetbrains.codeviewer.platform.VerticalScrollbar -import org.jetbrains.codeviewer.platform.pointerMoveFilter import org.jetbrains.codeviewer.util.withoutWidthConstraints @Composable @@ -76,25 +79,17 @@ private fun FileTreeItemView(fontSize: TextUnit, height: Dp, model: FileTree.Ite .height(height) .fillMaxWidth() ) { - val active = remember { mutableStateOf(false) } + val interactionSource = remember { MutableInteractionSource() } + val active by interactionSource.collectIsHoveredAsState() FileItemIcon(Modifier.align(Alignment.CenterVertically), model) Text( text = model.name, - color = if (active.value) LocalContentColor.current.copy(alpha = 0.60f) else LocalContentColor.current, + color = if (active) LocalContentColor.current.copy(alpha = 0.60f) else LocalContentColor.current, modifier = Modifier .align(Alignment.CenterVertically) .clipToBounds() - .pointerMoveFilter( - onEnter = { - active.value = true - true - }, - onExit = { - active.value = false - true - } - ), + .hoverable(interactionSource), softWrap = true, fontSize = fontSize, overflow = TextOverflow.Ellipsis, diff --git a/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt b/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt index 2fb7d7887c..7726dbb3e7 100644 --- a/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt +++ b/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt @@ -2,20 +2,9 @@ package org.jetbrains.codeviewer.platform import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier -import androidx.compose.ui.geometry.Offset import androidx.compose.ui.input.pointer.PointerIcon import androidx.compose.ui.input.pointer.pointerHoverIcon -import androidx.compose.ui.input.pointer.pointerMoveFilter import java.awt.Cursor -@OptIn(ExperimentalComposeUiApi::class) -actual fun Modifier.pointerMoveFilter( - onEnter: () -> Boolean, - onExit: () -> Boolean, - onMove: (Offset) -> Boolean -): Modifier = this.pointerMoveFilter(onEnter = onEnter, onExit = onExit, onMove = onMove) - - -@OptIn(ExperimentalComposeUiApi::class) actual fun Modifier.cursorForHorizontalResize(): Modifier = this.pointerHoverIcon(PointerIcon(Cursor(Cursor.E_RESIZE_CURSOR))) diff --git a/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt b/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt index 89efa1ddd3..fdecfe3ceb 100644 --- a/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt +++ b/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt @@ -6,5 +6,5 @@ import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight @Composable -actual fun Font(name: String, res: String, weight: FontWeight, style: FontStyle): Font = +actual fun font(name: String, res: String, weight: FontWeight, style: FontStyle): Font = androidx.compose.ui.text.platform.Font("font/$res.ttf", weight, style) \ No newline at end of file diff --git a/examples/codeviewer/desktop/build.gradle.kts b/examples/codeviewer/desktop/build.gradle.kts index b1c2566a7b..e7263fd745 100644 --- a/examples/codeviewer/desktop/build.gradle.kts +++ b/examples/codeviewer/desktop/build.gradle.kts @@ -1,4 +1,3 @@ -import org.jetbrains.compose.compose import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { diff --git a/examples/codeviewer/gradle.properties b/examples/codeviewer/gradle.properties index 6849fa0b48..07a190fac2 100644 --- a/examples/codeviewer/gradle.properties +++ b/examples/codeviewer/gradle.properties @@ -19,6 +19,6 @@ android.useAndroidX=true android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official -kotlin.version=1.6.10 -agp.version=7.0.4 -compose.version=1.1.0 +kotlin.version=1.7.20 +agp.version=7.1.3 +compose.version=1.2.0 diff --git a/examples/codeviewer/gradle/wrapper/gradle-wrapper.properties b/examples/codeviewer/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100644 --- a/examples/codeviewer/gradle/wrapper/gradle-wrapper.properties +++ b/examples/codeviewer/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/codeviewer/screenshots/desktop-run-configuration.png b/examples/codeviewer/screenshots/desktop-run-configuration.png new file mode 100644 index 0000000000..3688407c6f Binary files /dev/null and b/examples/codeviewer/screenshots/desktop-run-configuration.png differ diff --git a/examples/falling-balls/.run/desktop.run.xml b/examples/falling-balls/.run/desktop.run.xml new file mode 100644 index 0000000000..d4d6b92cb3 --- /dev/null +++ b/examples/falling-balls/.run/desktop.run.xml @@ -0,0 +1,23 @@ + + + + + + + true + true + false + + + \ No newline at end of file diff --git a/examples/falling-balls/README.md b/examples/falling-balls/README.md new file mode 100644 index 0000000000..f4eba98b85 --- /dev/null +++ b/examples/falling-balls/README.md @@ -0,0 +1,7 @@ +Falling Balls game + +### Running desktop application + * To run, launch command: `./gradlew run` + * Or choose **desktop** configuration in IDE and run it. + ![desktop-run-configuration.png](screenshots/desktop-run-configuration.png) + diff --git a/examples/falling-balls/build.gradle.kts b/examples/falling-balls/build.gradle.kts index 18cfc5e907..afa3c552ef 100644 --- a/examples/falling-balls/build.gradle.kts +++ b/examples/falling-balls/build.gradle.kts @@ -1,4 +1,3 @@ -import org.jetbrains.compose.compose import org.jetbrains.compose.desktop.application.dsl.TargetFormat import org.jetbrains.kotlin.gradle.tasks.KotlinCompile diff --git a/examples/falling-balls/gradle.properties b/examples/falling-balls/gradle.properties index 9bb8d52f7d..dbfb6452d2 100644 --- a/examples/falling-balls/gradle.properties +++ b/examples/falling-balls/gradle.properties @@ -1,3 +1,3 @@ kotlin.code.style=official -kotlin.version=1.6.10 -compose.version=1.1.0 +kotlin.version=1.7.20 +compose.version=1.2.0 diff --git a/examples/falling-balls/gradle/wrapper/gradle-wrapper.properties b/examples/falling-balls/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100644 --- a/examples/falling-balls/gradle/wrapper/gradle-wrapper.properties +++ b/examples/falling-balls/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/falling-balls/screenshots/desktop-run-configuration.png b/examples/falling-balls/screenshots/desktop-run-configuration.png new file mode 100644 index 0000000000..3688407c6f Binary files /dev/null and b/examples/falling-balls/screenshots/desktop-run-configuration.png differ diff --git a/examples/imageviewer/README.md b/examples/imageviewer/README.md index 1bbb38891a..3d79c52613 100755 --- a/examples/imageviewer/README.md +++ b/examples/imageviewer/README.md @@ -1,13 +1,13 @@ An example of image gallery for remote server image viewing, based on Jetpack Compose UI library (desktop and android). ### Running desktop application -``` -./gradlew :desktop:run -``` + * To run, launch command: `./gradlew :desktop:run` + * Or choose **desktop** configuration in IDE and run it. + ![desktop-run-configuration.png](screenshots/desktop-run-configuration.png) ### Building native desktop distribution ``` -./gradlew :desktop:package +./gradlew :desktop:packageDistributionForCurrentOS # outputs are written to desktop/build/compose/binaries ``` diff --git a/examples/imageviewer/android/build.gradle.kts b/examples/imageviewer/android/build.gradle.kts index 58c1d38d15..d5807ca5f3 100755 --- a/examples/imageviewer/android/build.gradle.kts +++ b/examples/imageviewer/android/build.gradle.kts @@ -5,11 +5,11 @@ plugins { } android { - compileSdk = 31 + compileSdk = 32 defaultConfig { - minSdk = 21 - targetSdk = 31 + minSdk = 26 + targetSdk = 32 versionCode = 1 versionName = "1.0" } @@ -22,5 +22,5 @@ android { dependencies { implementation(project(":common")) - implementation("androidx.activity:activity-compose:1.3.1") + implementation("androidx.activity:activity-compose:1.5.0") } diff --git a/examples/imageviewer/android/src/main/AndroidManifest.xml b/examples/imageviewer/android/src/main/AndroidManifest.xml index c8d8007950..5b1501c058 100755 --- a/examples/imageviewer/android/src/main/AndroidManifest.xml +++ b/examples/imageviewer/android/src/main/AndroidManifest.xml @@ -17,7 +17,7 @@ + > diff --git a/examples/imageviewer/common/build.gradle.kts b/examples/imageviewer/common/build.gradle.kts index 1ad8f76dfd..3a67917bbe 100755 --- a/examples/imageviewer/common/build.gradle.kts +++ b/examples/imageviewer/common/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.compose.compose - plugins { id("com.android.library") kotlin("multiplatform") @@ -20,8 +18,8 @@ kotlin { } named("androidMain") { dependencies { - api("androidx.appcompat:appcompat:1.3.1") - api("androidx.core:core-ktx:1.3.1") + api("androidx.appcompat:appcompat:1.5.1") + api("androidx.core:core-ktx:1.8.0") implementation("io.ktor:ktor-client-cio:1.4.1") } } @@ -35,11 +33,11 @@ kotlin { } android { - compileSdk = 31 + compileSdk = 32 defaultConfig { - minSdk = 21 - targetSdk = 31 + minSdk = 26 + targetSdk = 32 } compileOptions { diff --git a/examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/view/AndroidHover.kt b/examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/view/AndroidHover.kt deleted file mode 100644 index 1a5d3c9173..0000000000 --- a/examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/view/AndroidHover.kt +++ /dev/null @@ -1,10 +0,0 @@ -package example.imageviewer.view - -import androidx.compose.ui.Modifier -import androidx.compose.ui.geometry.Offset - -actual fun Modifier.hover( - onEnter: () -> Boolean, - onExit: () -> Boolean, - onMove: (Offset) -> Boolean -): Modifier = this \ No newline at end of file diff --git a/examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/Draggable.kt b/examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/Draggable.kt index f9f3b30bcf..eabbadc4ef 100755 --- a/examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/Draggable.kt +++ b/examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/Draggable.kt @@ -4,7 +4,6 @@ import androidx.compose.foundation.gestures.detectDragGestures import androidx.compose.material.Surface import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf -import androidx.compose.ui.input.pointer.consumePositionChange import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset @@ -28,7 +27,7 @@ fun Draggable( ) { change, dragAmount -> dragHandler.drag(dragAmount) onUpdate?.invoke() - change.consumePositionChange() + change.consume() } } ) { diff --git a/examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/PointerMoveFilter.kt b/examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/PointerMoveFilter.kt deleted file mode 100644 index 7eb8ec6adc..0000000000 --- a/examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/PointerMoveFilter.kt +++ /dev/null @@ -1,10 +0,0 @@ -package example.imageviewer.view - -import androidx.compose.ui.Modifier -import androidx.compose.ui.geometry.Offset - -expect fun Modifier.hover( - onEnter: () -> Boolean = { true }, - onExit: () -> Boolean = { true }, - onMove: (Offset) -> Boolean = { true } -): Modifier \ No newline at end of file diff --git a/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/model/DesktopContentState.kt b/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/model/DesktopContentState.kt index 73daf71680..36e0983da8 100644 --- a/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/model/DesktopContentState.kt +++ b/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/model/DesktopContentState.kt @@ -3,8 +3,8 @@ package example.imageviewer.model import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf import androidx.compose.ui.window.WindowState -import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.graphics.ImageBitmap +import androidx.compose.ui.graphics.toComposeImageBitmap import example.imageviewer.ResString import example.imageviewer.core.FilterType import example.imageviewer.model.filtration.FiltersManager @@ -18,13 +18,9 @@ import example.imageviewer.utils.cropBitmapByScale import example.imageviewer.utils.toByteArray import java.awt.image.BufferedImage import java.io.File -import java.util.concurrent.ExecutorService -import java.util.concurrent.Executors import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Job -import kotlinx.coroutines.delay import org.jetbrains.skia.Image object ContentState { @@ -250,7 +246,7 @@ object ContentState { drag ) ) - ).asImageBitmap() + ).toComposeImageBitmap() } fun swipeNext() { @@ -358,7 +354,7 @@ private object MainImageWrapper { } private fun copy(bitmap: BufferedImage) : BufferedImage { - var result = BufferedImage(bitmap.width, bitmap.height, bitmap.type) + val result = BufferedImage(bitmap.width, bitmap.height, bitmap.type) val graphics = result.createGraphics() graphics.drawImage(bitmap, 0, 0, result.width, result.height, null) return result diff --git a/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/FullscreenImage.kt b/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/FullscreenImage.kt index cd27a48085..e8e91e4930 100644 --- a/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/FullscreenImage.kt +++ b/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/FullscreenImage.kt @@ -1,8 +1,6 @@ package example.imageviewer.view -import androidx.compose.foundation.Image -import androidx.compose.foundation.background -import androidx.compose.foundation.horizontalScroll +import androidx.compose.foundation.* import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -12,22 +10,20 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width -import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.ScrollState +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsHoveredAsState import androidx.compose.foundation.shape.CircleShape -import androidx.compose.material.CircularProgressIndicator import androidx.compose.material.MaterialTheme import androidx.compose.material.Surface import androidx.compose.material.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.input.key.Key import androidx.compose.ui.input.key.key @@ -36,14 +32,12 @@ import androidx.compose.ui.input.key.KeyEventType import androidx.compose.ui.input.key.onPreviewKeyEvent import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.unit.dp -import androidx.compose.ui.window.WindowSize import example.imageviewer.core.FilterType import example.imageviewer.model.AppState import example.imageviewer.model.ContentState import example.imageviewer.model.ScreenType import example.imageviewer.ResString import example.imageviewer.style.DarkGray -import example.imageviewer.style.DarkGreen import example.imageviewer.style.Foreground import example.imageviewer.style.MiniatureColor import example.imageviewer.style.TranslucentBlack @@ -74,7 +68,8 @@ fun ToolBar( text: String, content: ContentState ) { - val backButtonHover = remember { mutableStateOf(false) } + val backButtonInteractionSource = remember { MutableInteractionSource() } + val backButtonHover by backButtonInteractionSource.collectIsHoveredAsState() Surface( color = MiniatureColor, modifier = Modifier.height(44.dp) @@ -87,16 +82,9 @@ fun ToolBar( ) { Tooltip(ResString.back) { Clickable( - modifier = Modifier.hover( - onEnter = { - backButtonHover.value = true - false - }, - onExit = { - backButtonHover.value = false - false - }) - .background(color = if (backButtonHover.value) TranslucentBlack else Transparent), + modifier = Modifier + .hoverable(backButtonInteractionSource) + .background(color = if (backButtonHover) TranslucentBlack else Transparent), onClick = { if (content.isContentReady()) { content.restoreMainImage() @@ -145,33 +133,27 @@ fun FilterButton( type: FilterType, modifier: Modifier = Modifier.size(38.dp) ) { - val filterButtonHover = remember { mutableStateOf(false) } - Box( - modifier = Modifier.background(color = Transparent).clip(CircleShape) - ) { - Tooltip("$type") { - Clickable( - modifier = Modifier.hover( - onEnter = { - filterButtonHover.value = true - false - }, - onExit = { - filterButtonHover.value = false - false - }) - .background(color = if (filterButtonHover.value) TranslucentBlack else Transparent), - onClick = { content.toggleFilter(type)} - ) { - Image( - getFilterImage(type = type, content = content), - contentDescription = null, - modifier - ) - } + val interactionSource = remember { MutableInteractionSource() } + val filterButtonHover by interactionSource.collectIsHoveredAsState() + Box( + modifier = Modifier.background(color = Transparent).clip(CircleShape) + ) { + Tooltip("$type") { + Clickable( + modifier = Modifier + .hoverable(interactionSource) + .background(color = if (filterButtonHover) TranslucentBlack else Transparent), + onClick = { content.toggleFilter(type)} + ) { + Image( + getFilterImage(type = type, content = content), + contentDescription = null, + modifier + ) } } - Spacer(Modifier.width(20.dp)) + } + Spacer(Modifier.width(20.dp)) } @Composable diff --git a/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MainScreen.kt b/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MainScreen.kt index ab57a2b9ad..edf1f4b27b 100755 --- a/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MainScreen.kt +++ b/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MainScreen.kt @@ -1,9 +1,6 @@ package example.imageviewer.view -import androidx.compose.foundation.Image -import androidx.compose.foundation.VerticalScrollbar -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable +import androidx.compose.foundation.* import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -12,32 +9,26 @@ import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width -import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.rememberScrollbarAdapter -import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.ScrollState +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsHoveredAsState import androidx.compose.foundation.shape.CircleShape -import androidx.compose.foundation.verticalScroll import androidx.compose.material.Card -import androidx.compose.material.CircularProgressIndicator import androidx.compose.material.Divider import androidx.compose.material.MaterialTheme import androidx.compose.material.Surface import androidx.compose.material.Text import androidx.compose.material.TopAppBar import androidx.compose.runtime.Composable -import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.graphics.painter.BitmapPainter import androidx.compose.ui.graphics.RectangleShape +import androidx.compose.ui.graphics.toComposeImageBitmap import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.unit.dp import example.imageviewer.ResString @@ -81,7 +72,8 @@ fun TopContent(content: ContentState) { @Composable fun TitleBar(text: String, content: ContentState) { - val refreshButtonHover = remember { mutableStateOf(false) } + val interactionSource = remember { MutableInteractionSource() } + val refreshButtonHover by interactionSource.collectIsHoveredAsState() TopAppBar( backgroundColor = DarkGreen, title = { @@ -98,17 +90,9 @@ fun TitleBar(text: String, content: ContentState) { ) { Tooltip(ResString.refresh) { Clickable( - modifier = Modifier.hover( - onEnter = { - refreshButtonHover.value = true - false - }, - onExit = { - refreshButtonHover.value = false - false - } - ) - .background(color = if (refreshButtonHover.value) TranslucentBlack else Transparent), + modifier = Modifier + .hoverable(interactionSource) + .background(color = if (refreshButtonHover) TranslucentBlack else Transparent), onClick = { if (content.isContentReady()) { content.refresh() @@ -160,20 +144,15 @@ fun Miniature( picture: Picture, content: ContentState ) { - val cardHover = remember { mutableStateOf(false) } - val infoButtonHover = remember { mutableStateOf(false) } + val cardHoverInteractionSource = remember { MutableInteractionSource() } + val cardHover by cardHoverInteractionSource.collectIsHoveredAsState() + val infoButtonInteractionSource = remember { MutableInteractionSource() } + val infoButtonHover by infoButtonInteractionSource.collectIsHoveredAsState() Card( - backgroundColor = if (cardHover.value) MiniatureHoverColor else MiniatureColor, + backgroundColor = if (cardHover) MiniatureHoverColor else MiniatureColor, modifier = Modifier.padding(start = 10.dp, end = 18.dp).height(70.dp) .fillMaxWidth() - .hover(onEnter = { - cardHover.value = true - false - }, - onExit = { - cardHover.value = false - false - }) + .hoverable(cardHoverInteractionSource) .clickable { content.setMainImage(picture) }, @@ -188,7 +167,7 @@ fun Miniature( Image( org.jetbrains.skia.Image.makeFromEncoded( toByteArray(picture.image) - ).asImageBitmap(), + ).toComposeImageBitmap(), contentDescription = null, modifier = Modifier.height(70.dp) .width(90.dp) @@ -209,16 +188,8 @@ fun Miniature( Clickable( modifier = Modifier.height(70.dp) .width(30.dp) - .hover( - onEnter = { - infoButtonHover.value = true - false - }, - onExit = { - infoButtonHover.value = false - false - }) - .background(color = if (infoButtonHover.value) TranslucentWhite else Transparent), + .hoverable(infoButtonInteractionSource) + .background(color = if (infoButtonHover) TranslucentWhite else Transparent), onClick = { showPopUpMessage( "${ResString.picture} " + diff --git a/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MouseHover.kt b/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MouseHover.kt deleted file mode 100644 index 2f0acedcd2..0000000000 --- a/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MouseHover.kt +++ /dev/null @@ -1,13 +0,0 @@ -package example.imageviewer.view - -import androidx.compose.ui.ExperimentalComposeUiApi -import androidx.compose.ui.Modifier -import androidx.compose.ui.geometry.Offset -import androidx.compose.ui.input.pointer.pointerMoveFilter - -@OptIn(ExperimentalComposeUiApi::class) -actual fun Modifier.hover( - onEnter: () -> Boolean, - onExit: () -> Boolean, - onMove: (Offset) -> Boolean -): Modifier = this.pointerMoveFilter(onEnter = onEnter, onExit = onExit, onMove = onMove) \ No newline at end of file diff --git a/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/Toast.kt b/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/Toast.kt index 5e5b290fba..d214552818 100755 --- a/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/Toast.kt +++ b/examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/Toast.kt @@ -7,18 +7,13 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Surface import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.DisposableEffect -import androidx.compose.runtime.MutableState -import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import example.imageviewer.style.Foreground import example.imageviewer.style.ToastBackground -import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay -import kotlinx.coroutines.launch enum class ToastDuration(val value: Int) { Short(1000), Long(3000) @@ -53,13 +48,10 @@ fun Toast( color = Foreground ) } - DisposableEffect(Unit) { - GlobalScope.launch { - delay(duration.value.toLong()) - isShown = false - visibility.value = false - } - onDispose { } + LaunchedEffect(Unit) { + delay(duration.value.toLong()) + isShown = false + visibility.value = false } } } diff --git a/examples/imageviewer/desktop/build.gradle.kts b/examples/imageviewer/desktop/build.gradle.kts index 7365a9e788..2116a0481a 100755 --- a/examples/imageviewer/desktop/build.gradle.kts +++ b/examples/imageviewer/desktop/build.gradle.kts @@ -1,4 +1,3 @@ -import org.jetbrains.compose.compose import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { diff --git a/examples/imageviewer/gradle.properties b/examples/imageviewer/gradle.properties index 6849fa0b48..07a190fac2 100755 --- a/examples/imageviewer/gradle.properties +++ b/examples/imageviewer/gradle.properties @@ -19,6 +19,6 @@ android.useAndroidX=true android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official -kotlin.version=1.6.10 -agp.version=7.0.4 -compose.version=1.1.0 +kotlin.version=1.7.20 +agp.version=7.1.3 +compose.version=1.2.0 diff --git a/examples/imageviewer/gradle/wrapper/gradle-wrapper.properties b/examples/imageviewer/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100755 --- a/examples/imageviewer/gradle/wrapper/gradle-wrapper.properties +++ b/examples/imageviewer/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/imageviewer/screenshots/desktop-run-configuration.png b/examples/imageviewer/screenshots/desktop-run-configuration.png new file mode 100644 index 0000000000..3688407c6f Binary files /dev/null and b/examples/imageviewer/screenshots/desktop-run-configuration.png differ diff --git a/examples/intellij-plugin/.run/runIde.run.xml b/examples/intellij-plugin/.run/runIde.run.xml new file mode 100644 index 0000000000..52aca017c2 --- /dev/null +++ b/examples/intellij-plugin/.run/runIde.run.xml @@ -0,0 +1,23 @@ + + + + + + + true + true + false + + + \ No newline at end of file diff --git a/examples/intellij-plugin/README.md b/examples/intellij-plugin/README.md index 1b510009c5..c78000edee 100644 --- a/examples/intellij-plugin/README.md +++ b/examples/intellij-plugin/README.md @@ -2,7 +2,10 @@ To run the example: -1. from directory `compose-jb/examples/intellij-plugin` run command in terminal: `./gradlew runIde` +1. from directory `compose-jb/examples/intellij-plugin`: + * Run command in terminal `./gradlew runIde`. + * Or choose **runIde** configuration in IDE and run it. + ![ide-run-configuration.png](screenshots/ide-run-configuration.png) 2. create project or open any existing 3. from menu `Tools` select `Show Compose Demo...` diff --git a/examples/intellij-plugin/build.gradle.kts b/examples/intellij-plugin/build.gradle.kts index 6966fa1443..d060be0232 100644 --- a/examples/intellij-plugin/build.gradle.kts +++ b/examples/intellij-plugin/build.gradle.kts @@ -1,7 +1,5 @@ -import org.jetbrains.compose.compose - plugins { - id("org.jetbrains.intellij") version "1.6.0" + id("org.jetbrains.intellij") version "1.9.0" java kotlin("jvm") id("org.jetbrains.compose") diff --git a/examples/intellij-plugin/gradle.properties b/examples/intellij-plugin/gradle.properties index 9bb8d52f7d..dbfb6452d2 100644 --- a/examples/intellij-plugin/gradle.properties +++ b/examples/intellij-plugin/gradle.properties @@ -1,3 +1,3 @@ kotlin.code.style=official -kotlin.version=1.6.10 -compose.version=1.1.0 +kotlin.version=1.7.20 +compose.version=1.2.0 diff --git a/examples/intellij-plugin/gradle/wrapper/gradle-wrapper.properties b/examples/intellij-plugin/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100644 --- a/examples/intellij-plugin/gradle/wrapper/gradle-wrapper.properties +++ b/examples/intellij-plugin/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/intellij-plugin/screenshots/ide-run-configuration.png b/examples/intellij-plugin/screenshots/ide-run-configuration.png new file mode 100644 index 0000000000..9dc9453a38 Binary files /dev/null and b/examples/intellij-plugin/screenshots/ide-run-configuration.png differ diff --git a/examples/intellij-plugin/src/main/kotlin/com/jetbrains/compose/widgets/LazyScrollable.kt b/examples/intellij-plugin/src/main/kotlin/com/jetbrains/compose/widgets/LazyScrollable.kt index e5bba421a0..c898fa0804 100755 --- a/examples/intellij-plugin/src/main/kotlin/com/jetbrains/compose/widgets/LazyScrollable.kt +++ b/examples/intellij-plugin/src/main/kotlin/com/jetbrains/compose/widgets/LazyScrollable.kt @@ -1,6 +1,5 @@ package com.jetbrains.compose.widgets -import androidx.compose.desktop.DesktopTheme import androidx.compose.foundation.background import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.lazy.LazyColumn @@ -27,28 +26,26 @@ import androidx.compose.ui.unit.dp @Composable fun LazyScrollable() { MaterialTheme { - DesktopTheme { - Box( - modifier = Modifier.fillMaxSize() - .padding(10.dp) - ) { + Box( + modifier = Modifier.fillMaxSize() + .padding(10.dp) + ) { - val state = rememberLazyListState() - val itemCount = 100 + val state = rememberLazyListState() + val itemCount = 100 - LazyColumn(Modifier.fillMaxSize().padding(end = 12.dp), state) { - items(itemCount) { x -> - TextBox("Item in ScrollableColumn #$x") - Spacer(modifier = Modifier.height(5.dp)) - } + LazyColumn(Modifier.fillMaxSize().padding(end = 12.dp), state) { + items(itemCount) { x -> + TextBox("Item in ScrollableColumn #$x") + Spacer(modifier = Modifier.height(5.dp)) } - VerticalScrollbar( - modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(), - adapter = rememberScrollbarAdapter( - scrollState = state - ) - ) } + VerticalScrollbar( + modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(), + adapter = rememberScrollbarAdapter( + scrollState = state + ) + ) } } } diff --git a/examples/issues/.run/desktop.run.xml b/examples/issues/.run/desktop.run.xml new file mode 100644 index 0000000000..c10d50877a --- /dev/null +++ b/examples/issues/.run/desktop.run.xml @@ -0,0 +1,23 @@ + + + + + + + true + true + false + + + \ No newline at end of file diff --git a/examples/issues/README.md b/examples/issues/README.md index 18db020e27..e6361890ce 100644 --- a/examples/issues/README.md +++ b/examples/issues/README.md @@ -2,13 +2,13 @@ Github Issues viewer example written in Jetpack Compose UI library. ### Running desktop application -``` -./gradlew :desktop:run -``` +* To run, launch command: `./gradlew :desktop:run` +* Or choose **desktop** configuration in IDE and run it. + ![desktop-run-configuration.png](screenshots/desktop-run-configuration.png) ### Building native desktop distribution ``` -./gradlew :desktop:package +./gradlew :desktop:packageDistributionForCurrentOS # outputs are written to desktop/build/compose/binaries ``` diff --git a/examples/issues/android/build.gradle.kts b/examples/issues/android/build.gradle.kts index 73574362f6..d5807ca5f3 100644 --- a/examples/issues/android/build.gradle.kts +++ b/examples/issues/android/build.gradle.kts @@ -5,11 +5,11 @@ plugins { } android { - compileSdk = 31 + compileSdk = 32 defaultConfig { minSdk = 26 - targetSdk = 31 + targetSdk = 32 versionCode = 1 versionName = "1.0" } @@ -22,5 +22,5 @@ android { dependencies { implementation(project(":common")) - implementation("androidx.activity:activity-compose:1.3.1") + implementation("androidx.activity:activity-compose:1.5.0") } diff --git a/examples/issues/android/src/main/AndroidManifest.xml b/examples/issues/android/src/main/AndroidManifest.xml index 37db4c8f9b..76e9f4d885 100644 --- a/examples/issues/android/src/main/AndroidManifest.xml +++ b/examples/issues/android/src/main/AndroidManifest.xml @@ -12,7 +12,7 @@ + > diff --git a/examples/issues/common/build.gradle.kts b/examples/issues/common/build.gradle.kts index 65d9d2e6db..798637826f 100644 --- a/examples/issues/common/build.gradle.kts +++ b/examples/issues/common/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.compose.compose - plugins { id("com.android.library") kotlin("multiplatform") @@ -24,8 +22,8 @@ kotlin { named("androidMain") { kotlin.srcDirs("src/jvmAndAndroidMain/kotlin") dependencies { - api("androidx.appcompat:appcompat:1.3.1") - api("androidx.core:core-ktx:1.3.1") + api("androidx.appcompat:appcompat:1.5.1") + api("androidx.core:core-ktx:1.8.0") } } named("desktopMain") { @@ -40,11 +38,11 @@ apollo { } android { - compileSdk = 31 + compileSdk = 32 defaultConfig { minSdk = 26 - targetSdk = 31 + targetSdk = 32 } compileOptions { diff --git a/examples/issues/common/src/jvmAndAndroidMain/kotlin/androidx/ui/examples/jetissues/view/JetIssuesView.kt b/examples/issues/common/src/jvmAndAndroidMain/kotlin/androidx/ui/examples/jetissues/view/JetIssuesView.kt index f6572433fe..2f09d79e38 100644 --- a/examples/issues/common/src/jvmAndAndroidMain/kotlin/androidx/ui/examples/jetissues/view/JetIssuesView.kt +++ b/examples/issues/common/src/jvmAndAndroidMain/kotlin/androidx/ui/examples/jetissues/view/JetIssuesView.kt @@ -19,6 +19,8 @@ import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.material.* +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -31,6 +33,7 @@ import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp import androidx.ui.examples.jetissues.data.* import androidx.ui.examples.jetissues.query.IssueQuery import androidx.ui.examples.jetissues.query.IssuesQuery @@ -83,10 +86,12 @@ fun SingleColumnLayout(currentIssue: MutableState) { ) }, navigationIcon = { - Button(onClick = { - currentIssue.value = null - }) { - Text(text = "Back") + IconButton( + onClick = { + currentIssue.value = null + } + ) { + Icon(Icons.Default.ArrowBack, contentDescription = "Back") } } ) diff --git a/examples/issues/desktop/build.gradle.kts b/examples/issues/desktop/build.gradle.kts index 39d1ebc1f0..b2c4eae1bb 100644 --- a/examples/issues/desktop/build.gradle.kts +++ b/examples/issues/desktop/build.gradle.kts @@ -1,4 +1,3 @@ -import org.jetbrains.compose.compose import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { diff --git a/examples/issues/gradle.properties b/examples/issues/gradle.properties index 242c14d70f..6e0cf3e57f 100644 --- a/examples/issues/gradle.properties +++ b/examples/issues/gradle.properties @@ -19,6 +19,6 @@ kotlin.code.style=official android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true -kotlin.version=1.6.10 -agp.version=7.0.4 -compose.version=1.1.0 +kotlin.version=1.7.20 +agp.version=7.1.3 +compose.version=1.2.0 diff --git a/examples/issues/gradle/wrapper/gradle-wrapper.properties b/examples/issues/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100644 --- a/examples/issues/gradle/wrapper/gradle-wrapper.properties +++ b/examples/issues/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/issues/screenshots/desktop-run-configuration.png b/examples/issues/screenshots/desktop-run-configuration.png new file mode 100644 index 0000000000..3688407c6f Binary files /dev/null and b/examples/issues/screenshots/desktop-run-configuration.png differ diff --git a/examples/notepad/README.md b/examples/notepad/README.md index 027509aef0..15b106a9f5 100644 --- a/examples/notepad/README.md +++ b/examples/notepad/README.md @@ -1,13 +1,13 @@ Notepad example for desktop written in Compose for Desktop library, using Composable Window API ### Running desktop application -``` -./gradlew run -``` +* To run, launch command: `./gradlew run` +* Or choose **desktop** configuration in IDE and run it. + ![desktop-run-configuration.png](screenshots/desktop-run-configuration.png) ### Building native desktop distribution ``` -./gradlew package +./gradlew packageDistributionForCurrentOS # outputs are written to build/compose/binaries ``` ![Desktop](screenshots/notepad.gif) \ No newline at end of file diff --git a/examples/notepad/build.gradle.kts b/examples/notepad/build.gradle.kts index 86d04093e6..20b11e9744 100644 --- a/examples/notepad/build.gradle.kts +++ b/examples/notepad/build.gradle.kts @@ -1,4 +1,3 @@ -import org.jetbrains.compose.compose import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { diff --git a/examples/notepad/gradle.properties b/examples/notepad/gradle.properties index 654c3e3d5f..d97adcef50 100644 --- a/examples/notepad/gradle.properties +++ b/examples/notepad/gradle.properties @@ -1,4 +1,4 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 kotlin.code.style=official -kotlin.version=1.6.10 -compose.version=1.1.0 \ No newline at end of file +kotlin.version=1.7.20 +compose.version=1.2.0 \ No newline at end of file diff --git a/examples/notepad/gradle/wrapper/gradle-wrapper.properties b/examples/notepad/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100644 --- a/examples/notepad/gradle/wrapper/gradle-wrapper.properties +++ b/examples/notepad/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/notepad/screenshots/desktop-run-configuration.png b/examples/notepad/screenshots/desktop-run-configuration.png new file mode 100644 index 0000000000..3688407c6f Binary files /dev/null and b/examples/notepad/screenshots/desktop-run-configuration.png differ diff --git a/examples/notepad/src/main/kotlin/common/AppResources.kt b/examples/notepad/src/main/kotlin/common/AppResources.kt index a1fd633023..865e53e040 100644 --- a/examples/notepad/src/main/kotlin/common/AppResources.kt +++ b/examples/notepad/src/main/kotlin/common/AppResources.kt @@ -34,5 +34,6 @@ fun rememberVectorPainter(image: ImageVector, tintColor: Color) = name = image.name, tintColor = tintColor, tintBlendMode = image.tintBlendMode, + autoMirror = false, content = { _, _ -> RenderVectorGroup(group = image.root) } ) diff --git a/examples/todoapp-lite/.run/desktop.run.xml b/examples/todoapp-lite/.run/desktop.run.xml new file mode 100644 index 0000000000..c10d50877a --- /dev/null +++ b/examples/todoapp-lite/.run/desktop.run.xml @@ -0,0 +1,23 @@ + + + + + + + true + true + false + + + \ No newline at end of file diff --git a/examples/todoapp-lite/README.md b/examples/todoapp-lite/README.md index 67023dabed..e0526a0209 100755 --- a/examples/todoapp-lite/README.md +++ b/examples/todoapp-lite/README.md @@ -3,13 +3,13 @@ A simplified version of the [TodoApp example](https://github.com/JetBrains/compo Supported targets: Android and Desktop. ### Running desktop application -``` -./gradlew :desktop:run -``` + * To run, launch command: `./gradlew :desktop:run` + * Or choose **desktop** configuration in IDE and run it. + ![desktop-run-configuration.png](screenshots/desktop-run-configuration.png) ### Building native desktop distribution ``` -./gradlew :desktop:package +./gradlew :desktop:packageDistributionForCurrentOS # outputs are written to desktop/build/compose/binaries ``` diff --git a/examples/todoapp-lite/android/build.gradle.kts b/examples/todoapp-lite/android/build.gradle.kts index 9e99b62de6..e479462fba 100755 --- a/examples/todoapp-lite/android/build.gradle.kts +++ b/examples/todoapp-lite/android/build.gradle.kts @@ -5,11 +5,11 @@ plugins { } android { - compileSdk = 31 + compileSdk = 32 defaultConfig { - minSdk = 21 - targetSdk = 31 + minSdk = 26 + targetSdk = 32 versionCode = 1 versionName = "1.0" } @@ -23,7 +23,7 @@ android { dependencies { implementation(project(":common")) implementation(compose.material) - implementation("androidx.appcompat:appcompat:1.3.0") - implementation("androidx.activity:activity-compose:1.3.0") + implementation("androidx.appcompat:appcompat:1.5.1") + implementation("androidx.activity:activity-compose:1.5.0") } diff --git a/examples/todoapp-lite/android/src/main/AndroidManifest.xml b/examples/todoapp-lite/android/src/main/AndroidManifest.xml index e55a10c995..daf0c85ca6 100755 --- a/examples/todoapp-lite/android/src/main/AndroidManifest.xml +++ b/examples/todoapp-lite/android/src/main/AndroidManifest.xml @@ -13,7 +13,7 @@ + > diff --git a/examples/todoapp-lite/common/build.gradle.kts b/examples/todoapp-lite/common/build.gradle.kts index 9d690d5244..af3568551d 100755 --- a/examples/todoapp-lite/common/build.gradle.kts +++ b/examples/todoapp-lite/common/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.compose.compose - plugins { id("com.android.library") kotlin("multiplatform") @@ -22,11 +20,11 @@ kotlin { } android { - compileSdk = 31 + compileSdk = 32 defaultConfig { - minSdk = 21 - targetSdk = 31 + minSdk = 26 + targetSdk = 32 } compileOptions { diff --git a/examples/todoapp-lite/desktop/build.gradle.kts b/examples/todoapp-lite/desktop/build.gradle.kts index e634f8ca9c..81678409de 100755 --- a/examples/todoapp-lite/desktop/build.gradle.kts +++ b/examples/todoapp-lite/desktop/build.gradle.kts @@ -1,4 +1,3 @@ -import org.jetbrains.compose.compose import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { diff --git a/examples/todoapp-lite/gradle.properties b/examples/todoapp-lite/gradle.properties index 6849fa0b48..07a190fac2 100755 --- a/examples/todoapp-lite/gradle.properties +++ b/examples/todoapp-lite/gradle.properties @@ -19,6 +19,6 @@ android.useAndroidX=true android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official -kotlin.version=1.6.10 -agp.version=7.0.4 -compose.version=1.1.0 +kotlin.version=1.7.20 +agp.version=7.1.3 +compose.version=1.2.0 diff --git a/examples/todoapp-lite/gradle/wrapper/gradle-wrapper.properties b/examples/todoapp-lite/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100755 --- a/examples/todoapp-lite/gradle/wrapper/gradle-wrapper.properties +++ b/examples/todoapp-lite/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/todoapp-lite/screenshots/desktop-run-configuration.png b/examples/todoapp-lite/screenshots/desktop-run-configuration.png new file mode 100644 index 0000000000..3688407c6f Binary files /dev/null and b/examples/todoapp-lite/screenshots/desktop-run-configuration.png differ diff --git a/examples/todoapp/.run/browser.run.xml b/examples/todoapp/.run/browser.run.xml new file mode 100644 index 0000000000..246a33bdbf --- /dev/null +++ b/examples/todoapp/.run/browser.run.xml @@ -0,0 +1,23 @@ + + + + + + + true + true + false + + + \ No newline at end of file diff --git a/examples/todoapp/.run/desktop.run.xml b/examples/todoapp/.run/desktop.run.xml new file mode 100644 index 0000000000..c10d50877a --- /dev/null +++ b/examples/todoapp/.run/desktop.run.xml @@ -0,0 +1,23 @@ + + + + + + + true + true + false + + + \ No newline at end of file diff --git a/examples/todoapp/README.md b/examples/todoapp/README.md index ee267b1d9c..5a348940b7 100755 --- a/examples/todoapp/README.md +++ b/examples/todoapp/README.md @@ -34,13 +34,13 @@ Features: - Pluggable UI - Compose UI for Android, Desktop and Web, SwiftUI (not Compose) for iOS ### Running desktop application -``` -./gradlew :desktop:run -``` + * To run, launch command: `./gradlew :desktop:run` + * Or choose **desktop** configuration in IDE and run it. + ![desktop-run-configuration.png](screenshots/desktop-run-configuration.png) #### Building native desktop distribution ``` -./gradlew :desktop:package +./gradlew :desktop:packageDistributionForCurrentOS # outputs are written to desktop/build/compose/binaries ``` @@ -49,9 +49,9 @@ Features: Open project in Intellij IDEA or Android Studio and run "android" configuration. ### Running Web browser application -``` -./gradlew :web:jsBrowserDevelopmentRun -``` + * To run, launch command: `./gradlew :web:jsBrowserDevelopmentRun` + * Or choose **browser** configuration in IDE and run it. + ![browser-run-configuration.png](screenshots/browser-run-configuration.png) ### Running iOS application diff --git a/examples/todoapp/android/build.gradle.kts b/examples/todoapp/android/build.gradle.kts index 15cdab46f0..83ae73020d 100755 --- a/examples/todoapp/android/build.gradle.kts +++ b/examples/todoapp/android/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.compose.compose - plugins { id("com.android.application") kotlin("android") @@ -7,11 +5,11 @@ plugins { } android { - compileSdkVersion(31) + compileSdk = 32 defaultConfig { - minSdkVersion(23) - targetSdkVersion(31) + minSdk = 26 + targetSdk = 32 versionCode = 1 versionName = "1.0" } diff --git a/examples/todoapp/buildSrc/buildSrc/src/main/kotlin/Deps.kt b/examples/todoapp/buildSrc/buildSrc/src/main/kotlin/Deps.kt index bc5b542f1d..57e28c9d2e 100644 --- a/examples/todoapp/buildSrc/buildSrc/src/main/kotlin/Deps.kt +++ b/examples/todoapp/buildSrc/buildSrc/src/main/kotlin/Deps.kt @@ -20,6 +20,11 @@ object Deps { val testAnnotationsCommon get() = "org.jetbrains.kotlin:kotlin-test-annotations-common:$VERSION" } + object Coroutines { + private val VERSION get() = "1.6.4" + val swing get() = "org.jetbrains.kotlinx:kotlinx-coroutines-swing:$VERSION" + } + object Compose { private val VERSION get() = properties["compose.version"] val gradlePlugin get() = "org.jetbrains.compose:compose-gradle-plugin:$VERSION" diff --git a/examples/todoapp/buildSrc/gradle.properties b/examples/todoapp/buildSrc/gradle.properties index 5aab64a51b..fa9ca12895 100755 --- a/examples/todoapp/buildSrc/gradle.properties +++ b/examples/todoapp/buildSrc/gradle.properties @@ -1,3 +1,3 @@ # TODO can we get rid of duplication with root gradle.properties? -kotlin.version=1.6.10 -compose.version=1.1.0 +kotlin.version=1.7.10 +compose.version=1.2.0-rc02 diff --git a/examples/todoapp/buildSrc/src/main/kotlin/multiplatform-compose-setup.gradle.kts b/examples/todoapp/buildSrc/src/main/kotlin/multiplatform-compose-setup.gradle.kts index dd7083a01d..15749498b9 100644 --- a/examples/todoapp/buildSrc/src/main/kotlin/multiplatform-compose-setup.gradle.kts +++ b/examples/todoapp/buildSrc/src/main/kotlin/multiplatform-compose-setup.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.compose.compose - plugins { id("com.android.library") id("kotlin-multiplatform") diff --git a/examples/todoapp/common/compose-ui/src/commonMain/kotlin/example/todo/common/ui/TodoEditUi.kt b/examples/todoapp/common/compose-ui/src/commonMain/kotlin/example/todo/common/ui/TodoEditUi.kt index 93e1bb1e03..0a805b44da 100644 --- a/examples/todoapp/common/compose-ui/src/commonMain/kotlin/example/todo/common/ui/TodoEditUi.kt +++ b/examples/todoapp/common/compose-ui/src/commonMain/kotlin/example/todo/common/ui/TodoEditUi.kt @@ -46,7 +46,7 @@ fun TodoEditContent(component: TodoEdit) { onValueChange = component::onTextChanged ) - Row(modifier = Modifier.padding(8.dp)) { + Row(modifier = Modifier.padding(8.dp), verticalAlignment = Alignment.CenterVertically) { Text(text = "Completed") Spacer(modifier = Modifier.width(8.dp)) diff --git a/examples/todoapp/desktop/build.gradle.kts b/examples/todoapp/desktop/build.gradle.kts index b1f790b076..db755cbebd 100755 --- a/examples/todoapp/desktop/build.gradle.kts +++ b/examples/todoapp/desktop/build.gradle.kts @@ -1,4 +1,3 @@ -import org.jetbrains.compose.compose import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { @@ -19,6 +18,7 @@ kotlin { implementation(project(":common:database")) implementation(project(":common:root")) implementation(project(":common:compose-ui")) + implementation(Deps.JetBrains.Coroutines.swing) implementation(Deps.ArkIvanov.Decompose.decompose) implementation(Deps.ArkIvanov.Decompose.extensionsCompose) implementation(Deps.ArkIvanov.MVIKotlin.mvikotlin) diff --git a/examples/todoapp/desktop/src/jvmMain/kotlin/example/todo/desktop/Main.kt b/examples/todoapp/desktop/src/jvmMain/kotlin/example/todo/desktop/Main.kt index 08a7de3b87..005a1f5f36 100644 --- a/examples/todoapp/desktop/src/jvmMain/kotlin/example/todo/desktop/Main.kt +++ b/examples/todoapp/desktop/src/jvmMain/kotlin/example/todo/desktop/Main.kt @@ -1,6 +1,5 @@ package example.todo.desktop -import androidx.compose.desktop.DesktopTheme import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material.MaterialTheme import androidx.compose.material.Surface @@ -11,7 +10,6 @@ import androidx.compose.ui.window.rememberWindowState import com.arkivanov.decompose.ComponentContext import com.arkivanov.decompose.DefaultComponentContext import com.arkivanov.decompose.extensions.compose.jetbrains.lifecycle.LifecycleController -import com.arkivanov.decompose.extensions.compose.jetbrains.rememberRootComponent import com.arkivanov.essenty.lifecycle.LifecycleRegistry import com.arkivanov.mvikotlin.main.store.DefaultStoreFactory import com.badoo.reaktive.coroutinesinterop.asScheduler @@ -40,9 +38,7 @@ fun main() { ) { Surface(modifier = Modifier.fillMaxSize()) { MaterialTheme { - DesktopTheme { - TodoRootContent(root) - } + TodoRootContent(root) } } } diff --git a/examples/todoapp/gradle.properties b/examples/todoapp/gradle.properties index b8b81092a6..19d08d0797 100755 --- a/examples/todoapp/gradle.properties +++ b/examples/todoapp/gradle.properties @@ -23,6 +23,6 @@ org.gradle.parallel=true org.gradle.caching=true kotlin.native.disableCompilerDaemon=true -#todo remove -Pkotlin.version=1.6.20 from Xcode project, when stable version on Compose with Koltin 1.6.20 or later released -kotlin.version=1.6.10 -compose.version=1.1.0 \ No newline at end of file +#TODO also change version in buildSrc/gradle.properties +kotlin.version=1.7.10 +compose.version=1.2.0 \ No newline at end of file diff --git a/examples/todoapp/gradle/wrapper/gradle-wrapper.properties b/examples/todoapp/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100755 --- a/examples/todoapp/gradle/wrapper/gradle-wrapper.properties +++ b/examples/todoapp/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/todoapp/screenshots/browser-run-configuration.png b/examples/todoapp/screenshots/browser-run-configuration.png new file mode 100644 index 0000000000..8a08eeac53 Binary files /dev/null and b/examples/todoapp/screenshots/browser-run-configuration.png differ diff --git a/examples/todoapp/screenshots/desktop-run-configuration.png b/examples/todoapp/screenshots/desktop-run-configuration.png new file mode 100644 index 0000000000..3688407c6f Binary files /dev/null and b/examples/todoapp/screenshots/desktop-run-configuration.png differ diff --git a/examples/todoapp/web/build.gradle.kts b/examples/todoapp/web/build.gradle.kts index 07ddd968d5..89e634612b 100755 --- a/examples/todoapp/web/build.gradle.kts +++ b/examples/todoapp/web/build.gradle.kts @@ -18,7 +18,7 @@ kotlin { named("jsMain") { dependencies { implementation(compose.runtime) - implementation(compose.web.widgets) + implementation(compose.web.core) implementation(project(":common:utils")) implementation(project(":common:database")) implementation(project(":common:root")) @@ -38,6 +38,6 @@ kotlin { afterEvaluate { rootProject.extensions.configure { versions.webpackDevServer.version = "4.0.0" - versions.webpackCli.version = "4.9.0" + versions.webpackCli.version = "4.10.0" } } diff --git a/examples/todoapp/web/src/jsMain/kotlin/example/todo/web/App.kt b/examples/todoapp/web/src/jsMain/kotlin/example/todo/web/App.kt index 61af087e5e..b59b5b8467 100644 --- a/examples/todoapp/web/src/jsMain/kotlin/example/todo/web/App.kt +++ b/examples/todoapp/web/src/jsMain/kotlin/example/todo/web/App.kt @@ -8,9 +8,7 @@ import example.todo.common.database.DefaultTodoSharedDatabase import example.todo.common.database.todoDatabaseDriver import example.todo.common.root.integration.TodoRootComponent import kotlinx.browser.document -import org.jetbrains.compose.web.css.Style import org.jetbrains.compose.web.renderComposable -import org.jetbrains.compose.web.ui.Styles import org.w3c.dom.HTMLElement fun main() { @@ -28,8 +26,6 @@ fun main() { lifecycle.resume() renderComposable(root = rootElement) { - Style(Styles) - TodoRootUi(root) } } diff --git a/examples/todoapp/web/src/jsMain/kotlin/example/todo/web/Components.kt b/examples/todoapp/web/src/jsMain/kotlin/example/todo/web/Components.kt index 0262901d3a..829dab3323 100644 --- a/examples/todoapp/web/src/jsMain/kotlin/example/todo/web/Components.kt +++ b/examples/todoapp/web/src/jsMain/kotlin/example/todo/web/Components.kt @@ -1,8 +1,6 @@ package example.todo.web import androidx.compose.runtime.Composable -import org.jetbrains.compose.common.material.Text -import org.jetbrains.compose.common.ui.ExperimentalComposeWebWidgetsApi import org.jetbrains.compose.web.attributes.InputType import org.jetbrains.compose.web.css.AlignItems import org.jetbrains.compose.web.css.DisplayStyle @@ -66,7 +64,6 @@ fun Card(attrs: AttrBuilderContext<*> = {}, content: @Composable () -> Unit) { } } -@OptIn(ExperimentalComposeWebWidgetsApi::class) @Composable fun MaterialTextArea( id: String, @@ -95,7 +92,7 @@ fun MaterialTextArea( ) Label(forId = id) { - Text(text = label) + Text(value = label) } } } diff --git a/examples/visual-effects/.run/desktop.run.xml b/examples/visual-effects/.run/desktop.run.xml new file mode 100644 index 0000000000..29d5ed2ecd --- /dev/null +++ b/examples/visual-effects/.run/desktop.run.xml @@ -0,0 +1,23 @@ + + + + + + + true + true + false + + + \ No newline at end of file diff --git a/examples/visual-effects/README.md b/examples/visual-effects/README.md index 3eee5cb963..0943c31b12 100644 --- a/examples/visual-effects/README.md +++ b/examples/visual-effects/README.md @@ -1 +1,7 @@ Several visual effects implmented with Compose Multiplatform, used in 1.0 release announce video. + +### Running desktop application +* To run, launch command: `./gradlew run` +* Or choose **desktop** configuration in IDE and run it. + ![desktop-run-configuration.png](screenshots/desktop-run-configuration.png) + diff --git a/examples/visual-effects/build.gradle.kts b/examples/visual-effects/build.gradle.kts index 231c515a30..8fabdf370a 100644 --- a/examples/visual-effects/build.gradle.kts +++ b/examples/visual-effects/build.gradle.kts @@ -1,4 +1,3 @@ -import org.jetbrains.compose.compose import org.jetbrains.compose.desktop.application.dsl.TargetFormat import org.jetbrains.kotlin.gradle.tasks.KotlinCompile diff --git a/examples/visual-effects/gradle.properties b/examples/visual-effects/gradle.properties index 9bb8d52f7d..dbfb6452d2 100644 --- a/examples/visual-effects/gradle.properties +++ b/examples/visual-effects/gradle.properties @@ -1,3 +1,3 @@ kotlin.code.style=official -kotlin.version=1.6.10 -compose.version=1.1.0 +kotlin.version=1.7.20 +compose.version=1.2.0 diff --git a/examples/visual-effects/gradle/wrapper/gradle-wrapper.properties b/examples/visual-effects/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100644 --- a/examples/visual-effects/gradle/wrapper/gradle-wrapper.properties +++ b/examples/visual-effects/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/visual-effects/screenshots/desktop-run-configuration.png b/examples/visual-effects/screenshots/desktop-run-configuration.png new file mode 100644 index 0000000000..3688407c6f Binary files /dev/null and b/examples/visual-effects/screenshots/desktop-run-configuration.png differ diff --git a/examples/visual-effects/src/main/kotlin/HappyNY.kt b/examples/visual-effects/src/main/kotlin/HappyNY.kt index 74bd53ddc8..ca1d797055 100644 --- a/examples/visual-effects/src/main/kotlin/HappyNY.kt +++ b/examples/visual-effects/src/main/kotlin/HappyNY.kt @@ -23,11 +23,11 @@ import java.lang.Math.random import kotlin.math.* import kotlin.random.Random -val width = 1200 -val height = 800 -val snowCount = 80 -val starCount = 60 -val rocketPartsCount = 30 +const val width = 1200 +const val height = 800 +const val snowCount = 80 +const val starCount = 60 +const val rocketPartsCount = 30 data class SnowFlake( var x: Dp, @@ -42,14 +42,14 @@ data class SnowFlake( data class Star(val x: Dp, val y: Dp, val color: Color, val size: Dp) -val HNYString = "Happy New Year!" +const val HNYString = "Happy New Year!" class DoubleRocket(val particle: Particle) { - val STATE_ROCKET = 0 - val STATE_SMALL_ROCKETS = 1 + private val STATE_ROCKET = 0 + private val STATE_SMALL_ROCKETS = 1 var state = STATE_ROCKET var rockets: Array = emptyArray() - fun checkState(time: Long) { + private fun checkState(time: Long) { if (particle.vy > -3.0 && state == STATE_ROCKET) { explode(time) } @@ -69,7 +69,7 @@ class DoubleRocket(val particle: Particle) { } } - fun reset() { + private fun reset() { if (particle.vx < 0) return //to stop drawing after the second rocket. This could be commented out state = STATE_ROCKET particle.x = if (particle.vx > 0) width - 0.0 else 0.0 @@ -78,9 +78,9 @@ class DoubleRocket(val particle: Particle) { particle.vy = -12.5 } - fun explode(time: Long) { + private fun explode(time: Long) { val colors = arrayOf(Color(0xff, 0, 0), Color(192, 255, 192), Color(192, 212, 255)) - rockets = Array(7) { + rockets = Array(7) { val v = 1.2f + 1.0 * random() val angle = 2 * PI * random() Rocket( @@ -131,8 +131,8 @@ class Rocket(val particle: Particle, val color: Color, val startTime: Long = 0) } } - fun explode() { - parts = Array(rocketPartsCount) { + private fun explode() { + parts = Array(rocketPartsCount) { val v = 0.5f + 1.5 * random() val angle = 2 * PI * random() Particle(particle.x, particle.y, v * sin(angle) + particle.vx, v * cos(angle) + particle.vy, color, 1) @@ -202,7 +202,7 @@ val rocket = DoubleRocket(Particle(0.0, 1000.0, 2.1, -12.5, Color.White)) @Composable fun NYWindow(onCloseRequest: () -> Unit) { val windowState = remember { WindowState(width = width.dp, height = height.dp) } - Window(onCloseRequest = {}, undecorated = true, transparent = true, state = windowState) { + Window(onCloseRequest = onCloseRequest, undecorated = true, transparent = true, state = windowState) { NYContent() } } @@ -249,9 +249,7 @@ fun NYContent() { remember { prepareStarsAndSnowFlakes(stars, snowFlakes) } Surface( - modifier = Modifier.fillMaxSize().padding(5.dp).shadow(3.dp, RoundedCornerShape(20.dp)) - .pointerMoveFilter(onMove = { false; }, - onEnter = { false; }, onExit = { false; }), + modifier = Modifier.fillMaxSize().padding(5.dp).shadow(3.dp, RoundedCornerShape(20.dp)), color = Color.Black, shape = RoundedCornerShape(20.dp) ) { @@ -266,7 +264,7 @@ fun NYContent() { } if (!started) { //animation starts with delay, so there is some time to start recording - if (time - startTime > 7000000000 && time - startTime < 7100000000) println("ready!") + if (time - startTime in 7000000001..7099999999) println("ready!") if (time - startTime > 10000000000) { startTime = time //restarting timer started = true @@ -303,7 +301,7 @@ fun NYContent() { color = Color.White ) - if (started) { //delay to be able start recording + if (started) { //delay to be able to start recording //HNY var i = 0 val angle = (HNYString.length / 2 * 5) * -1.0f @@ -370,7 +368,7 @@ fun flickeringAlpha(time: Long): Float { val time = (time / 10000000) % 100 var result = 0.2f if (time > 75) { - result = result + 0.6f * ((time - 75) % 3) / 3 + result += 0.6f * ((time - 75) % 3) / 3 } return result } diff --git a/examples/visual-effects/src/main/kotlin/WaveEffect.kt b/examples/visual-effects/src/main/kotlin/WaveEffect.kt index c311f12519..1f09d139e9 100644 --- a/examples/visual-effects/src/main/kotlin/WaveEffect.kt +++ b/examples/visual-effects/src/main/kotlin/WaveEffect.kt @@ -10,6 +10,8 @@ import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.draw.* import androidx.compose.ui.graphics.Color +import androidx.compose.ui.input.pointer.PointerEventType +import androidx.compose.ui.input.pointer.onPointerEvent import androidx.compose.ui.input.pointer.pointerMoveFilter import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp @@ -20,7 +22,7 @@ import kotlin.math.* @Composable fun WaveEffect(onCloseRequest: () -> Unit, showControls: Boolean) { - var windowState = remember { WindowState(width = 1200.dp, height = 800.dp) } + val windowState = remember { WindowState(width = 1200.dp, height = 800.dp) } Window(onCloseRequest = {}, undecorated = true, transparent = true, state = windowState) { Grid() } @@ -70,8 +72,16 @@ fun Grid() { Surface( modifier = Modifier.fillMaxSize().padding(5.dp).shadow(3.dp, RoundedCornerShape(20.dp)) - .pointerMoveFilter(onMove = { mouseX = it.x.toInt(); mouseY = it.y.toInt(); false; }, - onEnter = { State.mouseUsed = true; false; }, onExit = { State.mouseUsed = false; false; }), + .onPointerEvent(PointerEventType.Move) { + mouseX = it.changes.first().position.x.toInt() + mouseY = it.changes.first().position.y.toInt() + } + .onPointerEvent(PointerEventType.Enter) { + State.mouseUsed = true + } + .onPointerEvent(PointerEventType.Exit) { + State.mouseUsed = false + }, color = Color(0, 0, 0), shape = RoundedCornerShape(20.dp) ) { @@ -80,13 +90,13 @@ fun Grid() { var y = 10 // initial position val shift = 25 var evenRow = false - var pointerOffsetX = (centerX / 2) - var pointerOffsety = (centerY / 2) + val pointerOffsetX = (centerX / 2) + val pointerOffsety = (centerY / 2) while (y < 790) { x = if (evenRow) 10 + shift else 10 while (x < 1190) { - var size: Int = size(x, y, pointerOffsetX, pointerOffsety) - var color = boxColor(x, y, time, pointerOffsetX, pointerOffsety) + val size: Int = size(x, y, pointerOffsetX, pointerOffsety) + val color = boxColor(x, y, time, pointerOffsetX, pointerOffsety) Dot(size, Modifier.offset(x.dp, y.dp), color, time) x += shift * 2 } @@ -111,19 +121,19 @@ fun Grid() { fun HighPanel(mouseX: Int, mouseY: Int) { Text( "Compose", - androidx.compose.ui.Modifier.offset(270.dp, 600.dp).scale(7.0f).alpha(alpha(mouseX, mouseY, 270, 700)), + Modifier.offset(270.dp, 600.dp).scale(7.0f).alpha(alpha(mouseX, mouseY, 270, 700)), color = colorMouse(mouseX, mouseY, 270, 700), fontWeight = FontWeight.Bold ) Text( "Multiplatform", - androidx.compose.ui.Modifier.offset(350.dp, 700.dp).scale(7.0f).alpha(alpha(mouseX, mouseY, 550, 800)), + Modifier.offset(350.dp, 700.dp).scale(7.0f).alpha(alpha(mouseX, mouseY, 550, 800)), color = colorMouse(mouseX, mouseY, 550, 800), fontWeight = FontWeight.Bold ) Text( "1.0", - androidx.compose.ui.Modifier.offset(800.dp, 700.dp).scale(7.0f).alpha(alpha(mouseX, mouseY, 800, 800)), + Modifier.offset(800.dp, 700.dp).scale(7.0f).alpha(alpha(mouseX, mouseY, 800, 800)), color = colorMouse(mouseX, mouseY, 800, 800), fontWeight = FontWeight.Bold ) @@ -137,7 +147,7 @@ private fun alpha(mouseX: Int, mouseY: Int, x: Int, y: Int): Float { } private fun colorMouse(mouseX: Int, mouseY: Int, x: Int, y: Int): Color { - var d = distance(mouseX, mouseY, x, y) / 450 + val d = distance(mouseX, mouseY, x, y) / 450 val color1 = Color(0x6B, 0x57, 0xFF) val color2 = Color(0xFE, 0x28, 0x57) val color3 = Color(0xFD, 0xB6, 0x0D) @@ -178,7 +188,7 @@ private fun size(x: Int, y: Int, mouseX: Int, mouseY: Int): Int { var result = 5 if (y > 550 && x < 550) return result if (y > 650 && x < 900) return result - var distance2 = sqrt((x - mouseX) * (x - mouseX) + (y - mouseY) * (y - mouseY).toDouble()) / 200 + val distance2 = sqrt((x - mouseX) * (x - mouseX) + (y - mouseY) * (y - mouseY).toDouble()) / 200 val scale: Double = (if (distance2 < 1) { addSize * (1 - distance2) } else 0.toDouble()) @@ -205,13 +215,13 @@ private fun boxColor(x: Int, y: Int, time: Long, mouseX: Int, mouseY: Int): Colo var color = Color.White if (c1 <= 0) { - var d = c2 / (c2 + c3) + val d = c2 / (c2 + c3) color = balancedColor(d, color2, color3) } else if (c2 <= 0) { - var d = c3 / (c1 + c3) + val d = c3 / (c1 + c3) color = balancedColor(d, color3, color1) } else if (c3 <= 0) { - var d = c1 / (c1 + c2) + val d = c1 / (c1 + c2) color = balancedColor(d, color1, color2) } diff --git a/examples/web-compose-bird/.run/browser.run.xml b/examples/web-compose-bird/.run/browser.run.xml new file mode 100644 index 0000000000..75289b1c79 --- /dev/null +++ b/examples/web-compose-bird/.run/browser.run.xml @@ -0,0 +1,23 @@ + + + + + + + true + true + false + + + \ No newline at end of file diff --git a/examples/web-compose-bird/README.md b/examples/web-compose-bird/README.md index f0aede880b..2f2db4e10f 100644 --- a/examples/web-compose-bird/README.md +++ b/examples/web-compose-bird/README.md @@ -1,6 +1,6 @@ # 🐦 Compose Bird -![](demo.gif) +![](screenshots/demo.gif) ![latestVersion](https://img.shields.io/github/v/release/theapache64/compose-bird) @@ -12,12 +12,13 @@ ## ▶️ Play - https://theapache64.github.io/compose-bird/ +- Use arrow **Up** key to fly ## 🏃 Run -``` -./gradlew jsBrowserRun -``` +* To run, launch command: `./gradlew jsBrowserRun` +* Or choose **browser** configuration in IDE and run it. + ![browser-run-configuration.png](screenshots/browser-run-configuration.png) ## 📦 Distribute diff --git a/examples/web-compose-bird/build.gradle.kts b/examples/web-compose-bird/build.gradle.kts index 444e94c391..8632c4639d 100644 --- a/examples/web-compose-bird/build.gradle.kts +++ b/examples/web-compose-bird/build.gradle.kts @@ -33,6 +33,6 @@ kotlin { afterEvaluate { rootProject.extensions.configure { versions.webpackDevServer.version = "4.0.0" - versions.webpackCli.version = "4.9.0" + versions.webpackCli.version = "4.10.0" } } diff --git a/examples/web-compose-bird/cover.jpeg b/examples/web-compose-bird/cover.jpeg deleted file mode 100644 index 7ad7efca86..0000000000 Binary files a/examples/web-compose-bird/cover.jpeg and /dev/null differ diff --git a/examples/web-compose-bird/gradle.properties b/examples/web-compose-bird/gradle.properties index 2e1d6a4d40..ba79da52a7 100644 --- a/examples/web-compose-bird/gradle.properties +++ b/examples/web-compose-bird/gradle.properties @@ -1,4 +1,3 @@ kotlin.code.style=official -org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -kotlin.version=1.6.10 -compose.version=1.1.0 +kotlin.version=1.7.10 +compose.version=1.2.0 diff --git a/examples/web-compose-bird/gradle/wrapper/gradle-wrapper.properties b/examples/web-compose-bird/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100644 --- a/examples/web-compose-bird/gradle/wrapper/gradle-wrapper.properties +++ b/examples/web-compose-bird/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/web-compose-bird/screenshots/browser-run-configuration.png b/examples/web-compose-bird/screenshots/browser-run-configuration.png new file mode 100644 index 0000000000..8a08eeac53 Binary files /dev/null and b/examples/web-compose-bird/screenshots/browser-run-configuration.png differ diff --git a/examples/web-compose-bird/demo.gif b/examples/web-compose-bird/screenshots/demo.gif similarity index 100% rename from examples/web-compose-bird/demo.gif rename to examples/web-compose-bird/screenshots/demo.gif diff --git a/examples/web-compose-in-js/.run/browser.run.xml b/examples/web-compose-in-js/.run/browser.run.xml new file mode 100644 index 0000000000..66615b40fd --- /dev/null +++ b/examples/web-compose-in-js/.run/browser.run.xml @@ -0,0 +1,23 @@ + + + + + + + true + true + false + + + \ No newline at end of file diff --git a/examples/web-compose-in-js/README.MD b/examples/web-compose-in-js/README.MD index 1360ca32f3..6876abee02 100644 --- a/examples/web-compose-in-js/README.MD +++ b/examples/web-compose-in-js/README.MD @@ -72,6 +72,11 @@ config.output = config.output || {}; config.output.library = "MyComposables"; ``` +### Running Web browser application +* To run, launch command: `./gradlew :jsBrowserDevelopmentRun` +* Or choose **browser** configuration in IDE and run it. + ![browser-run-configuration.png](screenshots/browser-run-configuration.png) + ### Building and using the output ``` diff --git a/examples/web-compose-in-js/build.gradle.kts b/examples/web-compose-in-js/build.gradle.kts index e01aa8b934..6a2ea7c9a6 100644 --- a/examples/web-compose-in-js/build.gradle.kts +++ b/examples/web-compose-in-js/build.gradle.kts @@ -1,8 +1,6 @@ -import org.jetbrains.compose.compose - plugins { - kotlin("multiplatform") version "1.6.10" - id("org.jetbrains.compose") version "1.0.1" + kotlin("multiplatform") + id("org.jetbrains.compose") } group = "me.user" diff --git a/examples/web-compose-in-js/gradle.properties b/examples/web-compose-in-js/gradle.properties index 65c9278611..07f5071b57 100644 --- a/examples/web-compose-in-js/gradle.properties +++ b/examples/web-compose-in-js/gradle.properties @@ -2,3 +2,5 @@ kotlin.code.style=official kotlin.mpp.enableGranularSourceSetsMetadata=true kotlin.native.enableDependencyPropagation=false kotlin.js.webpack.major.version=4 +kotlin.version=1.7.10 +compose.version=1.2.0 diff --git a/examples/web-compose-in-js/gradle/wrapper/gradle-wrapper.properties b/examples/web-compose-in-js/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100644 --- a/examples/web-compose-in-js/gradle/wrapper/gradle-wrapper.properties +++ b/examples/web-compose-in-js/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/web-compose-in-js/screenshots/browser-run-configuration.png b/examples/web-compose-in-js/screenshots/browser-run-configuration.png new file mode 100644 index 0000000000..8a08eeac53 Binary files /dev/null and b/examples/web-compose-in-js/screenshots/browser-run-configuration.png differ diff --git a/examples/web-compose-in-js/settings.gradle.kts b/examples/web-compose-in-js/settings.gradle.kts index ae8fb66b50..5df0eb175c 100644 --- a/examples/web-compose-in-js/settings.gradle.kts +++ b/examples/web-compose-in-js/settings.gradle.kts @@ -3,7 +3,11 @@ pluginManagement { gradlePluginPortal() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") } - + + plugins { + kotlin("multiplatform").version(extra["kotlin.version"] as String) + id("org.jetbrains.compose").version(extra["compose.version"] as String) + } } rootProject.name = "web-compose-in-js" diff --git a/examples/web-landing/.run/browser.run.xml b/examples/web-landing/.run/browser.run.xml new file mode 100644 index 0000000000..ab1d4d1969 --- /dev/null +++ b/examples/web-landing/.run/browser.run.xml @@ -0,0 +1,23 @@ + + + + + + + true + true + false + + + \ No newline at end of file diff --git a/examples/web-landing/README.md b/examples/web-landing/README.md old mode 100644 new mode 100755 index 9543f483ad..5e7f325b85 --- a/examples/web-landing/README.md +++ b/examples/web-landing/README.md @@ -1,4 +1,6 @@ +Landing page of Compose for Web -**Run in browser:** - -`./gradlew jsRun` +### Running Web browser application + * To run, launch command: `./gradlew :jsBrowserRun` + * Or choose **browser** configuration in IDE and run it. + ![browser-run-configuration.png](screenshots/browser-run-configuration.png) diff --git a/examples/web-landing/gradle.properties b/examples/web-landing/gradle.properties index 9bb8d52f7d..ba79da52a7 100644 --- a/examples/web-landing/gradle.properties +++ b/examples/web-landing/gradle.properties @@ -1,3 +1,3 @@ kotlin.code.style=official -kotlin.version=1.6.10 -compose.version=1.1.0 +kotlin.version=1.7.10 +compose.version=1.2.0 diff --git a/examples/web-landing/gradle/wrapper/gradle-wrapper.properties b/examples/web-landing/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100644 --- a/examples/web-landing/gradle/wrapper/gradle-wrapper.properties +++ b/examples/web-landing/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/web-landing/screenshots/browser-run-configuration.png b/examples/web-landing/screenshots/browser-run-configuration.png new file mode 100644 index 0000000000..8a08eeac53 Binary files /dev/null and b/examples/web-landing/screenshots/browser-run-configuration.png differ diff --git a/examples/web-with-react/.run/browser.run.xml b/examples/web-with-react/.run/browser.run.xml new file mode 100644 index 0000000000..ab1d4d1969 --- /dev/null +++ b/examples/web-with-react/.run/browser.run.xml @@ -0,0 +1,23 @@ + + + + + + + true + true + false + + + \ No newline at end of file diff --git a/examples/web-with-react/README.md b/examples/web-with-react/README.md index c5fc03c24e..8706bbfa81 100644 --- a/examples/web-with-react/README.md +++ b/examples/web-with-react/README.md @@ -19,6 +19,6 @@ It requires adding `external` declarations. For example: [ReactYoutubePlayer.kt] Here is a good tutorial - [Using packages from NPM](https://play.kotlinlang.org/hands-on/Building%20Web%20Applications%20with%20React%20and%20Kotlin%20JS/07_Using_Packages_From_NPM) ### Running web application -``` -./gradlew jsBrowserRun -``` \ No newline at end of file +* To run, launch command: `./gradlew :jsBrowserRun` +* Or choose **browser** configuration in IDE and run it. + ![browser-run-configuration.png](screenshots/browser-run-configuration.png) diff --git a/examples/web-with-react/build.gradle.kts b/examples/web-with-react/build.gradle.kts index 658afacc94..e60cbf1fd6 100644 --- a/examples/web-with-react/build.gradle.kts +++ b/examples/web-with-react/build.gradle.kts @@ -36,6 +36,6 @@ kotlin { afterEvaluate { rootProject.extensions.configure { versions.webpackDevServer.version = "4.0.0" - versions.webpackCli.version = "4.9.0" + versions.webpackCli.version = "4.10.0" } } diff --git a/examples/web-with-react/gradle.properties b/examples/web-with-react/gradle.properties index 9bb8d52f7d..ba79da52a7 100644 --- a/examples/web-with-react/gradle.properties +++ b/examples/web-with-react/gradle.properties @@ -1,3 +1,3 @@ kotlin.code.style=official -kotlin.version=1.6.10 -compose.version=1.1.0 +kotlin.version=1.7.10 +compose.version=1.2.0 diff --git a/examples/web-with-react/gradle/wrapper/gradle-wrapper.properties b/examples/web-with-react/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100644 --- a/examples/web-with-react/gradle/wrapper/gradle-wrapper.properties +++ b/examples/web-with-react/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/web-with-react/screenshots/browser-run-configuration.png b/examples/web-with-react/screenshots/browser-run-configuration.png new file mode 100644 index 0000000000..8a08eeac53 Binary files /dev/null and b/examples/web-with-react/screenshots/browser-run-configuration.png differ diff --git a/examples/widgets-gallery/README.md b/examples/widgets-gallery/README.md index 985bfb2854..262f9759d0 100644 --- a/examples/widgets-gallery/README.md +++ b/examples/widgets-gallery/README.md @@ -9,13 +9,13 @@ An example of Compose application for Desktop and Android platforms, demonstrating how to use various Material widgets. ### Running desktop application -``` -./gradlew :desktop:run -``` + * To run, launch command: `./gradlew :desktop:run` + * Or choose **desktop** configuration in IDE and run it. + ![desktop-run-configuration.png](screenshots/desktop-run-configuration.png) ### Building native desktop distribution ``` -./gradlew :desktop:package +./gradlew :desktop:packageDistributionForCurrentOS # outputs are written to desktop/build/compose/binaries ``` diff --git a/examples/widgets-gallery/android/build.gradle.kts b/examples/widgets-gallery/android/build.gradle.kts index ea3aaf410d..13073d45fb 100644 --- a/examples/widgets-gallery/android/build.gradle.kts +++ b/examples/widgets-gallery/android/build.gradle.kts @@ -5,11 +5,11 @@ plugins { } android { - compileSdk = 31 + compileSdk = 32 defaultConfig { minSdk = 26 - targetSdk = 30 + targetSdk = 32 versionCode = 1 versionName = "1.0" } @@ -22,5 +22,5 @@ android { dependencies { implementation(project(":common")) - implementation("androidx.activity:activity-compose:1.3.0") + implementation("androidx.activity:activity-compose:1.5.0") } \ No newline at end of file diff --git a/examples/widgets-gallery/android/src/main/AndroidManifest.xml b/examples/widgets-gallery/android/src/main/AndroidManifest.xml index bbfbcf26cc..fc44b2f2bc 100644 --- a/examples/widgets-gallery/android/src/main/AndroidManifest.xml +++ b/examples/widgets-gallery/android/src/main/AndroidManifest.xml @@ -10,8 +10,9 @@ android:supportsRtl="true" android:theme="@style/Theme.AppCompat.Light.NoActionBar"> + > diff --git a/examples/widgets-gallery/common/build.gradle.kts b/examples/widgets-gallery/common/build.gradle.kts index 0b8317b3da..7e1d3865b2 100644 --- a/examples/widgets-gallery/common/build.gradle.kts +++ b/examples/widgets-gallery/common/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.compose.compose - plugins { id("com.android.library") kotlin("multiplatform") @@ -21,8 +19,8 @@ kotlin { } named("androidMain") { dependencies { - api("androidx.appcompat:appcompat:1.3.1") - api("androidx.core:core-ktx:1.3.1") + api("androidx.appcompat:appcompat:1.5.1") + api("androidx.core:core-ktx:1.8.0") } } named("desktopMain") { @@ -34,11 +32,11 @@ kotlin { } android { - compileSdk = 30 + compileSdk = 32 defaultConfig { - minSdk = 21 - targetSdk = 30 + minSdk = 26 + targetSdk = 32 } compileOptions { diff --git a/examples/widgets-gallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt b/examples/widgets-gallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt index 30eed99b90..a49921fe64 100644 --- a/examples/widgets-gallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt +++ b/examples/widgets-gallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt @@ -3,10 +3,4 @@ package org.jetbrains.compose.demo.widgets.platform import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset -actual fun Modifier.pointerMoveFilter( - onEnter: () -> Boolean, - onExit: () -> Boolean, - onMove: (Offset) -> Boolean -): Modifier = this - actual fun Modifier.cursorForHorizontalResize() = this \ No newline at end of file diff --git a/examples/widgets-gallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt b/examples/widgets-gallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt index 18176214db..552d284f9a 100644 --- a/examples/widgets-gallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt +++ b/examples/widgets-gallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt @@ -1,10 +1,7 @@ package org.jetbrains.compose.demo.widgets.platform import androidx.compose.runtime.Composable -import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.painter.Painter -import androidx.compose.ui.graphics.vector.ImageVector -import org.jetbrains.compose.demo.widgets.platform.R @Composable actual fun painterResource(res: String): Painter { @@ -17,6 +14,5 @@ private fun drawableId(res: String): Int { val imageName = res.substringAfterLast("/").substringBeforeLast(".") val drawableClass = R.drawable::class.java val field = drawableClass.getDeclaredField(imageName) - val idValue = field.get(drawableClass) as Integer - return idValue.toInt() + return field.get(drawableClass) as Int } \ No newline at end of file diff --git a/examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt b/examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt index 1d20d024a2..c6b3b3af40 100644 --- a/examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt +++ b/examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt @@ -3,10 +3,4 @@ package org.jetbrains.compose.demo.widgets.platform import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset -expect fun Modifier.pointerMoveFilter( - onEnter: () -> Boolean = { true }, - onExit: () -> Boolean = { true }, - onMove: (Offset) -> Boolean = { true } -): Modifier - expect fun Modifier.cursorForHorizontalResize(): Modifier \ No newline at end of file diff --git a/examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/MainView.kt b/examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/MainView.kt index dc52e21dc0..5049b3dbb4 100644 --- a/examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/MainView.kt +++ b/examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/MainView.kt @@ -4,6 +4,9 @@ import androidx.compose.animation.core.Spring import androidx.compose.animation.core.SpringSpec import androidx.compose.animation.core.animateDpAsState import androidx.compose.foundation.clickable +import androidx.compose.foundation.hoverable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsHoveredAsState import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items @@ -26,7 +29,6 @@ import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import org.jetbrains.compose.demo.widgets.platform.VerticalScrollbar -import org.jetbrains.compose.demo.widgets.platform.pointerMoveFilter import org.jetbrains.compose.demo.widgets.theme.WidgetGalleryTheme import org.jetbrains.compose.demo.widgets.ui.utils.PanelState import org.jetbrains.compose.demo.widgets.ui.utils.ResizablePanel @@ -132,7 +134,8 @@ private fun WidgetsListItemViewImpl( .height(height) .padding(start = 16.dp) ) { - var inFocus by remember { mutableStateOf(false) } + val inFocusInteractionSource = remember { MutableInteractionSource() } + val inFocus by inFocusInteractionSource.collectIsHoveredAsState() val textColor = LocalContentColor.current.let { when { isCurrent -> it @@ -147,16 +150,7 @@ private fun WidgetsListItemViewImpl( modifier = Modifier .align(Alignment.CenterVertically) .clipToBounds() - .pointerMoveFilter( - onEnter = { - inFocus = true - true - }, - onExit = { - inFocus = false - true - } - ), + .hoverable(inFocusInteractionSource), softWrap = true, fontSize = fontSize, overflow = TextOverflow.Ellipsis, diff --git a/examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/WidgetsType.kt b/examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/WidgetsType.kt index d2c32e396d..cdbc0b08e1 100644 --- a/examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/WidgetsType.kt +++ b/examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/WidgetsType.kt @@ -1,5 +1,7 @@ package org.jetbrains.compose.demo.widgets.ui +import java.util.Locale + enum class WidgetsType(private val customTitle: String? = null) { APP_BARS, BUTTONS, @@ -13,9 +15,11 @@ enum class WidgetsType(private val customTitle: String? = null) { val readableName: String by lazy { name.split("_") - .map { it.toLowerCase() } + .map { it.lowercase(Locale.getDefault()) } .mapIndexed { i, it -> - if (i == 0) it.capitalize() else it + if (i == 0) it.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() + } else it }.joinToString(" ") } diff --git a/examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/utils/Text.kt b/examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/utils/Text.kt index 81254ab169..083e8165cb 100644 --- a/examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/utils/Text.kt +++ b/examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/utils/Text.kt @@ -14,7 +14,7 @@ fun SubtitleText(subtitle: String, modifier: Modifier = Modifier) { } @Composable -fun TitleText(title: String, modifier: Modifier = Modifier) { +fun TitleText(title: String) { Text( text = title, style = typography.h6.copy(fontSize = 14.sp), diff --git a/examples/widgets-gallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt b/examples/widgets-gallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt index e2010717a9..4fa07e3eb5 100644 --- a/examples/widgets-gallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt +++ b/examples/widgets-gallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt @@ -8,13 +8,5 @@ import androidx.compose.ui.input.pointer.pointerHoverIcon import androidx.compose.ui.input.pointer.pointerMoveFilter import java.awt.Cursor -@OptIn(ExperimentalComposeUiApi::class) -actual fun Modifier.pointerMoveFilter( - onEnter: () -> Boolean, - onExit: () -> Boolean, - onMove: (Offset) -> Boolean -): Modifier = this.pointerMoveFilter(onEnter = onEnter, onExit = onExit, onMove = onMove) - -@OptIn(ExperimentalComposeUiApi::class) actual fun Modifier.cursorForHorizontalResize(): Modifier = this.pointerHoverIcon(PointerIcon(Cursor(Cursor.E_RESIZE_CURSOR))) diff --git a/examples/widgets-gallery/desktop/build.gradle.kts b/examples/widgets-gallery/desktop/build.gradle.kts index 43706a4d6b..aeaf89a327 100644 --- a/examples/widgets-gallery/desktop/build.gradle.kts +++ b/examples/widgets-gallery/desktop/build.gradle.kts @@ -1,4 +1,3 @@ -import org.jetbrains.compose.compose import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { diff --git a/examples/widgets-gallery/gradle.properties b/examples/widgets-gallery/gradle.properties index a960629879..64161edf1a 100644 --- a/examples/widgets-gallery/gradle.properties +++ b/examples/widgets-gallery/gradle.properties @@ -19,6 +19,6 @@ android.useAndroidX=true android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official -kotlin.version=1.6.10 -compose.version=1.1.0 -agp.version=7.0.4 +kotlin.version=1.7.20 +compose.version=1.2.0 +agp.version=7.1.3 diff --git a/examples/widgets-gallery/gradle/wrapper/gradle-wrapper.properties b/examples/widgets-gallery/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100644 --- a/examples/widgets-gallery/gradle/wrapper/gradle-wrapper.properties +++ b/examples/widgets-gallery/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/widgets-gallery/screenshots/desktop-run-configuration.png b/examples/widgets-gallery/screenshots/desktop-run-configuration.png new file mode 100644 index 0000000000..3688407c6f Binary files /dev/null and b/examples/widgets-gallery/screenshots/desktop-run-configuration.png differ diff --git a/experimental/examples/chat-mpp/build.gradle.kts b/experimental/examples/chat-mpp/build.gradle.kts index 04d04a3f1c..e8e2e4ce02 100644 --- a/experimental/examples/chat-mpp/build.gradle.kts +++ b/experimental/examples/chat-mpp/build.gradle.kts @@ -193,11 +193,11 @@ project.tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile::class.ja } android { - compileSdk = 31 + compileSdk = 32 defaultConfig { - minSdk = 21 - targetSdk = 31 + minSdk = 26 + targetSdk = 32 } compileOptions { diff --git a/experimental/examples/chat-mpp/gradle.properties b/experimental/examples/chat-mpp/gradle.properties index ac08e49268..70880bc2ed 100644 --- a/experimental/examples/chat-mpp/gradle.properties +++ b/experimental/examples/chat-mpp/gradle.properties @@ -7,8 +7,8 @@ kotlin.mpp.enableGranularSourceSetsMetadata=true kotlin.native.binary.memoryModel=experimental compose.desktop.verbose=true android.useAndroidX=true -compose.version=1.2.0-alpha01-dev725 -kotlin.version=1.6.21 +compose.version=1.2.0-rc02 +kotlin.version=1.7.10 agp.version=7.0.4 kotlin.js.webpack.major.version=4 org.jetbrains.compose.experimental.jscanvas.enabled=true diff --git a/experimental/examples/chat-mpp/gradle/wrapper/gradle-wrapper.properties b/experimental/examples/chat-mpp/gradle/wrapper/gradle-wrapper.properties index aa991fceae..ae04661ee7 100644 --- a/experimental/examples/chat-mpp/gradle/wrapper/gradle-wrapper.properties +++ b/experimental/examples/chat-mpp/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/experimental/examples/falling-balls-mpp/build.gradle.kts b/experimental/examples/falling-balls-mpp/build.gradle.kts index 01b05ff5e4..dde5bb35e1 100644 --- a/experimental/examples/falling-balls-mpp/build.gradle.kts +++ b/experimental/examples/falling-balls-mpp/build.gradle.kts @@ -104,8 +104,8 @@ kotlin { dependsOn(commonMain) kotlin.srcDirs("src/jvmMain/kotlin") dependencies { - api("androidx.appcompat:appcompat:1.4.1") - implementation("androidx.activity:activity-compose:1.4.0") + implementation("androidx.appcompat:appcompat:1.5.1") + implementation("androidx.activity:activity-compose:1.5.0") } } @@ -223,11 +223,11 @@ project.tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile::class.ja } android { - compileSdk = 31 + compileSdk = 32 defaultConfig { - minSdk = 21 - targetSdk = 31 + minSdk = 26 + targetSdk = 32 } compileOptions { diff --git a/experimental/examples/falling-balls-mpp/gradle.properties b/experimental/examples/falling-balls-mpp/gradle.properties index db26638086..ea3c3d3b2d 100644 --- a/experimental/examples/falling-balls-mpp/gradle.properties +++ b/experimental/examples/falling-balls-mpp/gradle.properties @@ -1,6 +1,6 @@ org.gradle.jvmargs=-Xmx3g -compose.version=1.2.0-alpha01-dev725 -kotlin.version=1.6.21 +compose.version=1.2.0-rc02 +kotlin.version=1.7.10 kotlin.code.style=official kotlin.native.cacheKind=none kotlin.native.useEmbeddableCompilerJar=true diff --git a/experimental/examples/falling-balls-mpp/gradle/wrapper/gradle-wrapper.properties b/experimental/examples/falling-balls-mpp/gradle/wrapper/gradle-wrapper.properties index aa991fceae..ae04661ee7 100644 --- a/experimental/examples/falling-balls-mpp/gradle/wrapper/gradle-wrapper.properties +++ b/experimental/examples/falling-balls-mpp/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/experimental/examples/falling-balls-mpp/src/commonMain/kotlin/bouncingBalls/BouncingBalls.kt b/experimental/examples/falling-balls-mpp/src/commonMain/kotlin/bouncingBalls/BouncingBalls.kt index 9ca392be3b..58f5b65adb 100644 --- a/experimental/examples/falling-balls-mpp/src/commonMain/kotlin/bouncingBalls/BouncingBalls.kt +++ b/experimental/examples/falling-balls-mpp/src/commonMain/kotlin/bouncingBalls/BouncingBalls.kt @@ -26,7 +26,7 @@ import kotlin.math.max import kotlin.math.sin import kotlin.random.Random -private inline fun Modifier.noRippleClickable(crossinline onClick: (Offset) -> Unit): Modifier = +private fun Modifier.noRippleClickable(onClick: (Offset) -> Unit): Modifier = composed { clickable( indication = null, diff --git a/examples/intellij-plugin-with-experimental-shared-base/.gitignore b/experimental/examples/intellij-plugin-with-experimental-shared-base/.gitignore similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/.gitignore rename to experimental/examples/intellij-plugin-with-experimental-shared-base/.gitignore diff --git a/experimental/examples/intellij-plugin-with-experimental-shared-base/.run/runIde.run.xml b/experimental/examples/intellij-plugin-with-experimental-shared-base/.run/runIde.run.xml new file mode 100644 index 0000000000..52aca017c2 --- /dev/null +++ b/experimental/examples/intellij-plugin-with-experimental-shared-base/.run/runIde.run.xml @@ -0,0 +1,23 @@ + + + + + + + true + true + false + + + \ No newline at end of file diff --git a/examples/intellij-plugin-with-experimental-shared-base/README.md b/experimental/examples/intellij-plugin-with-experimental-shared-base/README.md similarity index 77% rename from examples/intellij-plugin-with-experimental-shared-base/README.md rename to experimental/examples/intellij-plugin-with-experimental-shared-base/README.md index e8d43a50bc..8af73b48ec 100644 --- a/examples/intellij-plugin-with-experimental-shared-base/README.md +++ b/experimental/examples/intellij-plugin-with-experimental-shared-base/README.md @@ -10,8 +10,9 @@ and allows sharing Compose runtime between multiple plugins ### Usage 1. Start test IDE: - * Choose the `runIde` task in the Gradle panel in Intellij; - * Or run the following command in terminal: `./gradlew runIde`; + * Run the following command in terminal: `./gradlew runIde` + * Or choose **runIde** configuration in IDE and run it. + ![ide-run-configuration.png](screenshots/ide-run-configuration.png) 2. Create a new project or open any existing; 3. Select `Show Compose Demo...` from the `Tools` menu. diff --git a/examples/intellij-plugin-with-experimental-shared-base/build.gradle.kts b/experimental/examples/intellij-plugin-with-experimental-shared-base/build.gradle.kts similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/build.gradle.kts rename to experimental/examples/intellij-plugin-with-experimental-shared-base/build.gradle.kts diff --git a/examples/intellij-plugin-with-experimental-shared-base/gradle.properties b/experimental/examples/intellij-plugin-with-experimental-shared-base/gradle.properties similarity index 57% rename from examples/intellij-plugin-with-experimental-shared-base/gradle.properties rename to experimental/examples/intellij-plugin-with-experimental-shared-base/gradle.properties index bf812e078f..8cf2d8fd5a 100644 --- a/examples/intellij-plugin-with-experimental-shared-base/gradle.properties +++ b/experimental/examples/intellij-plugin-with-experimental-shared-base/gradle.properties @@ -1,5 +1,5 @@ kotlin.stdlib.default.dependency=false kotlin.code.style=official -kotlin.version=1.6.10 -compose.version=1.1.0 +kotlin.version=1.7.10 +compose.version=1.2.0-rc02 diff --git a/examples/intellij-plugin-with-experimental-shared-base/gradle/wrapper/gradle-wrapper.jar b/experimental/examples/intellij-plugin-with-experimental-shared-base/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/gradle/wrapper/gradle-wrapper.jar rename to experimental/examples/intellij-plugin-with-experimental-shared-base/gradle/wrapper/gradle-wrapper.jar diff --git a/examples/intellij-plugin-with-experimental-shared-base/gradle/wrapper/gradle-wrapper.properties b/experimental/examples/intellij-plugin-with-experimental-shared-base/gradle/wrapper/gradle-wrapper.properties similarity index 92% rename from examples/intellij-plugin-with-experimental-shared-base/gradle/wrapper/gradle-wrapper.properties rename to experimental/examples/intellij-plugin-with-experimental-shared-base/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100644 --- a/examples/intellij-plugin-with-experimental-shared-base/gradle/wrapper/gradle-wrapper.properties +++ b/experimental/examples/intellij-plugin-with-experimental-shared-base/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/intellij-plugin-with-experimental-shared-base/gradlew b/experimental/examples/intellij-plugin-with-experimental-shared-base/gradlew similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/gradlew rename to experimental/examples/intellij-plugin-with-experimental-shared-base/gradlew diff --git a/examples/intellij-plugin-with-experimental-shared-base/gradlew.bat b/experimental/examples/intellij-plugin-with-experimental-shared-base/gradlew.bat similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/gradlew.bat rename to experimental/examples/intellij-plugin-with-experimental-shared-base/gradlew.bat diff --git a/experimental/examples/intellij-plugin-with-experimental-shared-base/screenshots/ide-run-configuration.png b/experimental/examples/intellij-plugin-with-experimental-shared-base/screenshots/ide-run-configuration.png new file mode 100644 index 0000000000..9dc9453a38 Binary files /dev/null and b/experimental/examples/intellij-plugin-with-experimental-shared-base/screenshots/ide-run-configuration.png differ diff --git a/examples/intellij-plugin-with-experimental-shared-base/settings.gradle.kts b/experimental/examples/intellij-plugin-with-experimental-shared-base/settings.gradle.kts similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/settings.gradle.kts rename to experimental/examples/intellij-plugin-with-experimental-shared-base/settings.gradle.kts diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/ComposeDemoAction.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/ComposeDemoAction.kt old mode 100755 new mode 100644 similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/ComposeDemoAction.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/ComposeDemoAction.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/IntellijTheme.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/IntellijTheme.kt similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/IntellijTheme.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/IntellijTheme.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/color/ColorLineMarkerProvider.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/color/ColorLineMarkerProvider.kt similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/color/ColorLineMarkerProvider.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/color/ColorLineMarkerProvider.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/color/ColorPicker.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/color/ColorPicker.kt similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/color/ColorPicker.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/color/ColorPicker.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/color/HSV.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/color/HSV.kt similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/color/HSV.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/color/HSV.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/panel/ComposeToolWindow.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/panel/ComposeToolWindow.kt similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/panel/ComposeToolWindow.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/panel/ComposeToolWindow.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/panel/CounterPanel.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/panel/CounterPanel.kt similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/panel/CounterPanel.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/panel/CounterPanel.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/panel/CounterState.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/panel/CounterState.kt similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/panel/CounterState.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/panel/CounterState.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/Color.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/Color.kt similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/Color.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/Color.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/Shape.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/Shape.kt similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/Shape.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/Shape.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/Theme.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/Theme.kt similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/Theme.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/Theme.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/Type.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/Type.kt similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/Type.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/Type.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/intellij/SwingColor.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/intellij/SwingColor.kt similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/intellij/SwingColor.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/intellij/SwingColor.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/intellij/ThemeChangeListener.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/intellij/ThemeChangeListener.kt similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/intellij/ThemeChangeListener.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/theme/intellij/ThemeChangeListener.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/Buttons.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/Buttons.kt old mode 100755 new mode 100644 similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/Buttons.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/Buttons.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/LazyScrollable.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/LazyScrollable.kt old mode 100755 new mode 100644 similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/LazyScrollable.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/LazyScrollable.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/Loaders.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/Loaders.kt old mode 100755 new mode 100644 similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/Loaders.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/Loaders.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/TextInputs.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/TextInputs.kt old mode 100755 new mode 100644 similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/TextInputs.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/TextInputs.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/Toggles.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/Toggles.kt old mode 100755 new mode 100644 similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/Toggles.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/kotlin/com/jetbrains/compose/widgets/Toggles.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/resources/META-INF/plugin.xml b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/resources/META-INF/plugin.xml similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/resources/META-INF/plugin.xml rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/resources/META-INF/plugin.xml diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/main/resources/icons/compose.svg b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/resources/icons/compose.svg similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/main/resources/icons/compose.svg rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/main/resources/icons/compose.svg diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/test/kotlin/com/jetbrains/compose/color/ColorPickerUITest.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/test/kotlin/com/jetbrains/compose/color/ColorPickerUITest.kt similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/test/kotlin/com/jetbrains/compose/color/ColorPickerUITest.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/test/kotlin/com/jetbrains/compose/color/ColorPickerUITest.kt diff --git a/examples/intellij-plugin-with-experimental-shared-base/src/test/kotlin/com/jetbrains/compose/color/HSVTest.kt b/experimental/examples/intellij-plugin-with-experimental-shared-base/src/test/kotlin/com/jetbrains/compose/color/HSVTest.kt similarity index 100% rename from examples/intellij-plugin-with-experimental-shared-base/src/test/kotlin/com/jetbrains/compose/color/HSVTest.kt rename to experimental/examples/intellij-plugin-with-experimental-shared-base/src/test/kotlin/com/jetbrains/compose/color/HSVTest.kt diff --git a/experimental/examples/minesweeper/build.gradle.kts b/experimental/examples/minesweeper/build.gradle.kts index 2c216cb93b..3d7b2e393a 100644 --- a/experimental/examples/minesweeper/build.gradle.kts +++ b/experimental/examples/minesweeper/build.gradle.kts @@ -15,8 +15,8 @@ buildscript { } plugins { - kotlin("multiplatform") version "1.6.21" - id("org.jetbrains.compose") version "1.2.0-alpha01-dev725" + kotlin("multiplatform") version "1.7.10" + id("org.jetbrains.compose") version "1.2.0-rc02" } version = "1.0-SNAPSHOT" diff --git a/experimental/examples/minesweeper/gradle/wrapper/gradle-wrapper.properties b/experimental/examples/minesweeper/gradle/wrapper/gradle-wrapper.properties index aa991fceae..ae04661ee7 100644 --- a/experimental/examples/minesweeper/gradle/wrapper/gradle-wrapper.properties +++ b/experimental/examples/minesweeper/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradle-plugins/gradle.properties b/gradle-plugins/gradle.properties index d16b53a8b6..c8b8f42e47 100644 --- a/gradle-plugins/gradle.properties +++ b/gradle-plugins/gradle.properties @@ -2,7 +2,7 @@ org.gradle.parallel=true kotlin.code.style=official # Default version of Compose Libraries used by Gradle plugin -compose.version=1.2.0-beta02 +compose.version=1.2.0 # The latest version of Compose Compiler used by Gradle plugin. Used only in tests. compose.tests.compiler.version=1.3.2 # The latest version of Kotlin compatible with compose.tests.compiler.version. Used only in tests. diff --git a/templates/desktop-template/build.gradle.kts b/templates/desktop-template/build.gradle.kts index 23b948a759..fcabd18e01 100644 --- a/templates/desktop-template/build.gradle.kts +++ b/templates/desktop-template/build.gradle.kts @@ -1,4 +1,3 @@ -import org.jetbrains.compose.compose import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { diff --git a/templates/desktop-template/gradle.properties b/templates/desktop-template/gradle.properties index 5679ab5bab..5c878d8016 100644 --- a/templates/desktop-template/gradle.properties +++ b/templates/desktop-template/gradle.properties @@ -1,4 +1,4 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 kotlin.code.style=official -kotlin.version=1.6.10 -compose.version=1.1.0 +kotlin.version=1.7.20 +compose.version=1.2.0 diff --git a/templates/desktop-template/gradle/wrapper/gradle-wrapper.properties b/templates/desktop-template/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100644 --- a/templates/desktop-template/gradle/wrapper/gradle-wrapper.properties +++ b/templates/desktop-template/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/templates/multiplatform-template/android/build.gradle.kts b/templates/multiplatform-template/android/build.gradle.kts index 3d06374e92..13073d45fb 100644 --- a/templates/multiplatform-template/android/build.gradle.kts +++ b/templates/multiplatform-template/android/build.gradle.kts @@ -5,11 +5,11 @@ plugins { } android { - compileSdkVersion(31) + compileSdk = 32 defaultConfig { - minSdkVersion(21) - targetSdkVersion(31) + minSdk = 26 + targetSdk = 32 versionCode = 1 versionName = "1.0" } @@ -22,5 +22,5 @@ android { dependencies { implementation(project(":common")) - implementation("androidx.activity:activity-compose:1.3.0") + implementation("androidx.activity:activity-compose:1.5.0") } \ No newline at end of file diff --git a/templates/multiplatform-template/android/src/main/AndroidManifest.xml b/templates/multiplatform-template/android/src/main/AndroidManifest.xml index f4fea5dec1..8a21a18925 100644 --- a/templates/multiplatform-template/android/src/main/AndroidManifest.xml +++ b/templates/multiplatform-template/android/src/main/AndroidManifest.xml @@ -12,7 +12,7 @@ + > diff --git a/templates/multiplatform-template/common/build.gradle.kts b/templates/multiplatform-template/common/build.gradle.kts index e9dea64bcf..eb05262148 100644 --- a/templates/multiplatform-template/common/build.gradle.kts +++ b/templates/multiplatform-template/common/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.compose.compose - plugins { id("com.android.library") kotlin("multiplatform") @@ -22,19 +20,19 @@ kotlin { } named("androidMain") { dependencies { - api("androidx.appcompat:appcompat:1.3.1") - api("androidx.core:core-ktx:1.6.0") + api("androidx.appcompat:appcompat:1.5.1") + api("androidx.core:core-ktx:1.8.0") } } } } android { - compileSdkVersion(31) + compileSdk = 32 defaultConfig { - minSdkVersion(21) - targetSdkVersion(31) + minSdk = 26 + targetSdk = 32 } compileOptions { diff --git a/templates/multiplatform-template/desktop/build.gradle.kts b/templates/multiplatform-template/desktop/build.gradle.kts index 18042da48d..e2f2d8466f 100644 --- a/templates/multiplatform-template/desktop/build.gradle.kts +++ b/templates/multiplatform-template/desktop/build.gradle.kts @@ -1,4 +1,3 @@ -import org.jetbrains.compose.compose import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { diff --git a/templates/multiplatform-template/gradle.properties b/templates/multiplatform-template/gradle.properties index c0554eeeca..c32d311951 100644 --- a/templates/multiplatform-template/gradle.properties +++ b/templates/multiplatform-template/gradle.properties @@ -2,6 +2,6 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 android.useAndroidX=true android.enableJetifier=true kotlin.code.style=official -kotlin.version=1.6.10 -agp.version=7.0.4 -compose.version=1.1.0 +kotlin.version=1.7.20 +agp.version=7.1.3 +compose.version=1.2.0 diff --git a/templates/multiplatform-template/gradle/wrapper/gradle-wrapper.properties b/templates/multiplatform-template/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100644 --- a/templates/multiplatform-template/gradle/wrapper/gradle-wrapper.properties +++ b/templates/multiplatform-template/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/templates/web-template/.gitignore b/templates/web-template/.gitignore new file mode 100644 index 0000000000..a32b16597b --- /dev/null +++ b/templates/web-template/.gitignore @@ -0,0 +1,15 @@ +*.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 diff --git a/templates/web-template/.run/browser.run.xml b/templates/web-template/.run/browser.run.xml new file mode 100644 index 0000000000..ab1d4d1969 --- /dev/null +++ b/templates/web-template/.run/browser.run.xml @@ -0,0 +1,23 @@ + + + + + + + true + true + false + + + \ No newline at end of file diff --git a/templates/web-template/README.md b/templates/web-template/README.md new file mode 100644 index 0000000000..fcd77188f5 --- /dev/null +++ b/templates/web-template/README.md @@ -0,0 +1,4 @@ +Compose Web Application + +- `./gradlew jsBrowserRun` - run application in a browser +- `./gradlew jsBrowserProductionWebpack` - produce the output in `build/distributions` \ No newline at end of file diff --git a/templates/web-template/build.gradle.kts b/templates/web-template/build.gradle.kts index 94a67bfbd0..2414d946d4 100644 --- a/templates/web-template/build.gradle.kts +++ b/templates/web-template/build.gradle.kts @@ -1,4 +1,3 @@ -import org.jetbrains.compose.compose import org.jetbrains.compose.desktop.application.dsl.TargetFormat import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension @@ -36,7 +35,7 @@ afterEvaluate { rootProject.extensions.configure { nodeVersion = "16.0.0" versions.webpackDevServer.version = "4.0.0" - versions.webpackCli.version = "4.9.0" + versions.webpackCli.version = "4.10.0" } } diff --git a/templates/web-template/gradle.properties b/templates/web-template/gradle.properties index 5679ab5bab..8f61b3884d 100644 --- a/templates/web-template/gradle.properties +++ b/templates/web-template/gradle.properties @@ -1,4 +1,4 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 kotlin.code.style=official -kotlin.version=1.6.10 -compose.version=1.1.0 +kotlin.version=1.7.10 +compose.version=1.2.0 diff --git a/templates/web-template/gradle/wrapper/gradle-wrapper.properties b/templates/web-template/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..ae04661ee7 100644 --- a/templates/web-template/gradle/wrapper/gradle-wrapper.properties +++ b/templates/web-template/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/tools/replace.sh b/tools/replace.sh deleted file mode 100755 index 46512a1c10..0000000000 --- a/tools/replace.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash - -# Replace hard-coded Compose version in Compose repo projects. Usage: ./replace.sh 1.0.0-rc6 - -ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"/.. - -# Add folders which should contain up-to-date versions -declare -a folders=( - "templates" - "examples" - "gradle-plugins" - "components" - "ci" - "web" - "tutorials" -) - -if [ -z "$@" ]; then -echo "Specify Compose version. For example: ./replace.sh 1.0.0-rc6" -exit 1 -fi -COMPOSE_VERSION=$@ - -if [[ $OSTYPE == 'darwin'* ]]; then - SED=gsed -else - SED=sed -fi - -replaceCompose() { - $SED -i -e "s/$1/$2/g" $3 -} - -replaceComposeInFile() { - echo "Replace in $1" - replaceCompose '^compose.version=.*' 'compose.version='"$COMPOSE_VERSION"'' $1 - replaceCompose '^COMPOSE_CORE_VERSION=.*' 'COMPOSE_CORE_VERSION='"$COMPOSE_VERSION"'' $1 - replaceCompose '^COMPOSE_WEB_VERSION=.*' 'COMPOSE_WEB_VERSION='"$COMPOSE_VERSION"'' $1 - replaceCompose 'id("org.jetbrains.compose") version ".*"' 'id("org.jetbrains.compose") version "'"$COMPOSE_VERSION"'"' $1 - replaceCompose '"org.jetbrains.compose:compose-gradle-plugin:.*"' '"org.jetbrains.compose:compose-gradle-plugin:'"$COMPOSE_VERSION"'"' $1 -} - -replaceComposeInFolder() { - find $ROOT/$1 -wholename $2 -not -path "**/build**" -not -path "**/.gradle**" | while read file; do replaceComposeInFile "$file"; done -} - -for folder in "${folders[@]}" -do - replaceComposeInFolder $folder "**gradle.properties" - replaceComposeInFolder $folder "**README.md" -done diff --git a/tools/replaceVersion.sh b/tools/replaceVersion.sh new file mode 100755 index 0000000000..5fff3033ac --- /dev/null +++ b/tools/replaceVersion.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +# Replace hard-coded Compose version in Compose repo projects. Usage: ./replace.sh 1.0.0-rc6 + +ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"/.. + +# Add folders which should contain up-to-date versions +declare -a folders=( + "templates" + "examples" + "gradle-plugins" + "components" + "ci" + "web" + "tutorials" +) + +if [ -z "$1" ]; then +echo "Specify Compose version. For example: ./replace.sh 1.2.0-beta02 1.7.10" +exit 1 +fi + +if [ -z "$2" ]; then +echo "Specify Kotlin version. For example: ./replace.sh 1.2.0-beta02 1.7.10" +exit 1 +fi + +COMPOSE_VERSION=$1 +KOTLIN_VERSION=$2 + +if [[ $OSTYPE == 'darwin'* ]]; then + SED=gsed +else + SED=sed +fi + +replaceVersion() { + $SED -i -e "s/$1/$2/g" $3 +} + +replaceVersionInFile() { + echo "Replace in $1" + replaceVersion '^compose.version=.*' 'compose.version='"$COMPOSE_VERSION"'' $1 + replaceVersion '^COMPOSE_CORE_VERSION=.*' 'COMPOSE_CORE_VERSION='"$COMPOSE_VERSION"'' $1 + replaceVersion '^COMPOSE_WEB_VERSION=.*' 'COMPOSE_WEB_VERSION='"$COMPOSE_VERSION"'' $1 + replaceVersion 'id("org.jetbrains.compose") version ".*"' 'id("org.jetbrains.compose") version "'"$COMPOSE_VERSION"'"' $1 + replaceVersion '"org.jetbrains.compose:compose-gradle-plugin:.*"' '"org.jetbrains.compose:compose-gradle-plugin:'"$COMPOSE_VERSION"'"' $1 + replaceVersion '^kotlin.version=.*' 'kotlin.version='"$KOTLIN_VERSION"'' $1 + replaceVersion 'kotlin("multiplatform") version ".*"' 'kotlin("multiplatform") version "'"$KOTLIN_VERSION"'"' $1 + replaceVersion 'kotlin("jvm") version ".*"' 'kotlin("jvm") version "'"$KOTLIN_VERSION"'"' $1 +} + +replaceVersionInFolder() { + find $ROOT/$1 -wholename $2 -not -path "**/build**" -not -path "**/.gradle**" | while read file; do replaceVersionInFile "$file"; done +} + +for folder in "${folders[@]}" +do + replaceVersionInFolder $folder "**gradle.properties" + replaceVersionInFolder $folder "**README.md" +done diff --git a/tutorials/Getting_Started/README.md b/tutorials/Getting_Started/README.md index 7657d5f426..315e954cf9 100644 --- a/tutorials/Getting_Started/README.md +++ b/tutorials/Getting_Started/README.md @@ -44,8 +44,8 @@ The Compose plugin version used in the wizard above might not be the latest. Upd For the latest versions, see the [latest versions](https://github.com/JetBrains/compose-jb/releases) site and the [Kotlin](https://kotlinlang.org/) site. ``` plugins { - kotlin("jvm") version "1.6.10" - id("org.jetbrains.compose") version "1.1.0" + kotlin("jvm") version "1.7.20" + id("org.jetbrains.compose") version "1.2.0" } ``` @@ -80,8 +80,8 @@ Then create `build.gradle.kts` with the following content: import org.jetbrains.compose.compose plugins { - kotlin("jvm") version "1.6.10" - id("org.jetbrains.compose") version "1.1.0" + kotlin("jvm") version "1.7.20" + id("org.jetbrains.compose") version "1.2.0" } repositories { diff --git a/tutorials/Image_And_Icons_Manipulations/README.md b/tutorials/Image_And_Icons_Manipulations/README.md index 653db7a3e0..227fa791b9 100755 --- a/tutorials/Image_And_Icons_Manipulations/README.md +++ b/tutorials/Image_And_Icons_Manipulations/README.md @@ -1,313 +1,313 @@ -# Image and in-app icons manipulations - -## What is covered - -In this tutorial we will show you how to work with images using Compose for Desktop. - -## Loading images from resources - -Using images from application resources is very simple. Suppose we have a PNG image that is placed in the `resources` directory in our project. For this tutorial we will use the image sample: - -Sample - -```kotlin -import androidx.compose.foundation.Image -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.window.singleWindowApplication - -fun main() = singleWindowApplication { - Image( - painter = painterResource("sample.png"), - contentDescription = "Sample", - modifier = Modifier.fillMaxSize() - ) -} -``` - -`painterResource` supports raster (BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP) and vector formats (SVG, [XML vector drawable](https://developer.android.com/guide/topics/graphics/vector-drawable-resources)). - -Resources - -## Loading images from device storage or network asynchronously - -To load an image stored in the device memory (or from network) you can use `loadImageBitmap`, `loadSvgPainter` or `loadXmlImageVector`. The example below shows how to use them to load an image asynchronously. - -```kotlin -import androidx.compose.foundation.Image -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.width -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.produceState -import androidx.compose.runtime.remember -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.ImageBitmap -import androidx.compose.ui.graphics.painter.BitmapPainter -import androidx.compose.ui.graphics.painter.Painter -import androidx.compose.ui.graphics.vector.ImageVector -import androidx.compose.ui.graphics.vector.rememberVectorPainter -import androidx.compose.ui.layout.ContentScale -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.res.loadImageBitmap -import androidx.compose.ui.res.loadSvgPainter -import androidx.compose.ui.res.loadXmlImageVector -import androidx.compose.ui.unit.Density -import androidx.compose.ui.unit.dp -import androidx.compose.ui.window.singleWindowApplication -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext -import org.xml.sax.InputSource -import java.io.File -import java.io.IOException -import java.net.URL - -fun main() = singleWindowApplication { - val density = LocalDensity.current - Column { - AsyncImage( - load = { loadImageBitmap(File("sample.png")) }, - painterFor = { remember { BitmapPainter(it) } }, - contentDescription = "Sample", - modifier = Modifier.width(200.dp) - ) - AsyncImage( - load = { loadSvgPainter("https://github.com/JetBrains/compose-jb/raw/master/artwork/idea-logo.svg", density) }, - painterFor = { it }, - contentDescription = "Idea logo", - contentScale = ContentScale.FillWidth, - modifier = Modifier.width(200.dp) - ) - AsyncImage( - load = { loadXmlImageVector(File("compose-logo.xml"), density) }, - painterFor = { rememberVectorPainter(it) }, - contentDescription = "Compose logo", - contentScale = ContentScale.FillWidth, - modifier = Modifier.width(200.dp) - ) - } -} - -@Composable -fun AsyncImage( - load: suspend () -> T, - painterFor: @Composable (T) -> Painter, - contentDescription: String, - modifier: Modifier = Modifier, - contentScale: ContentScale = ContentScale.Fit, -) { - val image: T? by produceState(null) { - value = withContext(Dispatchers.IO) { - try { - load() - } catch (e: IOException) { - // instead of printing to console, you can also write this to log, - // or show some error placeholder - e.printStackTrace() - null - } - } - } - - if (image != null) { - Image( - painter = painterFor(image!!), - contentDescription = contentDescription, - contentScale = contentScale, - modifier = modifier - ) - } -} - -/* Loading from file with java.io API */ - -fun loadImageBitmap(file: File): ImageBitmap = - file.inputStream().buffered().use(::loadImageBitmap) - -fun loadSvgPainter(file: File, density: Density): Painter = - file.inputStream().buffered().use { loadSvgPainter(it, density) } - -fun loadXmlImageVector(file: File, density: Density): ImageVector = - file.inputStream().buffered().use { loadXmlImageVector(InputSource(it), density) } - -/* Loading from network with java.net API */ - -fun loadImageBitmap(url: String): ImageBitmap = - URL(url).openStream().buffered().use(::loadImageBitmap) - -fun loadSvgPainter(url: String, density: Density): Painter = - URL(url).openStream().buffered().use { loadSvgPainter(it, density) } - -fun loadXmlImageVector(url: String, density: Density): ImageVector = - URL(url).openStream().buffered().use { loadXmlImageVector(InputSource(it), density) } - -/* Loading from network with Ktor client API (https://ktor.io/docs/client.html). */ - -/* - -suspend fun loadImageBitmap(url: String): ImageBitmap = - urlStream(url).use(::loadImageBitmap) - -suspend fun loadSvgPainter(url: String, density: Density): Painter = - urlStream(url).use { loadSvgPainter(it, density) } - -suspend fun loadXmlImageVector(url: String, density: Density): ImageVector = - urlStream(url).use { loadXmlImageVector(InputSource(it), density) } - -@OptIn(KtorExperimentalAPI::class) -private suspend fun urlStream(url: String) = HttpClient(CIO).use { - ByteArrayInputStream(it.get(url)) -} - - */ -``` - -Storage - -[PNG](sample.png) - -[SVG](../../artwork/idea-logo.svg) - -[XML vector drawable](../../artwork/compose-logo.xml) - -## Drawing images using Canvas -```kotlin -import androidx.compose.foundation.Canvas -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.runtime.remember -import androidx.compose.ui.Modifier -import androidx.compose.ui.geometry.Offset -import androidx.compose.ui.geometry.Size -import androidx.compose.ui.graphics.Paint -import androidx.compose.ui.graphics.drawscope.drawIntoCanvas -import androidx.compose.ui.graphics.vector.rememberVectorPainter -import androidx.compose.ui.graphics.withSave -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.res.loadImageBitmap -import androidx.compose.ui.res.loadSvgPainter -import androidx.compose.ui.res.loadXmlImageVector -import androidx.compose.ui.res.useResource -import androidx.compose.ui.window.singleWindowApplication -import org.xml.sax.InputSource - -fun main() = singleWindowApplication { - val density = LocalDensity.current // to calculate the intrinsic size of vector images (SVG, XML) - - val sample = remember { - useResource("sample.png", ::loadImageBitmap) - } - val ideaLogo = remember { - useResource("idea-logo.svg") { loadSvgPainter(it, density) } - } - val composeLogo = rememberVectorPainter( - remember { - useResource("compose-logo.xml") { loadXmlImageVector(InputSource(it), density) } - } - ) - - Canvas( - modifier = Modifier.fillMaxSize() - ) { - drawIntoCanvas { canvas -> - canvas.withSave { - canvas.drawImage(sample, Offset.Zero, Paint()) - canvas.translate(sample.width.toFloat(), 0f) - with(ideaLogo) { - draw(ideaLogo.intrinsicSize) - } - canvas.translate(ideaLogo.intrinsicSize.width, 0f) - with(composeLogo) { - draw(Size(100f, 100f)) - } - } - } - } -} -``` - -[PNG](sample.png) - -[SVG](../../artwork/idea-logo.svg) - -[XML vector drawable](../../artwork/compose-logo.xml) - -## Setting the application window icon - -You can set the icon for the window via parameter in the `Window` function. - -Note that to change the icon on the taskbar on some OS (macOs), you should change icon in [build.gradle](/tutorials/Native_distributions_and_local_execution#app-icon) - -```kotlin -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.paint -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.window.Window -import androidx.compose.ui.window.application - -fun main() = application { - val icon = painterResource("sample.png") - Window( - onCloseRequest = ::exitApplication, - icon = icon - ) { - Box(Modifier.paint(icon).fillMaxSize()) - } -} -``` - -Window icon - -In case of `singleWindowApplication` usage, you can use the following approach: - -```kotlin -import androidx.compose.material.Text -import androidx.compose.ui.graphics.painter.BitmapPainter -import androidx.compose.ui.res.loadImageBitmap -import androidx.compose.ui.res.useResource -import androidx.compose.ui.window.singleWindowApplication - -fun main() { - val icon = BitmapPainter(useResource("sample.png", ::loadImageBitmap)) - singleWindowApplication(icon = icon) { - Text("Hello World!") - } -} -``` - -## Setting the application tray icon - -You can create a tray icon for your application: - -```kotlin -import androidx.compose.foundation.Image -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.window.Tray -import androidx.compose.ui.window.Window -import androidx.compose.ui.window.application - -fun main() = application { - val icon = painterResource("sample.png") - - Tray( - icon = icon, - menu = { - Item("Quit App", onClick = ::exitApplication) - } - ) - - Window(onCloseRequest = ::exitApplication, icon = icon) { - Image( - painter = icon, - contentDescription = "Icon", - modifier = Modifier.fillMaxSize() - ) - } -} -``` - -Tray icon +# Image and in-app icons manipulations + +## What is covered + +In this tutorial we will show you how to work with images using Compose for Desktop. + +## Loading images from resources + +Using images from application resources is very simple. Suppose we have a PNG image that is placed in the `resources` directory in our project. For this tutorial we will use the image sample: + +Sample + +```kotlin +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.window.singleWindowApplication + +fun main() = singleWindowApplication { + Image( + painter = painterResource("sample.png"), + contentDescription = "Sample", + modifier = Modifier.fillMaxSize() + ) +} +``` + +`painterResource` supports raster (BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP) and vector formats (SVG, [XML vector drawable](https://developer.android.com/guide/topics/graphics/vector-drawable-resources)). + +Resources + +## Loading images from device storage or network asynchronously + +To load an image stored in the device memory (or from network) you can use `loadImageBitmap`, `loadSvgPainter` or `loadXmlImageVector`. The example below shows how to use them to load an image asynchronously. + +```kotlin +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.width +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.produceState +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.ImageBitmap +import androidx.compose.ui.graphics.painter.BitmapPainter +import androidx.compose.ui.graphics.painter.Painter +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.graphics.vector.rememberVectorPainter +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.res.loadImageBitmap +import androidx.compose.ui.res.loadSvgPainter +import androidx.compose.ui.res.loadXmlImageVector +import androidx.compose.ui.unit.Density +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.singleWindowApplication +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import org.xml.sax.InputSource +import java.io.File +import java.io.IOException +import java.net.URL + +fun main() = singleWindowApplication { + val density = LocalDensity.current + Column { + AsyncImage( + load = { loadImageBitmap(File("sample.png")) }, + painterFor = { remember { BitmapPainter(it) } }, + contentDescription = "Sample", + modifier = Modifier.width(200.dp) + ) + AsyncImage( + load = { loadSvgPainter("https://github.com/JetBrains/compose-jb/raw/master/artwork/idea-logo.svg", density) }, + painterFor = { it }, + contentDescription = "Idea logo", + contentScale = ContentScale.FillWidth, + modifier = Modifier.width(200.dp) + ) + AsyncImage( + load = { loadXmlImageVector(File("compose-logo.xml"), density) }, + painterFor = { rememberVectorPainter(it) }, + contentDescription = "Compose logo", + contentScale = ContentScale.FillWidth, + modifier = Modifier.width(200.dp) + ) + } +} + +@Composable +fun AsyncImage( + load: suspend () -> T, + painterFor: @Composable (T) -> Painter, + contentDescription: String, + modifier: Modifier = Modifier, + contentScale: ContentScale = ContentScale.Fit, +) { + val image: T? by produceState(null) { + value = withContext(Dispatchers.IO) { + try { + load() + } catch (e: IOException) { + // instead of printing to console, you can also write this to log, + // or show some error placeholder + e.printStackTrace() + null + } + } + } + + if (image != null) { + Image( + painter = painterFor(image!!), + contentDescription = contentDescription, + contentScale = contentScale, + modifier = modifier + ) + } +} + +/* Loading from file with java.io API */ + +fun loadImageBitmap(file: File): ImageBitmap = + file.inputStream().buffered().use(::loadImageBitmap) + +fun loadSvgPainter(file: File, density: Density): Painter = + file.inputStream().buffered().use { loadSvgPainter(it, density) } + +fun loadXmlImageVector(file: File, density: Density): ImageVector = + file.inputStream().buffered().use { loadXmlImageVector(InputSource(it), density) } + +/* Loading from network with java.net API */ + +fun loadImageBitmap(url: String): ImageBitmap = + URL(url).openStream().buffered().use(::loadImageBitmap) + +fun loadSvgPainter(url: String, density: Density): Painter = + URL(url).openStream().buffered().use { loadSvgPainter(it, density) } + +fun loadXmlImageVector(url: String, density: Density): ImageVector = + URL(url).openStream().buffered().use { loadXmlImageVector(InputSource(it), density) } + +/* Loading from network with Ktor client API (https://ktor.io/docs/client.html). */ + +/* + +suspend fun loadImageBitmap(url: String): ImageBitmap = + urlStream(url).use(::loadImageBitmap) + +suspend fun loadSvgPainter(url: String, density: Density): Painter = + urlStream(url).use { loadSvgPainter(it, density) } + +suspend fun loadXmlImageVector(url: String, density: Density): ImageVector = + urlStream(url).use { loadXmlImageVector(InputSource(it), density) } + +@OptIn(KtorExperimentalAPI::class) +private suspend fun urlStream(url: String) = HttpClient(CIO).use { + ByteArrayInputStream(it.get(url)) +} + + */ +``` + +Storage + +[PNG](sample.png) + +[SVG](../../artwork/idea-logo.svg) + +[XML vector drawable](../../artwork/compose-logo.xml) + +## Drawing images using Canvas +```kotlin +import androidx.compose.foundation.Canvas +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.geometry.Size +import androidx.compose.ui.graphics.Paint +import androidx.compose.ui.graphics.drawscope.drawIntoCanvas +import androidx.compose.ui.graphics.vector.rememberVectorPainter +import androidx.compose.ui.graphics.withSave +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.res.loadImageBitmap +import androidx.compose.ui.res.loadSvgPainter +import androidx.compose.ui.res.loadXmlImageVector +import androidx.compose.ui.res.useResource +import androidx.compose.ui.window.singleWindowApplication +import org.xml.sax.InputSource + +fun main() = singleWindowApplication { + val density = LocalDensity.current // to calculate the intrinsic size of vector images (SVG, XML) + + val sample = remember { + useResource("sample.png", ::loadImageBitmap) + } + val ideaLogo = remember { + useResource("idea-logo.svg") { loadSvgPainter(it, density) } + } + val composeLogo = rememberVectorPainter( + remember { + useResource("compose-logo.xml") { loadXmlImageVector(InputSource(it), density) } + } + ) + + Canvas( + modifier = Modifier.fillMaxSize() + ) { + drawIntoCanvas { canvas -> + canvas.withSave { + canvas.drawImage(sample, Offset.Zero, Paint()) + canvas.translate(sample.width.toFloat(), 0f) + with(ideaLogo) { + draw(ideaLogo.intrinsicSize) + } + canvas.translate(ideaLogo.intrinsicSize.width, 0f) + with(composeLogo) { + draw(Size(100f, 100f)) + } + } + } + } +} +``` + +[PNG](sample.png) + +[SVG](../../artwork/idea-logo.svg) + +[XML vector drawable](../../artwork/compose-logo.xml) + +## Setting the application window icon + +You can set the icon for the window via parameter in the `Window` function. + +Note that to change the icon on the taskbar on some OS (macOs), you should change icon in [build.gradle](/tutorials/Native_distributions_and_local_execution#app-icon) + +```kotlin +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.paint +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.window.Window +import androidx.compose.ui.window.application + +fun main() = application { + val icon = painterResource("sample.png") + Window( + onCloseRequest = ::exitApplication, + icon = icon + ) { + Box(Modifier.paint(icon).fillMaxSize()) + } +} +``` + +Window icon + +In case of `singleWindowApplication` usage, you can use the following approach: + +```kotlin +import androidx.compose.material.Text +import androidx.compose.ui.graphics.painter.BitmapPainter +import androidx.compose.ui.res.loadImageBitmap +import androidx.compose.ui.res.useResource +import androidx.compose.ui.window.singleWindowApplication + +fun main() { + val icon = BitmapPainter(useResource("sample.png", ::loadImageBitmap)) + singleWindowApplication(icon = icon) { + Text("Hello World!") + } +} +``` + +## Setting the application tray icon + +You can create a tray icon for your application: + +```kotlin +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.window.Tray +import androidx.compose.ui.window.Window +import androidx.compose.ui.window.application + +fun main() = application { + val icon = painterResource("sample.png") + + Tray( + icon = icon, + menu = { + Item("Quit App", onClick = ::exitApplication) + } + ) + + Window(onCloseRequest = ::exitApplication, icon = icon) { + Image( + painter = icon, + contentDescription = "Icon", + modifier = Modifier.fillMaxSize() + ) + } +} +``` + +Tray icon diff --git a/tutorials/Native_distributions_and_local_execution/README.md b/tutorials/Native_distributions_and_local_execution/README.md index b62a6d4fbc..fd23282714 100755 --- a/tutorials/Native_distributions_and_local_execution/README.md +++ b/tutorials/Native_distributions_and_local_execution/README.md @@ -62,7 +62,7 @@ The plugin creates the following tasks: Note, that there is no cross-compilation support available at the moment, so the formats can only be built using the specific OS (e.g. to build `.dmg` you have to use macOS). Tasks that are not compatible with the current OS are skipped by default. -* `package` is a [lifecycle](https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:lifecycle_tasks) task, +* `packageDistributionForCurrentOS` is a [lifecycle](https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:lifecycle_tasks) task, aggregating all package tasks for an application. * `packageUberJarForCurrentOS` is used to create a single jar file, containing all dependencies for current OS. The task is available starting from the M2 release. diff --git a/tutorials/Web/Getting_Started/README.md b/tutorials/Web/Getting_Started/README.md index be90390b33..bdcdb54070 100644 --- a/tutorials/Web/Getting_Started/README.md +++ b/tutorials/Web/Getting_Started/README.md @@ -38,8 +38,8 @@ pluginManagement { ``` kotlin // Add compose gradle plugin plugins { - kotlin("multiplatform") version "1.6.10" - id("org.jetbrains.compose") version "1.1.0" + kotlin("multiplatform") version "1.7.10" + id("org.jetbrains.compose") version "1.2.0" } // Add maven repositories diff --git a/web/gradle.properties b/web/gradle.properties index 1838132f93..42de5f34c3 100644 --- a/web/gradle.properties +++ b/web/gradle.properties @@ -1,4 +1,4 @@ -compose.version=1.1.0 +compose.version=1.2.0 compose.web.buildSamples=false compose.web.tests.integration.withFirefox compose.web.tests.skip.benchmarks=false