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
10 changes: 6 additions & 4 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,26 @@ export default class MaskedInput extends Component<IMaskedInputProps, IMaskedInp
this.updateMaskedValue(text);
}

public componentWillReceiveProps(nextProps: Readonly<IMaskedInputProps>, nextContext: any): void {
this.userInputProcessorFunction = createInputProcessor(nextProps.mask);
this.updateMaskedValue(nextProps.value || "");
public componentDidUpdate(prevProps: Readonly<IMaskedInputProps>, prevState: Readonly<IMaskedInputState>, snapshot?: any) {
if (prevProps.mask !== this.props.mask) {
this.userInputProcessorFunction = createInputProcessor(this.props.mask);
}
this.updateMaskedValue(this.props.value || "");
}

private updateMaskedValue(inputValue: string): void {
const maskResult = this.userInputProcessorFunction(inputValue, UserInputType.INSERTION);
const previousValue = this.state.value;
const currentValue = maskResult.text;

this.setState({ value: currentValue });
if (this.props.onTextChange && currentValue !== previousValue) {
this.setState({ value: currentValue });
this.props.onTextChange(maskResult.text, maskResult.complete);
}
}

public render(): ReactNode {
let { mask, value, onTextChange, ...attributes } = this.props;
let { mask, value, onTextChange, ...attributes } = this.props;
return (
<TextInput
value={this.state.value}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test": "jest --coverage"
},
"peerDependencies": {
"react": "^16.8.6"
"react": "^16.13.1"
},
"keywords": [
"react-native",
Expand Down