Skip to content

Commit 4b3cce4

Browse files
committed
feat: add emptied props and rename acceleration props
1 parent d9bf38b commit 4b3cce4

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

PROPS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
| Property | Description | Type | Default | Note |
66
| ----------------------- | ---------------------------------------------------------------------------------------- | ---------------- | ---------------- | --------------------------------- |
7+
| `accelerationDelay` | Delay time before start the `onLongPress` event and increase or decrease and continually | Number | `750 ` | |
78
| `activeOpacity` | Opacity on pressed button | Number | `0.85` |
89
| `append` | Custom element before right button | Component | |
910
| `arrows` | Labels on button will be arrows (< and >) instead of plus and minus | Boolean | `false` |
@@ -31,6 +32,7 @@
3132
| `color` | Custom color of the Spinner | String | `#3E525F` | |
3233
| `disabled` | Disable the Spinner or not | Boolean | `false` | |
3334
| `editable` | Set if input number field is editable or not | Boolean | `true` | |
35+
| `emptied` | Set if input can be empty | Boolean | `false` | |
3436
| `fontFamily` | Custom fontFamily of the text input of the Spinner | String | System Default | |
3537
| `fontSize` | Custom fontSize of the text input of the Spinner | Number | `14` | |
3638
| `height` | Custom height of the Spinner | Number | `50` | |
@@ -48,8 +50,6 @@
4850
| `onIncrease` | When increase button is clicked get value increased | Function | | `(increased) => { ... }` |
4951
| `onKeyPress` | Callback that is called when a key is pressed. | (e) => { ... } |
5052
| `onLongPress` | Callback that is called when holding the right or the left button | Function | | |
51-
| `onLongPressDelay` | Delay time before start the `onLongPress` event and increase or decrease and continually | Number | `750 ` | |
52-
| `onLongPressSpeed` | Speed of increase or decrease and continually | Number | `7` | (value from `1` to `10`) |
5353
| `onMax` | When max is reached get max number permitted | Function | | `(max) => { ... }` |
5454
| `onMin` | When min is reached get min number permitted | Function | | `(min) => { ... }` |
5555
| `onSubmitEditing` | Callback that is called when the text input's submit button is pressed | (e) => { ... } |
@@ -66,6 +66,7 @@
6666
| `showBorder` | Show the border of the Spinner or not | Boolean | `false` | Use with `rounded={false}` |
6767
| `step` | Value to increment or decrement the current spinner value | String<br>Number | `1` | |
6868
| `style` | Container style | Object | | Could overwrite other props |
69+
| `speed` | Speed acceleration ratio of increase or decrease `onLongPress` | Number | `7` | (value from `1` to `10`) |
6970
| `textColor` | Custom number color | String | `#000000` | |
7071
| `type` | Type of spinner | String | `int` | Can be `int` or `real`/`float`... |
7172
| `typingTime` | Time before debounce and trigger `onChange` event | Number | `750` | |

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,18 @@ Check the "[Props List](PROPS.md)" file to have the complete list of component p
103103

