Skip to content

Commit 3f3324f

Browse files
committed
PasswordInput: Use Pressable for show/hide icon button
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`.
1 parent 322b330 commit 3f3324f

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/common/PasswordInput.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
/* @flow strict-local */
22
import React, { useState, useCallback } from 'react';
33
import type { Node } from 'react';
4-
import { View } from 'react-native';
4+
import { View, Pressable } from 'react-native';
55

66
import { Icon } from './Icons';
77
import Input from './Input';
88
import type { Props as InputProps } from './Input';
9-
import { BRAND_COLOR, createStyleSheet } from '../styles';
10-
import Touchable from './Touchable';
9+
import { BRAND_COLOR, HIGHLIGHT_COLOR, createStyleSheet } from '../styles';
1110

1211
const styles = createStyleSheet({
1312
showPasswordButton: {
1413
marginLeft: 8,
1514
},
16-
showPasswordButtonIcon: {
17-
// 24 (icon size) + 12 + 12 = 48px min touch target:
18-
// https://material.io/design/usability/accessibility.html#layout-and-typography
19-
margin: 12,
20-
color: BRAND_COLOR,
21-
},
2215
passwordTextInput: {
2316
flex: 1,
2417
},
@@ -57,9 +50,21 @@ export default function PasswordInput(props: Props): Node {
5750
autoCapitalize="none"
5851
style={styles.passwordTextInput}
5952
/>
60-
<Touchable style={styles.showPasswordButton} onPress={handleShow}>
61-
<Icon name={isHidden ? 'eye-off' : 'eye'} size={24} style={styles.showPasswordButtonIcon} />
62-
</Touchable>
53+
<Pressable
54+
// 24 (icon size) + 12 + 12 = 48px min touch target:
55+
// https://material.io/design/usability/accessibility.html#layout-and-typography
56+
hitSlop={12}
57+
style={styles.showPasswordButton}
58+
onPress={handleShow}
59+
>
60+
{({ pressed }) => (
61+
<Icon
62+
color={pressed ? HIGHLIGHT_COLOR : BRAND_COLOR}
63+
name={isHidden ? 'eye-off' : 'eye'}
64+
size={24}
65+
/>
66+
)}
67+
</Pressable>
6368
</View>
6469
);
6570
}

0 commit comments

Comments
 (0)