Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions docs/zh/guide/code-editor-in-compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Jetpack Compose是用于Android开发的新框架。如果您尝试使用Sora Ed

```kotlin
data class CodeEditorState(
val editor: CodeEditor? = null,
var editor: CodeEditor? = null,
val initialContent: Content = Content()
) {
var content by mutableStateOf(initialContent)
Expand Down Expand Up @@ -99,12 +99,21 @@ fun CodeEditor(

### 为`CodeEditor`的状态设置`LaunchedEffect`

当`CodeEditor`的状态发生变化时执行某些代码,我们需要使用`LaunchedEffect`
AndroidView在重组时不会重新执行factory,当`CodeEditor`的状态发生变化时执行某些代码,我们需要使用`update`参数

```kotlin
LaunchedEffect(key1 = state.content) {
state.editor?.setText(state.content)
}
...
AndroidView(
factory = { editor },
modifier = modifier,
onRelease = {
it.release()
},
update = {
it.setText(state.content)
}
)
....
```

## 使用`CodeEditor`可组合项
Expand Down Expand Up @@ -148,4 +157,4 @@ fun MainScreen(

---

以上便是全部。我并不知道在JetPack Compose中使用Sora编辑器的`CodeEditor`是否是一个正确的选择,但我希望您能通过本指南获得灵感。感谢您的阅读。
以上便是全部。我并不知道在JetPack Compose中使用Sora编辑器的`CodeEditor`是否是一个正确的选择,但我希望您能通过本指南获得灵感。感谢您的阅读。