Skip to content

Commit

Permalink
Added custom render function for dropdown Icon and placeholder prop
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraggarg committed Oct 6, 2020
1 parent 050587a commit 72651a3
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 14 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,12 @@ export default App;
- `defaultValue?`: string
- `disabled?`: boolean
- `disableArrowIcon?`: boolean
- `placeholder?`: string;
- `onChangeText?`: (text: string) => void;
- `onChangeFormattedText?`: (text: string) => void;
- `containerStyle?`: `StyleProp<ViewStyle>`;
- `textContainerStyle?`: `StyleProp<ViewStyle>`;
- `renderDropdownImage?`: `JSX.Element`;
- `textInputProps?`: [TextInputProps](https://reactnative.dev/docs/textinput);
- `textInputStyle?`: `StyleProp<TextStyle>`;
- `codeTextStyle?`: `StyleProp<TextStyle>`;
Expand All @@ -142,7 +145,7 @@ export default App;

- `getCountryCode`: () => [CountryCode](https://github.com/xcarpentier/react-native-country-picker-modal/blob/master/src/types.ts#L252)
- `getCallingCode`: () => string | undefined
- `isValidNumber`: (number: number) => boolean
- `isValidNumber`: (number: string) => boolean

## FAQ

Expand Down Expand Up @@ -189,7 +192,6 @@ Reach out to me at one of the following places!
[![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://badges.mit-license.org)

- **[MIT license](http://opensource.org/licenses/mit-license.php)**
- Copyright 2020 © <a href="https://twitter.com/AnuragG94634191" target="_blank">Anurag Garg</a>.

## Hire

Expand Down
9 changes: 9 additions & 0 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const App = () => {
const [value, setValue] = useState('');
const [formattedValue, setFormattedValue] = useState('');
const [valid, setValid] = useState(false);
const [disabled, setDisabled] = useState(false);
const [showMessage, setShowMessage] = useState(false);
const phoneInput = useRef<PhoneInput>(null);
return (
Expand All @@ -38,6 +39,7 @@ const App = () => {
onChangeFormattedText={(text) => {
setFormattedValue(text);
}}
disabled={disabled}
withDarkTheme
withShadow
autoFocus
Expand All @@ -51,6 +53,13 @@ const App = () => {
}}>
<Text>Check</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
setDisabled(!disabled);
}}>
<Text>{disabled ? 'Activate' : 'Disable'}</Text>
</TouchableOpacity>
</SafeAreaView>
</View>
</>
Expand Down
1 change: 0 additions & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ SPEC REPOS:
- Flipper
- Flipper-DoubleConversion
- Flipper-Glog
- FlipperKit
https://github.com/cocoapods/specs.git:
- CocoaAsyncSocket
- CocoaLibEvent
Expand Down
8 changes: 4 additions & 4 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3155,9 +3155,9 @@ globals@^12.1.0:
type-fest "^0.8.1"

google-libphonenumber@^3.2.10:
version "3.2.10"
resolved "https://registry.yarnpkg.com/google-libphonenumber/-/google-libphonenumber-3.2.10.tgz#021a314652747d736a39e2e60dc670f0431425ad"
integrity sha512-TsckE9O8QgqaIeaOXPjcJa4/kX3BzFdO1oCbMfmUpRZckml4xJhjJVxaT9Mdt/VrZZkT9lX44eHAEWfJK1tHtw==
version "3.2.13"
resolved "https://registry.yarnpkg.com/google-libphonenumber/-/google-libphonenumber-3.2.13.tgz#8f41f2ce1739d40e2b9ebccc75dca95474cdf0b5"
integrity sha512-USnpjJkD8St+wyshy154lF74JeauNCd8vrcusSlWjSFWitXzl7ZSuCunA/XxeVLqBv6DShrSfFMYdwGZ7x4hOw==

graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.3, graceful-fs@^4.1.6, graceful-fs@^4.1.9, graceful-fs@^4.2.0, graceful-fs@^4.2.4:
version "4.2.4"
Expand Down Expand Up @@ -5535,7 +5535,7 @@ react-native-country-picker-modal@^1.11.0:
react-async-hook "3.6.1"

react-native-phone-number-input@../:
version "1.0.0"
version "1.0.5"
dependencies:
google-libphonenumber "^3.2.10"
react-native-country-picker-modal "^1.11.0"
Expand Down
4 changes: 3 additions & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export interface PhoneInputProps {
defaultValue?: string;
disabled?: boolean;
disableArrowIcon?: boolean;
placeholder?: string;
onChangeText?: (text: string) => void;
onChangeFormattedText?: (text: string) => void;
renderDropdownImage?: JSX.Element;
containerStyle?: StyleProp<ViewStyle>;
textContainerStyle?: StyleProp<ViewStyle>;
textInputProps?: TextInputProps;
Expand Down Expand Up @@ -288,7 +290,7 @@ export default class PhoneInput extends Component<
| "HK"
| "AX";
getCallingCode: () => string | undefined;
isValidNumber: (number: number) => boolean;
isValidNumber: (number: string) => boolean;
onSelect: (country: Country) => void;
onChangeText: (text: string) => void;
render(): JSX.Element;
Expand Down
26 changes: 20 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ export default class PhoneInput extends Component {
}
};

renderDropdownImage = () => {
return (
<Image
source={{ uri: dropDown }}
resizeMode="contain"
style={styles.dropDownImage}
/>
);
};

render() {
const {
withShadow,
Expand All @@ -101,10 +111,13 @@ export default class PhoneInput extends Component {
textInputProps,
textInputStyle,
autoFocus,
placeholder,
disableArrowIcon,
flagButtonStyle,
containerStyle,
textContainerStyle,
renderDropdownImage,
countryPickerProps = {},
} = this.props;
const { modalVisible, code, countryCode, number, disabled } = this.state;
return (
Expand Down Expand Up @@ -135,13 +148,14 @@ export default class PhoneInput extends Component {
visible={modalVisible}
theme={withDarkTheme ? DARK_THEME : DEFAULT_THEME}
onClose={() => this.setState({ modalVisible: false })}
{...countryPickerProps}
/>
{!disableArrowIcon && (
<Image
source={{ uri: dropDown }}
resizeMode="contain"
style={styles.dropDownImage}
/>
<React.Fragment>
{renderDropdownImage
? renderDropdownImage
: this.renderDropdownImage()}
</React.Fragment>
)}
</TouchableOpacity>
<View
Expand All @@ -157,7 +171,7 @@ export default class PhoneInput extends Component {
)}
<TextInput
style={[styles.numberText, textInputStyle ? textInputStyle : {}]}
placeholder="Phone Number"
placeholder={placeholder ? placeholder : "Phone Number"}
onChangeText={this.onChangeText}
value={number}
editable={disabled ? false : true}
Expand Down

0 comments on commit 72651a3

Please sign in to comment.