Skip to content

fix: paddingHorizontal with TextInput.Affix #2312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

fix: paddingHorizontal with TextInput.Affix #2312

wants to merge 1 commit into from

Conversation

dcangulo
Copy link
Contributor

@dcangulo dcangulo commented Oct 23, 2020

Summary

Fixes: #2303

paddingHorizontal is disregarded when using left prop on TextInput.

Test plan

Snack: https://snack.expo.io/@dcangulo/textinput

Sample Code in screenshot:

import React from 'react';
import { SafeAreaView, View } from 'react-native';
import { TextInput } from 'react-native-paper';

export default function App() {
  const [text, setText] = React.useState('');

  return (
    <SafeAreaView>
      <View style={{ padding: 20 }}>
        <TextInput
          label='Contact Number'
          value={text}
          onChangeText={setText}
          left={<TextInput.Affix text='+63' />}
          style={{ paddingHorizontal: 60 }}
        />
      </View>
    </SafeAreaView>
  );
}

Before this PR:
Screen Shot 2020-10-23 at 10 08 14 PM

After this PR:
Screen Shot 2020-10-23 at 10 17 53 PM

@callstack-bot
Copy link

callstack-bot commented Oct 23, 2020

Hey @dcangulo, thank you for your pull request 🤗. The documentation from this branch can be viewed here.

@dcangulo
Copy link
Contributor Author

@Trancever @unikvozm @jbinda @matkoson @OlimpiaZurek Please check. Thanks.

@@ -29,6 +29,7 @@ type ContextState = {
visible?: Animated.Value;
textStyle?: StyleProp<TextStyle>;
side: AdornmentSide;
paddingHorizontal?: string | number | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we type it as paddingHorizontal?: number;?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Trancever

I'm not sure but I get Type 'string | number | undefined' is not assignable to type 'number'. error if I use paddingHorizontal?: number;. I am also new to typescript, any pointers will be appreciated.

Also according to the docs, paddingHorizontal has a type of number, string.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see. Then it should be paddingHorizontal?: number | string. We don't have to add undefined, because we already have a question mark after the prop name.

const textColor = color(theme.colors.text)
.alpha(theme.dark ? 0.7 : 0.54)
.rgb()
.string();

const offset =
paddingHorizontal !== undefined && typeof paddingHorizontal === 'number'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we change the type we won't need this check typeof paddingHorizontal === 'number'

inputOffset = 0,
}: {
inputOffset?: number;
adornmentConfig: AdornmentConfig[];
leftAffixWidth: number;
rightAffixWidth: number;
paddingHorizontal?: string | number | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@@ -114,6 +121,7 @@ export interface TextInputAdornmentProps {
textStyle?: StyleProp<TextStyle>;
visible?: Animated.Value;
isTextInputFocused: boolean;
paddingHorizontal?: string | number | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

@dcangulo
Copy link
Contributor Author

@Trancever Updated to paddingHorizontal?: number | string. Please check. Thanks.

@Trancever
Copy link
Contributor

Merged in 4b1c150

@Trancever Trancever closed this Dec 8, 2020
@ecmap
Copy link

ecmap commented May 5, 2023

Does TextInput.Icon support?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

paddingHorizontal doesn't work if used with left prop
4 participants