Skip to content

Commit

Permalink
add textsizeRem parameter to FilledTextInput
Browse files Browse the repository at this point in the history
  • Loading branch information
paullinator committed Jan 17, 2024
1 parent 7a0a44d commit fa3bd3f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
21 changes: 21 additions & 0 deletions src/components/scenes/InputTesterScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export function InputTesterScene() {
const [filledTextInputValue2, setFilledTextInputValue2] = useState<string>('')
const [filledTextInputValue3, setFilledTextInputValue3] = useState<string>('')
const [filledTextInputValue4, setFilledTextInputValue4] = useState<string>('')
const [filledTextInputValue5, setFilledTextInputValue5] = useState<string>('')
const [filledTextInputValue6, setFilledTextInputValue6] = useState<string>('')
const walletId = selectedWallet?.wallet.id ?? ''
const tokenId = selectedWallet?.tokenId ?? null
const exchangedFlipInputRef = React.useRef<ExchangedFlipInputRef>(null)
Expand Down Expand Up @@ -80,6 +82,25 @@ export function InputTesterScene() {
return (
<SceneWrapper scroll hasTabs hasHeader={false}>
<View style={styles.headerContainer}>
<FilledTextInput
vertical={1}
value={filledTextInputValue5}
onChangeText={setFilledTextInputValue5}
autoFocus={false}
placeholder="Test big text"
textsizeRem={1.5}
maxLength={100}
/>
<FilledTextInput
numeric
vertical={1}
value={filledTextInputValue6}
onChangeText={setFilledTextInputValue6}
autoFocus={false}
placeholder="Test big number"
textsizeRem={1.5}
maxLength={100}
/>
<FilledTextInput
vertical={1}
value={filledTextInputValue}
Expand Down
25 changes: 17 additions & 8 deletions src/components/themed/FilledTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface FilledTextInputProps extends SpaceProps {
showSpinner?: boolean
prefix?: string // Text input is left-left justified with a persistent prefix
suffix?: string // Text input is right-right justified with a persistent suffix
textsizeRem?: number

// Callbacks:
onBlur?: () => void
Expand Down Expand Up @@ -124,6 +125,7 @@ export const FilledTextInput = React.forwardRef<FilledTextInputRef, FilledTextIn
maxLength,
secureTextEntry,
testID,
textsizeRem,
...spaceProps
} = props
const theme = useTheme()
Expand Down Expand Up @@ -216,7 +218,7 @@ export const FilledTextInput = React.forwardRef<FilledTextInputRef, FilledTextIn
<InnerContainer focusValue={focusValue} hasPlaceholder={placeholder != null}>
{placeholder == null ? null : (
<Placeholder shift={focusValue}>
<PlaceholderText disableAnimation={disableAnimation} focusAnimation={focusAnimation} scale={scale} shift={focusValue}>
<PlaceholderText disableAnimation={disableAnimation} focusAnimation={focusAnimation} scale={scale} shift={focusValue} textsizeRem={textsizeRem}>
{placeholder}
</PlaceholderText>
</Placeholder>
Expand All @@ -239,6 +241,7 @@ export const FilledTextInput = React.forwardRef<FilledTextInputRef, FilledTextIn
selectionColor={theme.textInputTextColor}
testID={`${testID}.textInput`}
textAlignVertical="top"
textsizeRem={textsizeRem}
scale={scale}
value={value}
// Callbacks:
Expand Down Expand Up @@ -351,6 +354,7 @@ const InnerContainer = styled(Animated.View)<{

return [
{
// backgroundColor: 'red',
left: androidHShift,
flex: 1,
flexDirection: 'row',
Expand Down Expand Up @@ -405,6 +409,7 @@ const Placeholder = styled(Animated.View)<{ shift: SharedValue<number> }>(theme
const androidVShift = isAndroid ? rem / 16 : 0
return [
{
// backgroundColor: 'green',
position: 'absolute',
top: androidVShift,
left: rem * 0.4,
Expand Down Expand Up @@ -432,8 +437,10 @@ const PlaceholderText = styled(Animated.Text)<{
focusAnimation: SharedValue<number>
scale: SharedValue<number>
shift: SharedValue<number>
}>(theme => ({ disableAnimation, focusAnimation, scale, shift }) => {
const fontSizeBase = theme.rem(scale.value)
textsizeRem?: number
}>(theme => ({ disableAnimation, focusAnimation, scale, shift, textsizeRem }) => {
const fontSizeBase = theme.rem(textsizeRem ?? scale.value)
const fontSizeScaled = theme.rem(scale.value) * 0.75
const interpolatePlaceholderTextColor = useAnimatedColorInterpolateFn(
theme.textInputPlaceholderColor,
theme.textInputPlaceholderColorFocused,
Expand All @@ -449,7 +456,7 @@ const PlaceholderText = styled(Animated.Text)<{
useAnimatedStyle(() => {
return {
color: interpolatePlaceholderTextColor(focusAnimation, disableAnimation),
fontSize: interpolate(shift.value, [0, 1], [fontSizeBase, 0.75 * fontSizeBase])
fontSize: interpolate(shift.value, [0, 1], [fontSizeBase, fontSizeScaled])
}
})
]
Expand All @@ -459,8 +466,9 @@ const StyledAnimatedTextInput = styledWithRef(AnimatedTextInput)<{
disableAnimation: SharedValue<number>
focusAnimation: SharedValue<number>
scale: SharedValue<number>
}>(theme => ({ disableAnimation, focusAnimation, scale }) => {
const rem = theme.rem(1)
textsizeRem?: number
}>(theme => ({ disableAnimation, focusAnimation, scale, textsizeRem }) => {
const rem = theme.rem(textsizeRem ?? 1)
const interpolateTextColor = useAnimatedColorInterpolateFn(theme.textInputTextColor, theme.textInputTextColorFocused, theme.textInputTextColorDisabled)

return [
Expand All @@ -484,8 +492,9 @@ const StyledNumericInput = styledWithRef(NumericInput)<{
disableAnimation: SharedValue<number>
focusAnimation: SharedValue<number>
scale: SharedValue<number>
}>(theme => ({ disableAnimation, focusAnimation, scale }) => {
const rem = theme.rem(1)
textsizeRem?: number
}>(theme => ({ disableAnimation, focusAnimation, textsizeRem, scale }) => {
const rem = theme.rem(textsizeRem ?? 1)
const interpolateTextColor = useAnimatedColorInterpolateFn(theme.textInputTextColor, theme.textInputTextColorFocused, theme.textInputTextColorDisabled)

return [
Expand Down

0 comments on commit fa3bd3f

Please sign in to comment.