-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add show password toggle to secureTextInput #6501
Merged
johnmlee101
merged 5 commits into
Expensify:main
from
anthony-hull:anthony--toggle-show-password2
Nov 30, 2021
+83
−22
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c96e703
add show password toggle to secureTextInput
anthony-hull ff42609
move padding right to use utility function
anthony-hull ca44dfb
fix stacking contexts bug
anthony-hull bc26dfc
move pointer events to props
anthony-hull 44b1789
merge main
anthony-hull File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 | ||
---|---|---|---|---|
@@ -1,13 +1,15 @@ | ||||
import _ from 'underscore'; | ||||
import React, {Component} from 'react'; | ||||
import { | ||||
Animated, TextInput, View, TouchableWithoutFeedback, | ||||
Animated, TextInput, View, TouchableWithoutFeedback, Pressable, | ||||
} from 'react-native'; | ||||
import Str from 'expensify-common/lib/str'; | ||||
import ExpensiTextInputLabel from './ExpensiTextInputLabel'; | ||||
import {propTypes, defaultProps} from './baseExpensiTextInputPropTypes'; | ||||
import themeColors from '../../styles/themes/default'; | ||||
import styles from '../../styles/styles'; | ||||
import Icon from '../Icon'; | ||||
import * as Expensicons from '../Icon/Expensicons'; | ||||
import InlineErrorText from '../InlineErrorText'; | ||||
|
||||
const ACTIVE_LABEL_TRANSLATE_Y = -12; | ||||
|
@@ -31,6 +33,7 @@ class BaseExpensiTextInput extends Component { | |||
labelTranslateX: new Animated.Value(activeLabel | ||||
? ACTIVE_LABEL_TRANSLATE_X(props.translateX) : INACTIVE_LABEL_TRANSLATE_X), | ||||
labelScale: new Animated.Value(activeLabel ? ACTIVE_LABEL_SCALE : INACTIVE_LABEL_SCALE), | ||||
passwordHidden: props.secureTextEntry, | ||||
}; | ||||
|
||||
this.input = null; | ||||
|
@@ -39,6 +42,7 @@ class BaseExpensiTextInput extends Component { | |||
this.onFocus = this.onFocus.bind(this); | ||||
this.onBlur = this.onBlur.bind(this); | ||||
this.setValue = this.setValue.bind(this); | ||||
this.togglePasswordVisibility = this.togglePasswordVisibility.bind(this); | ||||
} | ||||
|
||||
componentDidMount() { | ||||
|
@@ -145,6 +149,10 @@ class BaseExpensiTextInput extends Component { | |||
]).start(); | ||||
} | ||||
|
||||
togglePasswordVisibility() { | ||||
this.setState(prevState => ({passwordHidden: !prevState.passwordHidden})); | ||||
} | ||||
|
||||
render() { | ||||
const inputProps = _.omit(this.props, _.keys(propTypes)); | ||||
const hasLabel = Boolean(this.props.label.length); | ||||
|
@@ -167,7 +175,7 @@ class BaseExpensiTextInput extends Component { | |||
{hasLabel ? ( | ||||
<> | ||||
{/* Adding this background to the label only for multiline text input, | ||||
to prevent text overlaping with label when scrolling */} | ||||
to prevent text overlapping with label when scrolling */} | ||||
{this.props.multiline && <View style={styles.expensiTextInputLabelBackground} />} | ||||
<ExpensiTextInputLabel | ||||
label={this.props.label} | ||||
|
@@ -181,25 +189,40 @@ class BaseExpensiTextInput extends Component { | |||
/> | ||||
</> | ||||
) : null} | ||||
<TextInput | ||||
ref={(ref) => { | ||||
if (typeof this.props.innerRef === 'function') { this.props.innerRef(ref); } | ||||
this.input = ref; | ||||
}} | ||||
// eslint-disable-next-line | ||||
{...inputProps} | ||||
value={this.props.value} | ||||
placeholder={(this.state.isFocused || !this.props.label) ? this.props.placeholder : null} | ||||
placeholderTextColor={themeColors.placeholderText} | ||||
underlineColorAndroid="transparent" | ||||
style={[this.props.inputStyle, !hasLabel && styles.pv0]} | ||||
multiline={this.props.multiline} | ||||
onFocus={this.onFocus} | ||||
onBlur={this.onBlur} | ||||
onChangeText={this.setValue} | ||||
onPressOut={this.props.onPress} | ||||
translateX={this.props.translateX} | ||||
/> | ||||
<View style={[styles.flexRow]}> | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the Line 633 in 85edddd
|
||||
<TextInput | ||||
ref={(ref) => { | ||||
if (typeof this.props.innerRef === 'function') { this.props.innerRef(ref); } | ||||
this.input = ref; | ||||
}} | ||||
// eslint-disable-next-line | ||||
{...inputProps} | ||||
value={this.props.value} | ||||
placeholder={(this.state.isFocused || !this.props.label) ? this.props.placeholder : null} | ||||
placeholderTextColor={themeColors.placeholderText} | ||||
underlineColorAndroid="transparent" | ||||
style={[this.props.inputStyle, styles.flex1, styles.w100, !hasLabel && styles.pv0, this.props.secureTextEntry && styles.expensiTextInputWithIcon]} | ||||
anthony-hull marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
multiline={this.props.multiline} | ||||
onFocus={this.onFocus} | ||||
onBlur={this.onBlur} | ||||
onChangeText={this.setValue} | ||||
secureTextEntry={this.state.passwordHidden} | ||||
onPressOut={this.props.onPress} | ||||
translateX={this.props.translateX} | ||||
/> | ||||
{this.props.secureTextEntry && ( | ||||
<Pressable | ||||
accessibilityRole="button" | ||||
style={styles.secureInputEyeButton} | ||||
onPress={this.togglePasswordVisibility} | ||||
> | ||||
<Icon | ||||
src={this.state.passwordHidden ? Expensicons.Eye : Expensicons.EyeDisabled} | ||||
fill={themeColors.icon} | ||||
/> | ||||
</Pressable> | ||||
)} | ||||
</View> | ||||
</View> | ||||
</TouchableWithoutFeedback> | ||||
</View> | ||||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add
pointerEvents="none"
to thisView
. it fixes one bug, not from your PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think pointerEvents=none only work as a prop.