Skip to content

Commit 496b018

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 3157bdb + 245a3eb commit 496b018

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

PROPS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
| `inputStyle` | Input Style (Text number at middle) | Object | | Could overwrite other props |
4242
| `inputProps` | Customized TextInput Component props | Object | `null` | |
4343
| `leftButtonProps` | Customized left button (Touchable Component) props | Object | `null` | |
44+
| `longStep` | Value to increment or decrement the current spinner value `onLongPress` | String<br>Number | `step` |
4445
| `maxLength` | Limits the maximum number of characters that can be entered. | Number | | |
4546
| `max` | Max number permitted | String<br>Number | `null` | |
4647
| `min` | Min value permitted | String<br>Number | `0` | |

src/InputSpinner.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ class InputSpinner extends Component {
112112
}
113113
this.setState({longStep: spinnerLongStep});
114114
}
115-
116115
}
117116

118117
/**
@@ -563,12 +562,21 @@ class InputSpinner extends Component {
563562

564563
/**
565564
* Increase
565+
* @param event
566+
* @param isLongPress
567+
* @returns {Promise<void>}
566568
*/
567-
async increase(event) {
569+
async increase(event, isLongPress = false) {
568570
if (this._isDisabledButtonRight()) return;
569571
let currentValue = this._parseNum(this.state.value);
570-
let num = currentValue + this._parseNum((!event && this.state.longStep > 0) ? this.state.longStep : this.state.step);
571-
if (!event && this.state.longStep > 0) {
572+
let num =
573+
currentValue +
574+
this._parseNum(
575+
isLongPress && this.state.longStep > 0
576+
? this.state.longStep
577+
: this.state.step,
578+
);
579+
if (isLongPress && this.state.longStep > 0) {
572580
num = Math.round(num / this.state.longStep) * this.state.longStep;
573581
}
574582
if (this.isTypeDecimal()) {
@@ -601,18 +609,30 @@ class InputSpinner extends Component {
601609
this.onLongPress(num);
602610
}
603611

604-
this.increaseTimer = setTimeout(this.increase.bind(this), wait);
612+
this.increaseTimer = setTimeout(
613+
this.increase.bind(this, event, true),
614+
wait,
615+
);
605616
this.onChange(num, true);
606617
}
607618

608619
/**
609620
* Decrease
621+
* @param event
622+
* @param isLongPress
623+
* @returns {Promise<void>}
610624
*/
611-
async decrease(event) {
625+
async decrease(event, isLongPress = false) {
612626
if (this._isDisabledButtonLeft()) return;
613627
let currentValue = this._parseNum(this.state.value);
614-
let num = currentValue - this._parseNum((!event && this.state.longStep > 0) ? this.state.longStep : this.state.step);
615-
if (!event && this.state.longStep > 0) {
628+
let num =
629+
currentValue -
630+
this._parseNum(
631+
isLongPress && this.state.longStep > 0
632+
? this.state.longStep
633+
: this.state.step,
634+
);
635+
if (isLongPress && this.state.longStep > 0) {
616636
num = Math.round(num / this.state.longStep) * this.state.longStep;
617637
}
618638
if (this.isTypeDecimal()) {
@@ -645,7 +665,10 @@ class InputSpinner extends Component {
645665
this.onLongPress(num);
646666
}
647667

648-
this.decreaseTimer = setTimeout(this.decrease.bind(this), wait);
668+
this.decreaseTimer = setTimeout(
669+
this.decrease.bind(this, event, true),
670+
wait,
671+
);
649672
this.onChange(num, true);
650673
}
651674

src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface ReactNativeInputSpinnerProps {
88
value?: string | number;
99
initialValue?: string | number;
1010
step?: string | number;
11+
longStep?: string | number;
1112
precision?: number;
1213
shadow?: boolean;
1314
rounded?: boolean;

0 commit comments

Comments
 (0)