Skip to content

Commit

Permalink
Fix regression in "Rendered Markdown" label
Browse files Browse the repository at this point in the history
It scrolling with the actual rendered Markdown instead of staying at the top and remaining there.
  • Loading branch information
soupslurpr committed Dec 22, 2023
1 parent de6f3dc commit 8d71444
Showing 1 changed file with 42 additions and 39 deletions.
81 changes: 42 additions & 39 deletions app/src/main/kotlin/dev/soupslurpr/beautyxt/ui/FileEditScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,20 @@ fun FileEditScreen(
if (previewMarkdownRenderedToHtmlFullscreen) {
Spacer(modifier = Modifier.padding(4.dp))
}
Text(
text = stringResource(R.string.rendered_markdown),
color = MaterialTheme.colorScheme.primary,
modifier = Modifier.padding(horizontal = 16.dp, vertical = 0.dp),
style = typography.bodySmall,
fontWeight = FontWeight.Bold
)
Column(
modifier = Modifier
.fillMaxSize()
.weight(1f)
.padding(8.dp)
.verticalScroll(renderedMarkdownVerticalScrollState)
) {
Text(
text = stringResource(R.string.rendered_markdown),
color = MaterialTheme.colorScheme.primary,
modifier = Modifier.padding(horizontal = 8.dp, vertical = 0.dp),
style = typography.bodySmall,
fontWeight = FontWeight.Bold
)
AndroidView(
factory = { context ->
WebView(context).apply {
Expand Down Expand Up @@ -319,37 +319,39 @@ fun FileEditScreen(
Spacer(modifier = Modifier.padding(4.dp))
}
Column(
modifier = Modifier
.fillMaxSize()
.weight(1f)
.padding(8.dp)
.verticalScroll(renderedMarkdownVerticalScrollState)
modifier = Modifier.weight(1f)
) {
Text(
text = stringResource(R.string.rendered_markdown),
color = MaterialTheme.colorScheme.primary,
modifier = Modifier.padding(horizontal = 8.dp, vertical = 0.dp),
modifier = Modifier.padding(start = 16.dp, end = 16.dp, top = 6.dp),
style = typography.bodySmall,
fontWeight = FontWeight.Bold
)
AndroidView(
factory = { context ->
WebView(context).apply {
settings.javaScriptEnabled = false // disable JavaScript for security.
settings.setSupportZoom(false)
settings.builtInZoomControls = false
settings.displayZoomControls = false
setBackgroundColor(colorScheme.background.toArgb()) // set WebView background color to current colorScheme's background color.
}
},
update = { view ->
/**
* The markdown which is converted to HTML is inserted into the body of this.
* The default text color is set to the current colorScheme's onBackground color
* to match the TextField's text color.
*/
fileViewModel.setMarkdownToHtml()
val html = """
Column(
modifier = Modifier
.fillMaxSize()
.padding(start = 8.dp, end = 8.dp)
.verticalScroll(renderedMarkdownVerticalScrollState)
) {
AndroidView(
factory = { context ->
WebView(context).apply {
settings.javaScriptEnabled = false // disable JavaScript for security.
settings.setSupportZoom(false)
settings.builtInZoomControls = false
settings.displayZoomControls = false
setBackgroundColor(colorScheme.background.toArgb()) // set WebView background color to current colorScheme's background color.
}
},
update = { view ->
/**
* The markdown which is converted to HTML is inserted into the body of this.
* The default text color is set to the current colorScheme's onBackground color
* to match the TextField's text color.
*/
fileViewModel.setMarkdownToHtml()
val html = """
<!DOCTYPE html>
<html>
<head>
Expand All @@ -369,17 +371,18 @@ fun FileEditScreen(
</head>
<body>
${if (contentConvertedToHtml == "") {
fileUiState.contentConvertedToHtml.value
} else {
contentConvertedToHtml
}
}
fileUiState.contentConvertedToHtml.value
} else {
contentConvertedToHtml
}
}
</body>
</html>
""".trimIndent()
view.loadData(html, "text/html", "UTF-8")
}
)
view.loadData(html, "text/html", "UTF-8")
}
)
}
}
}
}
Expand Down

0 comments on commit 8d71444

Please sign in to comment.