Skip to content

Commit

Permalink
Revert "Mobile chat: Pressing enter on a hardware keyboard should sen…
Browse files Browse the repository at this point in the history
…d chat message, shift-enter should add newline (keybase#23430)" (keybase#23477)

This reverts commit c23b405.
  • Loading branch information
cjb authored Apr 3, 2020
1 parent c23b405 commit f3fc476
Show file tree
Hide file tree
Showing 14 changed files with 7,511 additions and 7,973 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;

import android.view.KeyEvent;
import com.github.emilioicai.hwkeyboardevent.HWKeyboardEventModule;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -72,7 +69,6 @@
public class MainActivity extends ReactActivity {
private static final String TAG = MainActivity.class.getName();
private PermissionListener listener;
private boolean isUsingHardwareKeyboard = false;
static boolean createdReact = false;

@Override
Expand Down Expand Up @@ -172,8 +168,6 @@ public void run() {
}, 300);

KeybasePushNotificationListenerService.createNotificationChannel(this);

updateIsUsingHardwareKeyboard();
}

@Override
Expand Down Expand Up @@ -434,12 +428,8 @@ public void onConfigurationChanged(Configuration newConfig) {

try {
setBackgroundColor(GuiConfig.getInstance(getFilesDir()).getDarkMode());
} catch (Exception e) {}
} catch (Exception e) {

if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
isUsingHardwareKeyboard = true;
} else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
isUsingHardwareKeyboard = false;
}
}

Expand All @@ -459,26 +449,4 @@ public void setBackgroundColor(DarkModePreference pref) {
mainWindow.setBackgroundDrawableResource(bgColor);
});
}

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (isUsingHardwareKeyboard && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
// Detects user pressing the enter key
if (event.getAction() == KeyEvent.ACTION_DOWN && !event.isShiftPressed()) {
// Enter is pressed
HWKeyboardEventModule.getInstance().keyPressed("enter");
return true;
}
if (event.getAction() == KeyEvent.ACTION_DOWN && event.isShiftPressed()) {
// Shift-Enter is pressed
HWKeyboardEventModule.getInstance().keyPressed("shift-enter");
return true;
}
}
return super.dispatchKeyEvent(event);
}

private void updateIsUsingHardwareKeyboard() {
isUsingHardwareKeyboard = getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {parseUri, launchCameraAsync, launchImageLibraryAsync} from '../../../../
import {BotCommandUpdateStatus} from './shared'
import {formatDurationShort} from '../../../../util/timestamp'
import {indefiniteArticle} from '../../../../util/string'
import {isOpen} from '../../../../util/keyboard'
import AudioRecorder from '../../../audio/audio-recorder.native'
import {
AnimatedBox2,
Expand All @@ -26,7 +25,6 @@ import {
runToggle,
runRotateToggle,
} from './platform-input-animation.native'
import HWKeyboardEvent from 'react-native-hw-keyboard-event'

type menuType = 'exploding' | 'filepickerpopup' | 'moremenu'

Expand Down Expand Up @@ -99,26 +97,6 @@ class _PlatformInput extends React.PureComponent<PlatformInputPropsInternal, Sta
}
}

// Enter should send a message like on desktop, when a hardware keyboard's attached.
private handleHardwareEnterPress = (hwKeyEvent: {pressedKey: string}) => {
switch (hwKeyEvent.pressedKey) {
case 'enter':
!isOpen() ? this.onSubmit() : this.insertText('\n')
break
case 'shift-enter':
this.insertText('\n')
}
}

componentDidMount() {
// @ts-ignore supplied type seems incorrect, has the onHWKeyPressed param as an object
HWKeyboardEvent.onHWKeyPressed(this.handleHardwareEnterPress)
}

componentWillUnmount() {
HWKeyboardEvent.removeOnHWKeyPressed()
}

