diff --git a/examples/codeviewer/build.gradle.kts b/examples/codeviewer/build.gradle.kts index 907708a042..836e211443 100644 --- a/examples/codeviewer/build.gradle.kts +++ b/examples/codeviewer/build.gradle.kts @@ -9,7 +9,7 @@ buildscript { dependencies { // __LATEST_COMPOSE_RELEASE_VERSION__ - classpath("org.jetbrains.compose:compose-gradle-plugin:0.1.0-build113") + classpath("org.jetbrains.compose:compose-gradle-plugin:0.2.0-build124") classpath("com.android.tools.build:gradle:4.0.1") classpath(kotlin("gradle-plugin", version = "1.4.0")) } 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 bcf0741e5e..fc0e00ce90 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 @@ -2,9 +2,9 @@ package org.jetbrains.codeviewer.platform import android.graphics.BitmapFactory import androidx.compose.runtime.Composable -import androidx.compose.ui.graphics.ImageAsset -import androidx.compose.ui.graphics.asImageAsset -import androidx.compose.ui.platform.ContextAmbient +import androidx.compose.ui.graphics.ImageBitmap +import androidx.compose.ui.graphics.asImageBitmap +import androidx.compose.ui.platform.AmbientContext import androidx.compose.ui.text.font.Font import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight @@ -12,20 +12,20 @@ import java.io.InputStream import java.net.URL @Composable -actual fun imageResource(res: String): ImageAsset { - val context = ContextAmbient.current +actual fun imageResource(res: String): ImageBitmap { + val context = AmbientContext.current val id = context.resources.getIdentifier(res, "drawable", context.packageName) return androidx.compose.ui.res.imageResource(id) } -actual suspend fun imageFromUrl(url: String): ImageAsset { +actual suspend fun imageFromUrl(url: String): ImageBitmap { val bytes = URL(url).openStream().buffered().use(InputStream::readBytes) - return BitmapFactory.decodeByteArray(bytes, 0, bytes.size).asImageAsset() + return BitmapFactory.decodeByteArray(bytes, 0, bytes.size).asImageBitmap() } @Composable actual fun font(name: String, res: String, weight: FontWeight, style: FontStyle): Font { - val context = ContextAmbient.current + val context = AmbientContext.current val id = context.resources.getIdentifier(res, "font", context.packageName) return androidx.compose.ui.text.font.font(id, weight, style) } \ 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 0f72f42a83..5a752b6dd4 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 @@ -1,15 +1,15 @@ package org.jetbrains.codeviewer.platform import androidx.compose.runtime.Composable -import androidx.compose.ui.graphics.ImageAsset +import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.text.font.Font import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight @Composable -expect fun imageResource(res: String): ImageAsset +expect fun imageResource(res: String): ImageBitmap -expect suspend fun imageFromUrl(url: String): ImageAsset +expect suspend fun imageFromUrl(url: String): ImageBitmap @Composable 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/editor/Editor.kt b/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/Editor.kt index 062cf78483..30676f1ed6 100644 --- a/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/Editor.kt +++ b/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/Editor.kt @@ -6,7 +6,6 @@ import kotlinx.coroutines.CoroutineScope import org.jetbrains.codeviewer.platform.File import org.jetbrains.codeviewer.util.EmptyTextLines import org.jetbrains.codeviewer.util.SingleSelection -import org.jetbrains.codeviewer.util.afterSet class Editor( val fileName: String, @@ -27,7 +26,7 @@ class Editor( interface Lines { val lineNumberDigitCount: Int get() = size.toString().length val size: Int - fun get(index: Int): Line + operator fun get(index: Int): Line } class Content(val value: State, val isCode: Boolean) diff --git a/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorView.kt b/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorView.kt index 3760eff8d9..8a3fd87000 100644 --- a/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorView.kt +++ b/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorView.kt @@ -14,7 +14,7 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.drawOpacity -import androidx.compose.ui.platform.DensityAmbient +import androidx.compose.ui.platform.AmbientDensity import androidx.compose.ui.selection.DisableSelection import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.SpanStyle @@ -27,14 +27,13 @@ import org.jetbrains.codeviewer.ui.common.AppTheme import org.jetbrains.codeviewer.ui.common.Fonts import org.jetbrains.codeviewer.ui.common.Settings import org.jetbrains.codeviewer.util.LazyColumnFor -import org.jetbrains.codeviewer.util.loadable import org.jetbrains.codeviewer.util.loadableScoped import org.jetbrains.codeviewer.util.withoutWidthConstraints import kotlin.text.Regex.Companion.fromLiteral @Composable fun EditorView(model: Editor, settings: Settings) = key(model) { - with (DensityAmbient.current) { + with (AmbientDensity.current) { SelectionContainer { Surface( Modifier.fillMaxSize(), @@ -68,7 +67,7 @@ fun EditorView(model: Editor, settings: Settings) = key(model) { } @Composable -private fun Lines(lines: Editor.Lines, settings: Settings) = with(DensityAmbient.current) { +private fun Lines(lines: Editor.Lines, settings: Settings) = with(AmbientDensity.current) { val maxNum = remember(lines.lineNumberDigitCount) { (1..lines.lineNumberDigitCount).joinToString(separator = "") { "9" } } @@ -82,11 +81,8 @@ private fun Lines(lines: Editor.Lines, settings: Settings) = with(DensityAmbient modifier = Modifier.fillMaxSize(), state = scrollState, itemContent = { index -> - val line: Editor.Line? by loadable { lines.get(index) } Box(Modifier.height(lineHeight)) { - if (line != null) { - Line(Modifier.align(Alignment.CenterStart), maxNum, line!!, settings) - } + Line(Modifier.align(Alignment.CenterStart), maxNum, lines[index], settings) } } ) 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 1764e355de..5636f6acf7 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 @@ -17,7 +17,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clipToBounds import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.DensityAmbient +import androidx.compose.ui.platform.AmbientDensity import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.TextUnit @@ -46,7 +46,7 @@ fun FileTreeViewTabView() = Surface { fun FileTreeView(model: FileTree) = Surface( modifier = Modifier.fillMaxSize() ) { - with(DensityAmbient.current) { + with(AmbientDensity.current) { Box { val scrollState = rememberLazyListState() val fontSize = 14.sp diff --git a/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/statusbar/StatusBar.kt b/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/statusbar/StatusBar.kt index 1b87298406..f2e3a4593a 100644 --- a/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/statusbar/StatusBar.kt +++ b/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/statusbar/StatusBar.kt @@ -8,7 +8,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.Providers import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.DensityAmbient +import androidx.compose.ui.platform.AmbientDensity import androidx.compose.ui.unit.Density import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.lerp @@ -35,7 +35,7 @@ fun StatusBar(settings: Settings) = Box( Spacer(Modifier.width(8.dp)) - Providers(DensityAmbient provides DensityAmbient.current.scale(0.5f)) { + Providers(AmbientDensity provides AmbientDensity.current.scale(0.5f)) { Slider( (settings.fontSize - MinFontSize) / (MaxFontSize - MinFontSize), onValueChange = { settings.fontSize = lerp(MinFontSize, MaxFontSize, it) }, diff --git a/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/util/State.kt b/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/util/State.kt deleted file mode 100644 index 118d7e0a69..0000000000 --- a/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/util/State.kt +++ /dev/null @@ -1,14 +0,0 @@ -package org.jetbrains.codeviewer.util - -import androidx.compose.runtime.MutableState - -fun MutableState.afterSet( - action: (T) -> Unit -) = object : MutableState by this { - override var value: T - get() = this@afterSet.value - set(value) { - this@afterSet.value = value - action(value) - } -} \ No newline at end of file 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 6dd72562e1..7bd3f16edb 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 @@ -1,8 +1,8 @@ package org.jetbrains.codeviewer.platform import androidx.compose.runtime.Composable -import androidx.compose.ui.graphics.ImageAsset -import androidx.compose.ui.graphics.asImageAsset +import androidx.compose.ui.graphics.ImageBitmap +import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.text.font.Font import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight @@ -15,9 +15,9 @@ import java.net.URL @Composable actual fun imageResource(res: String) = androidx.compose.ui.res.imageResource("drawable/$res.png") -actual suspend fun imageFromUrl(url: String): ImageAsset = withContext(Dispatchers.IO) { +actual suspend fun imageFromUrl(url: String): ImageBitmap = withContext(Dispatchers.IO) { val bytes = URL(url).openStream().buffered().use(InputStream::readBytes) - Image.makeFromEncoded(bytes).asImageAsset() + Image.makeFromEncoded(bytes).asImageBitmap() } @Composable