-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[issue-444, issue-430] Save Master Password in Keychain & Update Logi…
…n screen
- Loading branch information
1 parent
a83e4d7
commit e0520f6
Showing
16 changed files
with
404 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 113 additions & 0 deletions
113
src/components/common/Field/Password/InlinePassword.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import React, { forwardRef, useMemo, useState } from 'react'; | ||
import { TextInput, View, ViewStyle } from 'react-native'; | ||
import { DisabledStyle } from 'styles/sharedStyles'; | ||
import { FieldBaseProps } from 'components/Field/Base'; | ||
import { Warning } from 'components/Warning'; | ||
import { useSubWalletTheme } from 'hooks/useSubWalletTheme'; | ||
import { Button, Icon, Input } from 'components/design-system-ui'; | ||
import { Eye, EyeSlash, Key } from 'phosphor-react-native'; | ||
import createStyles from './styles'; | ||
|
||
interface Props extends FieldBaseProps { | ||
onChangeText?: (text: string) => void; | ||
onEndEditing?: () => void; | ||
onBlur?: () => void; | ||
errorMessages?: string[]; | ||
isBusy?: boolean; | ||
autoFocus?: boolean; | ||
onSubmitField?: () => void; | ||
defaultValue?: string; | ||
showEyeButton?: boolean; | ||
placeholder?: string; | ||
containerStyle?: ViewStyle; | ||
disabled?: boolean; | ||
} | ||
|
||
const InlinePassword = forwardRef((passwordFieldProps: Props, ref: React.Ref<TextInput>) => { | ||
const { | ||
defaultValue, | ||
onChangeText, | ||
onEndEditing, | ||
onBlur, | ||
errorMessages, | ||
isBusy, | ||
autoFocus, | ||
onSubmitField, | ||
showEyeButton = true, | ||
placeholder, | ||
containerStyle, | ||
disabled, | ||
} = passwordFieldProps; | ||
const [isShowPassword, setShowPassword] = useState<boolean>(false); | ||
const [isFocus, setFocus] = useState<boolean>(false); | ||
const theme = useSubWalletTheme().swThemes; | ||
const styles = useMemo( | ||
() => createStyles(theme, !(errorMessages && errorMessages.length), undefined, isFocus), | ||
[theme, errorMessages, isFocus], | ||
); | ||
|
||
const onInputFocus = () => { | ||
setFocus(true); | ||
}; | ||
const onInputBlur = () => { | ||
onBlur && onBlur(); | ||
setFocus(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<View style={[styles.inputContainer, containerStyle, disabled && DisabledStyle]}> | ||
<Input | ||
ref={ref} | ||
leftPart={<Icon phosphorIcon={Key} weight={'regular'} size={'sm'} iconColor={theme['gray-5']} />} | ||
leftPartStyle={styles.leftInputStyle} | ||
inputStyle={styles.textInput} | ||
rightPart={ | ||
showEyeButton && | ||
(isShowPassword ? ( | ||
<Button | ||
disabled={isBusy} | ||
onPress={() => setShowPassword(false)} | ||
size={'xs'} | ||
type={'ghost'} | ||
icon={<Icon phosphorIcon={Eye} weight={'regular'} size={'sm'} iconColor={theme['gray-5']} />} | ||
/> | ||
) : ( | ||
<Button | ||
disabled={isBusy} | ||
onPress={() => setShowPassword(true)} | ||
size={'xs'} | ||
type={'ghost'} | ||
icon={<Icon phosphorIcon={EyeSlash} weight={'regular'} size={'sm'} iconColor={theme['gray-5']} />} | ||
/> | ||
)) | ||
} | ||
rightPartStyle={styles.rightInputStyle} | ||
isError={!!(errorMessages && errorMessages.length)} | ||
placeholder={placeholder} | ||
autoFocus={autoFocus} | ||
autoCorrect={false} | ||
placeholderTextColor={theme.colorTextTertiary} | ||
selectionColor={theme.colorTextDisabled} | ||
secureTextEntry={!isShowPassword} | ||
blurOnSubmit={false} | ||
textContentType="oneTimeCode" | ||
selectTextOnFocus={!isBusy} | ||
onSubmitEditing={onSubmitField} | ||
onChangeText={onChangeText} | ||
onEndEditing={onEndEditing} | ||
onBlur={onInputBlur} | ||
onFocus={onInputFocus} | ||
defaultValue={defaultValue || ''} | ||
/> | ||
</View> | ||
|
||
{!!(errorMessages && errorMessages.length) && | ||
errorMessages.map((message, index) => ( | ||
<Warning key={index} isDanger message={message} style={styles.warningStyle} /> | ||
))} | ||
</> | ||
); | ||
}); | ||
|
||
export default InlinePassword; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as InlinePassword } from './InlinePassword'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Platform, StyleSheet, TextStyle, ViewStyle } from 'react-native'; | ||
import { ThemeTypes } from 'styles/themes'; | ||
import { FontMedium } from 'styles/sharedStyles'; | ||
|
||
export interface ComponentStyle { | ||
inputContainer: ViewStyle; | ||
textInput: TextStyle; | ||
leftInputStyle: ViewStyle; | ||
rightInputStyle: ViewStyle; | ||
warningStyle: ViewStyle; | ||
} | ||
|
||
function createStyles(theme: ThemeTypes, isValid: boolean, readonly?: boolean, isFocus?: boolean) { | ||
return StyleSheet.create<ComponentStyle>({ | ||
inputContainer: { | ||
width: '100%', | ||
position: 'relative', | ||
marginBottom: 8, | ||
height: 48, | ||
}, | ||
textInput: { | ||
...FontMedium, | ||
paddingLeft: 44, | ||
paddingRight: 52, | ||
paddingTop: 13, | ||
paddingBottom: 13, | ||
borderColor: isFocus ? theme.colorPrimary : theme.colorBgSecondary, | ||
borderWidth: 2, | ||
borderRadius: theme.borderRadiusLG, | ||
backgroundColor: theme.colorBgSecondary, | ||
color: isValid ? (readonly ? theme.colorTextLight5 : theme.colorTextLight1) : theme.colorError, | ||
lineHeight: Platform.OS === 'ios' ? 17 : theme.lineHeight * theme.fontSize, | ||
fontSize: theme.fontSize, | ||
zIndex: 1, | ||
}, | ||
leftInputStyle: { left: 15, zIndex: 2 }, | ||
rightInputStyle: { right: 3, zIndex: 2 }, | ||
warningStyle: { marginBottom: 8 }, | ||
}); | ||
} | ||
|
||
export default createStyles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.