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

Allow keyboard shortcuts to work on native devices #14767

Merged
merged 52 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
61ba698
enable keycommands on native devices
azimgd Feb 2, 2023
f71d9aa
merge main
azimgd Feb 2, 2023
17e4188
merge main
azimgd Feb 2, 2023
fd695f2
fix shortcuts modal view
azimgd Feb 2, 2023
c39fab6
unify keycommands on web and native
azimgd Feb 2, 2023
cc11226
bump keycommand package
azimgd Feb 6, 2023
d073edd
register arrow keys
azimgd Feb 6, 2023
24c461b
update keycommand import order
azimgd Feb 6, 2023
4e47695
adjust non apple environment shortcuts
azimgd Feb 6, 2023
0919f45
Merge branch 'keycommand-v2' of github.com:azimgd/expensify-app into …
azimgd Feb 6, 2023
ae9b9c0
Merge branch 'main' of github.com:azimgd/expensify-app into keycomman…
azimgd Feb 6, 2023
bafa42a
package version bump
azimgd Feb 6, 2023
e9f04a1
CR request, putting back flex:1 on unswipeable modal
azimgd Feb 9, 2023
f67f793
fix shortcut comparison operator
azimgd Feb 9, 2023
3c2242e
enable aboutPage.viewKeyboardShortcuts link on native
azimgd Feb 9, 2023
c5f466c
cr comment
azimgd Feb 9, 2023
f2a9ed9
keycommand library mock
azimgd Feb 12, 2023
10a080e
handle longpress events on some android devices
azimgd Mar 1, 2023
db23ea5
update function comments
azimgd Mar 1, 2023
6bf85ea
fix ESC button interference with default RN instance by disabling ESC…
azimgd Mar 2, 2023
64c0843
move escape disable into const
azimgd Mar 2, 2023
d0b9002
merge commit
azimgd Mar 5, 2023
1f90cc3
merge commit
azimgd Mar 7, 2023
6e0468b
missing ios config
azimgd Mar 7, 2023
4bb5eb3
fix ios
azimgd Mar 7, 2023
2bbb9fc
validate tests
azimgd Mar 7, 2023
cc8cb23
merge main
azimgd Mar 7, 2023
5603110
unpushed changes for const file
azimgd Mar 7, 2023
9cc6c74
different platforms have different event casings
azimgd Mar 20, 2023
0ceb40a
fix eslint warnings
azimgd Mar 20, 2023
2c5c2e9
safe check to event triggers
azimgd Mar 20, 2023
2c602c5
typo fix
azimgd Mar 20, 2023
63ada03
add more safety checks
azimgd Mar 20, 2023
c0d5ad7
bump react-native-key-command
azimgd Mar 21, 2023
9519534
implement show keyboard shortcuts modal close
azimgd Mar 22, 2023
3ac4299
Merge branch 'main' into keycommand-v2
azimgd Mar 23, 2023
e034081
Update android/app/src/main/java/com/expensify/chat/MainActivity.java
azimgd Mar 28, 2023
4dd7d62
Update android/app/src/main/java/com/expensify/chat/MainActivity.java
azimgd Mar 28, 2023
3ef6f80
merge main
azimgd Mar 28, 2023
a18b07d
validate shortcutTrigger existance
azimgd Mar 31, 2023
3aa9348
merge main
azimgd Mar 31, 2023
adbd53c
bump react-native-key-command
azimgd Mar 31, 2023
0bb1b79
merge main
azimgd Mar 31, 2023
298805a
update podfile
azimgd Mar 31, 2023
eac72e7
merge commit
azimgd Apr 11, 2023
c28677b
merge main
azimgd Apr 12, 2023
b384dbb
react-native-keycommand version bump
azimgd Apr 13, 2023
8c90373
unroll reportactioncompose change
azimgd Apr 13, 2023
8917b6d
Merge branch 'Expensify:main' into keycommand-v2
azimgd Apr 13, 2023
e73d257
apply reverted ReportActionCompose subscriber change
azimgd Apr 13, 2023
c3d78f9
Merge branch 'Expensify:main' into keycommand-v2
azimgd Apr 14, 2023
8df40d8
Merge branch 'main' into keycommand-v2
azimgd Apr 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions __mocks__/react-native-key-command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const registerKeyCommands = () => {};
const unregisterKeyCommands = () => {};
const constants = {};
const eventEmitter = () => {};
const addListener = () => {};

