Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.03k stars 2.54k forks source link

Allow keyboard shortcuts to work on native devices #14767

Closed azimgd closed 1 year ago

azimgd commented 1 year ago

Details

Fixed Issues

$ https://github.com/Expensify/App/issues/6883 PROPOSAL: https://github.com/Expensify/App/issues/6883

Tests

Offline tests

Same as QA Steps.

QA Steps

Note: you need to connect hardware keyboard to test mobile keyboard shortcuts on iOS and Android.

  1. Press CMD + K to open "search" sidebar
  2. Press CMD + SHIFT + K to open "newGroup" sidebar
  3. Press CMD + I to open "shortcut" dialog
  4. Press ESC to close any sidebar or dialog
  5. Press ENTER to submit attachment dialog

https://github.com/Expensify/App/blob/ef6937c38197da7124341faefd2218260da7effe/src/CONST.js#L231-L282 All of the shortcuts here should work on Web.

List of known issues on Android and iOS: https://github.com/Expensify/App/pull/14767#issuecomment-1494158230 which are not counted as regressions.

PR Author Checklist

Screenshots/Videos

Web https://user-images.githubusercontent.com/4882133/217061211-7b10e95f-ca0c-46b1-bec7-64d143e0df37.mov
Mobile Web - Chrome https://user-images.githubusercontent.com/4882133/228418338-0c398127-98ba-43c6-a8f8-217a0ede50a6.mov
Mobile Web - Safari https://user-images.githubusercontent.com/4882133/228415502-02486d6c-e8a6-4e30-92bb-2ebd9260064d.mp4
Desktop https://user-images.githubusercontent.com/4882133/217061108-29148272-46de-4c5d-ae54-c5107f1d8927.mov
iOS https://user-images.githubusercontent.com/4882133/228414893-628d999f-0e2c-4de5-82ba-2b30dbb5734c.mp4
Android https://user-images.githubusercontent.com/4882133/216602144-6bc2ee7f-80f3-4578-bd92-cda60d071d29.MOV
parasharrajat commented 1 year ago

Built a production app and faced the same issue https://github.com/Expensify/App/pull/14767#issuecomment-1424833574 https://github.com/Expensify/App/pull/14767#issuecomment-1427092940. I suspect it might be related to OS.

@luacmartins Can you please help with the following?

  1. Testing the above-mentioned bug on Android.
  2. Testing shortcuts on iOS App on a real device. I can't run it on the simulator.
parasharrajat commented 1 year ago

Asking for help on Slack https://expensify.slack.com/archives/C01GTK53T8Q/p1677264003502069.

luacmartins commented 1 year ago

Sorry, I've been focused on a roadmap project and the ECX presentation so I haven't been able to prioritize this. I'll try to get back to it next week!

parasharrajat commented 1 year ago

No problem. Thanks.

alexxxwork commented 1 year ago

2. Testing shortcuts on iOS App on a real device. I can't run it on the simulator.

@parasharrajat Do you still need help?

parasharrajat commented 1 year ago

@alexxxwork Yeah, that is still remaining.

alexxxwork commented 1 year ago

Tested this PR on a hardware device with bluetooth keyboard attached. Key combos work (ctrl + I, ctrl + K, ctrl + shift + K ).

I don't see such a behaviour on search modal https://github.com/Expensify/App/pull/14767#issuecomment-1427092940 But there's another strange thing:

  1. Press Ctrl + K
  2. You see a searh modal and the focus is on search textbox. Arrow keys doesn't work
  3. Press Tab
  4. Press down keys several times
  5. In the end of the searh list selection behaves in a strange way - two elements are highlighted. This happens only for the first time. Next round of scrolling is ok.
