Skip to content

Commit 47e0b4f

Browse files
authored
Merge pull request #80 from halilozercan/compose-1.2.0-beta01
Update RichText to latest versions of Jetpack Compose and Desktop
2 parents b46cf26 + 76536d5 commit 47e0b4f

18 files changed

Lines changed: 160 additions & 57 deletions

File tree

.idea/codeStyles/Project.xml

Lines changed: 3 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android-sample/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ android {
1515
compose = true
1616
}
1717

18+
kotlinOptions { jvmTarget = "11" }
19+
1820
composeOptions {
1921
kotlinCompilerExtensionVersion = Compose.version
2022
}

android-sample/src/main/java/com/zachklipp/richtext/sample/SampleLauncher.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.compose.animation.Crossfade
55
import androidx.compose.foundation.clickable
66
import androidx.compose.foundation.layout.aspectRatio
77
import androidx.compose.foundation.layout.height
8+
import androidx.compose.foundation.layout.padding
89
import androidx.compose.foundation.lazy.LazyColumn
910
import androidx.compose.foundation.lazy.itemsIndexed
1011
import androidx.compose.material.ExperimentalMaterialApi
@@ -61,8 +62,8 @@ private val Samples = listOf<Pair<String, @Composable () -> Unit>>(
6162
topBar = {
6263
TopAppBar(title = { Text("Samples") })
6364
}
64-
) {
65-
LazyColumn {
65+
) { contentPadding ->
66+
LazyColumn(modifier = Modifier.padding(contentPadding)) {
6667
itemsIndexed(Samples) { index, (title, sampleContent) ->
6768
ListItem(
6869
Modifier.clickable(onClick = { onSampleClicked(index) }),

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ buildscript {
2222
}
2323

2424
plugins {
25-
id("org.jetbrains.dokka") version "1.6.0"
25+
id("org.jetbrains.dokka") version "1.6.21"
2626
}
2727

2828
repositories {
@@ -53,7 +53,7 @@ subprojects {
5353
allWarningsAsErrors = true
5454
}
5555

56-
freeCompilerArgs = listOf("-Xopt-in=kotlin.RequiresOptIn")
56+
freeCompilerArgs = listOf("-opt-in=kotlin.RequiresOptIn")
5757
}
5858
}
5959

buildSrc/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ plugins {
1010

1111
dependencies {
1212
// keep in sync with Dependencies.BuildPlugins.androidGradlePlugin
13-
implementation("com.android.tools.build:gradle:7.0.3")
13+
implementation("com.android.tools.build:gradle:7.4.0-alpha01")
1414
// keep in sync with Dependencies.Kotlin.gradlePlugin
15-
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31")
15+
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
1616
implementation(kotlin("script-runtime"))
1717
}

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
object BuildPlugins {
2-
val androidGradlePlugin = "com.android.tools.build:gradle:7.0.3"
2+
val androidGradlePlugin = "com.android.tools.build:gradle:7.4.0-alpha01"
33
}
44

55
object AndroidX {
6-
val activity = "androidx.activity:activity:1.1.0"
6+
val activity = "androidx.activity:activity:1.5.0-rc01"
77
val annotations = "androidx.annotation:annotation:1.1.0"
88
val appcompat = "androidx.appcompat:appcompat:1.3.0"
99
val constraintLayout = "androidx.constraintlayout:constraintlayout:1.1.3"
1010
val fragment = "androidx.fragment:fragment:1.2.2"
1111
val material = "com.google.android.material:material:1.1.0"
1212
val recyclerview = "androidx.recyclerview:recyclerview:1.1.0"
13-
val savedstate = "androidx.savedstate:savedstate:1.0.0"
13+
val savedstate = "androidx.savedstate:savedstate-ktx:1.2.0-rc01"
1414
val transition = "androidx.transition:transition:1.3.1"
1515
val viewbinding = "androidx.databinding:viewbinding:3.6.1"
1616
}
@@ -20,8 +20,8 @@ object Network {
2020
}
2121

2222
object Kotlin {
23-
val version = "1.5.31"
24-
val binaryCompatibilityValidatorPlugin = "org.jetbrains.kotlinx:binary-compatibility-validator:0.5.0"
23+
val version = "1.6.21"
24+
val binaryCompatibilityValidatorPlugin = "org.jetbrains.kotlinx:binary-compatibility-validator:0.9.0"
2525
val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version"
2626

2727
object Test {
@@ -35,8 +35,8 @@ object Kotlin {
3535
val ktlint = "org.jlleitschuh.gradle:ktlint-gradle:10.0.0"
3636

3737
object Compose {
38-
val version = "1.1.0-beta03"
39-
val activity = "androidx.activity:activity-compose:1.3.0"
38+
val version = "1.2.0-beta01"
39+
val activity = "androidx.activity:activity-compose:1.5.0-rc01"
4040
val foundation = "androidx.compose.foundation:foundation:$version"
4141
val layout = "androidx.compose.foundation:foundation-layout:$version"
4242
val material = "androidx.compose.material:material:$version"
@@ -58,6 +58,6 @@ object Commonmark {
5858

5959
object AndroidConfiguration {
6060
val minSdk = 21
61-
val targetSdk = 31
61+
val targetSdk = 32
6262
val compileSdk = targetSdk
6363
}

buildSrc/src/main/kotlin/richtext-android-library.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ android {
1717
targetSdk = AndroidConfiguration.targetSdk
1818
}
1919

20+
kotlinOptions { jvmTarget = "11" }
21+
2022
buildFeatures {
2123
compose = true
2224
}

buildSrc/src/main/kotlin/richtext-kmp-library.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ kotlin {
1919
}
2020

2121
android {
22-
compileSdk = 31
22+
compileSdk = 32
2323
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
2424
defaultConfig {
2525
minSdk = 21
26-
targetSdk = 31
26+
targetSdk = compileSdk
2727
}
2828
}

desktop-sample/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat
33

44
plugins {
55
kotlin("jvm")
6-
id("org.jetbrains.compose") version "1.0.0"
6+
id("org.jetbrains.compose") version "1.2.0-alpha01-dev683"
77
}
88

99
dependencies {

desktop-sample/src/main/kotlin/com/halilibo/richtext/desktop/Main.kt

Lines changed: 115 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,83 @@ import androidx.compose.foundation.LocalScrollbarStyle
44
import androidx.compose.foundation.background
55
import androidx.compose.foundation.defaultScrollbarStyle
66
import androidx.compose.foundation.layout.Arrangement
7+
import androidx.compose.foundation.layout.Column
78
import androidx.compose.foundation.layout.Row
89
import androidx.compose.foundation.layout.fillMaxHeight
910
import androidx.compose.foundation.layout.fillMaxSize
11+
import androidx.compose.foundation.layout.fillMaxWidth
12+
import androidx.compose.foundation.layout.offset
1013
import androidx.compose.foundation.layout.padding
1114
import androidx.compose.foundation.rememberScrollState
1215
import androidx.compose.foundation.text.BasicTextField
1316
import androidx.compose.foundation.text.selection.SelectionContainer
1417
import androidx.compose.foundation.verticalScroll
18+
import androidx.compose.material.Slider
1519
import androidx.compose.material.Surface
20+
import androidx.compose.material.Text
21+
import androidx.compose.runtime.Composable
1622
import androidx.compose.runtime.CompositionLocalProvider
1723
import androidx.compose.runtime.getValue
1824
import androidx.compose.runtime.mutableStateOf
1925
import androidx.compose.runtime.remember
2026
import androidx.compose.runtime.setValue
2127
import androidx.compose.ui.Modifier
2228
import androidx.compose.ui.graphics.Color
29+
import androidx.compose.ui.unit.IntOffset
2330
import androidx.compose.ui.unit.dp
31+
import androidx.compose.ui.unit.sp
2432
import androidx.compose.ui.window.singleWindowApplication
2533
import com.halilibo.richtext.markdown.Markdown
2634
import com.halilibo.richtext.ui.CodeBlockStyle
35+
import com.halilibo.richtext.ui.RichText
2736
import com.halilibo.richtext.ui.RichTextStyle
37+
import com.halilibo.richtext.ui.Table
2838
import com.halilibo.richtext.ui.material.MaterialRichText
39+
import com.halilibo.richtext.ui.resolveDefaults
2940

3041
fun main(): Unit = singleWindowApplication(
3142
title = "RichText KMP"
3243
) {
44+
var richTextStyle by remember {
45+
mutableStateOf(
46+
RichTextStyle(
47+
codeBlockStyle = CodeBlockStyle(wordWrap = true)
48+
).resolveDefaults()
49+
)
50+
}
51+
3352
Surface {
34-
CompositionLocalProvider(LocalScrollbarStyle provides defaultScrollbarStyle().copy(
35-
hoverColor = Color.DarkGray,
36-
unhoverColor = Color.Gray
37-
)) {
53+
CompositionLocalProvider(
54+
LocalScrollbarStyle provides defaultScrollbarStyle().copy(
55+
hoverColor = Color.DarkGray,
56+
unhoverColor = Color.Gray
57+
)
58+
) {
3859
SelectionContainer {
60+
var text by remember { mutableStateOf(sampleMarkdown) }
3961
Row(
40-
modifier = Modifier.padding(32.dp).fillMaxSize(),
62+
modifier = Modifier
63+
.padding(32.dp)
64+
.fillMaxSize(),
4165
horizontalArrangement = Arrangement.spacedBy(32.dp)
4266
) {
43-
var text by remember { mutableStateOf(sampleMarkdown) }
44-
BasicTextField(
45-
value = text,
46-
onValueChange = { text = it },
47-
maxLines = Int.MAX_VALUE,
48-
modifier = Modifier.weight(1f)
49-
.fillMaxHeight()
50-
.background(Color.LightGray)
51-
.padding(8.dp)
52-
)
67+
Column(modifier = Modifier.weight(1f)) {
68+
RichTextStyleConfig(richTextStyle = richTextStyle, onChanged = { richTextStyle = it })
69+
BasicTextField(
70+
value = text,
71+
onValueChange = { text = it },
72+
maxLines = Int.MAX_VALUE,
73+
modifier = Modifier
74+
.fillMaxHeight()
75+
.background(Color.LightGray)
76+
.padding(8.dp)
77+
)
78+
}
5379
MaterialRichText(
54-
modifier = Modifier.weight(1f)
80+
modifier = Modifier
81+
.weight(1f)
5582
.verticalScroll(rememberScrollState()),
56-
style = RichTextStyle(codeBlockStyle = CodeBlockStyle(wordWrap = true))
83+
style = richTextStyle
5784
) {
5885
Markdown(content = text)
5986
}
@@ -63,6 +90,77 @@ fun main(): Unit = singleWindowApplication(
6390
}
6491
}
6592

93+
@Composable
94+
fun RichTextStyleConfig(
95+
richTextStyle: RichTextStyle,
96+
onChanged: (RichTextStyle) -> Unit
97+
) {
98+
Column(modifier = Modifier.fillMaxWidth()) {
99+
Row {
100+
Column(Modifier.weight(1f)) {
101+
Text("Paragraph spacing:\n${richTextStyle.paragraphSpacing}")
102+
Slider(
103+
value = richTextStyle.paragraphSpacing!!.value,
104+
valueRange = 0f..20f,
105+
onValueChange = {
106+
onChanged(richTextStyle.copy(paragraphSpacing = it.sp))
107+
}
108+
)
109+
}
110+
Column(Modifier.weight(1f)) {
111+
Text("List item spacing:\n${richTextStyle.listStyle!!.itemSpacing}")
112+
Slider(
113+
value = richTextStyle.listStyle!!.itemSpacing!!.value,
114+
valueRange = 0f..20f,
115+
onValueChange = {
116+
onChanged(
117+
richTextStyle.copy(
118+
listStyle = richTextStyle.listStyle!!.copy(
119+
itemSpacing = it.sp
120+
)
121+
)
122+
)
123+
}
124+
)
125+
}
126+
}
127+
Row {
128+
Column(Modifier.weight(1f)) {
129+
Text("Table cell padding:\n${richTextStyle.tableStyle!!.cellPadding}")
130+
Slider(
131+
value = richTextStyle.tableStyle!!.cellPadding!!.value,
132+
valueRange = 0f..20f,
133+
onValueChange = {
134+
onChanged(
135+
richTextStyle.copy(
136+
tableStyle = richTextStyle.tableStyle!!.copy(
137+
cellPadding = it.sp
138+
)
139+
)
140+
)
141+
}
142+
)
143+
}
144+
Column(Modifier.weight(1f)) {
145+
Text("Table border width padding:\n${richTextStyle.tableStyle!!.borderStrokeWidth!!}")
146+
Slider(
147+
value = richTextStyle.tableStyle!!.borderStrokeWidth!!,
148+
valueRange = 0f..20f,
149+
onValueChange = {
150+
onChanged(
151+
richTextStyle.copy(
152+
tableStyle = richTextStyle.tableStyle!!.copy(
153+
borderStrokeWidth = it
154+
)
155+
)
156+
)
157+
}
158+
)
159+
}
160+
}
161+
}
162+
}
163+
66164
private val sampleMarkdown = """
67165
# Demo
68166
Based on [this cheatsheet][cheatsheet]

0 commit comments

Comments
 (0)