Skip to content

Commit

Permalink
Fix index out of bounds crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedRejeb committed Mar 10, 2024
1 parent 7dba8a2 commit 5de91a7
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .fleet/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"run.destination.stop.already.running": "Always"
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
agp = "8.2.2"
kotlin = "1.9.22"
compose = "1.6.0-rc02"
compose = "1.6.0"
dokka = "1.9.10"

ksoup = "0.3.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ class RichTextState internal constructor(
}

styledRichSpanList.clear()
textFieldValue = newTextFieldValue.copy(text = newText)
textFieldValue = newTextFieldValue.copy(text = annotatedString.te)
visualTransformation = VisualTransformation { _ ->
TransformedText(
annotatedString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ internal fun BasicRichTextEditor(

CompositionLocalProvider(LocalClipboardManager provides richClipboardManager) {
BasicTextField(
value = state.textFieldValue.copy(annotatedString = state.annotatedString),
value = state.textFieldValue,
onValueChange = {
if (readOnly) return@BasicTextField
if (it.text.length > maxLength) return@BasicTextField
Expand Down Expand Up @@ -273,6 +273,7 @@ internal fun BasicRichTextEditor(
singleLine = singleLine,
maxLines = maxLines,
minLines = minLines,
visualTransformation = state.visualTransformation,
onTextLayout = {
state.onTextLayout(
textLayoutResult = it,
Expand Down
2 changes: 1 addition & 1 deletion sample/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ kotlin {
api(compose.material3)
api(compose.materialIconsExtended)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
api(compose.components.resources)
implementation(compose.components.resources)

// implementation(libs.richeditor.compose)
implementation(project(":richeditor-compose"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.automirrored.outlined.Send
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.outlined.Send
import androidx.compose.material.ripple.rememberRipple
Expand All @@ -26,18 +28,17 @@ import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.common.generated.resources.Res
import com.mohamedrejeb.richeditor.common.generated.resources.slack_logo
import com.mohamedrejeb.richeditor.model.RichTextState
import com.mohamedrejeb.richeditor.model.rememberRichTextState
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

@OptIn(ExperimentalMaterial3Api::class, ExperimentalRichTextApi::class, ExperimentalLayoutApi::class,
ExperimentalResourceApi::class,
)
@OptIn(ExperimentalMaterial3Api::class, ExperimentalRichTextApi::class, ExperimentalResourceApi::class)
@Composable
fun SlackDemoContent() {
val navigator = LocalNavigator.currentOrThrow
Expand Down Expand Up @@ -77,7 +78,7 @@ fun SlackDemoContent() {
IconButton(
onClick = { navigator.pop() }
) {
Icon(Icons.Default.ArrowBack, contentDescription = "Back")
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
}
},
colors = TopAppBarDefaults.mediumTopAppBarColors(
Expand All @@ -86,7 +87,8 @@ fun SlackDemoContent() {
navigationIconContentColor = Color.White,
)
)
Divider(color = Color(0xFFCBCCCD), thickness = 1.dp)

HorizontalDivider(color = Color(0xFFCBCCCD))
}
},
containerColor = Color(0xFF1a1d21),
Expand Down Expand Up @@ -121,7 +123,7 @@ fun SlackDemoContent() {
.background(Color.White)
) {
Image(
painterResource(DrawableResource("slack-logo.png")),
painterResource(Res.drawable.slack_logo),
contentDescription = "Slack Logo",
modifier = Modifier
.fillMaxSize()
Expand Down Expand Up @@ -206,7 +208,7 @@ fun SlackDemoContent() {
contentAlignment = Alignment.Center
) {
Icon(
imageVector = Icons.Outlined.Send,
imageVector = Icons.AutoMirrored.Outlined.Send,
contentDescription = "Send",
tint = Color.White,
modifier = Modifier
Expand All @@ -218,14 +220,13 @@ fun SlackDemoContent() {
}
}

if (openLinkDialog.value) {
if (openLinkDialog.value)
SlackDemoLinkDialog(
state = richTextState,
text = text,
link = link,
openLinkDialog = openLinkDialog
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<dict>
<key>SchemeUserState</key>
<dict>
<key>Compose Rich Editor.xcscheme_^#shared#^_</key>
<key>Compose Rich Editor.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
Expand Down

0 comments on commit 5de91a7

Please sign in to comment.