From 81ef2a4ead0d7f7d64dc448a52de852059f36c6c Mon Sep 17 00:00:00 2001 From: Daniel Dimitrov Date: Mon, 15 Jan 2018 16:31:02 +0100 Subject: [PATCH 1/2] Make sure that when we have a value, we also show the label --- FloatingLabel.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/FloatingLabel.js b/FloatingLabel.js index 5f18f65..c5cab74 100644 --- a/FloatingLabel.js +++ b/FloatingLabel.js @@ -22,6 +22,19 @@ class FloatingLabel extends Textbox { }; } + componentWillReceiveProps(next) { + + // Make sure that when we have a value, we also show the label + if(this.props.value !== next.value && next.value) { + this.setState({ + fadeAnim: new Animated.Value(1), + }) + } + + super.componentWillReceiveProps(next) + } + + getTemplate () { let self = this return function (locals) { From ca6cb2c81c40b0c3b6775de2bd301e275aaafb9c Mon Sep 17 00:00:00 2001 From: Daniel Dimitrov Date: Fri, 20 Apr 2018 13:47:07 +0200 Subject: [PATCH 2/2] handle 0 value --- FloatingLabel.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/FloatingLabel.js b/FloatingLabel.js index c5cab74..f7da65d 100644 --- a/FloatingLabel.js +++ b/FloatingLabel.js @@ -14,10 +14,14 @@ 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, }; } @@ -25,7 +29,7 @@ class FloatingLabel extends Textbox { componentWillReceiveProps(next) { // Make sure that when we have a value, we also show the label - if(this.props.value !== next.value && next.value) { + if(this.props.value !== next.value && this.getTransformer().format(next.value)) { this.setState({ fadeAnim: new Animated.Value(1), })