From 6288c53dd6f62c62eb685c5d3612af957146ee46 Mon Sep 17 00:00:00 2001 From: Matt Labrum Date: Thu, 15 Sep 2016 11:24:32 +0930 Subject: [PATCH] Fix underline not dynamicly resizing Updates the width to be calculated when RN calculates the element size, instead of only onComponentDidMount --- lib/Underline.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/Underline.js b/lib/Underline.js index 4368733..aada16a 100644 --- a/lib/Underline.js +++ b/lib/Underline.js @@ -10,16 +10,8 @@ export default class Underline extends Component { }; this.wrapperWidth = 0; } - componentDidMount() { - requestAnimationFrame(() => { - if (this.refs.wrapper == null) { - return; - } - const container = this.refs.wrapper; // un-box animated view - container.measure((left, top, width, height) => { - this.wrapperWidth = width; - }); - }); + measure(e) { + this.wrapperWidth = e.nativeEvent.layout.width } expandLine() { Animated.timing(this.state.lineLength, { @@ -43,7 +35,7 @@ export default class Underline extends Component { style={[styles.underlineWrapper, { backgroundColor: borderColor }]} - ref="wrapper" + onLayout={this.measure.bind(this)} >