-
Notifications
You must be signed in to change notification settings - Fork 110
Add support for long press functionality. #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,10 @@ export default class NumericInput extends Component { | |
updateBaseResolution = (width, height) => { | ||
calcSize = create({ width, height }) | ||
} | ||
|
||
startInc = () => {this.inc(); this.incInterval = setInterval(this.inc, 100); } | ||
startDec = () => {this.dec(); this.decInterval = setInterval(this.dec, 100); } | ||
|
||
inc = () => { | ||
let value = this.props.value && (typeof this.props.value === 'number') ? this.props.value : this.state.value | ||
if (this.props.maxValue === null || (value + this.props.step < this.props.maxValue)) { | ||
|
@@ -60,6 +64,17 @@ export default class NumericInput extends Component { | |
this.props.onChange && this.props.onChange(Number(value)) | ||
this.setState({ value, stringValue: value.toString() }) | ||
} | ||
|
||
stopInc = () => { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the extra empty line |
||
clearInterval(this.incInterval); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove the semicolon |
||
} | ||
|
||
stopDec = () => { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the extra empty line |
||
clearInterval(this.decInterval); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove the semicolon |
||
} | ||
|
||
isLegalValue = (value, mReal, mInt) => value === '' || (((this.props.valueType === 'real' && mReal(value)) || (this.props.valueType !== 'real' && mInt(value))) && (this.props.maxValue === null || (parseFloat(value) <= this.props.maxValue)) && (this.props.minValue === null || (parseFloat(value) >= this.props.minValue))) | ||
|
||
realMatch = (value) => value && value.match(/-?\d+(\.(\d+)?)?/) && value.match(/-?\d+(\.(\d+)?)?/)[0] === value.match(/-?\d+(\.(\d+)?)?/).input | ||
|
@@ -216,23 +231,23 @@ export default class NumericInput extends Component { | |
<View style={inputContainerStyle}> | ||
<TextInput {...this.props.extraTextInputProps} editable={editable} returnKeyType='done' underlineColorAndroid='rgba(0,0,0,0)' keyboardType='numeric' value={this.state.stringValue} onChangeText={this.onChange} style={inputStyle} ref={ref => this.ref = ref} onBlur={this.onBlur} onFocus={this.onFocus} /> | ||
<View style={upDownStyle}> | ||
<Button onPress={this.inc} style={{ flex: 1, width: '100%', alignItems: 'center' }}> | ||
<Button onPressIn={this.startInc} onPressOut={this.stopInc} style={{ flex: 1, width: '100%', alignItems: 'center' }}> | ||
<Icon name='ios-arrow-up' size={fontSize} style={[...iconStyle, maxReached ? this.props.reachMaxIncIconStyle : {}, minReached ? this.props.reachMinIncIconStyle : {}]} /> | ||
</Button> | ||
<Button onPress={this.dec} style={{ flex: 1, width: '100%', alignItems: 'center' }}> | ||
<Button onPressIn={this.startDec} onPressOut={this.stopDec} style={{ flex: 1, width: '100%', alignItems: 'center' }}> | ||
<Icon name='ios-arrow-down' size={fontSize} style={[...iconStyle, maxReached ? this.props.reachMaxDecIconStyle : {}, minReached ? this.props.reachMinDecIconStyle : {}]} /> | ||
</Button> | ||
</View> | ||
</View>) | ||
else return ( | ||
<View style={inputContainerStyle}> | ||
<Button onPress={this.dec} style={leftButtonStyle}> | ||
<Button onPressIn={this.startDec} onPressOut={this.stopDec} style={leftButtonStyle}> | ||
<Icon name='md-remove' size={fontSize} style={[...iconStyle, maxReached ? this.props.reachMaxDecIconStyle : {}, minReached ? this.props.reachMinDecIconStyle : {}]} /> | ||
</Button> | ||
<View style={[inputWraperStyle]}> | ||
<TextInput {...this.props.extraTextInputProps} editable={editable} returnKeyType='done' underlineColorAndroid='rgba(0,0,0,0)' keyboardType='numeric' value={this.state.stringValue} onChangeText={this.onChange} style={inputStyle} ref={ref => this.ref = ref} onBlur={this.onBlur} onFocus={this.onFocus} /> | ||
</View> | ||
<Button onPress={this.inc} style={rightButtonStyle}> | ||
<Button onPressIn={this.startInc} onPressOut={this.stopInc} style={rightButtonStyle}> | ||
<Icon name='md-add' size={fontSize} style={[...iconStyle, maxReached ? this.props.reachMaxIncIconStyle : {}, minReached ? this.props.reachMinIncIconStyle : {}]} /> | ||
</Button> | ||
</View>) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change them to be spread on a few lines, like the other functions, please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since they have more than one command
also please remove the semicolon from the end of lines, please