Skip to content

Commit

Permalink
TextInpuMask is able to receive any specilization of TextInput
Browse files Browse the repository at this point in the history
  • Loading branch information
helloncanella committed May 13, 2017
1 parent f81e083 commit d747e18
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/text-input-mask.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import React, { Component } from 'react';
import {
StyleSheet,
TextInput
StyleSheet,
TextInput
} from 'react-native';
import BaseTextComponent from './base-text-component';

const INPUT_TEXT_REF = '$input-text';

let Input = TextInput

export default class TextInputMask extends BaseTextComponent {
constructor(props) {
super(props);
if (props.customTextInput) Input = props.customTextInput
}

getElement() {
Expand All @@ -19,20 +22,20 @@ export default class TextInputMask extends BaseTextComponent {
_onChangeText(text) {
let self = this;

if(!this._checkText(text)) {
if (!this._checkText(text)) {
return;
}

self.updateValue(text)
.then(maskedText => {
if(self.props.onChangeText) {
if (self.props.onChangeText) {
self.props.onChangeText(maskedText);
}
});
}

_checkText(text) {
if(this.props.checkText) {
if (this.props.checkText) {
return this.props.checkText(this.state.value, text);
}

Expand All @@ -41,13 +44,13 @@ export default class TextInputMask extends BaseTextComponent {

render() {
return (
<TextInput
<Input
ref={INPUT_TEXT_REF}
keyboardType={this._maskHandler.getKeyboardType()}
{...this.props}
onChangeText={(text) => this._onChangeText(text)}
value={this.state.value}
/>
/>
);
}
}

0 comments on commit d747e18

Please sign in to comment.