@@ -15,6 +15,14 @@ const defaultColor = "#3E525F";
1515 * @author Marco Cesarato <[email protected] > 1616 */
1717class InputSpinner extends Component {
18+ // Timers
19+ increaseTimer = null ;
20+ decreaseTimer = null ;
21+
22+ // Press trigger timeouts
23+ pressStartTriggerTimeout = 1000 ;
24+ pressTriggerTimeout = 200 ;
25+
1826 /**
1927 * Constructor
2028 * @param props
@@ -262,6 +270,15 @@ class InputSpinner extends Component {
262270 ) ;
263271 }
264272
273+ clearTimers ( ) {
274+ if ( this . increaseTimer ) {
275+ clearTimeout ( this . increaseTimer ) ;
276+ }
277+ if ( this . decreaseTimer ) {
278+ clearTimeout ( this . decreaseTimer ) ;
279+ }
280+ }
281+
265282 /**
266283 * Increase
267284 */
@@ -276,6 +293,13 @@ class InputSpinner extends Component {
276293 }
277294 this . props . onIncrease ( increased_num ) ;
278295 }
296+
297+ let wait = this . pressTriggerTimeout ;
298+ if ( this . increaseTimer === null ) {
299+ wait = this . pressStartTriggerTimeout ;
300+ }
301+
302+ this . increaseTimer = setTimeout ( this . increase , wait ) ;
279303 this . onChange ( num ) ;
280304 }
281305
@@ -293,6 +317,13 @@ class InputSpinner extends Component {
293317 }
294318 this . props . onDecrease ( decreased_num ) ;
295319 }
320+
321+ let wait = this . pressTriggerTimeout ;
322+ if ( this . increaseTimer === null ) {
323+ wait = this . pressStartTriggerTimeout ;
324+ }
325+
326+ this . decreaseTimer = setTimeout ( this . decrease , wait ) ;
296327 this . onChange ( num ) ;
297328 }
298329
@@ -739,7 +770,8 @@ class InputSpinner extends Component {
739770 onShowUnderlay = { this . onShowUnderlay . bind ( this , "left" ) }
740771 disabled = { this . _isDisabledButtonLeft ( ) }
741772 style = { buttonStyle }
742- onPress = { ( ) => this . decrease ( ) }
773+ onPressIn = { this . decrease }
774+ onPressOut = { this . clearTimers }
743775 { ...this . props . leftButtonProps } >
744776 { this . _renderLeftButtonElement ( ) }
745777 </ TouchableHighlight >
@@ -774,7 +806,8 @@ class InputSpinner extends Component {
774806 onShowUnderlay = { this . onShowUnderlay . bind ( this , "right" ) }
775807 disabled = { this . _isDisabledButtonRight ( ) }
776808 style = { buttonStyle }
777- onPress = { ( ) => this . increase ( ) }
809+ onPressIn = { this . increase }
810+ onPressOut = { this . clearTimers }
778811 { ...this . props . rightButtonProps } >
779812 { this . _renderRightButtonElement ( ) }
780813 </ TouchableHighlight >
0 commit comments