Open oleksandr-serhiienko opened 1 month ago
Please, if smb has any suggestion how could I implement it, just let me know. I would be very thanfull!
Hello! Is the functionality you want to implement based on something that already exists in another reader app? If so, can you give us some examples?
Hello!
I am trying to implement the following functionality:
Single Tap: Select the word. Double Tap: Select the entire sentence. My question is: Can I somehow implement this using injectJavaScript? Or I need to rewrite the classes directly?
I have been experimenting with JavaScript in epubjs.ts, and I added the following function to select a sentence:
selectSentence(range) {
try {
let node = range.startContainer;
let startOffset = range.startOffset;
let endOffset = range.endOffset;
while (startOffset > 0 && !".!?".includes(node.textContent[startOffset - 1])) {
startOffset--;
}
while (endOffset < node.textContent.length && !".!?".includes(node.textContent[endOffset])) {
endOffset++;
}
endOffset++;
let sentenceRange = this.document.createRange();
sentenceRange.setStart(node, startOffset);
sentenceRange.setEnd(node, endOffset);
alert('Range selection completed');
alert(sentenceRange);
return sentenceRange;
} catch (error) {
alert('Error in set range: ' + error.message);
return null;
}
}
This code successfully returns the entire sentence when given a range from the triggerSelectedEvent(t)
method.
I am now stuck trying to integrate this into Single Tap and Double Tap gestures.
I attempted to trigger these gestures using onSingleTap and onDoubleTap from the GestureHandler
in View.tsx.
However, I couldn't get these gestures to fire (I added an alert in both handlers, but nothing was triggered on actual taps).
Even if I manage to trigger the gestures, I am unsure how to pass the appropriate range to the selectSentence(range)
method.
Summary
I am trying to expend the functionality and add an extension to the menuItems so I can select whole sentence. Normal onSelected={handleSelected} works for me. But it is not clear how could I add missing logic. I am checking the injectJavascript options, but I do not find there any clear way to implement it. The example about injectJavascript is very good, but not very helpfull for now, and epubjs.ts does have the implementetion of onSelected, but I need some help in understanding, where my logic should be implemented
What platform(s) does this occur on?
Android
What workflow(s) does this occur on?
Expo Workflow
Environment (or package.json)
expo-env-info@1.2.0
Your .epub file
No response
Minimal reproducible example
No response
I confirm that i have