From cacf90d13544433a0ce6cbb26914d882c7244ea1 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 6 Feb 2017 23:21:48 -0700 Subject: [PATCH] Move cursor to the right and thicken border of text box on focus --- src/components/resistor.js | 56 ++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/src/components/resistor.js b/src/components/resistor.js index 0278125..148cdbb 100644 --- a/src/components/resistor.js +++ b/src/components/resistor.js @@ -18,7 +18,6 @@ const styles = { flex: 1, height: 40, maxWidth: 80, - borderWidth: 1, textAlign: 'right', }, clearbutton: { @@ -34,6 +33,39 @@ const styles = { class Resistor extends Component { constructor(props) { super(props); + + this.state = { + borderWidth: 1, + selection: this.findEnd(), + } + } + + findEnd() { + const value = this.props.data.value || ''; + + return { + start: value.length, + end: value.length, + }; + } + + onFocus(x) { + this.setState({ + borderWidth: 1.5, + selection: this.findEnd(), + }); + } + + onBlur() { + this.setState({ + borderWidth: 1, + }); + } + + onSelectionChange(x) { + this.setState({ + selection: x.nativeEvent.selection, + }); } render() { @@ -53,16 +85,30 @@ class Resistor extends Component { } return data ? ( - + updatevalue(x)} - style={Object.assign({}, styles.resistorinput, { - borderColor: data.valid ? '#3f7d20' : 'red', - })} + style={{ + ...styles.resistorinput, + borderColor: data.valid ? '#619448' : 'red', + borderWidth: this.state.borderWidth, + }} underlineColorAndroid={'transparent'} autoCorrect={false} keyboardType={'numeric'} + selection={this.state.selection} + onFocus={(x) => this.onFocus(x)} + onBlur={() => this.onBlur()} + onSelectionChange={(x) => this.onSelectionChange(x)} /> this._picker = x}