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/gradle.properties b/examples/codeviewer/gradle.properties index 4e152adc88..ef72cbf492 100644 --- a/examples/codeviewer/gradle.properties +++ b/examples/codeviewer/gradle.properties @@ -20,5 +20,5 @@ android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official kotlin.version=1.7.10 -agp.version=7.0.4 +agp.version=7.1.3 compose.version=1.2.0-beta02 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..f956ba0d9d 100755 --- a/examples/imageviewer/common/build.gradle.kts +++ b/examples/imageviewer/common/build.gradle.kts @@ -20,8 +20,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 +35,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/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/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..df9d1d3e2e 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,17 +9,12 @@ 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 @@ -31,6 +23,7 @@ import androidx.compose.material.Surface import androidx.compose.material.Text import androidx.compose.material.TopAppBar 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 @@ -81,7 +74,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 +92,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 +146,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) }, @@ -209,16 +190,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/gradle.properties b/examples/imageviewer/gradle.properties index 4e152adc88..ef72cbf492 100755 --- a/examples/imageviewer/gradle.properties +++ b/examples/imageviewer/gradle.properties @@ -20,5 +20,5 @@ android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official kotlin.version=1.7.10 -agp.version=7.0.4 +agp.version=7.1.3 compose.version=1.2.0-beta02 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..e71878fa48 100644 --- a/examples/issues/common/build.gradle.kts +++ b/examples/issues/common/build.gradle.kts @@ -24,8 +24,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 +40,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/gradle.properties b/examples/issues/gradle.properties index 1a47da5db3..98b0b5847b 100644 --- a/examples/issues/gradle.properties +++ b/examples/issues/gradle.properties @@ -20,5 +20,5 @@ android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true kotlin.version=1.7.10 -agp.version=7.0.4 +agp.version=7.1.3 compose.version=1.2.0-beta02 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..692211784e 100755 --- a/examples/todoapp-lite/common/build.gradle.kts +++ b/examples/todoapp-lite/common/build.gradle.kts @@ -22,11 +22,11 @@ kotlin { } android { - compileSdk = 31 + compileSdk = 32 defaultConfig { - minSdk = 21 - targetSdk = 31 + minSdk = 26 + targetSdk = 32 } compileOptions { diff --git a/examples/todoapp-lite/gradle.properties b/examples/todoapp-lite/gradle.properties index 4e152adc88..ef72cbf492 100755 --- a/examples/todoapp-lite/gradle.properties +++ b/examples/todoapp-lite/gradle.properties @@ -20,5 +20,5 @@ android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official kotlin.version=1.7.10 -agp.version=7.0.4 +agp.version=7.1.3 compose.version=1.2.0-beta02 diff --git a/examples/visual-effects/.gitignore b/examples/visual-effects/.gitignore new file mode 100644 index 0000000000..ba8435b9c5 --- /dev/null +++ b/examples/visual-effects/.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 \ No newline at end of file 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..d502f9525d 100644 --- a/examples/widgets-gallery/common/build.gradle.kts +++ b/examples/widgets-gallery/common/build.gradle.kts @@ -21,8 +21,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 +34,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/gradle.properties b/examples/widgets-gallery/gradle.properties index 96e0eb201f..f128da9f9b 100644 --- a/examples/widgets-gallery/gradle.properties +++ b/examples/widgets-gallery/gradle.properties @@ -21,4 +21,4 @@ android.enableJetifier=true kotlin.code.style=official kotlin.version=1.7.10 compose.version=1.2.0-beta02 -agp.version=7.0.4 +agp.version=7.1.3