mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
use screenX/Y to store tap coordinate
This commit is contained in:
parent
5f2a667bec
commit
4e8c316fea
4 changed files with 29 additions and 12 deletions
File diff suppressed because one or more lines are too long
|
|
@ -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
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Reference in a new issue