Skip to content

Commit

Permalink
Revert "Fix initial view may not be able to load previewed content (#3)"
Browse files Browse the repository at this point in the history
This reverts commit 7d77c3b.
  • Loading branch information
DianQK authored Jan 28, 2023
1 parent 7d77c3b commit 7609d7e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ dependencies {
implementation "androidx.compose.material:material:$material_version"
implementation "androidx.compose.material3:material3:$material3_version"
implementation "com.google.accompanist:accompanist-navigation-animation:$accompanist_version"
implementation "com.google.accompanist:accompanist-webview:0.29.1-SNAPSHOT"
implementation "com.google.accompanist:accompanist-webview:$accompanist_version"

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.webkit.WebView
import android.widget.Toast
import androidx.annotation.WorkerThread
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -71,9 +72,15 @@ class MarkdownRichTextViewModel @Inject constructor(
fun MarkdownRichText(
modifier: Modifier = Modifier,
viewModel: MarkdownRichTextViewModel = hiltViewModel(),
htmlBodyText: String,
htmlBodyText: String?,
navigateToNote: (String) -> Unit,
) {
if (htmlBodyText == null) {
Box(modifier = modifier.background(MaterialTheme.colorScheme.background)) {

}
return
}
val webViewState = rememberWebViewStateWithHTMLData(
data = htmlBodyText,
)
Expand Down Expand Up @@ -145,20 +152,22 @@ fun MarkdownRichText(

val background = MaterialTheme.colorScheme.background

WebView(
state = webViewState,
modifier = modifier
.fillMaxSize()
.background(background),
captureBackPresses = false,
onCreated = { webView ->
webView.setBackgroundColor(background.toArgb())
val webViewSettings = webView.settings
webViewSettings.allowFileAccess = false
webViewSettings.allowContentAccess = false
},
client = client
)
Box(modifier = modifier.background(background)) {
WebView(
state = webViewState,
modifier = Modifier
.fillMaxSize()
.background(background),
captureBackPresses = false,
onCreated = { webView ->
webView.setBackgroundColor(background.toArgb())
val webViewSettings = webView.settings
webViewSettings.allowFileAccess = false
webViewSettings.allowContentAccess = false
},
client = client
)
}
}

private class LocalContentWebViewClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ data class NoteDetailUiState(
val title: String = "",
val body: String = "",
val isLoading: Boolean = false,
val previewHtml: String = "<!DOCTYPE html><html><body></body><html>"
val previewHtml: String? = null,
)

const val TAG = "NoteDetailViewModel"
Expand Down Expand Up @@ -222,7 +222,7 @@ class NoteDetailViewModel @Inject constructor(
}

fun updatePreviewHtml() {
if (!edited) {
if (!edited && _uiState.value.previewHtml != null) {
return
}
setPreviewHtml(body = _uiState.value.body)
Expand Down
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
}
rootProject.name = "Ruslin"
Expand Down

0 comments on commit 7609d7e

Please sign in to comment.