Skip to content
Open
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
12 changes: 10 additions & 2 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface PhoneInputProps {
onChangeCountry?: (country: Country) => void;
onChangeText?: (text: string) => void;
onChangeFormattedText?: (text: string) => void;
onBlur?: () => void;
onFocus?: () => void;
renderDropdownImage?: JSX.Element;
containerStyle?: StyleProp<ViewStyle>;
textContainerStyle?: StyleProp<ViewStyle>;
Expand Down Expand Up @@ -299,9 +301,15 @@ export default class PhoneInput extends Component<
getCallingCode: () => string | undefined;
isValidNumber: (number: string) => boolean;
onSelect: (country: Country) => void;
getNumberAfterPossiblyEliminatingZero: () => {number: string , formattedNumber: string };
getNumberAfterPossiblyEliminatingZero: () => {
number: string;
formattedNumber: string;
};
onChangeText: (text: string) => void;
render(): JSX.Element;
}

export function isValidNumber(number: string, countryCode: CountryCode ): boolean;
export function isValidNumber(
number: string,
countryCode: CountryCode
): boolean;
15 changes: 10 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ export default class PhoneInput extends PureComponent {

static getDerivedStateFromProps(nextProps, prevState) {
if (nextProps.disabled !== prevState.disabled) {
if ((nextProps.value || nextProps.value === "") && nextProps.value !== prevState.number) {
return ({ disabled: nextProps.disabled, number: nextProps.value });
if (
(nextProps.value || nextProps.value === "") &&
nextProps.value !== prevState.number
) {
return { disabled: nextProps.disabled, number: nextProps.value };
}
return ({ disabled: nextProps.disabled });
return { disabled: nextProps.disabled };
}
return null;
};
}

async componentDidMount() {
const { defaultCode } = this.props;
Expand Down Expand Up @@ -229,6 +232,8 @@ export default class PhoneInput extends PureComponent {
keyboardAppearance={withDarkTheme ? "dark" : "default"}
keyboardType="number-pad"
autoFocus={autoFocus}
onBlur={this.props.onBlur}
onFocus={this.props.onFocus}
{...textInputProps}
/>
</View>
Expand All @@ -245,4 +250,4 @@ export const isValidNumber = (number, countryCode) => {
} catch (err) {
return false;
}
};
};