2018-03-29 17:55:37 +00:00
|
|
|
import React from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { StyleSheet, Text, View } from 'react-native';
|
2018-11-14 21:42:03 +00:00
|
|
|
import { BorderlessButton } from 'react-native-gesture-handler';
|
2018-04-01 00:45:15 +00:00
|
|
|
|
2018-03-29 17:55:37 +00:00
|
|
|
import sharedStyles from '../views/Styles';
|
2019-12-04 16:39:53 +00:00
|
|
|
import TextInput from '../presentation/TextInput';
|
|
|
|
import { themes } from '../constants/colors';
|
2019-03-01 16:49:11 +00:00
|
|
|
import { CustomIcon } from '../lib/Icons';
|
2020-02-11 14:01:35 +00:00
|
|
|
import ActivityIndicator from './ActivityIndicator';
|
2018-03-29 17:55:37 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2019-12-04 16:39:53 +00:00
|
|
|
error: {
|
2020-11-30 21:47:05 +00:00
|
|
|
...sharedStyles.textAlignCenter,
|
2019-12-04 16:39:53 +00:00
|
|
|
paddingTop: 5
|
|
|
|
},
|
2018-03-29 17:55:37 +00:00
|
|
|
inputContainer: {
|
2018-11-14 21:42:03 +00:00
|
|
|
marginBottom: 10
|
2018-03-29 17:55:37 +00:00
|
|
|
},
|
|
|
|
label: {
|
2018-04-24 19:34:03 +00:00
|
|
|
marginBottom: 10,
|
|
|
|
fontSize: 14,
|
2019-12-04 16:39:53 +00:00
|
|
|
...sharedStyles.textSemibold
|
2018-03-29 17:55:37 +00:00
|
|
|
},
|
|
|
|
input: {
|
2018-11-14 21:42:03 +00:00
|
|
|
...sharedStyles.textRegular,
|
|
|
|
height: 48,
|
2019-03-29 19:36:07 +00:00
|
|
|
fontSize: 16,
|
2021-08-27 20:03:59 +00:00
|
|
|
padding: 14,
|
2019-12-04 16:39:53 +00:00
|
|
|
borderWidth: StyleSheet.hairlineWidth,
|
|
|
|
borderRadius: 2
|
2018-11-14 21:42:03 +00:00
|
|
|
},
|
|
|
|
inputIconLeft: {
|
|
|
|
paddingLeft: 45
|
|
|
|
},
|
|
|
|
inputIconRight: {
|
|
|
|
paddingRight: 45
|
2018-03-29 17:55:37 +00:00
|
|
|
},
|
2018-04-01 00:45:15 +00:00
|
|
|
wrap: {
|
|
|
|
position: 'relative'
|
|
|
|
},
|
2018-11-14 21:42:03 +00:00
|
|
|
iconContainer: {
|
2018-04-01 00:45:15 +00:00
|
|
|
position: 'absolute',
|
2018-11-14 21:42:03 +00:00
|
|
|
top: 14
|
|
|
|
},
|
|
|
|
iconLeft: {
|
|
|
|
left: 15
|
|
|
|
},
|
|
|
|
iconRight: {
|
|
|
|
right: 15
|
2018-03-29 17:55:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IRCTextInputProps {
|
|
|
|
label: string;
|
|
|
|
error: {
|
|
|
|
error: any;
|
|
|
|
reason: any;
|
|
|
|
};
|
|
|
|
loading: boolean;
|
|
|
|
secureTextEntry: boolean;
|
|
|
|
containerStyle: any;
|
|
|
|
inputStyle: object;
|
|
|
|
inputRef: any;
|
|
|
|
testID: string;
|
|
|
|
iconLeft: string;
|
|
|
|
iconRight: string;
|
|
|
|
placeholder: string;
|
|
|
|
left: JSX.Element;
|
|
|
|
onIconRightPress(): void;
|
|
|
|
theme: string;
|
|
|
|
}
|
2018-04-01 00:45:15 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
export default class RCTextInput extends React.PureComponent<IRCTextInputProps, any> {
|
2018-03-29 17:55:37 +00:00
|
|
|
static defaultProps = {
|
2019-12-04 16:39:53 +00:00
|
|
|
error: {},
|
|
|
|
theme: 'light'
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2018-04-01 00:45:15 +00:00
|
|
|
state = {
|
|
|
|
showPassword: false
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-04-01 00:45:15 +00:00
|
|
|
|
2018-11-14 21:42:03 +00:00
|
|
|
get iconLeft() {
|
2019-12-04 16:39:53 +00:00
|
|
|
const { testID, iconLeft, theme } = this.props;
|
2018-11-14 21:42:03 +00:00
|
|
|
return (
|
2019-03-01 16:49:11 +00:00
|
|
|
<CustomIcon
|
|
|
|
name={iconLeft}
|
2021-09-13 20:41:05 +00:00
|
|
|
testID={testID ? `${testID}-icon-left` : null}
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[styles.iconContainer, styles.iconLeft, { color: themes[theme].bodyText }]}
|
2019-03-01 16:49:11 +00:00
|
|
|
size={20}
|
2018-11-14 21:42:03 +00:00
|
|
|
/>
|
|
|
|
);
|
2018-09-25 19:28:42 +00:00
|
|
|
}
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2020-05-08 17:36:10 +00:00
|
|
|
get iconRight() {
|
|
|
|
const { iconRight, onIconRightPress, theme } = this.props;
|
|
|
|
return (
|
|
|
|
<BorderlessButton onPress={onIconRightPress} style={[styles.iconContainer, styles.iconRight]}>
|
2021-09-13 20:41:05 +00:00
|
|
|
<CustomIcon name={iconRight} style={{ color: themes[theme].bodyText }} size={20} />
|
2020-05-08 17:36:10 +00:00
|
|
|
</BorderlessButton>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-11-14 21:42:03 +00:00
|
|
|
get iconPassword() {
|
|
|
|
const { showPassword } = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { testID, theme } = this.props;
|
2018-11-14 21:42:03 +00:00
|
|
|
return (
|
|
|
|
<BorderlessButton onPress={this.tooglePassword} style={[styles.iconContainer, styles.iconRight]}>
|
2019-03-01 16:49:11 +00:00
|
|
|
<CustomIcon
|
2020-07-27 19:53:33 +00:00
|
|
|
name={showPassword ? 'unread-on-top' : 'unread-on-top-disabled'}
|
2021-09-13 20:41:05 +00:00
|
|
|
testID={testID ? `${testID}-icon-right` : null}
|
2019-12-04 16:39:53 +00:00
|
|
|
style={{ color: themes[theme].auxiliaryText }}
|
2019-03-01 16:49:11 +00:00
|
|
|
size={20}
|
2018-11-14 21:42:03 +00:00
|
|
|
/>
|
|
|
|
</BorderlessButton>
|
|
|
|
);
|
2018-09-25 19:28:42 +00:00
|
|
|
}
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2020-02-11 14:01:35 +00:00
|
|
|
get loading() {
|
|
|
|
const { theme } = this.props;
|
2021-09-13 20:41:05 +00:00
|
|
|
// @ts-ignore
|
2020-02-11 14:01:35 +00:00
|
|
|
return <ActivityIndicator style={[styles.iconContainer, styles.iconRight, { color: themes[theme].bodyText }]} />;
|
|
|
|
}
|
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
tooglePassword = () => {
|
2021-09-13 20:41:05 +00:00
|
|
|
this.setState((prevState: any) => ({ showPassword: !prevState.showPassword }));
|
|
|
|
};
|
2018-03-29 17:55:37 +00:00
|
|
|
|
|
|
|
render() {
|
2018-11-14 21:42:03 +00:00
|
|
|
const { showPassword } = this.state;
|
2018-03-29 17:55:37 +00:00
|
|
|
const {
|
2021-09-13 20:41:05 +00:00
|
|
|
label,
|
|
|
|
left,
|
|
|
|
error,
|
|
|
|
loading,
|
|
|
|
secureTextEntry,
|
|
|
|
containerStyle,
|
|
|
|
inputRef,
|
|
|
|
iconLeft,
|
|
|
|
iconRight,
|
|
|
|
inputStyle,
|
|
|
|
testID,
|
|
|
|
placeholder,
|
|
|
|
theme,
|
|
|
|
...inputProps
|
2018-03-29 17:55:37 +00:00
|
|
|
} = this.props;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { dangerColor } = themes[theme];
|
2018-03-29 17:55:37 +00:00
|
|
|
return (
|
2018-04-24 19:34:03 +00:00
|
|
|
<View style={[styles.inputContainer, containerStyle]}>
|
2019-12-04 16:39:53 +00:00
|
|
|
{label ? (
|
|
|
|
<Text
|
|
|
|
contentDescription={null}
|
2021-09-13 20:41:05 +00:00
|
|
|
// @ts-ignore
|
2019-12-04 16:39:53 +00:00
|
|
|
accessibilityLabel={null}
|
2021-09-13 20:41:05 +00:00
|
|
|
style={[styles.label, { color: themes[theme].titleText }, error.error && { color: dangerColor }]}>
|
2019-12-04 16:39:53 +00:00
|
|
|
{label}
|
|
|
|
</Text>
|
|
|
|
) : null}
|
2018-04-01 00:45:15 +00:00
|
|
|
<View style={styles.wrap}>
|
|
|
|
<TextInput
|
2021-09-13 20:41:05 +00:00
|
|
|
/* @ts-ignore*/
|
2018-04-24 19:34:03 +00:00
|
|
|
style={[
|
|
|
|
styles.input,
|
2018-11-14 21:42:03 +00:00
|
|
|
iconLeft && styles.inputIconLeft,
|
2020-05-08 17:36:10 +00:00
|
|
|
(secureTextEntry || iconRight) && styles.inputIconRight,
|
2019-12-04 16:39:53 +00:00
|
|
|
{
|
|
|
|
backgroundColor: themes[theme].backgroundColor,
|
|
|
|
borderColor: themes[theme].separatorColor,
|
|
|
|
color: themes[theme].titleText
|
|
|
|
},
|
2020-02-11 14:01:35 +00:00
|
|
|
error.error && {
|
|
|
|
color: dangerColor,
|
|
|
|
borderColor: dangerColor
|
|
|
|
},
|
2019-12-04 16:39:53 +00:00
|
|
|
inputStyle
|
2018-04-24 19:34:03 +00:00
|
|
|
]}
|
|
|
|
ref={inputRef}
|
2021-09-13 20:41:05 +00:00
|
|
|
/* @ts-ignore*/
|
2018-04-01 00:45:15 +00:00
|
|
|
autoCorrect={false}
|
|
|
|
autoCapitalize='none'
|
|
|
|
underlineColorAndroid='transparent'
|
|
|
|
secureTextEntry={secureTextEntry && !showPassword}
|
2018-05-23 13:39:18 +00:00
|
|
|
testID={testID}
|
|
|
|
accessibilityLabel={placeholder}
|
|
|
|
placeholder={placeholder}
|
2021-09-13 20:41:05 +00:00
|
|
|
/* @ts-ignore*/
|
2018-05-23 13:39:18 +00:00
|
|
|
contentDescription={placeholder}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2018-04-01 00:45:15 +00:00
|
|
|
{...inputProps}
|
|
|
|
/>
|
2018-11-14 21:42:03 +00:00
|
|
|
{iconLeft ? this.iconLeft : null}
|
2020-05-08 17:36:10 +00:00
|
|
|
{iconRight ? this.iconRight : null}
|
2018-11-14 21:42:03 +00:00
|
|
|
{secureTextEntry ? this.iconPassword : null}
|
2020-02-11 14:01:35 +00:00
|
|
|
{loading ? this.loading : null}
|
2020-03-30 20:19:01 +00:00
|
|
|
{left}
|
2018-04-01 00:45:15 +00:00
|
|
|
</View>
|
2020-02-11 14:01:35 +00:00
|
|
|
{error && error.reason ? <Text style={[styles.error, { color: dangerColor }]}>{error.reason}</Text> : null}
|
2018-03-29 17:55:37 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|