-
-
Notifications
You must be signed in to change notification settings - Fork 233
fix :huawei touch not working #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tiodot
wants to merge
12
commits into
pacexy:main
Choose a base branch
from
tiodot:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
45eb2b0
fix:huawei touch not working
tiodot acb0d26
fix error
tiodot 937434f
fix rm unused
tiodot 1e8a58d
fix order
tiodot 3753f52
fix order
tiodot 9bbe1bc
rm sentry
tiodot 1cba262
proxy github epub
tiodot bfd39b9
remove proxy
tiodot f498370
Revert "rm sentry"
pacexy 8a96b01
fix
pacexy cc31872
format
pacexy e708aa7
Update apps/reader/src/components/Reader.tsx
pacexy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,75 @@ | ||||||
import { useEventListener } from '@literal-ui/hooks' | ||||||
import { useCallback, useRef } from 'react' | ||||||
|
||||||
import { AsRef, BookTab } from '../models/reader' | ||||||
|
||||||
import { hasSelection } from './useTextSelection' | ||||||
|
||||||
export function useTouchEvent(props: { | ||||||
iframe?: Window & AsRef | ||||||
tab: BookTab | ||||||
}) { | ||||||
const { iframe, tab } = props | ||||||
const params = useRef({ x: -1, y: -1, t: 0, expired: false }) | ||||||
|
||||||
useEventListener(iframe, 'touchstart', (e) => { | ||||||
const x0 = e.targetTouches[0]?.clientX ?? 0 | ||||||
const y0 = e.targetTouches[0]?.clientY ?? 0 | ||||||
const t0 = Date.now() | ||||||
|
||||||
params.current = { x: x0, y: y0, t: t0, expired: false } | ||||||
|
||||||
if (!iframe) return | ||||||
|
||||||
// When selecting text with long tap, `touchend` is not fired, | ||||||
// so instead of use `addEventlistener`, we should use `on*` | ||||||
// to remove the previous listener. | ||||||
iframe.ontouchend = handleTouchEnd | ||||||
}) | ||||||
|
||||||
const handleTouchEnd = useCallback( | ||||||
function (e: TouchEvent) { | ||||||
if (!iframe) return | ||||||
iframe.ontouchend = undefined | ||||||
console.log('params:', params.current) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove console.log statement from production code. This debug logging should be removed or replaced with proper logging.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
const selection = iframe.getSelection() | ||||||
|
||||||
if (hasSelection(selection)) return | ||||||
if (params.current.expired) return | ||||||
|
||||||
params.current.expired = true | ||||||
|
||||||
const x1 = e.changedTouches[0]?.clientX ?? 0 | ||||||
const y1 = e.changedTouches[0]?.clientY ?? 0 | ||||||
const t1 = Date.now() | ||||||
|
||||||
const { x, y, t } = params.current | ||||||
|
||||||
const deltaX = x1 - x | ||||||
const deltaY = y1 - y | ||||||
const deltaT = t1 - t | ||||||
|
||||||
const absX = Math.abs(deltaX) | ||||||
const absY = Math.abs(deltaY) | ||||||
|
||||||
if (absX < 10) return | ||||||
|
||||||
if (absY / absX > 2) { | ||||||
if (deltaT > 100 || absX < 30) { | ||||||
return | ||||||
} | ||||||
} | ||||||
|
||||||
if (deltaX > 0) { | ||||||
tab.prev() | ||||||
} | ||||||
|
||||||
if (deltaX < 0) { | ||||||
tab.next() | ||||||
} | ||||||
}, | ||||||
[tab, iframe], | ||||||
) | ||||||
|
||||||
useEventListener(iframe, 'touchend', handleTouchEnd) | ||||||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential race condition: Setting
iframe.ontouchend
directly overwrites any existing handler. Consider checking if a handler already exists or use a more robust event management approach.Copilot uses AI. Check for mistakes.