Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit 7d77c3b

Browse files
authored
Fix initial view may not be able to load previewed content (#3)
1 parent 2a3c4f1 commit 7d77c3b

File tree

4 files changed

+19
-27
lines changed

4 files changed

+19
-27
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ dependencies {
137137
implementation "androidx.compose.material:material:$material_version"
138138
implementation "androidx.compose.material3:material3:$material3_version"
139139
implementation "com.google.accompanist:accompanist-navigation-animation:$accompanist_version"
140-
implementation "com.google.accompanist:accompanist-webview:$accompanist_version"
140+
implementation "com.google.accompanist:accompanist-webview:0.29.1-SNAPSHOT"
141141

142142
implementation 'com.google.android.material:material:1.8.0'
143143

app/src/main/java/org/dianqk/ruslin/ui/component/MarkdownRichText.kt

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import android.webkit.WebView
1212
import android.widget.Toast
1313
import androidx.annotation.WorkerThread
1414
import androidx.compose.foundation.background
15-
import androidx.compose.foundation.layout.Box
1615
import androidx.compose.foundation.layout.fillMaxSize
1716
import androidx.compose.material3.MaterialTheme
1817
import androidx.compose.runtime.Composable
@@ -72,15 +71,9 @@ class MarkdownRichTextViewModel @Inject constructor(
7271
fun MarkdownRichText(
7372
modifier: Modifier = Modifier,
7473
viewModel: MarkdownRichTextViewModel = hiltViewModel(),
75-
htmlBodyText: String?,
74+
htmlBodyText: String,
7675
navigateToNote: (String) -> Unit,
7776
) {
78-
if (htmlBodyText == null) {
79-
Box(modifier = modifier.background(MaterialTheme.colorScheme.background)) {
80-
81-
}
82-
return
83-
}
8477
val webViewState = rememberWebViewStateWithHTMLData(
8578
data = htmlBodyText,
8679
)
@@ -152,22 +145,20 @@ fun MarkdownRichText(
152145

153146
val background = MaterialTheme.colorScheme.background
154147

155-
Box(modifier = modifier.background(background)) {
156-
WebView(
157-
state = webViewState,
158-
modifier = Modifier
159-
.fillMaxSize()
160-
.background(background),
161-
captureBackPresses = false,
162-
onCreated = { webView ->
163-
webView.setBackgroundColor(background.toArgb())
164-
val webViewSettings = webView.settings
165-
webViewSettings.allowFileAccess = false
166-
webViewSettings.allowContentAccess = false
167-
},
168-
client = client
169-
)
170-
}
148+
WebView(
149+
state = webViewState,
150+
modifier = modifier
151+
.fillMaxSize()
152+
.background(background),
153+
captureBackPresses = false,
154+
onCreated = { webView ->
155+
webView.setBackgroundColor(background.toArgb())
156+
val webViewSettings = webView.settings
157+
webViewSettings.allowFileAccess = false
158+
webViewSettings.allowContentAccess = false
159+
},
160+
client = client
161+
)
171162
}
172163

173164
private class LocalContentWebViewClient(

app/src/main/java/org/dianqk/ruslin/ui/page/note_detail/NoteDetailViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ data class NoteDetailUiState(
2727
val title: String = "",
2828
val body: String = "",
2929
val isLoading: Boolean = false,
30-
val previewHtml: String? = null,
30+
val previewHtml: String = "<!DOCTYPE html><html><body></body><html>"
3131
)
3232

3333
const val TAG = "NoteDetailViewModel"
@@ -222,7 +222,7 @@ class NoteDetailViewModel @Inject constructor(
222222
}
223223

224224
fun updatePreviewHtml() {
225-
if (!edited && _uiState.value.previewHtml != null) {
225+
if (!edited) {
226226
return
227227
}
228228
setPreviewHtml(body = _uiState.value.body)

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencyResolutionManagement {
1010
repositories {
1111
google()
1212
mavenCentral()
13+
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
1314
}
1415
}
1516
rootProject.name = "Ruslin"

0 commit comments

Comments
 (0)