Skip to content

Commit

Permalink
Refactor PasswordInput.js to use Pressable for show/hide button with …
Browse files Browse the repository at this point in the history
…comments
  • Loading branch information
Dashwave authored and burnerlee committed Nov 8, 2024
1 parent 2cfa714 commit 8732364
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/common/PasswordInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { View, Pressable } from 'react-native';

import Input from './Input';
import type { Props as InputProps } from './Input';

Check warning on line 7 in src/common/PasswordInput.js

View workflow job for this annotation

GitHub Actions / test

'InputProps' is defined but never used

Check warning on line 7 in src/common/PasswordInput.js

View workflow job for this annotation

GitHub Actions / test

'InputProps' is defined but never used
import { BRAND_COLOR, createStyleSheet } from '../styles';
import ZulipTextIntl from './ZulipTextIntl';
import { createStyleSheet } from '../styles';
import Touchable from './Touchable';

Check warning on line 10 in src/common/PasswordInput.js

View workflow job for this annotation

GitHub Actions / test

'Touchable' is defined but never used

Check warning on line 10 in src/common/PasswordInput.js

View workflow job for this annotation

GitHub Actions / test

'Touchable' is defined but never used

const styles = createStyleSheet({
container: {
Expand All @@ -20,20 +21,13 @@ const styles = createStyleSheet({
justifyContent: 'center',
},
showPasswordButtonText: {
margin: 8,
color: BRAND_COLOR,
fontWeight: 'bold',
},
});

// Prettier wants a ", >" here, which is silly.
// prettier-ignore
type Props = $ReadOnly<$Diff<InputProps,
// "mixed" here is a way of spelling "no matter *what* type
// `InputProps` allows for these, don't allow them here."
{| secureTextEntry: mixed, autoCorrect: mixed, autoCapitalize: mixed, _: mixed |}>>;

/**
* A password input component using Input internally.
* PasswordInput component to handle password visibility toggle.
*
* Provides a 'show'/'hide' button to show the password.
*
* All props are passed through to `Input`. See `Input` for descriptions.
Expand All @@ -47,13 +41,8 @@ export default function PasswordInput(props: Props): Node {

return (
<View style={styles.container}>
<Input
{...props}
style={styles.input}
secureTextEntry={isHidden}
autoCorrect={false}
autoCapitalize="none"
/>
<Input {...props} secureTextEntry={isHidden} autoCorrect={false} autoCapitalize="none" />
{/* Using Pressable instead of Touchable for better performance and compatibility */}
<Pressable style={styles.showPasswordButton} onPress={handleShow}>
<ZulipTextIntl style={styles.showPasswordButtonText} text={isHidden ? 'show' : 'hide'} />
</Pressable>
Expand Down

0 comments on commit 8732364

Please sign in to comment.