multiply x and y tap coordinates by density to get correct bar positioning

This commit is contained in:
Satindar Dhillon
2023-02-07 13:29:49 -08:00
parent 2c738d111d
commit 82638eaf04
5 changed files with 7 additions and 10 deletions

File diff suppressed because one or more lines are too long

View File

@ -89,7 +89,6 @@ fun WebReader(
}
"existingHighlightTap" -> {
val tapCoordinates = Gson().fromJson(json, TapCoordinates::class.java)
Log.d("wv", "receive existing highlight tap action: $tapCoordinates")
CoroutineScope(Dispatchers.Main).launch {
webReaderViewModel.hasTappedExistingHighlight = true
webReaderViewModel.lastTapCoordinates = tapCoordinates
@ -135,6 +134,7 @@ fun WebReader(
class OmnivoreWebView(context: Context) : WebView(context), OnScrollChangeListener {
var viewModel: WebReaderViewModel? = null
var actionMode: ActionMode? = null
val density = resources.displayMetrics.density
init {
setOnScrollChangeListener(this)
@ -223,8 +223,8 @@ class OmnivoreWebView(context: Context) : WebView(context), OnScrollChangeListen
override fun onGetContentRect(mode: ActionMode?, view: View?, outRect: Rect?) {
Log.d("wv", "outRect: $outRect, View: $view")
if (viewModel?.lastTapCoordinates != null) {
val xValue = viewModel!!.lastTapCoordinates!!.tapX.toInt()
val yValue = viewModel!!.lastTapCoordinates!!.tapY.toInt()
val xValue = (viewModel!!.lastTapCoordinates!!.tapX * density).toInt()
val yValue = (viewModel!!.lastTapCoordinates!!.tapY * density).toInt()
val rect = Rect(xValue, yValue, xValue, yValue)
Log.d("wvt", "setting rect based on last tapped rect: ${viewModel?.lastTapCoordinates.toString()}")
@ -256,7 +256,6 @@ class OmnivoreWebView(context: Context) : WebView(context), OnScrollChangeListen
}
override fun onScrollChange(view: View?, x: Int, y: Int, oldX: Int, oldY: Int) {
viewModel?.scrollY = y
viewModel?.onScrollChange((oldY - y).toFloat())
}
}

View File

@ -38,7 +38,6 @@ class WebReaderViewModel @Inject constructor(
): ViewModel() {
var lastJavascriptActionLoopUUID: UUID = UUID.randomUUID()
var javascriptDispatchQueue: MutableList<String> = mutableListOf()
var scrollY = 0
var maxToolbarHeightPx = 0.0f
val webReaderParamsLiveData = MutableLiveData<WebReaderParams?>(null)
@ -205,7 +204,6 @@ class WebReaderViewModel @Inject constructor(
shouldPopViewLiveData.postValue(false)
webReaderParamsLiveData.value = null
annotationLiveData.value = null
scrollY = 0
javascriptDispatchQueue = mutableListOf()
hasTappedExistingHighlight = false
lastTapCoordinates = null

File diff suppressed because one or more lines are too long

View File

@ -15,8 +15,8 @@ export function useSelection(
const handleFinishTouch = useCallback(
async (mouseEvent) => {
const tapAttributes = {
tapX: mouseEvent.screenX,
tapY: mouseEvent.screenY,
tapX: mouseEvent.clientX,
tapY: mouseEvent.clientY,
}
window?.AndroidWebKitMessenger?.handleIdentifiableMessage(