Skip to content
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

Regarding Mobile Compatibility #36

Closed
AmalChandru opened this issue Jan 14, 2022 · 3 comments
Closed

Regarding Mobile Compatibility #36

AmalChandru opened this issue Jan 14, 2022 · 3 comments

Comments

@AmalChandru
Copy link

Instead of keypress event input event seems to work for mobile devices. By checking the user-agent, we can dynamically select which event to be fired ( ie input for mobile and keypress for desktop). @KSubedi What are your thoughts?

@vishruti-ajmera
Copy link

I have same issue input tool not working in mobile. I HAVE ALSO TRIED KEYDOWN AND INPUT EVENT IN BUNDLE JS FILE. Please help me to fix this issue as soon as possible.

@AmalChandru
Copy link
Author

I have been successful in doing the same on mobile devices by making a dynamic selection of the event based on the user agent.

Use a boolean to check whether the device is mobile or not.

const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);

Select the event according to isMobile.

return (
             (t.prototype.registerListeners = function () {
              this.transliterationProvider.inputArea.addEventListener(
              isMobile ? "input" : "keypress",
              this.handleKeyPress()
            );

Manage both mobile and web independently

(t.prototype.handleKeyPress = function () {
                       var t =
                           "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(
                               ""
                           );
                       return function (e) {
                           if (isMobile) {
                               const text =
                                   this.transliterationProvider.inputArea
                                       .value;

                               if (-1 !== t.indexOf(e.data)) {
                                   this.transliterationProvider.inputArea.value =
                                       text.slice(0, -1);
                                   this.transliterationProvider.suggestionBox.startSuggestions(
                                       e.data
                                   );
                               } else if (
                                   e.inputType === "insertText" &&
                                   -1 === t.indexOf(e.data)
                               ) {
                                   this.transliterationProvider.suggestionBox.endSuggestions();
                                   this.transliterationProvider.inputArea.value =
                                       text.slice(0, -1) + e.data;
                               } else if (e.inputType === "insertLineBreak") {
                                   this.transliterationProvider.inputArea.value =
                                       text + "\n";
                               } else if (
                                   e.inputType === "deleteContentBackward"
                               ) {
                                   this.transliterationProvider.inputArea.value =
                                       text.slice(0, -1);
                               }
                           } else {
                               -1 !== t.indexOf(e.key) &&
                                   (this.transliterationProvider.suggestionBox.startSuggestions(
                                       e.key
                                   ),
                                   e.preventDefault());
                           }
                       }.bind(this);
                   }),
                   t
               );
           })();
           e.EventHandler = i;
       }

Note: In the case of mobile implementation you have to manage edge cases and tweak the styles as per the context

@vishruti-ajmera
Copy link

Thank you so much. Your answer working perfect. Just has syntax error in 6th last line.
}.bind(this); }, t ); })(); e.EventHandler = i; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants