fix(annotator): fix instant action on Android (#3042)

This commit is contained in:
Huang Xin
2026-01-23 17:18:51 +01:00
committed by GitHub
parent 481d8198e9
commit 6c0f1b8b5f
37 changed files with 232 additions and 142 deletions
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useCallback, useMemo } from 'react';
import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
import { RiDeleteBinLine } from 'react-icons/ri';
import * as CFI from 'foliate-js/epubcfi.js';
@@ -89,6 +89,7 @@ const Annotator: React.FC<{ bookKey: string }> = ({ bookKey }) => {
const [selectedColor, setSelectedColor] = useState<HighlightColor>(
settings.globalReadSettings.highlightStyles[selectedStyle],
);
const androidTouchEndRef = useRef(false);
const showingPopup =
showAnnotPopup ||
@@ -239,8 +240,10 @@ const Annotator: React.FC<{ bookKey: string }> = ({ bookKey }) => {
const handleNativeTouch = (event: CustomEvent) => {
const ev = event.detail as NativeTouchEventType;
if (ev.type === 'touchstart') {
androidTouchEndRef.current = false;
handleTouchStart();
} else if (ev.type === 'touchend') {
androidTouchEndRef.current = true;
handleTouchEnd();
handlePointerUp(doc, index);
}
@@ -414,6 +417,7 @@ const Annotator: React.FC<{ bookKey: string }> = ({ bookKey }) => {
const handleQuickAction = () => {
const action = viewSettings.annotationQuickAction;
if (appService?.isAndroidApp && !androidTouchEndRef.current) return;
switch (action) {
case 'copy':
handleCopy(false);
@@ -27,7 +27,11 @@ const QuickActionMenu: React.FC<QuickActionMenuProps> = ({
eventDispatcher.dispatch('toast', {
type: 'info',
timeout: 2000,
message: _('Quick action disabled'),
message: _('Instant {{action}} Disabled', {
action: _(
annotationToolQuickActions.find((btn) => btn.type === action)?.label || _('Annotation'),
),
}),
});
} else {
eventDispatcher.dispatch('toast', {
@@ -53,7 +57,7 @@ const QuickActionMenu: React.FC<QuickActionMenuProps> = ({
{annotationToolQuickActions.map((button) => (
<MenuItem
key={button.type}
label={_(button.label)}
label={_('Instant {{action}}', { action: _(button.label) })}
tooltip={_(button.tooltip)}
buttonClass={selectedAction === button.type ? 'bg-base-300/85' : ''}
Icon={button.Icon}