104104
| Property | Description | Type | Default | Note |
105105
| ---------------------- | ---------------------------------------------------------------------------------------- | ---------------- | ------- | --------------------------------- |
106+
| `accelerationDelay` | Delay time before start the `onLongPress` event and increase or decrease and continually | Number | `750 ` | |
106107
| `append` | Custom element before right button | Component | | |
107108
| `autofocus` | If `true`, focuses the input on `componentDidMount`. | | `false` | |
108109
| `disabled` | Disable the Spinner or not | Boolean | `false` | |
109110
| `editable` | Set if input number field is editable or not | Boolean | `true` | |
111+
| `emptied` | Set if input can be empty | Boolean | `false` | |
110112
| `initialValue` | Initial value of the Spinner | String<br>Number | `0` | |
111113
| `inputProps` | Customized TextInput Component props | Object | `null` | Could overwrite other props |
112114
| `leftButtonProps` | Customized left button (Touchable Component) props | Object | `null` | Could overwrite other props |
113115
| `maxLength` | Limits the maximum number of characters that can be entered. | Number | | |
114116
| `max` | Max number permitted | String<br>Number | `null` |
115117
| `min` | Min value permitted | String<br>Number | `0` |
116-
| `onLongPressDelay` | Delay time before start the `onLongPress` event and increase or decrease and continually | Number | `750 ` | |
117-
| `onLongPressSpeed` | Speed of increase or decrease and continually | Number | `7` | (value from `1` to `10`) |
118118
| `placeholder` | The string that will be rendered when text input value is equal to zero | String | `null` | |
119119
| `placeholderTextColor` | The text color of the placeholder string. | String | `null` | |
120120
| `precision` | Max numbers permitted after comma | Integer | `2` |
@@ -125,6 +125,7 @@ Check the "[Props List](PROPS.md)" file to have the complete list of component p
125125
| `selectTextOnFocus` | If `true`, all text will automatically be selected on focus. | Bool | `false` | |
126126
| `selectionColor` | The highlight and cursor color of the text input. | String | `null` | |
127127
| `step` | Value to increment or decrement the current spinner value | String<br>Number | `1` |
128+
| `speed` | Speed acceleration ratio of increase or decrease `onLongPress` | Number | `7` | (value from `1` to `10`) |
128129
| `typingTime` | Time before debounce and trigger `onChange` event | Number | `750` | |
129130
| `type` | Type of spinner | String | `int` | Can be `int` or `real`/`float`... |
130131
| `value` | Controlled value of the Spinner | String<br>Number | `0` | |

src/InputSpinner.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,11 @@ class InputSpinner extends Component {
336336
* @returns {*}
337337
*/
338338
getPlaceholder() {
339-
if (isEmpty(this.props.placeholder)) {
339+
if (!isEmpty(this.props.placeholder)) {
340+
return this.props.placeholder;
341+
} else if (isEmpty(this.state.value) && this.isEmptied()) {
342+
return "";
343+
} else {
340344
return String(this.state.min);
341345
} else {
342346
return this.props.placeholder;
@@ -548,6 +552,14 @@ class InputSpinner extends Component {
548552
return !this.props.disabled && this.props.editable;
549553
}
550554

555+
/**
556+
* If input can be empty
557+
* @returns {boolean|Boolean}
558+
*/
559+
isEmptied() {
560+
return this.props.emptied;
561+
}
562+
551563
/**
552564
* Is text input focused
553565
* @returns {boolean|Boolean}
@@ -1011,8 +1023,9 @@ InputSpinner.propTypes = {
10111023
onDecrease: PropTypes.func,
10121024
onSubmit: PropTypes.func,
10131025
onLongPress: PropTypes.func,
1014-
onLongPressDelay: PropTypes.number,
1015-
onLongPressSpeed: PropTypes.number,
1026+
accelerationDelay: PropTypes.number,
1027+
speed: PropTypes.number,
1028+
emptied: PropTypes.bool,
10161029
typingTime: PropTypes.number,
10171030
buttonLeftDisabled: PropTypes.bool,
10181031
buttonRightDisabled: PropTypes.bool,
@@ -1069,8 +1082,9 @@ InputSpinner.defaultProps = {
10691082
returnKeyType: null,
10701083
width: 150,
10711084
height: 50,
1072-
onLongPressDelay: defaultLongPressDelay,
1073-
onLongPressSpeed: defaultLongPressSpeed,
1085+
accelerationDelay: defaultAccelerationDelay,
1086+
speed: defaultSpeed,
1087+
emptied: false,
10741088
typingTime: defaultTypingTime,
10751089
buttonLeftDisabled: false,
10761090
buttonRightDisabled: false,

src/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export interface ReactNativeInputSpinnerProps {
4848
onSubmit?(...args: unknown[]): unknown;
4949
onLongPressDelay?: number;
5050
onLongPressSpeed?: number;
51+
accelerationDelay?: number;
52+
speed?: number;
53+
emptied?: boolean;
5154
typingTime?: number;
5255
buttonLeftDisabled?: boolean;
5356
buttonRightDisabled?: boolean;

0 commit comments

Comments
 (0)