Move cursor to the right and thicken border of text box on focus

This commit is contained in:
Tanner Collin 2017-02-06 23:21:48 -07:00
parent 932dea9746
commit cacf90d135

View File

@ -18,7 +18,6 @@ const styles = {
flex: 1, flex: 1,
height: 40, height: 40,
maxWidth: 80, maxWidth: 80,
borderWidth: 1,
textAlign: 'right', textAlign: 'right',
}, },
clearbutton: { clearbutton: {
@ -34,6 +33,39 @@ const styles = {
class Resistor extends Component { class Resistor extends Component {
constructor(props) { constructor(props) {
super(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() { render() {
@ -53,16 +85,30 @@ class Resistor extends Component {
} }
return data ? ( return data ? (
<View style={{flex: 1, flexDirection: 'row', justifyContent: 'center', margin: 3}}> <View
style={{
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
margin: 3,
}}
>
<TextInput <TextInput
ref="textinput"
value={data.value || ''} value={data.value || ''}
onChangeText={(x) => updatevalue(x)} onChangeText={(x) => updatevalue(x)}
style={Object.assign({}, styles.resistorinput, { style={{
borderColor: data.valid ? '#3f7d20' : 'red', ...styles.resistorinput,
})} borderColor: data.valid ? '#619448' : 'red',
borderWidth: this.state.borderWidth,
}}
underlineColorAndroid={'transparent'} underlineColorAndroid={'transparent'}
autoCorrect={false} autoCorrect={false}
keyboardType={'numeric'} keyboardType={'numeric'}
selection={this.state.selection}
onFocus={(x) => this.onFocus(x)}
onBlur={() => this.onBlur()}
onSelectionChange={(x) => this.onSelectionChange(x)}
/> />
<Picker <Picker
ref={(x) => this._picker = x} ref={(x) => this._picker = x}