Skip to content
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

Fix issue95 no minus sign keyboard on iOS #97

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions NumericInput/NumericInput.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react'
import { View, TextInput, StyleSheet, Text } from 'react-native'
import { View, TextInput, StyleSheet, Text, Platform } from 'react-native'
import Icon from 'react-native-vector-icons/Ionicons'
import Button from '../Button'
import PropTypes from 'prop-types'
Expand Down Expand Up @@ -71,6 +71,7 @@ export default class NumericInput extends Component {
intMatch = (value) => value && value.match(/-?\d+/) && value.match(/-?\d+/)[0] === value.match(/-?\d+/).input

onChange = (value) => {
value = value.replace(",", ".");
let currValue = typeof this.props.value === 'number' ? this.props.value : this.state.value
if ((value.length === 1 && value === '-') || (value.length === 2 && value === '0-')) {
this.setState({ stringValue: '-' })
Expand Down Expand Up @@ -127,10 +128,10 @@ export default class NumericInput extends Component {
let legal = match && match[0] === match.input && ((this.props.maxValue === null || (parseFloat(this.state.stringValue) <= this.props.maxValue)) && (this.props.minValue === null || (parseFloat(this.state.stringValue) >= this.props.minValue)))
if (!legal) {
if (this.props.minValue !== null && (parseFloat(this.state.stringValue) <= this.props.minValue)) {
this.props.onLimitReached(true, 'Reached Minimum Value!')
this.props.onLimitReached(false, 'Reached Minimum Value!')
}
if (this.props.maxValue !== null && (parseFloat(this.state.stringValue) >= this.props.maxValue)) {
this.props.onLimitReached(false, 'Reached Maximum Value!')
this.props.onLimitReached(true, 'Reached Maximum Value!')
}
if (this.ref) {
this.ref.blur()
Expand Down Expand Up @@ -218,7 +219,7 @@ export default class NumericInput extends Component {
if (this.props.type === 'up-down')
return (
<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} />
<TextInput {...this.props.extraTextInputProps} editable={editable} returnKeyType='done' underlineColorAndroid='rgba(0,0,0,0)' keyboardType={Platform.OS === 'ios' ? 'numbers-and-punctuation' : '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' }}>
<Icon name='ios-arrow-up' size={fontSize} style={[...iconStyle, maxReached ? this.props.reachMaxIncIconStyle : {}, minReached ? this.props.reachMinIncIconStyle : {}]} />
Expand All @@ -234,7 +235,7 @@ export default class NumericInput extends Component {
<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} />
<TextInput {...this.props.extraTextInputProps} editable={editable} returnKeyType='done' underlineColorAndroid='rgba(0,0,0,0)' keyboardType={Platform.OS === 'ios' ? 'numbers-and-punctuation' : '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}>
<Icon name='md-add' size={fontSize} style={[...iconStyle, maxReached ? this.props.reachMaxIncIconStyle : {}, minReached ? this.props.reachMinIncIconStyle : {}]} />
Expand Down