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

[#18459] - Add cursor-based input handling to token-input #18594

Merged
merged 3 commits into from
Feb 2, 2024

Conversation

ulisesmac
Copy link
Contributor

@ulisesmac ulisesmac commented Jan 23, 2024

fixes #18459
fixes #18466

Summary

This PR adds capabilities to delete and type using the cursor position to the token input.

Screencast.from.2024-01-22.23-04-19.webm

NOTE: This PR doesn't handle the active cursor selection typing/erasing

NOT HANDLED:
image
It just does nothing if we press the keyboard

Review notes

Properly handling all possibilites and validations for the active cursor selection is an exhaustive task, and it's a little hard to know what do we exactly expect for every case, it's also an error-prone task.

If the handling in this PR is not the expected, I'd suggest opening a separate issue with the interactions we have and the result we expect (probably we should align with designers). I believe it's better to merge this PR since it adds parts of the total work that needs to get done.

Do we really want to reimplement this logic? inputs already handle this behavior if we use a regular keyboard (not our custom one).

Platforms

  • Android
  • iOS

Steps to test

  • Open Status
  • Go to wallet, pick an address with funds, press send, select and address to send and pick any token.
  • The Token input now is able to add numbers in cursor's position.

status: ready

@ulisesmac ulisesmac self-assigned this Jan 23, 2024
@@ -105,7 +142,14 @@
(if (> num-value current-limit-amount)
(reset! input-value (str current-limit-amount))
(reset! input-value v))
(reagent/flush))))]
(reagent/flush))))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@J-Son89 Just wondering if we really need the existing reagent/flush calls?

I tried removing them and I didn't find issues, but I didn't test it deeply.

@@ -77,6 +108,7 @@
input-value (reagent/atom "")
current-limit (reagent/atom {:amount limit-crypto
:currency token-symbol})
input-selection (reagent/atom {:start 0 :end 0})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Atom to track the cursor position 👀

@status-im-auto
Copy link
Member

status-im-auto commented Jan 23, 2024

Jenkins Builds

Click to see older builds (16)
Commit #️⃣ Finished (UTC) Duration Platform Result
36236bb #1 2024-01-23 05:15:48 ~4 min tests 📄log
✔️ 36236bb #1 2024-01-23 05:17:01 ~6 min ios 📱ipa 📲
✔️ 36236bb #1 2024-01-23 05:18:35 ~7 min android-e2e 🤖apk 📲
✔️ 36236bb #1 2024-01-23 05:18:39 ~7 min android 🤖apk 📲
e86253e #2 2024-01-25 19:47:10 ~1 min tests 📄log
✔️ e86253e #2 2024-01-25 19:51:02 ~5 min ios 📱ipa 📲
✔️ e86253e #2 2024-01-25 19:53:16 ~7 min android-e2e 🤖apk 📲
✔️ e86253e #2 2024-01-25 19:53:18 ~7 min android 🤖apk 📲
✔️ 2b7907e #3 2024-01-25 21:16:45 ~5 min tests 📄log
✔️ 2b7907e #3 2024-01-25 21:17:21 ~5 min ios 📱ipa 📲
✔️ 2b7907e #3 2024-01-25 21:19:03 ~7 min android-e2e 🤖apk 📲
✔️ 2b7907e #3 2024-01-25 21:19:04 ~7 min android 🤖apk 📲
✔️ 23c1af8 #4 2024-01-30 16:43:55 ~5 min tests 📄log
✔️ 23c1af8 #4 2024-01-30 16:44:16 ~5 min ios 📱ipa 📲
✔️ 23c1af8 #4 2024-01-30 16:46:43 ~7 min android-e2e 🤖apk 📲
✔️ 23c1af8 #4 2024-01-30 16:46:48 ~7 min android 🤖apk 📲
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ c85ef01 #5 2024-02-02 01:37:33 ~5 min tests 📄log
✔️ c85ef01 #5 2024-02-02 01:37:58 ~5 min ios 📱ipa 📲
✔️ c85ef01 #5 2024-02-02 01:39:58 ~7 min android-e2e 🤖apk 📲
✔️ c85ef01 #5 2024-02-02 01:39:58 ~7 min android 🤖apk 📲
✔️ 51786dd #7 2024-02-02 01:59:27 ~5 min tests 📄log
✔️ 51786dd #7 2024-02-02 01:59:46 ~5 min ios 📱ipa 📲
✔️ 51786dd #7 2024-02-02 02:00:59 ~6 min android-e2e 🤖apk 📲
✔️ 51786dd #7 2024-02-02 02:01:22 ~7 min android 🤖apk 📲

