Skip to content

Commit 9bdf6fc

Browse files
committed
Fix network image sources; Fix style with network image src; Add props to network height and width; Update example to include network images
1 parent 557e3dc commit 9bdf6fc

File tree

3 files changed

+59
-25
lines changed

3 files changed

+59
-25
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
A super simple react-native implementation of the classic UIStepper from iOS. Check out the props below for customization.
1111

1212
### Installation
13-
```
14-
npm i react-native-simple-stepper --save
13+
```npm i react-native-simple-stepper --save```
1514

16-
```
1715
### Usage
1816
```javascript
1917
import SimpleStepper from 'react-native-simple-stepper'
@@ -24,7 +22,7 @@ render() {
2422
)
2523
}
2624
valueChanged(value) {
27-
// Update UI ...
25+
// ...
2826
}
2927
//...
3028
```
@@ -50,3 +48,5 @@ valueChanged(value) {
5048
| ```decrementImage``` | String or Number | network or local image | require('./assets/decrement.png')
5149
| ```tintOnIncrementImage``` | Boolean | whether or not you want tintColor applied to increment image | true
5250
| ```tintOnDecrementImage``` | Boolean | whether or not you want tintColor applied to decrement image | true
51+
| ```imageHeight``` | Number | network image height | 36
52+
| ```imageWidth``` | Number | network image width | 36

SimpleStepper.js

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export default class SimpleStepper extends Component {
1414
valueChanged: PropTypes.func,
1515
tintOnIncrementImage: PropTypes.bool,
1616
tintOnDecrementImage: PropTypes.bool,
17+
imageHeight: PropTypes.number,
18+
imageWidth: PropTypes.number,
1719
incrementImage: PropTypes.oneOfType([
1820
PropTypes.string,
1921
PropTypes.number
@@ -36,7 +38,9 @@ export default class SimpleStepper extends Component {
3638
incrementImage: require('./assets/increment.png'),
3739
tintOnIncrementImage: true,
3840
tintOnDecrementImage: true,
39-
padding: 4
41+
padding: 4,
42+
imageHeight: 36,
43+
imageWidth: 36
4044
}
4145
constructor(props) {
4246
super(props)
@@ -100,22 +104,38 @@ export default class SimpleStepper extends Component {
100104
this.props.valueChanged(value)
101105
}
102106
}
103-
render() {
104-
var tintIncrementStyle
105-
var tintDecrementStyle
106-
if (this.props.tintOnIncrementImage) {
107-
tintIncrementStyle = {tintColor: this.props.tintColor}
107+
tintStyle(status) {
108+
if (status) {
109+
return {tintColor: this.props.tintColor}
110+
}
111+
return null
112+
}
113+
imageSrc(src) {
114+
if (typeof src == 'string') {
115+
return {'uri': src}
108116
}
109-
if (this.props.tintOnDecrementImage) {
110-
tintDecrementStyle = {tintColor: this.props.tintColor}
117+
return src
118+
}
119+
imageStyle(src) {
120+
if (typeof src == 'string') {
121+
return {width: this.props.imageWidth, height: this.props.imageHeight}
111122
}
123+
return null
124+
}
125+
render() {
126+
var tintIncrementStyle = this.tintStyle(this.props.tintOnIncrementImage)
127+
var tintDecrementStyle = this.tintStyle(this.props.tintOnDecrementImage)
128+
var decrementImageSrc = this.imageSrc(this.props.decrementImage)
129+
var incrementImageSrc = this.imageSrc(this.props.incrementImage)
130+
var incrementStyle = this.imageStyle(this.props.incrementImage)
131+
var decrementStyle = this.imageStyle(this.props.decrementImage)
112132
return (
113133
<View style={[styles.container, {backgroundColor: this.props.backgroundColor, borderColor: this.props.tintColor}]}>
114134
<TouchableHighlight style={[styles.leftButton, {opacity: this.state.decrementOpacity, borderColor: this.props.tintColor, padding: this.props.padding}]} underlayColor={this.props.underlayColor} onPress={this.decrementAction} disabled={this.state.hasReachedMin}>
115-
<Image style={tintDecrementStyle} source={this.props.decrementImage} resizeMode="contain" />
135+
<Image style={[decrementStyle, tintDecrementStyle]} source={decrementImageSrc} />
116136
</TouchableHighlight>
117137
<TouchableHighlight style={[styles.rightButton, {opacity: this.state.incrementOpacity, borderColor: this.props.tintColor, padding: this.props.padding}]} underlayColor={this.props.underlayColor} onPress={this.incrementAction} disabled={this.state.hasReachedMax}>
118-
<Image style={tintIncrementStyle} source={this.props.incrementImage} resizeMode="contain" />
138+
<Image style={[incrementStyle, tintIncrementStyle]} source={incrementImageSrc} />
119139
</TouchableHighlight>
120140
</View>
121141
)
@@ -128,7 +148,8 @@ var styles = StyleSheet.create({
128148
justifyContent: 'center',
129149
borderWidth: 1,
130150
borderRadius: 3,
131-
overflow: 'hidden'
151+
overflow: 'hidden',
152+
alignItems: 'center'
132153
},
133154
leftButton: {
134155
alignItems: 'center'

example/Main.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,34 @@ export default class Main extends Component {
1414
this.state = {
1515
blue: 0,
1616
peru: 0,
17-
red: 0
17+
red: 0,
18+
purple: 0
1819
}
19-
this.valueChangedBlue = this.valueChangedBlue.bind(this)
20-
this.valueChangedPeru = this.valueChangedPeru.bind(this)
21-
this.valueChangedRed = this.valueChangedRed.bind(this)
2220
}
2321
render() {
2422
return (
2523
<ScrollView contentContainerStyle={styles.container}>
2624
<Text style={[styles.text, {fontSize: 22}]}>{'Simple Stepper'}</Text>
2725
<View style={{flexDirection: 'column', alignItems: 'center'}}>
2826
<Text style={[styles.text, {fontSize: 32, color: 'blue'}]}>{this.state.blue}</Text>
29-
<SimpleStepper valueChanged={this.valueChangedBlue} />
30-
<Text style={styles.text}> {'\n'}{'min 0, max 10, initialValue is 0 and stepValue is 1'}{'\n'} </Text>
27+
<SimpleStepper valueChanged={(value) => this.valueChangedBlue(value)} />
28+
<Text style={styles.text}>{'min 0, max 10, initialValue is 0 and stepValue is 1'}{'\n'} </Text>
3129
<Text style={[styles.text, {fontSize: 32, color: 'peru'}]}>{this.state.peru}</Text>
32-
<SimpleStepper valueChanged={this.valueChangedPeru} tintColor={'peru'} maximumValue={15} initialValue={.99} stepValue={.99}/>
33-
<Text style={styles.text}> {'\n'}{'min is 0, max is 15, initialValue is .99 and stepValue is .99'}{'\n'} </Text>
30+
<SimpleStepper valueChanged={(value) => this.valueChangedPeru(value)} tintColor={'peru'} maximumValue={15} initialValue={.99} stepValue={.99}/>
31+
<Text style={styles.text}>{'min is 0, max is 15, initialValue is .99 and stepValue is .99'}{'\n'} </Text>
3432
<Text style={[styles.text, {fontSize: 32, color: '#cc3232'}]}>{this.state.red}</Text>
35-
<SimpleStepper valueChanged={this.valueChangedRed} tintColor={'#cc3232'} minimumValue={-100} maximumValue={100} initialValue={50} stepValue={25} />
36-
<Text style={styles.text}> {'\n'}{'min is -100, max is 100, initialValue is 50 and stepValue is 25'}{'\n'} </Text>
33+
<SimpleStepper valueChanged={(value) => this.valueChangedRed(value)} tintColor={'#cc3232'} minimumValue={-100} maximumValue={100} initialValue={50} stepValue={25} />
34+
<Text style={styles.text}>{'min is -100, max is 100, initialValue is 50 and stepValue is 25'}{'\n'} </Text>
35+
<Text style={[styles.text, {fontSize: 32, color: 'purple'}]}>{this.state.purple}</Text>
36+
<SimpleStepper
37+
tintColor={'purple'}
38+
valueChanged={(value) => this.valueChangedPurple(value)}
39+
tintOnIncrementImage={false}
40+
tintOnDecrementImage={false}
41+
incrementImage={'https://facebook.github.io/react/img/logo_og.png'}
42+
decrementImage={'https://facebook.github.io/react/img/logo_og.png'}
43+
/>
44+
<Text style={styles.text}>{'min 0, max 10, initialValue is 0 and stepValue is 1'}{'\n'} </Text>
3745
</View>
3846
</ScrollView>
3947
);
@@ -53,6 +61,11 @@ export default class Main extends Component {
5361
red: value
5462
})
5563
}
64+
valueChangedPurple(value) {
65+
this.setState({
66+
purple: value
67+
})
68+
}
5669
}
5770

5871
const styles = StyleSheet.create({

0 commit comments

Comments
 (0)