Screenshots ![Screenshot_20230228_075240_New Expensify](https://user-images.githubusercontent.com/3872759/221744580-bde04838-ef8c-42a7-b7b0-298404f2b1c6.jpg) ![Screenshot_20230228_075441_New Expensify](https://user-images.githubusercontent.com/3872759/221744594-e32cbbe2-eecc-43f3-a386-64efbc5d27eb.jpg)
parasharrajat commented 1 year ago

Thanks,@alexxxwork. You have similar results like mine. This will really help.

Cc @azimgd.

azimgd commented 1 year ago

Hey @alexxxwork, thank you for a quick feedback.

ESC doesn't work reliably - sometimes it's just closing the app and brings you to home screen.

I believe this happens on a home page, right? Pressing ESC on a home page will minimize the app per Android OS.

Can't manage to test Enter shortcut. It just closes popup on submit attachment window, you should select submit button with TAB.

Could you confirm if pressing ENTER doesn't send an attachment in the popup before closing it? We don't support pressing Tab to focus on elements.

Arrow keys work strange on a report page - up key scrolls down through chat messages and down key scroll up.

While I haven't noticed this behavior, Flatlist on a (home) report page is not wrapped with a keyboard subscription library and operates fully on a native side.

I don't see such a behaviour on search modal https://github.com/Expensify/App/pull/14767#issuecomment-1427092940

But search modal is wrapped.

In the end of the searh list selection behaves in a strange way - two elements are highlighted. This happens only for the first time. Next round of scrolling is ok.

Same with this one, keyboard subscription is interfering with a FlatList.

azimgd commented 1 year ago

@alexxxwork https://expensify.slack.com/archives/C049HHMV9SM/p1676401683622009

alexxxwork commented 1 year ago

I believe this happens on a home page, right? Pressing ESC on a home page will minimize the app per Android OS.

Not only homepage, but any popup in App. Seems like an app crash. It looks like an error calling back.

Could you confirm if pressing ENTER doesn't send an attachment in the popup before closing it?

Yes it doesn't

But search modal is wrapped.

I mean that I don't see problems, that @parasharrajat reported here - search elements scroll with arrow keys works just ok.

While I haven't noticed this behavior, Flatlist on a (home) report page is not wrapped with a keyboard subscription library and operates fully on a native side.

I think this should be fixed maybe in another issue

luacmartins commented 1 year ago

Thanks for helping with tests @alexxxwork!

parasharrajat commented 1 year ago

Every time you see a popup you should press TAB to make a selection with keyboard arrow keys

It happened to me on New Chat or New Group Page.

Arrow keys work strange on a report page - up key scrolls down through chat messages and down key scroll up.

Scrolls the whole chat list for me.


I think that for us native keyboard handling is interfering with custom shortcuts. For example, on the web, arrow keys normally will scroll the list and there are other shortcuts as well that are native to OS. I think the same thing is happening when a Hardware keyboard is attached to the device. OS detects the keyboard and enables native shortcuts like scrollable list scrolls with arrow keys, and tab keys.


It might not be happening if we are using a Bluetooth keyboard. I believe that the code is correct but there might be edge cases based on OS. Mine is MiUI.

Can we utilize BrowserStack to test this? Need to check.

alexxxwork commented 1 year ago

For example, on the web, arrow keys normally will scroll the list

@parasharrajat You're right, arrow keys works on web just the same - up/down reversed. I think that ESC and Enter issues should be fixed and also "keyboard focus" in popups. Arrows are another issue or maybe feature not bug πŸ˜„

azimgd commented 1 year ago

Hey @alexxxwork would you mind checking this again and see if the latest update fixed "Enter" and "Escape" bug you had.

alexxxwork commented 1 year ago

@azimgd Still there's problem with popups (you need to press Tab and then make a selection) Enter shortcut works now in upload attachment modal πŸ‘ ESC bug is still here. Pressing Ctrl-K then ESC brings me to phone home screen. Ctrl + I + ESC works ok. The error in Android Studio's logcat is the same Tried to remove non-existent frame callback

azimgd commented 1 year ago

Hey @alexxxwork, let's try to clarify some points from your feedback.

@azimgd Still there's problem with popups (you need to press Tab and then make a selection)

I'm not going to count this as a bug unless Carlos or Rajat has a very strong argumentation. It's a feature request since initial implementation was done for web only.

ESC bug is still here. Pressing Ctrl-K then ESC brings me to phone home screen. Ctrl + I + ESC works ok.

Would you mind checking this on main branch please? I think what you have there is an interference with native OS functionality. Shortcut popup (ctrl + i) is a modal while Search popup (ctrl + k) is a page.

Hope I addressed all outstanding comments.

alexxxwork commented 1 year ago

I'm not going to count this as a bug unless Carlos or Rajat has a very strong argumentation. It's a feature request since initial implementation was done for web only.

@azimgd I've just took a look at the original issue. 32k for this issue that's huge πŸ‘ I think @parasharrajat should clarify the amount of work to be done on this issue.

Would you mind checking this on main branch please?

Tested on release from google play. Obviously Ctrl+K don't work. But ESC from pages (settings, group chat, etc.) works correctly. So I suppose this is a bug in your implementation.

Do you need help solving this ESC problem?

azimgd commented 1 year ago

@azimgd I've just took a look at the original issue. 32k for this issue that's huge πŸ‘

Not sure I understand this part.

Tested on release from google play. Obviously Ctrl+K don't work. But ESC from pages (settings, group chat, etc.) works correctly. So I suppose this is a bug in your implementation.

Looking at this.

parasharrajat commented 1 year ago

Thanks @alexxxwork for continued feedback. I won't suggest investing time into this anymore if you are expecting compensation. Because I can't guarantee that.


Obviously, we will chase all the bugs or inconsistencies that are present on this PR.

But the main focus is to land the first working draft. Every shortcut should at least work. Edge cases can be tackled later.

alexxxwork commented 1 year ago

Not sure I understand this part.

@azimgd congratulations on winning an issue worth of $32k.

@parasharrajat I understand this. Anyway I can test this PR a few times more, not a problem.

azimgd commented 1 year ago

As I mentioned above ESC is interfering with native OS based implementation. There are couple of ways solving this but not directly related to the work being done in this PR.

  1. utilizing: https://reactnative.dev/docs/backhandler (Android only)
  2. disable ESC propagation on a application level:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  // disabling hardware ESCAPE support which acts as a button
  if (keyCode == 111) { return false; }

  KeyCommandModule.getInstance().onKeyDownEvent(keyCode, event);

  return super.onKeyDown(keyCode, event);
}

