From a88ffcdd71043f5cc61bde3e723c28f56a88069c Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Tue, 29 Oct 2019 12:18:47 -0500 Subject: [PATCH] Always set keyboard type on passcode setup, ability to change keyboard type during local passcode prompt --- src/components/SectionHeader.js | 10 +++++++-- src/screens/Authentication/Authenticate.js | 11 ++++++---- .../Sources/AuthenticationSource.js | 4 ++++ .../AuthenticationSourceLocalPasscode.js | 22 +++++++++++++++++++ src/screens/InputModal.js | 3 +-- src/screens/Settings/Settings.js | 7 +++--- 6 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/components/SectionHeader.js b/src/components/SectionHeader.js index 57b9e331..385f7469 100644 --- a/src/components/SectionHeader.js +++ b/src/components/SectionHeader.js @@ -17,8 +17,8 @@ export default class SectionHeader extends ThemedComponent { } {this.props.buttonText && - - {this.props.buttonText} + + {this.props.buttonText} } @@ -54,6 +54,12 @@ export default class SectionHeader extends ThemedComponent { color: StyleKit.variables.stylekitNeutralColor, }, + buttonContainer: { + flex: 1, + alignItems: "flex-end", + justifyContent: "center", + }, + button: { color: StyleKit.variables.stylekitInfoColor }, diff --git a/src/screens/Authentication/Authenticate.js b/src/screens/Authentication/Authenticate.js index bb040204..d7a85068 100644 --- a/src/screens/Authentication/Authenticate.js +++ b/src/screens/Authentication/Authenticate.js @@ -62,6 +62,10 @@ export default class Authenticate extends Abstract { this.successfulSources = []; } + get sources() { + return this.getProp("authenticationSources"); + } + componentWillUnmount() { // Typically there should be no way to exit this window if it doesn't have a cancel option. @@ -106,10 +110,6 @@ export default class Authenticate extends Abstract { this.beginNextAuthentication(); } - get sources() { - return this.getProp("authenticationSources"); - } - beginNextAuthentication() { if(this.pendingSources && this.pendingSources.length) { let firstSource = this.pendingSources[0]; @@ -290,6 +290,9 @@ export default class Authenticate extends Abstract { title={source.title + (source.status == "waiting-turn" ? " — Waiting" : "")} subtitle={hasHeaderSubtitle && source.label} tinted={source == this.state.activeSource} + buttonText={source.headerButtonText} + buttonAction={source.headerButtonAction} + buttonStyles={source.headerButtonStyles} /> {source.type == "input" && inputAuthenticationSource(source) diff --git a/src/screens/Authentication/Sources/AuthenticationSource.js b/src/screens/Authentication/Sources/AuthenticationSource.js index bed42f5a..3707e5b2 100644 --- a/src/screens/Authentication/Sources/AuthenticationSource.js +++ b/src/screens/Authentication/Sources/AuthenticationSource.js @@ -33,6 +33,10 @@ export default class AuthenticationSource { this.status = "did-fail"; } + isWaitingForInput() { + return this.status == "waiting-input"; + } + isInSuccessState() { return this.status == "did-succeed"; } diff --git a/src/screens/Authentication/Sources/AuthenticationSourceLocalPasscode.js b/src/screens/Authentication/Sources/AuthenticationSourceLocalPasscode.js index 0685a946..45eebbe8 100644 --- a/src/screens/Authentication/Sources/AuthenticationSourceLocalPasscode.js +++ b/src/screens/Authentication/Sources/AuthenticationSourceLocalPasscode.js @@ -2,6 +2,7 @@ import SF from '@SFJS/sfjs' import Storage from '@SFJS/storageManager' import KeysManager from '@Lib/keysManager' import AuthenticationSource from "./AuthenticationSource" +import StyleKit from "@Style/StyleKit" export default class AuthenticationSourceLocalPasscode extends AuthenticationSource { constructor() { @@ -13,6 +14,27 @@ export default class AuthenticationSourceLocalPasscode extends AuthenticationSou }); } + get headerButtonText() { + return this.isWaitingForInput() && "Change Keyboard"; + } + + get headerButtonStyles() { + return { + color: StyleKit.variables.stylekitNeutralColor, + fontSize: StyleKit.constants.mainTextFontSize - 5 + } + } + + headerButtonAction = () => { + if(this.keyboardType == "default") { + this.keyboardType = "numeric"; + } else { + this.keyboardType = "default"; + } + + this.requiresInterfaceReload(); + } + get sort() { return 0; } diff --git a/src/screens/InputModal.js b/src/screens/InputModal.js index 71e525ea..91c624a5 100644 --- a/src/screens/InputModal.js +++ b/src/screens/InputModal.js @@ -71,7 +71,7 @@ export default class InputModal extends Abstract { return; } } - this.getProp("onSubmit")(this.state.text); + this.getProp("onSubmit")(this.state.text, this.keyboardType); this.dismiss(); } @@ -97,7 +97,6 @@ export default class InputModal extends Abstract { this.keyboardType = option.key; this.forceUpdate(); this.refreshKeyboard(); - this.getProp("onKeyboardTypeChange")(option.key); } render() { diff --git a/src/screens/Settings/Settings.js b/src/screens/Settings/Settings.js index 5ded25d2..7f933653 100644 --- a/src/screens/Settings/Settings.js +++ b/src/screens/Settings/Settings.js @@ -159,7 +159,9 @@ export default class Settings extends Abstract { secureTextEntry: true, requireConfirm: true, showKeyboardChooser: true, - onSubmit: async (value) => { + onSubmit: async (value, keyboardType) => { + Storage.get().setItem("passcodeKeyboardType", keyboardType); + let identifier = await SF.get().crypto.generateUUID(); SF.get().crypto.generateInitialKeysAndAuthParamsForUser(identifier, value).then((results) => { @@ -179,9 +181,6 @@ export default class Settings extends Abstract { Alert.alert("Passcode Error", "There was an error setting up your passcode. Please try again."); } }); - }, - onKeyboardTypeChange: (type) => { - Storage.get().setItem("passcodeKeyboardType", type); } }); }