(str "0" v)
[current v input-selection-atom]
(let [{:keys [start end]} @input-selection-atom]
(if (= start end)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(= start end)

I'm only handling the cases when the cursor is not selecting text, validating everything seems really exhaustive.

@OmarBasem
Copy link
Contributor

@ulisesmac have you tried setting the selection onChangeText using setNativeProps, example: https://github.com/status-im/status-mobile/blob/develop/src/status_im/contexts/chat/messenger/composer/handlers.cljs#L133

@ulisesmac
Copy link
Contributor Author

@ulisesmac have you tried setting the selection onChangeText using setNativeProps, example: https://github.com/status-im/status-mobile/blob/develop/src/status_im/contexts/chat/messenger/composer/handlers.cljs#L133

Hi @OmarBasem !
Thanks for the suggestion.

Is there any advantage if we do this?
I think it's the same as if we just pass :selection

@OmarBasem
Copy link
Contributor

OmarBasem commented Jan 24, 2024

@ulisesmac have you tried setting the selection onChangeText using setNativeProps, example: https://github.com/status-im/status-mobile/blob/develop/src/status_im/contexts/chat/messenger/composer/handlers.cljs#L133

I think it could be a cleaner and shorter solution. I see multiple new methods like normalize-input and submethods within it. I have faced similar problems with text inputs before and did not have to use multiple custom methods.
I am thinking if we set the cursor-position on-selection-change and update the selection start and end inside on-change-text that could fix the problem.

So I was suggesting to try that solution as I believe it should be more concise (unless I misunderstood something from the original problem)

@ulisesmac
Copy link
Contributor Author

Thanks again for the suggestion @OmarBasem !

Well, this input isn't calling on-change-text when we press the keyboard to add numbers because the keyboard is a react component.

on-change-text is called when we update the input using an external keyboard or the OS's keyboard (but I noticed it works really bad atm).

I am thinking if we set the cursor-position on-selection-change

This is what it's being done in this PR, in on-selection-change we store the cursor position in an atom.

and update the selection start and end inside on-change-text that could fix the problem.

Since (as I said before) on-change-text doesn't work, it's being done in handle-keyboard-press.

I see multiple new methods like normalize-input and submethods within it.

I didn't add the function normalize-input but created the function move-input-cursor, so that when we type a new char, we move the cursor to the expected position, otherwise the cursor will stay in the same position.

I think the logic of this input has to be completely reworked, because when it was implemented it didn't consider the cursor's position for validations, new chars added, and chars erased. I see this PR as a step in that direction.

@OmarBasem
Copy link
Contributor

I think the logic of this input has to be completely reworked, because when it was implemented it didn't consider the cursor's position for validations, new chars added, and chars erased. I see this PR as a step in that direction.

Yeah makes sense. Thanks for the clarification!

@status-im-auto
Copy link
Member

90% of end-end tests have passed

Total executed tests: 48
Failed tests: 2
Expected to fail tests: 3
Passed tests: 43
IDs of failed tests: 704613,702775 
IDs of expected to fail tests: 703503,702808,703629 

Failed tests (2)

Click to expand
  • Rerun failed tests

  • Class TestDeepLinksOneDevice:

    1. test_links_open_universal_links_from_chat, id: 704613

    Device 1: Find `Button` by `xpath`: `//*[@text="open community"]`
    Device 1: Tap on found: Button

    critical/test_deep_and_universal_links.py:63: in test_links_open_universal_links_from_chat
        self.errors.verify_no_errors()
    base_test_case.py:191: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Closed community was not requested to join by the url https://status.app/c/G8EAAGTiXKuwNbVVAu0GNLD-XzX4oz_E8oC1-7qSLikaTnCuG9Ag13ZgQKrMd8En9Qcpuaj3Qx3mfZ1atZzH8Zw-x_sFJ_MDv0P_7YfqoV-pNr3V4dsza-jVk41GaCGWasJb92Oer8qggaoNWf0tYCgSH19VonXciKPUz3ITdgke#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK
    E    Closed community was not requested to join by the url https://status.app/c/Ow==#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK
    E    Closed community was not requested to join by the url https://status.app/c#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK
    E    Closed community was not requested to join by the url https://status.app/c/ixiACjAKCHRlc3RDb21tEhZkemZ4Z2Nodmpra2xra2xrbCAgbGxsGAYiByM4OEIwRkYqARQD#zQ3shuK3RAMBGtNWJ5QAKtuGeyEhiwko5gXhyGg6T89Q2xrHq
    



    Device sessions

    2. test_links_deep_links, id: 702775

    Device 1: Find BrowserTab by accessibility id: browser-stack-tab
    Device 1: Tap on found: BrowserTab

    critical/test_deep_and_universal_links.py:101: in test_links_deep_links
        self.errors.verify_no_errors()
    base_test_case.py:191: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Closed community was not requested to join by the deep link status-app://c/G8EAAGTiXKuwNbVVAu0GNLD-XzX4oz_E8oC1-7qSLikaTnCuG9Ag13ZgQKrMd8En9Qcpuaj3Qx3mfZ1atZzH8Zw-x_sFJ_MDv0P_7YfqoV-pNr3V4dsza-jVk41GaCGWasJb92Oer8qggaoNWf0tYCgSH19VonXciKPUz3ITdgke#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK
    E    Closed community was not requested to join by the deep link status-app://c/Ow==#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK
    E    Closed community was not requested to join by the deep link status-app://c#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK
    E    Closed community was not requested to join by the deep link status-app://c/ixiACjAKCHRlc3RDb21tEhZkemZ4Z2Nodmpra2xra2xrbCAgbGxsGAYiByM4OEIwRkYqARQD#zQ3shuK3RAMBGtNWJ5QAKtuGeyEhiwko5gXhyGg6T89Q2xrHq
    



    Device sessions

    Expected to fail tests (3)

    Click to expand

    Class TestCommunityOneDeviceMerged:

    1. test_community_discovery, id: 703503

    Test is not run, e2e blocker  
    

    [[reason: [NOTRUN] Curated communities not loading, https://github.com//issues/17852]]

    Class TestCommunityMultipleDeviceMergedTwo:

    1. test_community_join_when_node_owner_offline, id: 703629

    Device 2: Tap on found: Button
    Device 2: Looking for community: 'open community'

    critical/chats/test_public_chat_browsing.py:1178: in test_community_join_when_node_owner_offline
        self.errors.verify_no_errors()
    base_test_case.py:191: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     open community is not listed inside Pending communities tab
    E    open community is not listed inside Joined communities tab 
    

    [[Can't join a community if admin goes offline, https://github.com//issues/17678]]

    Device sessions

    Class TestGroupChatMultipleDeviceMergedNewUI:

    1. test_group_chat_offline_pn, id: 702808

    Device 3: Looking for a message by text: message from old member
    Device 3: Looking for a message by text: message from new member

    critical/chats/test_group_chat.py:324: in test_group_chat_offline_pn
        self.errors.verify_no_errors()
    base_test_case.py:191: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Messages PN was not fetched from offline 
    

    [[Data delivery issue]]

    Device sessions

    Passed tests (43)

    Click to expand

    Class TestCommunityOneDeviceMerged:

    1. test_restore_multiaccount_with_waku_backup_remove_switch, id: 703133
    Device sessions

    2. test_community_copy_and_paste_message_in_chat_input, id: 702742
    Device sessions

    3. test_community_undo_delete_message, id: 702869
    Device sessions

    4. test_community_navigate_to_channel_when_relaunch, id: 702846
    Device sessions

    5. test_community_mute_community_and_channel, id: 703382
    Device sessions

    Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_emoji_send_reply_and_open_link, id: 702782
    Device sessions

    2. test_1_1_chat_text_message_delete_push_disappear, id: 702733
    Device sessions

    3. test_1_1_chat_push_emoji, id: 702813
    Device sessions

    4. test_1_1_chat_non_latin_messages_stack_update_profile_photo, id: 702745
    Device sessions

    5. test_1_1_chat_edit_message, id: 702855
    Device sessions

    6. test_1_1_chat_send_image_save_and_share, id: 703391
    Device sessions

    7. test_1_1_chat_pin_messages, id: 702731
    Device sessions

    8. test_1_1_chat_message_reaction, id: 702730
    Device sessions

    Class TestOneToOneChatMultipleSharedDevicesNewUiTwo:

    1. test_1_1_chat_delete_via_long_press_relogin, id: 702784
    Device sessions

    2. test_1_1_chat_is_shown_message_sent_delivered_from_offline, id: 702783
    Device sessions

    3. test_1_1_chat_mute_chat, id: 703496
    Device sessions

    Class TestCommunityMultipleDeviceMergedTwo:

    1. test_community_markdown_support, id: 702809
    Device sessions

    2. test_community_hashtag_links_to_community_channels, id: 702948
    Device sessions

    3. test_community_mentions_push_notification, id: 702786
    Device sessions

    4. test_community_leave, id: 702845
    Device sessions

    Class TestActivityMultipleDevicePRTwo:

    1. test_activity_center_mentions, id: 702957
    Device sessions

    2. test_activity_center_admin_notification_accept_swipe, id: 702958
    Device sessions

    Class TestGroupChatMultipleDeviceMergedNewUI:

    1. test_group_chat_pin_messages, id: 702732
    Device sessions

    2. test_group_chat_mute_chat, id: 703495
    Device sessions

    3. test_group_chat_send_image_save_and_share, id: 703297
    Device sessions

    4. test_group_chat_reactions, id: 703202
    Device sessions

    5. test_group_chat_join_send_text_messages_push, id: 702807
    Device sessions

    Class TestActivityMultipleDevicePR:

    1. test_navigation_jump_to, id: 702936
    Device sessions

    2. test_activity_center_reply_read_unread_delete_filter_swipe, id: 702947
    Device sessions

    Class TestCommunityMultipleDeviceMerged:

    1. test_community_several_images_send_reply, id: 703194
    Device sessions

    2. test_community_one_image_send_reply, id: 702859
    Device sessions

    3. test_community_emoji_send_copy_paste_reply, id: 702840
    Device sessions

    4. test_community_mark_all_messages_as_read, id: 703086
    Device sessions

    5. test_community_contact_block_unblock_offline, id: 702894
    Device sessions

    6. test_community_edit_delete_message_when_offline, id: 704615
    Device sessions

    7. test_community_message_delete, id: 702839
    Device sessions

    8. test_community_message_send_check_timestamps_sender_username, id: 702838
    Device sessions

    9. test_community_links_with_previews_github_youtube_twitter_gif_send_enable, id: 702844
    Device sessions

    10. test_community_message_edit, id: 702843
    Device sessions

    11. test_community_unread_messages_badge, id: 702841
    Device sessions

    Class TestActivityCenterContactRequestMultipleDevicePR:

    1. test_add_contact_field_validation, id: 702777
    Device sessions

    2. test_activity_center_contact_request_accept_swipe_mark_all_as_read, id: 702851
    Device sessions

    3. test_activity_center_contact_request_decline, id: 702850
    Device sessions

    @ulisesmac ulisesmac force-pushed the 18466-token-input-cursor branch 2 times, most recently from e86253e to 2b7907e Compare January 25, 2024 21:11
    @VolodLytvynenko VolodLytvynenko self-assigned this Jan 30, 2024
    @pavloburykh pavloburykh force-pushed the 18466-token-input-cursor branch from 2b7907e to 23c1af8 Compare January 30, 2024 16:38
    @VolodLytvynenko
    Copy link
    Contributor

    Hi @ulisesmac , thank you for the PR. I will create separate follow-ups for this PR when I find the expected behavior from the design team. The PR is ready to be merged

    @ulisesmac ulisesmac force-pushed the 18466-token-input-cursor branch from c85ef01 to 01bb0bb Compare February 2, 2024 01:53
    @ulisesmac ulisesmac merged commit c7bf9f0 into develop Feb 2, 2024
    6 checks passed
    @ulisesmac ulisesmac deleted the 18466-token-input-cursor branch February 2, 2024 02:02
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    Archived in project
    Archived in project
    4 participants