private getText = () => {
return this.lastText || ''
}
Expand Down
25 changes: 0 additions & 25 deletions shared/ios/Keybase/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#import <UMCore/UMModuleRegistry.h>
#import <UMReactNativeAdapter/UMNativeModulesProxy.h>
#import <UMReactNativeAdapter/UMModuleRegistryAdapter.h>
#import <RNHWKeyboardEvent.h>

@interface AppDelegate ()
@property UIBackgroundTaskIdentifier backgroundTask;
Expand Down Expand Up @@ -299,28 +298,4 @@ - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
return extraModules;
}

RNHWKeyboardEvent *hwKeyEvent = nil;
- (NSMutableArray<UIKeyCommand *> *)keyCommands {
NSMutableArray *keys = [NSMutableArray new];
if (hwKeyEvent == nil) {
hwKeyEvent = [[RNHWKeyboardEvent alloc] init];
}
if ([hwKeyEvent isListening]) {
[keys addObject: [UIKeyCommand keyCommandWithInput:@"\r" modifierFlags:0 action:@selector(sendEnter:)]];
[keys addObject: [UIKeyCommand keyCommandWithInput:@"\r" modifierFlags:UIKeyModifierShift action:@selector(sendShiftEnter:)]];
}
return keys;
}

- (void)sendEnter:(UIKeyCommand *)sender {
// Detects user pressing the enter key
NSString *selected = sender.input;
[hwKeyEvent sendHWKeyEvent:@"enter"];
}
- (void)sendShiftEnter:(UIKeyCommand *)sender {
// Detects user pressing the shift-enter combination
NSString *selected = sender.input;
[hwKeyEvent sendHWKeyEvent:@"shift-enter"];
}

@end
8 changes: 1 addition & 7 deletions shared/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,6 @@ PODS:
- React
- react-native-geolocation (2.0.2):
- React
- react-native-hw-keyboard-event (0.0.4):
- React
- react-native-netinfo (5.6.2):
- React
- react-native-safe-area-context (0.7.3):
Expand Down Expand Up @@ -351,7 +349,6 @@ DEPENDENCIES:
- "react-native-cameraroll (from `../node_modules/@react-native-community/cameraroll`)"
- react-native-contacts (from `../node_modules/react-native-contacts`)
- "react-native-geolocation (from `../node_modules/@react-native-community/geolocation`)"
- react-native-hw-keyboard-event (from `../node_modules/react-native-hw-keyboard-event`)
- "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)"
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- react-native-video (from `../node_modules/react-native-video`)
Expand Down Expand Up @@ -460,8 +457,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-contacts"
react-native-geolocation:
:path: "../node_modules/@react-native-community/geolocation"
react-native-hw-keyboard-event:
:path: "../node_modules/react-native-hw-keyboard-event"
react-native-netinfo:
:path: "../node_modules/@react-native-community/netinfo"
react-native-safe-area-context:
Expand Down Expand Up @@ -574,7 +569,6 @@ SPEC CHECKSUMS:
react-native-cameraroll: 3e5e34d36d93548ae7770ee8ab7b2ae9e778f571
react-native-contacts: be6cde1ffc9c0196fbb57d987b9d40f12b85989c
react-native-geolocation: c956aeb136625c23e0dce0467664af2c437888c9
react-native-hw-keyboard-event: b517cefb8d5c659a38049c582de85ff43337dc53
react-native-netinfo: 73303369946c2487c600418961bfdc87748b832f
react-native-safe-area-context: e200d4433aba6b7e60b52da5f37af11f7a0b0392
react-native-video: d01ed7ff1e38fa7dcc6c15c94cf505e661b7bfd0
Expand Down Expand Up @@ -614,4 +608,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 843dc6df133334007d13b5c34a0fd83194e7fa0e

COCOAPODS: 1.9.1
COCOAPODS: 1.8.4
8 changes: 1 addition & 7 deletions shared/ios/Pods/Manifest.lock

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

Loading

0 comments on commit f3fc476

Please sign in to comment.