Skip to content

Commit bb1f49e

Browse files
author
Marco Cesarato
committed
feat: add color as background prop
1 parent ea17c37 commit bb1f49e

File tree

5 files changed

+28
-25
lines changed

5 files changed

+28
-25
lines changed

src/InputSpinner.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from "react-native";
99
import PropTypes from "prop-types";
1010
import {Style, defaultColor} from "./Style";
11-
import {debounce, isNumeric, isEmpty} from "./Utils";
11+
import {debounce, isNumeric, isEmpty, isCallable} from "./Utils";
1212

1313
/**
1414
* Default constants
@@ -197,7 +197,7 @@ class InputSpinner extends Component {
197197
* @param number
198198
*/
199199
onIncrease(number) {
200-
if (this._isCallable(this.props.onIncrease)) {
200+
if (isCallable(this.props.onIncrease)) {
201201
return this.props.onIncrease(number);
202202
}
203203
return true;
@@ -208,7 +208,7 @@ class InputSpinner extends Component {
208208
* @param number
209209
*/
210210
onDecrease(number) {
211-
if (this._isCallable(this.props.onDecrease)) {
211+
if (isCallable(this.props.onDecrease)) {
212212
return this.props.onDecrease(number);
213213
}
214214
return true;
@@ -219,7 +219,7 @@ class InputSpinner extends Component {
219219
* @param number
220220
*/
221221
onMax(number) {
222-
if (this._isCallable(this.props.onMax)) {
222+
if (isCallable(this.props.onMax)) {
223223
this.props.onMax(number);
224224
}
225225
this._resetHoldTime();
@@ -230,7 +230,7 @@ class InputSpinner extends Component {
230230
* @param number
231231
*/
232232
onMin(number) {
233-
if (this._isCallable(this.props.onMin)) {
233+
if (isCallable(this.props.onMin)) {
234234
this.props.onMin(number);
235235
}
236236
this._resetHoldTime();
@@ -241,7 +241,7 @@ class InputSpinner extends Component {
241241
* @param number
242242
*/
243243
onLongPress(number) {
244-
if (this._isCallable(this.props.onLongPress)) {
244+
if (isCallable(this.props.onLongPress)) {
245245
this.props.onLongPress(number);
246246
}
247247
}
@@ -301,7 +301,7 @@ class InputSpinner extends Component {
301301
num = parsedNum = null;
302302
}
303303

304-
if (this.state.value !== num && this._isCallable(this.props.onChange)) {
304+
if (this.state.value !== num && isCallable(this.props.onChange)) {
305305
const res = await this.props.onChange(parsedNum);
306306
if (!isEmptyValue) {
307307
if (res === false) {
@@ -348,7 +348,7 @@ class InputSpinner extends Component {
348348
* @param e
349349
*/
350350
onSubmit(e) {
351-
if (this._isCallable(this.props.onSubmit)) {
351+
if (isCallable(this.props.onSubmit)) {
352352
this.props.onSubmit(this._parseNum(e.nativeEvent.text));
353353
}
354354
}
@@ -748,19 +748,6 @@ class InputSpinner extends Component {
748748
this.textInput.clear();
749749
}
750750

751-
/**
752-
* Is variable callable
753-
* @private
754-
* @param callback
755-
* @returns {boolean}
756-
*/
757-
_isCallable(callback) {
758-
return (
759-
callback != null &&
760-
(callback instanceof Function || typeof callback === "function")
761-
);
762-
}
763-
764751
/**
765752
* Is text input editable
766753
* @returns {boolean|Boolean}
@@ -945,12 +932,13 @@ class InputSpinner extends Component {
945932
* @private
946933
*/
947934
_getContainerStyle() {
935+
const backgroundColor = this.props.colorAsBackground ? this._getColor() : this.props.background;
948936
return [
949937
Style.container,
950938
{
951939
minHeight: this.props.height,
952940
width: this.props.width,
953-
backgroundColor: this.props.background,
941+
backgroundColor: backgroundColor,
954942
},
955943
this.props.showBorder
956944
? {borderWidth: 0.5, borderColor: this._getColor()}
@@ -1239,6 +1227,7 @@ InputSpinner.propTypes = {
12391227
colorLeft: PropTypes.string,
12401228
colorMax: PropTypes.string,
12411229
colorMin: PropTypes.string,
1230+
colorAsBackground: PropTypes.bool,
12421231
background: PropTypes.string,
12431232
textColor: PropTypes.string,
12441233
arrows: PropTypes.bool,
@@ -1333,6 +1322,7 @@ InputSpinner.defaultProps = {
13331322
colorPress: defaultColor,
13341323
colorRight: defaultColor,
13351324
colorLeft: defaultColor,
1325+
colorAsBackground: false,
13361326
background: "transparent",
13371327
textColor: "#000000",
13381328
arrows: false,

src/Utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ export const isEmpty = (x) => {
2929
return false;
3030
};
3131

32+
/**
33+
* Is variable callable
34+
* @private
35+
* @param callback
36+
* @returns {boolean}
37+
*/
38+
export const isCallable = (callback) => {
39+
return (
40+
callback != null &&
41+
(callback instanceof Function || typeof callback === "function")
42+
);
43+
};
44+
3245
/**
3346
* Debounce
3447
* @param callback

src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface ReactNativeInputSpinnerProps {
2020
colorLeft?: string;
2121
colorMax?: string;
2222
colorMin?: string;
23+
colorAsBackground?: boolean;
2324
background?: string;
2425
textColor?: string;
2526
arrows?: boolean;

src/skins/CleanSkin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const getProps = (props) => {
77
return {
88
shadow: props.shadow ? props.shadow : true,
99
color: backgroundFallback,
10-
background: props.background ? props.background : backgroundFallback,
10+
colorAsBackground: true,
1111
buttonTextColor: props.buttonTextColor
1212
? props.buttonTextColor
1313
: colorFallback,

src/skins/RoundSkin.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import React from "react";
2-
import {defaultColor} from "../Style";
32
import {mergeViewStyle} from "../Utils";
43

54
export const getProps = (props) => {
65
return {
76
shadow: props.shadow ? props.shadow : true,
8-
background: props.color ? props.color : defaultColor,
7+
colorAsBackground: true,
98
buttonPressTextColor: props.buttonPressTextColor
109
? props.buttonPressTextColor
1110
: "#EEE",

0 commit comments

Comments
 (0)