Browse Source

Fix keyboard navigation in password generator screen

monorepo
Ramkumar 4 months ago
committed by Guillaume Vincent
parent
commit
9e355cdb46
No known key found for this signature in database GPG Key ID: 2F5D4A32E293E1D0
3 changed files with 39 additions and 26 deletions
  1. +2
    -0
      packages/lesspass-mobile/src/password/MasterPassword.js
  2. +36
    -26
      packages/lesspass-mobile/src/password/PasswordGeneratorScreen.js
  3. +1
    -0
      packages/lesspass-mobile/src/ui/TextInput.js

+ 2
- 0
packages/lesspass-mobile/src/password/MasterPassword.js View File

@@ -57,6 +57,8 @@ export default class MasterPassword extends Component {
value={masterPassword} value={masterPassword}
secureTextEntry secureTextEntry
onChangeText={this.onChangeMasterPassword} onChangeText={this.onChangeMasterPassword}
onSubmitEditing={this.props.onSubmitEditing}
outerRef={this.props.outerRef}
/> />
{masterPassword && fingerprint ? ( {masterPassword && fingerprint ? (
<Fingerprint fingerprint={fingerprint} /> <Fingerprint fingerprint={fingerprint} />


+ 36
- 26
packages/lesspass-mobile/src/password/PasswordGeneratorScreen.js View File

@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useState, useRef } from "react";
import { import {
ScrollView, ScrollView,
View, View,
@@ -61,6 +61,8 @@ export default function PasswordGeneratorScreen() {
const settings = useSelector((state) => state.settings); const settings = useSelector((state) => state.settings);
const auth = useSelector((state) => state.auth); const auth = useSelector((state) => state.auth);
const dispatch = useDispatch(); const dispatch = useDispatch();
const ref_login = useRef();
const ref_masterPassword = useRef();
const [copied, setCopied] = useState(false); const [copied, setCopied] = useState(false);
const [seePassword, setSeePassword] = useState(false); const [seePassword, setSeePassword] = useState(false);
const [saved, setSaved] = useState(false); const [saved, setSaved] = useState(false);
@@ -88,6 +90,28 @@ export default function PasswordGeneratorScreen() {
}; };
}, [state.password]); }, [state.password]);


async function generate() {
const passwordProfile = _getPasswordProfile(state);
if (isProfileValid(passwordProfile)) {
dispatch(cleanErrors());
const password = await generatePassword(
state.masterPassword,
passwordProfile
);
if (state.copyPasswordAfterGeneration) {
NativeModules.LessPassClipboard.copy(password);
setCopied(true);
}
setState((state) => ({ ...state, password }));
} else {
dispatch(
addError(
"Password profile is invalid, cannot generate password. Site is required."
)
);
}
}

return ( return (
<KeyboardAvoidingView <KeyboardAvoidingView
behavior={Platform.OS === "ios" ? "padding" : "height"} behavior={Platform.OS === "ios" ? "padding" : "height"}
@@ -98,15 +122,25 @@ export default function PasswordGeneratorScreen() {
<TextInput <TextInput
label="Site" label="Site"
value={state.site} value={state.site}
autoFocus={true}
returnKeyType="next"
blurOnSubmit={false}
onSubmitEditing={() => ref_login.current.focus()}
onChangeText={(site) => setState((state) => ({ ...state, site }))} onChangeText={(site) => setState((state) => ({ ...state, site }))}
/> />
<TextInput <TextInput
label="Login" label="Login"
value={state.login} value={state.login}
outerRef={ref_login}
returnKeyType="next"
blurOnSubmit={false}
onSubmitEditing={() => ref_masterPassword.current.focus()}
onChangeText={(login) => setState((state) => ({ ...state, login }))} onChangeText={(login) => setState((state) => ({ ...state, login }))}
/> />
<MasterPassword <MasterPassword
masterPassword={state.masterPassword} masterPassword={state.masterPassword}
outerRef={ref_masterPassword}
onSubmitEditing={generate}
onChangeText={(masterPassword) => onChangeText={(masterPassword) =>
setState((state) => ({ ...state, masterPassword })) setState((state) => ({ ...state, masterPassword }))
} }
@@ -149,31 +183,7 @@ export default function PasswordGeneratorScreen() {
isValueValid={isCounterValid} isValueValid={isCounterValid}
/> />
</View> </View>
<Button
mode="contained"
icon="cogs"
onPress={async () => {
const passwordProfile = _getPasswordProfile(state);
if (isProfileValid(passwordProfile)) {
dispatch(cleanErrors());
const password = await generatePassword(
state.masterPassword,
passwordProfile
);
if (state.copyPasswordAfterGeneration) {
NativeModules.LessPassClipboard.copy(password);
setCopied(true);
}
setState((state) => ({ ...state, password }));
} else {
dispatch(
addError(
"Password profile is invalid, cannot generate password. Site is required."
)
);
}
}}
>
<Button mode="contained" icon="cogs" onPress={generate}>
{state.copyPasswordAfterGeneration ? "GENERATE & COPY" : "GENERATE"} {state.copyPasswordAfterGeneration ? "GENERATE & COPY" : "GENERATE"}
</Button> </Button>
<View <View


+ 1
- 0
packages/lesspass-mobile/src/ui/TextInput.js View File

@@ -12,6 +12,7 @@ export default function Input({ showError = false, errorText, ...props }) {
}} }}
style={{ marginBottom: 5 }} style={{ marginBottom: 5 }}
mode="outlined" mode="outlined"
ref={props.outerRef}
{...props} {...props}
/> />
); );


Loading…
Cancel
Save