Browse Source
Changes: - update all examples to Kotlin 2.0 - migrate to using kotlin("plugin.compose") for Compose compiler configuration - remove deprecated Compose Web gradle API usages - added a workaround for https://github.com/JetBrains/compose-multiplatform/issues/4848 in Jetsnack example Testing: - `./gradlew build` in every example - run some examples in simulators (or desktop, browser)pull/4857/head
Oleksandr Karpovich
7 months ago
committed by
GitHub
114 changed files with 1036 additions and 760 deletions
@ -1,4 +1,4 @@ |
|||||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 |
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 |
||||||
kotlin.code.style=official |
kotlin.code.style=official |
||||||
kotlin.version=1.9.24 |
kotlin.version=2.0.0 |
||||||
compose.version=1.6.10 |
compose.version=1.6.10 |
||||||
|
@ -1,4 +1,4 @@ |
|||||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 |
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 |
||||||
kotlin.code.style=official |
kotlin.code.style=official |
||||||
kotlin.version=1.9.24 |
kotlin.version=2.0.0 |
||||||
compose.version=1.6.10 |
compose.version=1.6.10 |
||||||
|
@ -1,183 +0,0 @@ |
|||||||
/** |
|
||||||
* This file is an example (we can open it in iOS application) |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.jetbrains.codeviewer.ui.editor |
|
||||||
|
|
||||||
import androidx.compose.foundation.background |
|
||||||
import androidx.compose.foundation.layout.* |
|
||||||
import androidx.compose.foundation.text.selection.DisableSelection |
|
||||||
import androidx.compose.material.AmbientContentColor |
|
||||||
import androidx.compose.material.CircularProgressIndicator |
|
||||||
import androidx.compose.material.Surface |
|
||||||
import androidx.compose.material.Text |
|
||||||
import androidx.compose.runtime.Composable |
|
||||||
import androidx.compose.runtime.getValue |
|
||||||
import androidx.compose.runtime.key |
|
||||||
import androidx.compose.ui.Alignment |
|
||||||
import androidx.compose.ui.Modifier |
|
||||||
import androidx.compose.ui.draw.alpha |
|
||||||
import androidx.compose.ui.platform.LocalDensity |
|
||||||
import androidx.compose.ui.text.* |
|
||||||
import androidx.compose.ui.unit.dp |
|
||||||
import org.jetbrains.codeviewer.platform.SelectionContainer |
|
||||||
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.loadableScoped |
|
||||||
import org.jetbrains.codeviewer.util.withoutWidthConstraints |
|
||||||
import kotlin.text.Regex.Companion.fromLiteral |
|
||||||
|
|
||||||
@Composable |
|
||||||
fun EditorView(model: Editor, settings: Settings) = key(model) { |
|
||||||
with (LocalDensity.current) { |
|
||||||
SelectionContainer { |
|
||||||
Surface( |
|
||||||
Modifier.fillMaxSize(), |
|
||||||
color = AppTheme.colors.backgroundDark, |
|
||||||
) { |
|
||||||
val lines by loadableScoped(model.lines) |
|
||||||
|
|
||||||
if (lines != null) { |
|
||||||
Box { |
|
||||||
Lines(lines!!, settings) |
|
||||||
Box( |
|
||||||
Modifier |
|
||||||
.offset( |
|
||||||
x = settings.fontSize.toDp() * 0.5f * settings.maxLineSymbols |
|
||||||
) |
|
||||||
.width(1.dp) |
|
||||||
.fillMaxHeight() |
|
||||||
.background(AppTheme.colors.codeGuide) |
|
||||||
) |
|
||||||
} |
|
||||||
} else { |
|
||||||
CircularProgressIndicator( |
|
||||||
modifier = Modifier |
|
||||||
.size(36.dp) |
|
||||||
.padding(4.dp) |
|
||||||
) |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Composable |
|
||||||
private fun Lines(lines: Editor.Lines, settings: Settings) = with(DensityAmbient.current) { |
|
||||||
val maxNumber = remember(lines.lineNumberDigitCount) { |
|
||||||
(1..lines.lineNumberDigitCount).joinToString(separator = "") { "9" } |
|
||||||
} |
|
||||||
|
|
||||||
Box(Modifier.fillMaxSize()) { |
|
||||||
val scrollState = rememberLazyListState() |
|
||||||
val lineHeight = settings.fontSize.toDp() * 1.6f |
|
||||||
|
|
||||||
LazyColumnFor( |
|
||||||
lines.size, |
|
||||||
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), maxNumber, line!!, settings) |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
) |
|
||||||
|
|
||||||
VerticalScrollbar( |
|
||||||
Modifier.align(Alignment.CenterEnd), |
|
||||||
scrollState, |
|
||||||
lines.size, |
|
||||||
lineHeight |
|
||||||
) |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Поддержка русского языка |
|
||||||
// دعم اللغة العربية |
|
||||||
// 中文支持 |
|
||||||
@Composable |
|
||||||
private fun Line(modifier: Modifier, maxNumber: String, line: Editor.Line, settings: Settings) { |
|
||||||
Row(modifier = modifier) { |
|
||||||
DisableSelection { |
|
||||||
Box { |
|
||||||
LineNumber(maxNumber, Modifier.alpha(0f), settings) |
|
||||||
LineNumber(line.number.toString(), Modifier.align(Alignment.CenterEnd), settings) |
|
||||||
} |
|
||||||
} |
|
||||||
LineContent( |
|
||||||
line.content, |
|
||||||
modifier = Modifier |
|
||||||
.weight(1f) |
|
||||||
.withoutWidthConstraints() |
|
||||||
.padding(start = 28.dp, end = 12.dp), |
|
||||||
settings = settings |
|
||||||
) |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Composable |
|
||||||
private fun LineNumber(number: String, modifier: Modifier, settings: Settings) = Text( |
|
||||||
text = number, |
|
||||||
fontSize = settings.fontSize, |
|
||||||
fontFamily = Fonts.jetbrainsMono(), |
|
||||||
color = AmbientContentColor.current.copy(alpha = 0.30f), |
|
||||||
modifier = modifier.padding(start = 12.dp) |
|
||||||
) |
|
||||||
|
|
||||||
@Composable |
|
||||||
private fun LineContent(content: Editor.Content, modifier: Modifier, settings: Settings) = Text( |
|
||||||
text = if (content.isCode) { |
|
||||||
codeString(content.value.value) |
|
||||||
} else { |
|
||||||
AnnotatedString(content.value.value) |
|
||||||
}, |
|
||||||
fontSize = settings.fontSize, |
|
||||||
fontFamily = Fonts.jetbrainsMono(), |
|
||||||
modifier = modifier, |
|
||||||
softWrap = false |
|
||||||
) |
|
||||||
|
|
||||||
private fun codeString(str: String) = buildAnnotatedString { |
|
||||||
withStyle(AppTheme.code.simple) { |
|
||||||
append(str.replace("\t", " ")) |
|
||||||
addStyle(AppTheme.code.punctuation, ":") |
|
||||||
addStyle(AppTheme.code.punctuation, "=") |
|
||||||
addStyle(AppTheme.code.punctuation, "\"") |
|
||||||
addStyle(AppTheme.code.punctuation, "[") |
|
||||||
addStyle(AppTheme.code.punctuation, "]") |
|
||||||
addStyle(AppTheme.code.punctuation, "{") |
|
||||||
addStyle(AppTheme.code.punctuation, "}") |
|
||||||
addStyle(AppTheme.code.punctuation, "(") |
|
||||||
addStyle(AppTheme.code.punctuation, ")") |
|
||||||
addStyle(AppTheme.code.punctuation, ",") |
|
||||||
addStyle(AppTheme.code.keyword, "fun ") |
|
||||||
addStyle(AppTheme.code.keyword, "val ") |
|
||||||
addStyle(AppTheme.code.keyword, "var ") |
|
||||||
addStyle(AppTheme.code.keyword, "private ") |
|
||||||
addStyle(AppTheme.code.keyword, "internal ") |
|
||||||
addStyle(AppTheme.code.keyword, "for ") |
|
||||||
addStyle(AppTheme.code.keyword, "expect ") |
|
||||||
addStyle(AppTheme.code.keyword, "actual ") |
|
||||||
addStyle(AppTheme.code.keyword, "import ") |
|
||||||
addStyle(AppTheme.code.keyword, "package ") |
|
||||||
addStyle(AppTheme.code.value, "true") |
|
||||||
addStyle(AppTheme.code.value, "false") |
|
||||||
addStyle(AppTheme.code.value, Regex("[0-9]*")) |
|
||||||
addStyle(AppTheme.code.annotation, Regex("^@[a-zA-Z_]*")) |
|
||||||
addStyle(AppTheme.code.comment, Regex("^\\s*//.*")) |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private fun AnnotatedString.Builder.addStyle(style: SpanStyle, regexp: String) { |
|
||||||
addStyle(style, fromLiteral(regexp)) |
|
||||||
} |
|
||||||
|
|
||||||
private fun AnnotatedString.Builder.addStyle(style: SpanStyle, regexp: Regex) { |
|
||||||
for (result in regexp.findAll(toString())) { |
|
||||||
addStyle(style, result.range.first, result.range.last + 1) |
|
||||||
} |
|
||||||
} |
|
@ -1,5 +1,5 @@ |
|||||||
kotlin.code.style=official |
kotlin.code.style=official |
||||||
kotlin.version=1.9.24 |
kotlin.version=2.0.0 |
||||||
compose.version=1.6.10 |
compose.version=1.6.10 |
||||||
org.gradle.configuration-cache=true |
org.gradle.configuration-cache=true |
||||||
org.gradle.caching=true |
org.gradle.caching=true |
||||||
|
@ -1,6 +1,6 @@ |
|||||||
kotlin.code.style=official |
kotlin.code.style=official |
||||||
kotlin.js.webpack.major.version=4 |
kotlin.js.webpack.major.version=4 |
||||||
kotlin.version=1.9.24 |
kotlin.version=2.0.0 |
||||||
compose.version=1.6.10 |
compose.version=1.6.10 |
||||||
org.gradle.configuration-cache=true |
org.gradle.configuration-cache=true |
||||||
org.gradle.caching=true |
org.gradle.caching=true |
||||||
|
@ -1,5 +1,5 @@ |
|||||||
kotlin.code.style=official |
kotlin.code.style=official |
||||||
kotlin.version=1.9.24 |
kotlin.version=2.0.0 |
||||||
compose.version=1.6.10 |
compose.version=1.6.10 |
||||||
org.gradle.configuration-cache=true |
org.gradle.configuration-cache=true |
||||||
org.gradle.caching=true |
org.gradle.caching=true |
||||||
|
@ -1,5 +1,5 @@ |
|||||||
kotlin.code.style=official |
kotlin.code.style=official |
||||||
kotlin.version=1.9.24 |
kotlin.version=2.0.0 |
||||||
compose.version=1.6.10 |
compose.version=1.6.10 |
||||||
org.gradle.configuration-cache=true |
org.gradle.configuration-cache=true |
||||||
org.gradle.caching=true |
org.gradle.caching=true |
||||||
|
@ -1,15 +1,13 @@ |
|||||||
kotlin.code.style=official |
kotlin.code.style=official |
||||||
xcodeproj=iosApp |
xcodeproj=iosApp |
||||||
android.useAndroidX=true |
android.useAndroidX=true |
||||||
org.gradle.jvmargs=-Xmx3g |
org.gradle.jvmargs=-Xmx8g |
||||||
|
|
||||||
# TODO: enable configuration cache once we update on kotlin 2.0 |
org.gradle.configuration-cache=true |
||||||
# see https://youtrack.jetbrains.com/issue/KT-64851 (k/wasm issue) |
|
||||||
org.gradle.configuration-cache=false |
|
||||||
org.gradle.caching=true |
org.gradle.caching=true |
||||||
org.jetbrains.compose.experimental.jscanvas.enabled=true |
org.jetbrains.compose.experimental.jscanvas.enabled=true |
||||||
org.jetbrains.compose.experimental.macos.enabled=true |
org.jetbrains.compose.experimental.macos.enabled=true |
||||||
org.jetbrains.compose.experimental.wasm.enabled=true |
org.jetbrains.compose.experimental.wasm.enabled=true |
||||||
kotlin.version=1.9.24 |
kotlin.version=2.0.0 |
||||||
agp.version=8.0.2 |
agp.version=8.0.2 |
||||||
compose.version=1.6.10 |
compose.version=1.6.10 |
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@ |
|||||||
kotlin.code.style=official |
kotlin.code.style=official |
||||||
kotlin.version=1.9.24 |
kotlin.version=2.0.0 |
||||||
compose.version=1.6.10 |
compose.version=1.6.10 |
||||||
org.gradle.configuration-cache=true |
org.gradle.configuration-cache=true |
||||||
org.gradle.caching=true |
org.gradle.caching=true |
||||||
|
@ -1,5 +1,5 @@ |
|||||||
kotlin.code.style=official |
kotlin.code.style=official |
||||||
xcodeproj=./iosApp |
xcodeproj=./iosApp |
||||||
org.gradle.jvmargs=-Xmx3g |
org.gradle.jvmargs=-Xmx3g |
||||||
kotlin.version=1.9.24 |
kotlin.version=2.0.0 |
||||||
compose.version=1.6.10 |
compose.version=1.6.10 |
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@ |
|||||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 |
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 |
||||||
kotlin.code.style=official |
kotlin.code.style=official |
||||||
kotlin.version=1.9.24 |
kotlin.version=2.0.0 |
||||||
compose.version=1.6.10 |
compose.version=1.6.10 |
||||||
org.gradle.configuration-cache=true |
org.gradle.configuration-cache=true |
||||||
org.gradle.caching=true |
org.gradle.caching=true |
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue