Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/Input/InputOtp/InputOtp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ export const InputOtp = memo<InputOtpProps>(
onFocus,
onBlur,
accessibilityState,
allowFontScaling = true,
autoComplete = 'one-time-code',
maxFontSizeMultiplier,
selection,
textContentType = 'oneTimeCode',
editable,
Expand Down Expand Up @@ -156,6 +158,7 @@ export const InputOtp = memo<InputOtpProps>(
>
{Array.from({ length }, (_, index) => (
<InputOtpItem
allowFontScaling={allowFontScaling}
disabled={!isInputEditable}
error={error}
focused={Boolean(
Expand All @@ -165,6 +168,7 @@ export const InputOtp = memo<InputOtpProps>(
index === activeIndex
)}
key={`Otp-Item-${index}`}
maxFontSizeMultiplier={maxFontSizeMultiplier}
testIdPrefix={testIds.root}
testOnly_pressed={testOnly_pressed}
value={inputValue[index]}
Expand All @@ -178,10 +182,12 @@ export const InputOtp = memo<InputOtpProps>(
...accessibilityState,
disabled: !isInputEditable,
}}
allowFontScaling={allowFontScaling}
autoComplete={autoComplete}
editable={isInputEditable}
inputMode='numeric'
keyboardType='number-pad'
maxFontSizeMultiplier={maxFontSizeMultiplier}
ref={inputRef}
selection={inputSelection}
style={styles.input}
Expand Down
98 changes: 63 additions & 35 deletions src/components/Input/InputOtp/InputOtpItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
View,
Text,
type PressableProps,
type TextProps,
type TextStyle,
} from 'react-native'

Expand All @@ -15,10 +16,10 @@ import effects from '../../../theme/tokens/semantic/effects.json'

import { createInputOtpTestIds } from './testIds'

export interface InputOtpItemProps extends Pick<
PressableProps,
'onPress' | 'testOnly_pressed'
> {
export interface InputOtpItemProps
extends
Pick<PressableProps, 'onPress' | 'testOnly_pressed'>,
Pick<TextProps, 'allowFontScaling' | 'maxFontSizeMultiplier'> {
value?: string
error: boolean
disabled: boolean
Expand Down Expand Up @@ -57,6 +58,8 @@ export const InputOtpItem = memo<InputOtpItemProps>(
focused,
testIdPrefix,
testOnly_pressed,
allowFontScaling,
maxFontSizeMultiplier,
onPress,
}) => {
const [isHovered, setIsHovered] = useState(false)
Expand All @@ -80,36 +83,52 @@ export const InputOtpItem = memo<InputOtpItemProps>(
onHoverOut={() => setIsHovered(false)}
onPress={onPress}
>
{focused ? (
<View style={styles.textRow} testID={testIds.cursorRow}>
{value ? (
<>
<Text
accessibilityElementsHidden
importantForAccessibility='no-hide-descendants'
style={[styles.text, styles.cursorSpacer]}
>
|
</Text>
<Text style={styles.text} testID={testIds.item}>
{value}
</Text>
</>
) : null}
<Animated.Text
accessibilityElementsHidden
importantForAccessibility='no-hide-descendants'
style={[styles.text, styles.cursor, cursorAnimationStyle]}
testID={testIds.cursor}
<View style={styles.content}>
{focused ? (
<View style={styles.textRow} testID={testIds.cursorRow}>
{value ? (
<>
<Text
accessibilityElementsHidden
allowFontScaling={allowFontScaling}
importantForAccessibility='no-hide-descendants'
maxFontSizeMultiplier={maxFontSizeMultiplier}
style={[styles.text, styles.cursorSpacer]}
>
|
</Text>
<Text
allowFontScaling={allowFontScaling}
maxFontSizeMultiplier={maxFontSizeMultiplier}
style={styles.text}
testID={testIds.item}
>
{value}
</Text>
</>
) : null}
<Animated.Text
accessibilityElementsHidden
allowFontScaling={allowFontScaling}
importantForAccessibility='no-hide-descendants'
maxFontSizeMultiplier={maxFontSizeMultiplier}
style={[styles.text, cursorAnimationStyle]}
testID={testIds.cursor}
>
|
</Animated.Text>
</View>
) : (
<Text
allowFontScaling={allowFontScaling}
maxFontSizeMultiplier={maxFontSizeMultiplier}
style={styles.text}
testID={testIds.item}
>
|
</Animated.Text>
</View>
) : (
<Text style={styles.text} testID={testIds.item}>
{value}
</Text>
)}
{value}
</Text>
)}
</View>
</Pressable>
)
}
Expand All @@ -129,14 +148,23 @@ const styles = StyleSheet.create(({ components, semantic, fonts }) => ({
justifyContent: 'center',
},

content: {
position: 'absolute',
top: 0,
right: 0,
bottom: 0,
left: 0,
alignItems: 'center',
justifyContent: 'center',
},

textRow: { flexDirection: 'row', alignItems: 'center' },

cursorSpacer: { opacity: semantic.effects.opacity[0] },

cursor: { lineHeight: fonts.lineHeight[400] },

text: {
fontSize: fonts.fontSize[200],
lineHeight: fonts.lineHeight[300],
fontFamily: fonts.fontFamily.base,
fontWeight: fonts.fontWeight.regular,
letterSpacing: fonts.letterSpacing[500],
Expand Down
Loading