From 231136ecd5d3c1d3912f10a5496a87f250c81460 Mon Sep 17 00:00:00 2001 From: Wavesonics Date: Sat, 27 Jan 2024 16:40:42 -0800 Subject: [PATCH 1/3] Upgrade to compose 1.6.0-beta01 --- gradle/libs.versions.toml | 8 ++++---- .../mohamedrejeb/richeditor/parser/html/CssEncoder.kt | 5 ++--- .../mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt | 11 ++++------- .../mohamedrejeb/richeditor/ui/material/RichText.kt | 11 ++++++++--- .../richeditor/ui/material3/OutlinedRichTextEditor.kt | 8 ++------ .../mohamedrejeb/richeditor/ui/material3/RichText.kt | 6 +----- .../mohamedrejeb/richeditor/utils/RichParagraphExt.kt | 8 ++++---- .../sample/common/slack/SlackDemoContent.kt | 6 ++---- 8 files changed, 27 insertions(+), 36 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 359d0d6d..c12b3f85 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] -agp = "8.1.0" -kotlin = "1.9.21" -compose = "1.5.11" +agp = "8.2.1" +kotlin = "1.9.22" +compose = "1.6.0-beta01" dokka = "1.9.0" ksoup = "0.3.0" @@ -11,7 +11,7 @@ nexus-publish = "2.0.0-rc-1" # For sample compose-compiler = "1.5.4" -activity-compose = "1.8.1" +activity-compose = "1.8.2" voyager = "1.0.0" richeditor = "1.0.0-beta05" android-minSdk = "21" diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/html/CssEncoder.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/html/CssEncoder.kt index 916474d3..f608dab7 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/html/CssEncoder.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/html/CssEncoder.kt @@ -12,7 +12,6 @@ import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.em import androidx.compose.ui.unit.isSpecified import androidx.compose.ui.unit.sp -import com.mohamedrejeb.richeditor.model.RichParagraph internal object CssEncoder { @@ -143,8 +142,8 @@ internal object CssEncoder { */ internal fun parseCssStyleMapToParagraphStyle(cssStyleMap: Map): ParagraphStyle { return ParagraphStyle( - textAlign = cssStyleMap["text-align"]?.let { parseCssTextAlign(it) }, - textDirection = cssStyleMap["direction"]?.let { parseCssTextDirection(it) }, + textAlign = cssStyleMap["text-align"]?.let { parseCssTextAlign(it) } ?: TextAlign.Unspecified, + textDirection = cssStyleMap["direction"]?.let { parseCssTextDirection(it) } ?: TextDirection.Unspecified, lineHeight = cssStyleMap["line-height"]?.let { parseCssLineHeight(it) } ?: TextUnit.Unspecified, textIndent = cssStyleMap["text-indent"]?.let { parseCssTextIndent(it) }, ) diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt index 04332b33..4b0779e1 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt @@ -16,17 +16,13 @@ import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor -import androidx.compose.ui.platform.LocalClipboardManager -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.platform.LocalLayoutDirection -import androidx.compose.ui.text.* +import androidx.compose.ui.platform.* +import androidx.compose.ui.text.TextLayoutResult +import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType -import androidx.compose.ui.text.style.TextIndent import androidx.compose.ui.unit.Density import androidx.compose.ui.unit.LayoutDirection -import androidx.compose.ui.unit.sp -import com.mohamedrejeb.richeditor.model.RichParagraph import com.mohamedrejeb.richeditor.model.RichTextState import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch @@ -193,6 +189,7 @@ internal fun BasicRichTextEditor( maxLength: Int = Int.MAX_VALUE, onTextLayout: (TextLayoutResult) -> Unit = {}, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, + uriHandler: UriHandler = LocalUriHandler.current, cursorBrush: Brush = SolidColor(Color.Black), decorationBox: @Composable (innerTextField: @Composable () -> Unit) -> Unit = @Composable { innerTextField -> innerTextField() }, diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material/RichText.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material/RichText.kt index d386a2f3..4b7ecc96 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material/RichText.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material/RichText.kt @@ -1,12 +1,17 @@ package com.mohamedrejeb.richeditor.ui.material import androidx.compose.foundation.text.InlineTextContent -import androidx.compose.material.* +import androidx.compose.material.LocalContentAlpha +import androidx.compose.material.LocalContentColor +import androidx.compose.material.LocalTextStyle +import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.takeOrElse -import androidx.compose.ui.text.* +import androidx.compose.ui.text.Paragraph +import androidx.compose.ui.text.TextLayoutResult +import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight @@ -66,7 +71,7 @@ fun RichText( fontFamily: FontFamily? = null, letterSpacing: TextUnit = TextUnit.Unspecified, textDecoration: TextDecoration? = null, - textAlign: TextAlign? = null, + textAlign: TextAlign = TextAlign.Unspecified, lineHeight: TextUnit = TextUnit.Unspecified, overflow: TextOverflow = TextOverflow.Clip, softWrap: Boolean = true, diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material3/OutlinedRichTextEditor.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material3/OutlinedRichTextEditor.kt index 070a0625..7650bf60 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material3/OutlinedRichTextEditor.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material3/OutlinedRichTextEditor.kt @@ -6,14 +6,11 @@ import androidx.compose.foundation.layout.* import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.selection.LocalTextSelectionColors -import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.LocalTextStyle -import androidx.compose.material3.TextFieldColors +import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.TextFieldDefaults -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.runtime.remember +import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.drawWithContent @@ -24,7 +21,6 @@ import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.graphics.drawscope.clipRect import androidx.compose.ui.graphics.takeOrElse import androidx.compose.ui.layout.* -import androidx.compose.ui.layout.layoutId import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.TextStyle diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material3/RichText.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material3/RichText.kt index 1e7597c1..d1217f73 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material3/RichText.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material3/RichText.kt @@ -5,13 +5,9 @@ import androidx.compose.material3.LocalContentColor import androidx.compose.material3.LocalTextStyle import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.takeOrElse -import androidx.compose.ui.input.pointer.PointerIcon -import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.text.Paragraph import androidx.compose.ui.text.TextLayoutResult import androidx.compose.ui.text.TextStyle @@ -72,7 +68,7 @@ fun RichText( fontFamily: FontFamily? = null, letterSpacing: TextUnit = TextUnit.Unspecified, textDecoration: TextDecoration? = null, - textAlign: TextAlign? = null, + textAlign: TextAlign = TextAlign.Unspecified, lineHeight: TextUnit = TextUnit.Unspecified, overflow: TextOverflow = TextOverflow.Clip, softWrap: Boolean = true, diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/utils/RichParagraphExt.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/utils/RichParagraphExt.kt index 6e95d53b..51347ee0 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/utils/RichParagraphExt.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/utils/RichParagraphExt.kt @@ -34,14 +34,14 @@ internal fun List.getCommonStyle(): ParagraphStyle? { } return ParagraphStyle( - textAlign = textAlign, - textDirection = textDirection, + textAlign = textAlign ?: TextAlign.Unspecified, + textDirection = textDirection ?: TextDirection.Unspecified, lineHeight = lineHeight, textIndent = textIndent, platformStyle = platformStyle, lineHeightStyle = lineHeightStyle, - lineBreak = lineBreak, - hyphens = hyphens + lineBreak = lineBreak ?: LineBreak.Unspecified, + hyphens = hyphens ?: Hyphens.Unspecified, ) } diff --git a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/slack/SlackDemoContent.kt b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/slack/SlackDemoContent.kt index 10cb4dda..5ce037e1 100644 --- a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/slack/SlackDemoContent.kt +++ b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/slack/SlackDemoContent.kt @@ -16,11 +16,9 @@ import androidx.compose.material.ripple.rememberRipple import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment -import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalSoftwareKeyboardController import androidx.compose.ui.semantics.Role import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextDecoration @@ -30,10 +28,10 @@ import cafe.adriel.voyager.navigator.currentOrThrow import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi import com.mohamedrejeb.richeditor.model.RichTextState import com.mohamedrejeb.richeditor.model.rememberRichTextState -import com.mohamedrejeb.richeditor.sample.common.ui.theme.ComposeRichEditorTheme import com.mohamedrejeb.richeditor.ui.material3.RichText import com.mohamedrejeb.richeditor.ui.material3.RichTextEditor import com.mohamedrejeb.richeditor.ui.material3.RichTextEditorDefaults +import org.jetbrains.compose.resources.DrawableResource import org.jetbrains.compose.resources.ExperimentalResourceApi import org.jetbrains.compose.resources.painterResource @@ -123,7 +121,7 @@ fun SlackDemoContent() { .background(Color.White) ) { Image( - painterResource("slack-logo.png"), + painterResource(DrawableResource("slack-logo.png")), contentDescription = "Slack Logo", modifier = Modifier .fillMaxSize() From 78127a474bc9449b76e097b2aed359c5d1d1c643 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Sun, 28 Jan 2024 16:00:44 -0800 Subject: [PATCH 2/3] Removed uriHandler --- .../kotlin/com/mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt index c744ba3e..f9581515 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt @@ -188,7 +188,6 @@ internal fun BasicRichTextEditor( maxLength: Int = Int.MAX_VALUE, onTextLayout: (TextLayoutResult) -> Unit = {}, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, - uriHandler: UriHandler = LocalUriHandler.current, cursorBrush: Brush = SolidColor(Color.Black), decorationBox: @Composable (innerTextField: @Composable () -> Unit) -> Unit = @Composable { innerTextField -> innerTextField() }, From 53b8587c56ec457087bf36cceaafbfaa6ed250e1 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Sun, 28 Jan 2024 16:04:44 -0800 Subject: [PATCH 3/3] dont revert --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c12b3f85..f0fe76da 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -agp = "8.2.1" +agp = "8.2.2" kotlin = "1.9.22" compose = "1.6.0-beta01" dokka = "1.9.0"