diff --git a/FloatingLabel.js b/FloatingLabel.js index 5f18f65..f7da65d 100644 --- a/FloatingLabel.js +++ b/FloatingLabel.js @@ -14,14 +14,31 @@ const Textbox = t.form.Textbox class FloatingLabel extends Textbox { constructor (props) { super(props); + + // run the value through the transformer, because 0 is also a valid input in some cases + const hasValue = this.getTransformer().format(props.value) + this.state = { - fieldFocused: (props.value) ? true : false, - value: (props.value) ? String(props.value) : undefined, - fadeAnim: (props.value) ? new Animated.Value(1) : new Animated.Value(0), + fieldFocused: hasValue ? true : false, + value: hasValue ? String(props.value) : undefined, + fadeAnim: hasValue ? new Animated.Value(1) : new Animated.Value(0), placeholderString: undefined, }; } + componentWillReceiveProps(next) { + + // Make sure that when we have a value, we also show the label + if(this.props.value !== next.value && this.getTransformer().format(next.value)) { + this.setState({ + fadeAnim: new Animated.Value(1), + }) + } + + super.componentWillReceiveProps(next) + } + + getTemplate () { let self = this return function (locals) {