Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ function _handlePress(callback){
const Button = (props) => {
return (
Platform.OS === 'ios'
? <TouchableOpacity disabled={props.disabled} style={props.style} onPress={() => _handlePress(props.onPress)}>{props.children}</TouchableOpacity>
: <TouchableNativeFeedback disabled={props.disabled} onPress={() => _handlePress(props.onPress)}><View style={props.style}>{props.children}</View></TouchableNativeFeedback>
? <TouchableOpacity disabled={props.disabled} style={props.style} onPressIn={() => _handlePress(props.onPressIn) } onPressOut={() => _handlePress(props.onPressOut) }>{props.children}</TouchableOpacity>
: <TouchableNativeFeedback disabled={props.disabled} onPressIn={() => _handlePress(props.onPressIn) } onPressOut={() => _handlePress(props.onPressOut) }><View style={props.style}>{props.children}</View></TouchableNativeFeedback>
)
}

Button.defaultProps = {
onPress : () => {}
}

export default Button;
export default Button;
23 changes: 19 additions & 4 deletions NumericInput/NumericInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Copy link
Owner

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

Copy link
Owner

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


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)) {
Expand Down Expand Up @@ -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 = () => {

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the extra empty line

clearInterval(this.incInterval);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the semicolon

}

stopDec = () => {

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the extra empty line

clearInterval(this.decInterval);
Copy link
Owner

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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>)
Expand Down