export {
registerKeyCommands,
unregisterKeyCommands,
constants,
eventEmitter,
addListener,
};
34 changes: 33 additions & 1 deletion android/app/src/main/java/com/expensify/chat/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import android.os.Bundle;
import android.content.pm.ActivityInfo;
import android.view.KeyEvent;
import com.expensify.chat.bootsplash.BootSplash;
import com.expensify.reactnativekeycommand.KeyCommandModule;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
Expand Down Expand Up @@ -44,4 +46,34 @@ protected void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
}

/**
* This method is called when a key down event has occurred.
* Forwards the event to the KeyCommandModule
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Disabling hardware ESCAPE support which is handled by Android
if (event.getKeyCode() == KeyEvent.KEYCODE_ESCAPE) {
return false;
}
KeyCommandModule.getInstance().onKeyDownEvent(keyCode, event);
return super.onKeyDown(keyCode, event);
}

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
// Disabling hardware ESCAPE support which is handled by Android
if (event.getKeyCode() == KeyEvent.KEYCODE_ESCAPE) { return false; }
KeyCommandModule.getInstance().onKeyDownEvent(keyCode, event);
return super.onKeyLongPress(keyCode, event);
}

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
// Disabling hardware ESCAPE support which is handled by Android
if (event.getKeyCode() == KeyEvent.KEYCODE_ESCAPE) { return false; }
KeyCommandModule.getInstance().onKeyDownEvent(keyCode, event);
return super.onKeyUp(keyCode, event);
}
}
10 changes: 8 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ PODS:
- React
- react-native-image-picker (5.1.0):
- React-Core
- react-native-key-command (0.9.1):
- React-Core
- react-native-netinfo (8.3.1):
- React-Core
- react-native-pdf (6.6.2):
Expand Down Expand Up @@ -765,6 +767,7 @@ DEPENDENCIES:
- react-native-flipper (from `../node_modules/react-native-flipper`)
- "react-native-image-manipulator (from `../node_modules/@oguzhnatly/react-native-image-manipulator`)"
- react-native-image-picker (from `../node_modules/react-native-image-picker`)
- react-native-key-command (from `../node_modules/react-native-key-command`)
- "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)"
- react-native-pdf (from `../node_modules/react-native-pdf`)
- react-native-performance (from `../node_modules/react-native-performance`)
Expand Down Expand Up @@ -916,6 +919,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/@oguzhnatly/react-native-image-manipulator"
react-native-image-picker:
:path: "../node_modules/react-native-image-picker"
react-native-key-command:
:path: "../node_modules/react-native-key-command"
react-native-netinfo:
:path: "../node_modules/@react-native-community/netinfo"
react-native-pdf:
Expand Down Expand Up @@ -1002,7 +1007,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Airship: 19ead2c0bdc791c1b9d6ebb7940aaac99614414e
AirshipFrameworkProxy: 037a0ad6491757c45de2c70a6cc47bae5fcfa32b
boost: 57d2868c099736d80fcd648bf211b4431e51a558
boost: a7c83b31436843459a1961bfd74b96033dc77234
Copy link
Member

Choose a reason for hiding this comment

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

Are these changes part of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes.

CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
FBLazyVector: ff54429f0110d3c722630a98096ba689c39f6d5f
Expand Down Expand Up @@ -1045,7 +1050,7 @@ SPEC CHECKSUMS:
Permission-LocationWhenInUse: 3ba99e45c852763f730eabecec2870c2382b7bd4
Plaid: 7d340abeadb46c7aa1a91f896c5b22395a31fcf2
PromisesObjC: 09985d6d70fbe7878040aa746d78236e6946d2ef
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
RCT-Folly: 0080d0a6ebf2577475bda044aa59e2ca1f909cda
Copy link
Member

Choose a reason for hiding this comment

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

Are these changes part of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes.

RCTRequired: e9e7b8b45aa9bedb2fdad71740adf07a7265b9be
RCTTypeSafety: 9ae0e9206625e995f0df4d5b9ddc94411929fb30
React: a71c8e1380f07e01de721ccd52bcf9c03e81867d
Expand All @@ -1067,6 +1072,7 @@ SPEC CHECKSUMS:
react-native-flipper: dc5290261fbeeb2faec1bdc57ae6dd8d562e1de4
react-native-image-manipulator: c48f64221cfcd46e9eec53619c4c0374f3328a56
react-native-image-picker: c33d4e79f0a14a2b66e5065e14946ae63749660b
react-native-key-command: e49d6e44d44705779696d8d3a5ac6b9e3a198941
react-native-netinfo: 1a6035d3b9780221d407c277ebfb5722ace00658
react-native-pdf: 33c622cbdf776a649929e8b9d1ce2d313347c4fa
react-native-performance: 224bd53e6a835fda4353302cf891d088a0af7406
Expand Down
53 changes: 39 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"react-native-image-pan-zoom": "^2.1.12",
"react-native-image-picker": "^5.1.0",
"react-native-image-size": "git+https://github.com/Expensify/react-native-image-size#6b5ab5110dc3ed554f8eafbc38d7d87c17147972",
"react-native-key-command": "^0.9.1",
"react-native-localize": "^2.2.6",
"react-native-modal": "^13.0.0",
"react-native-onyx": "1.0.38",
Expand Down
59 changes: 58 additions & 1 deletion src/CONST.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import lodashGet from 'lodash/get';
import Config from 'react-native-config';
import * as KeyCommand from 'react-native-key-command';
import * as Url from './libs/Url';

const CLOUDFRONT_DOMAIN = 'cloudfront.net';
const CLOUDFRONT_URL = `https://d2k5nsl2zxldvw.${CLOUDFRONT_DOMAIN}`;
const ACTIVE_EXPENSIFY_URL = Url.addTrailingForwardSlash(lodashGet(Config, 'NEW_EXPENSIFY_URL', 'https://new.expensify.com'));
const USE_EXPENSIFY_URL = 'https://use.expensify.com';
const PLATFORM_OS_MACOS = 'Mac OS';
const PLATFORM_IOS = 'iOS';
const ANDROID_PACKAGE_NAME = 'com.expensify.chat';
const USA_COUNTRY_NAME = 'United States';
const CURRENT_YEAR = new Date().getFullYear();

const keyModifierControl = lodashGet(KeyCommand, 'constants.keyModifierControl', 'keyModifierControl');
const keyModifierCommand = lodashGet(KeyCommand, 'constants.keyModifierCommand', 'keyModifierCommand');
const keyModifierShiftControl = lodashGet(KeyCommand, 'constants.keyModifierShiftControl', 'keyModifierShiftControl');
const keyModifierShiftCommand = lodashGet(KeyCommand, 'constants.keyModifierShiftCommand', 'keyModifierShiftCommand');
const keyInputEscape = lodashGet(KeyCommand, 'constants.keyInputEscape', 'keyInputEscape');
const keyInputEnter = lodashGet(KeyCommand, 'constants.keyInputEnter', 'keyInputEnter');
const keyInputUpArrow = lodashGet(KeyCommand, 'constants.keyInputUpArrow', 'keyInputUpArrow');
const keyInputDownArrow = lodashGet(KeyCommand, 'constants.keyInputDownArrow', 'keyInputDownArrow');

const CONST = {
ANDROID_PACKAGE_NAME,
ANIMATED_TRANSITION: 300,
Expand Down Expand Up @@ -223,6 +234,7 @@ const CONST = {
CTRL: {
DEFAULT: 'control',
[PLATFORM_OS_MACOS]: 'meta',
[PLATFORM_IOS]: 'meta',
},
SHIFT: {
DEFAULT: 'shift',
Expand All @@ -233,46 +245,91 @@ const CONST = {
descriptionKey: 'search',
shortcutKey: 'K',
modifiers: ['CTRL'],
trigger: {
DEFAULT: {input: 'k', modifierFlags: keyModifierControl},
[PLATFORM_OS_MACOS]: {input: 'k', modifierFlags: keyModifierCommand},
[PLATFORM_IOS]: {input: 'k', modifierFlags: keyModifierCommand},
},
},
NEW_GROUP: {
descriptionKey: 'newGroup',
shortcutKey: 'K',
modifiers: ['CTRL', 'SHIFT'],
trigger: {
DEFAULT: {input: 'k', modifierFlags: keyModifierShiftControl},
[PLATFORM_OS_MACOS]: {input: 'k', modifierFlags: keyModifierShiftCommand},
[PLATFORM_IOS]: {input: 'k', modifierFlags: keyModifierShiftCommand},
},
},
SHORTCUT_MODAL: {
descriptionKey: 'openShortcutDialog',
shortcutKey: 'I',
modifiers: ['CTRL'],
trigger: {
DEFAULT: {input: 'i', modifierFlags: keyModifierControl},
[PLATFORM_OS_MACOS]: {input: 'i', modifierFlags: keyModifierCommand},
[PLATFORM_IOS]: {input: 'i', modifierFlags: keyModifierCommand},
},
},
ESCAPE: {
descriptionKey: 'escape',
shortcutKey: 'Escape',
modifiers: [],
trigger: {
DEFAULT: {input: keyInputEscape},
[PLATFORM_OS_MACOS]: {input: keyInputEscape},
[PLATFORM_IOS]: {input: keyInputEscape},
},
},
ENTER: {
descriptionKey: null,
shortcutKey: 'Enter',
modifiers: [],
trigger: {
DEFAULT: {input: keyInputEnter},
[PLATFORM_OS_MACOS]: {input: keyInputEnter},
[PLATFORM_IOS]: {input: keyInputEnter},
},
},
CTRL_ENTER: {
descriptionKey: null,
shortcutKey: 'Enter',
modifiers: ['CTRL'],
trigger: {
DEFAULT: {input: keyInputEnter, modifierFlags: keyModifierControl},
[PLATFORM_OS_MACOS]: {input: keyInputEnter, modifierFlags: keyModifierCommand},
[PLATFORM_IOS]: {input: keyInputEnter, modifierFlags: keyModifierCommand},
},
},
COPY: {
descriptionKey: 'copy',
shortcutKey: 'C',
modifiers: ['CTRL'],
trigger: {
DEFAULT: {input: 'c', modifierFlags: keyModifierControl},
[PLATFORM_OS_MACOS]: {input: 'c', modifierFlags: keyModifierCommand},
[PLATFORM_IOS]: {input: 'c', modifierFlags: keyModifierCommand},
},
},
ARROW_UP: {
descriptionKey: null,
shortcutKey: 'ArrowUp',
modifiers: [],
trigger: {
DEFAULT: {input: keyInputUpArrow},
[PLATFORM_OS_MACOS]: {input: keyInputUpArrow},
[PLATFORM_IOS]: {input: keyInputUpArrow},
},
},
ARROW_DOWN: {
descriptionKey: null,
shortcutKey: 'ArrowDown',
modifiers: [],
trigger: {
DEFAULT: {input: keyInputDownArrow},
[PLATFORM_OS_MACOS]: {input: keyInputDownArrow},
[PLATFORM_IOS]: {input: keyInputDownArrow},
},
},
TAB: {
descriptionKey: null,
Expand Down Expand Up @@ -780,7 +837,7 @@ const CONST = {
WINDOWS: 'Windows',
MAC_OS: PLATFORM_OS_MACOS,
ANDROID: 'Android',
IOS: 'iOS',
IOS: PLATFORM_IOS,
LINUX: 'Linux',
NATIVE: 'Native',
},
Expand Down
Loading