Skip to content

Commit

Permalink
enable scroll configuration in htmltext2
Browse files Browse the repository at this point in the history
  • Loading branch information
X1nto committed Dec 23, 2023
1 parent 10d6b09 commit 55fab44
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
23 changes: 15 additions & 8 deletions androidApp/src/main/java/dev/xinto/argos/ui/component/HtmlText2.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.xinto.argos.ui.component

import android.annotation.SuppressLint
import android.view.MotionEvent
import android.webkit.WebView
import android.widget.FrameLayout
import android.widget.FrameLayout.LayoutParams
Expand Down Expand Up @@ -31,12 +30,14 @@ import org.intellij.lang.annotations.Language
fun MaterialHtmlText2(
@Language("HTML")
text: String,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
userScrollEnabled: Boolean = true
) {
HtmlText2(
modifier = modifier,
text = text,
typography = HtmlText2Defaults.material3Typography()
typography = HtmlText2Defaults.material3Typography(),
userScrollEnabled = userScrollEnabled
)
}

Expand All @@ -48,7 +49,8 @@ fun HtmlText2(
@Language("HTML")
text: String,
typography: HtmlText2Typography,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
userScrollEnabled: Boolean = true,
) {
val textCss = typography.asCss(LocalDensity.current)
AndroidView(
Expand All @@ -61,10 +63,6 @@ fun HtmlText2(
isLongClickable = false
setOnLongClickListener { true }
isHapticFeedbackEnabled = false
setOnTouchListener { _, event ->
event.action == MotionEvent.ACTION_MOVE
}
setInitialScale(250)
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
}
FrameLayout(it).apply { //FrameLayout needed to prevent crashes
Expand All @@ -89,6 +87,15 @@ fun HtmlText2(
</html>
""".trimIndent()
webView.loadData(htmlText, "text/html; charset=utf-8", "UTF-8")

if (userScrollEnabled) {
webView.setOnTouchListener { v, event ->
webView.requestDisallowInterceptTouchEvent(true)
false
}
} else {
webView.setOnTouchListener(null)
}
},
onReset = {
//enable reuse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package dev.xinto.argos.ui.screen.course.page.syllabus

import androidx.annotation.StringRes
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -88,17 +85,12 @@ fun SyllabusPage(
append("</div>")
}
}
Box(
MaterialHtmlText2(
text = text,
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.horizontalScroll(rememberScrollState())
) {
MaterialHtmlText2(
text = text,
modifier = Modifier.padding(16.dp)
)
}
.padding(16.dp),
)
}

is SyllabusState.Error -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ fun MessageScreen(
${state.message.body}
</div>
""".trimIndent()
}
},
userScrollEnabled = false
)
}
}
Expand Down

0 comments on commit 55fab44

Please sign in to comment.