Skip to content

Commit

Permalink
PasswordInput: Use Pressable for show/hide icon button
Browse files Browse the repository at this point in the history
This lets us have a more compact layout (e.g., the left edge of the
icon is just 8px away from the right edge of the password input,
instead of that 8px plus 12px of padding in the Touchable) while
maintaining the 48px touch-target size with the help of `hitSlop`.
  • Loading branch information
chrisbobbe committed Feb 10, 2023
1 parent 322b330 commit 3f3324f
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/common/PasswordInput.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
/* @flow strict-local */
import React, { useState, useCallback } from 'react';
import type { Node } from 'react';
import { View } from 'react-native';
import { View, Pressable } from 'react-native';

import { Icon } from './Icons';
import Input from './Input';
import type { Props as InputProps } from './Input';
import { BRAND_COLOR, createStyleSheet } from '../styles';
import Touchable from './Touchable';
import { BRAND_COLOR, HIGHLIGHT_COLOR, createStyleSheet } from '../styles';

const styles = createStyleSheet({
showPasswordButton: {
marginLeft: 8,
},
showPasswordButtonIcon: {
// 24 (icon size) + 12 + 12 = 48px min touch target:
// https://material.io/design/usability/accessibility.html#layout-and-typography
margin: 12,
color: BRAND_COLOR,
},
passwordTextInput: {
flex: 1,
},
Expand Down Expand Up @@ -57,9 +50,21 @@ export default function PasswordInput(props: Props): Node {
autoCapitalize="none"
style={styles.passwordTextInput}
/>
<Touchable style={styles.showPasswordButton} onPress={handleShow}>
<Icon name={isHidden ? 'eye-off' : 'eye'} size={24} style={styles.showPasswordButtonIcon} />
</Touchable>
<Pressable
// 24 (icon size) + 12 + 12 = 48px min touch target:
// https://material.io/design/usability/accessibility.html#layout-and-typography
hitSlop={12}
style={styles.showPasswordButton}
onPress={handleShow}
>
{({ pressed }) => (
<Icon
color={pressed ? HIGHLIGHT_COLOR : BRAND_COLOR}
name={isHidden ? 'eye-off' : 'eye'}
size={24}
/>
)}
</Pressable>
</View>
);
}

0 comments on commit 3f3324f

Please sign in to comment.