mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
dispatch to main when UI functions are called from js interface
This commit is contained in:
parent
4e8c316fea
commit
f31ea67fe6
1 changed files with 12 additions and 4 deletions
|
|
@ -27,6 +27,9 @@ import androidx.compose.ui.viewinterop.AndroidView
|
|||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import app.omnivore.omnivore.R
|
||||
import com.google.gson.Gson
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.*
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
|
@ -170,14 +173,18 @@ fun WebReader(
|
|||
"userTap" -> {
|
||||
val tapCoordinates = Gson().fromJson(json, TapCoordinates::class.java)
|
||||
Log.d("wvt", "received tap action: $tapCoordinates")
|
||||
webReaderViewModel.lastTappedLocationRect = tapCoordinates.asRect()
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
webReaderViewModel.lastTappedLocationRect = tapCoordinates.asRect()
|
||||
}
|
||||
}
|
||||
"existingHighlightTap" -> {
|
||||
val actionTapCoordinates = Gson().fromJson(json, ActionTapCoordinates::class.java)
|
||||
Log.d("wv", "receive existing highlight tap action: $actionTapCoordinates")
|
||||
webReaderViewModel.hasTappedExistingHighlight = true
|
||||
webReaderViewModel.lastTappedLocationRect = actionTapCoordinates.asRect()
|
||||
startActionMode(null, ActionMode.TYPE_FLOATING)
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
webReaderViewModel.hasTappedExistingHighlight = true
|
||||
webReaderViewModel.lastTappedLocationRect = actionTapCoordinates.asRect()
|
||||
startActionMode(null, ActionMode.TYPE_FLOATING)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
webReaderViewModel.handleIncomingWebMessage(actionID, json)
|
||||
|
|
@ -225,6 +232,7 @@ class OmnivoreWebView(context: Context) : WebView(context) {
|
|||
// Called each time the action mode is shown. Always called after onCreateActionMode, but
|
||||
// may be called multiple times if the mode is invalidated.
|
||||
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||
Log.d("wv", "preparing action mode $menu")
|
||||
return false // Return false if nothing is done
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue