use screenX/Y to store tap coordinate

This commit is contained in:
Satindar Dhillon 2022-11-29 22:46:14 -08:00
parent 5f2a667bec
commit 4e8c316fea
4 changed files with 29 additions and 12 deletions

File diff suppressed because one or more lines are too long

View file

@ -168,7 +168,7 @@ fun WebReader(
when (actionID) {
"userTap" -> {
val tapCoordinates = Gson().fromJson(json, ActionTapCoordinates::class.java)
val tapCoordinates = Gson().fromJson(json, TapCoordinates::class.java)
Log.d("wvt", "received tap action: $tapCoordinates")
webReaderViewModel.lastTappedLocationRect = tapCoordinates.asRect()
}
@ -268,7 +268,7 @@ class OmnivoreWebView(context: Context) : WebView(context) {
override fun onGetContentRect(mode: ActionMode?, view: View?, outRect: Rect?) {
Log.d("wv", "outRect: $outRect, View: $view")
if (viewModel?.lastTappedLocationRect != null) {
Log.d("wv", "setting rect based on last tapped rect")
Log.d("wv", "setting rect based on last tapped rect: ${viewModel?.lastTappedLocationRect.toString()}")
outRect?.set(viewModel!!.lastTappedLocationRect!!)
} else {
outRect?.set(left, top, right, bottom)
@ -317,3 +317,17 @@ data class ActionTapCoordinates(
)
}
}
data class TapCoordinates(
val tapX: Double,
val tapY: Double
) {
fun asRect(): Rect {
return Rect(
tapX.toInt(),
tapY.toInt(),
tapX.toInt(),
tapY.toInt()
)
}
}

File diff suppressed because one or more lines are too long

View file

@ -270,18 +270,14 @@ export function HighlightsLayer(props: HighlightsLayerProps): JSX.Element {
return
}
const rect = (target as Element).getBoundingClientRect()
const rectAttributes = {
rectX: rect.x,
rectY: rect.y,
rectWidth: rect.width,
rectHeight: rect.height,
const tapAttributes = {
tapX: event.screenX,
tapY: event.screenY,
}
window?.AndroidWebKitMessenger?.handleIdentifiableMessage(
'userTap',
JSON.stringify(rectAttributes)
JSON.stringify(tapAttributes)
)
focusedHighlightMousePos.current = { pageX, pageY }
@ -297,9 +293,13 @@ export function HighlightsLayer(props: HighlightsLayerProps): JSX.Element {
if (highlight) {
// In the native app we post a message with the rect of the
// highlight, so the app can display a native menu
const rect = (target as Element).getBoundingClientRect()
const message = {
rectX: rect.x,
rectY: rect.y,
rectWidth: rect.width,
rectHeight: rect.height,
highlightID: highlight.id,
...rectAttributes,
}
window?.webkit?.messageHandlers.viewerAction?.postMessage({
actionID: 'showMenu',