Skipping this as it's not related to: "Allow keyboard shortcuts to work on native devices"

alexxxwork commented 1 year ago

@azimgd @parasharrajat if you need my opinion here, I think that QA test steps for this PR should work without errors, but they don't for now:

QA Steps

Note: you need to connect hardware keyboard to test mobile keyboard shortcuts.

  1. Press CMD + K to open "search" sidebar
  2. Press CMD + SHIFT + K to open "newGroup" sidebar
  3. Press CMD + I to open "shortcut" dialog
  4. Press ESC to close any sidebar or dialog There's an error in logcat at this step and the key doesn't work as intended
  5. Press ENTER to submit attachment dialog This step works
azimgd commented 1 year ago

@alexxxwork you were absolutely right about the ESC button, which was broken after "ENTER" support fix. This should be fixed now. Thank you.

Do we have any unresolved points left from your feedback ?

alexxxwork commented 1 year ago

@azimgd Actually it was broken before ENTER fix, the first time I tested it.

Enter and ESC works ok now πŸ‘

tested all these QA steps.

  1. Press CMD + K to open "search" sidebar
  2. Press CMD + SHIFT + K to open "newGroup" sidebar
  3. Press CMD + I to open "shortcut" dialog
  4. Press ESC to close any sidebar or dialog
  5. Press ENTER to submit attachment dialog

There's also a minor edge case. When you press Enter in a "search" sidebar it closes the page, but I think it shouldn't. Maybe this is a side-effect of the previous Enter fixing commit https://github.com/Expensify/App/pull/14767/commits/10a080eab1c68bdebdfe0d8bc3b777b892cb21c2

@parasharrajat if you need my opinion for native keyboard navigation in general - it's hard to use it whithout right assigned tabindexes. When you use it in a dialog it's hard to switch to text input using keyboard only because you got to scroll ALL messages.

luacmartins commented 1 year ago

When you press Enter in a "search" sidebar it closes the page, but I think it shouldn't. Maybe this is a side-effect of the previous Enter fixing commit

This seems to be the behavior on main too, so I think we can tackle it as a separate PR! Thanks for all the testing @alexxxwork!

luacmartins commented 1 year ago

@azimgd would you mind fixing the conflicts so we can do a final review?

alexxxwork commented 1 year ago

This seems to be the behavior on main too, so I think we can tackle it as a separate PR!

@luacmartins Should I first report this as a bug?

luacmartins commented 1 year ago

Go for it @alexxxwork

parasharrajat commented 1 year ago

@luacmartins Can you please test this on ioS? I guess it needs to build an app on iOS. Maybe add the label ready to build to help us test it out.

luacmartins commented 1 year ago

I triggered the testing builds. We still have conflicts though

parasharrajat commented 1 year ago

@azimgd Please merge main.

azimgd commented 1 year ago

@luacmartins I get "This app cannot be installed because its integrity could not be verified."

note: "developer mode" is enabled on my device.

luacmartins commented 1 year ago

I'm building a new version for testing since we merged main and resolved conflicts. I posted in Slack about the iOS integrity issue.

azimgd commented 1 year ago

Same error. Are you able to run it on your end?

luacmartins commented 1 year ago

No, I get the same error

azimgd commented 1 year ago

Could you try building it manually from your machine?

luacmartins commented 1 year ago

@azimgd gonna look into this now. Meanwhile, some jest tests are failing on this branch, you might wanna take a look at that.

azimgd commented 1 year ago

Tests are failing on main.

azimgd commented 1 year ago

I will be mostly unavailable starting this Thursday, for about a month. I will appreciate if we can get this merged within next 2 days.

luacmartins commented 1 year ago

@azimgd tests on main seem to be passing for me. I also see recent PRs, e.g. this one where tests are passing.

luacmartins commented 1 year ago

@azimgd we tested on android and iOS but had a few issues:

Android

  1. CMD + SHIFT + K doesn't seem to work
  2. CMD + I opens the shortcut modal, but immediately closes it
  3. All other shortcuts seem to work great!

iOS

  1. None of the shortcuts seem to work for me and another contributor also had issues. Maybe we are holding something wrong?
azimgd commented 1 year ago

That should be ctrl, not cmd right?

luacmartins commented 1 year ago

Correct!

azimgd commented 1 year ago

@alexxxwork ctrl + shift + k was working for your right ?

luacmartins commented 1 year ago

@azimgd an update. ctrl + shift + k seems to be working for me now, not sure why it didn't before.

I'm still having issues with ctrl + i though. It seems like when I release the keys before the animation finishes, it closes the modal right away. However, if I keep the keys pressed until after the animation is over, the modal stays open.

luacmartins commented 1 year ago

@azimgd Never mind, ctrl + i seems to work fine now. Maybe it's an issue with my device + keyboard πŸ€”

luacmartins commented 1 year ago

So only the issue with iOS remains. I'm testing that again now.

alexxxwork commented 1 year ago

@alexxxwork ctrl + shift + k was working for your right ?

yeah, all worked ok.

azimgd commented 1 year ago

Could you please check if the commit above fixes iOS ?