Skip to content

fix: paddingHorizontal with TextInput.Affix - #2312

Closed
dcangulo wants to merge 1 commit into
callstack:masterfrom
dcangulo:feature/affix-padding
Closed

dcangulo wants to merge 1 commit into
callstack:masterfrom
dcangulo:feature/affix-padding

Conversation

@dcangulo

@dcangulo dcangulo commented Oct 23, 2020 •

Copy link
Copy Markdown
Contributor

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

callstack-bot commented Oct 23, 2020 •

Copy link
Copy Markdown

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

@dcangulo

Copy link
Copy Markdown
Contributor Author

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

visible?: Animated.Value;
textStyle?: StyleProp<TextStyle>;
side: AdornmentSide;
paddingHorizontal?: string | number | undefined;

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

.string();

const offset =
paddingHorizontal !== undefined && typeof paddingHorizontal === 'number'

Copy link
Copy Markdown
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'

adornmentConfig: AdornmentConfig[];
leftAffixWidth: number;
rightAffixWidth: number;
paddingHorizontal?: string | number | undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here

textStyle?: StyleProp<TextStyle>;
visible?: Animated.Value;
isTextInputFocused: boolean;
paddingHorizontal?: string | number | undefined;

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

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

@Trancever

Copy link
Copy Markdown
Contributor

Merged in 4b1c150

@Trancever Trancever closed this Dec 8, 2020
@ecmap

ecmap commented May 5, 2023

Copy link
Copy Markdown

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