Skip to content

Commit 727a6d1

Browse files
committed
Add "setDisable()" method. #2
1 parent 581d281 commit 727a6d1

File tree

3 files changed

+65
-15
lines changed

3 files changed

+65
-15
lines changed

Diff for: MultiSlider.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class MultiSlider extends Component {
4343
height: 0
4444
},
4545

46+
disabled: false,
4647
leftValue: new Animated.Value(this.props.leftValue),
4748
rightValue: new Animated.Value(this.props.rightValue),
4849
};
@@ -91,7 +92,6 @@ class MultiSlider extends Component {
9192
}
9293

9394
componentWillMount() {
94-
9595
// gesture func of left thumb
9696
this._leftPanResponder = PanResponder.create({
9797
onStartShouldSetPanResponder: (evt, gestureState) => this._handleStartShouldSetPanResponder (evt, gestureState),
@@ -115,7 +115,16 @@ class MultiSlider extends Component {
115115
});
116116
}
117117

118+
// Sets whether the slider can slide, and true is disabled
119+
setDisable(flag) {
120+
this.setState({
121+
disabled: flag,
122+
});
123+
}
124+
118125
render() {
126+
console.log('=========================');
127+
console.log(this.state.disabled);
119128
const {
120129
minValue,
121130
maxValue,
@@ -217,6 +226,13 @@ class MultiSlider extends Component {
217226
rightValue,
218227
} = this.state;
219228

229+
if (this.state.disabled) {
230+
console.log('------------------00001');
231+
return;
232+
}
233+
console.log('------------------111111111');
234+
235+
220236
let nextX = this._getValue(gestureState.dx);
221237

222238
if (currentThumb === 'left' && (rightValue._value - nextX) > this.props.minSpace) {

Diff for: index.android.js

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
/**
2-
* Sample React Native App
3-
* https://github.com/facebook/react-native
4-
* @flow
5-
*/
6-
71
import React, { Component } from 'react';
82
import {
93
AppRegistry,
104
StyleSheet,
115
Text,
12-
View
6+
View,
7+
TouchableOpacity
138
} from 'react-native';
149

1510
import MultiSliders from './MultiSlider'
@@ -28,6 +23,7 @@ class MultiSlider extends Component {
2823
<View style = {{flex: 1, backgroundColor: 'white'}}>
2924
<View style = {styles.container}>
3025
<MultiSliders
26+
ref = {(ms) => {this._ms = ms }}
3127
trackWidth = {300}
3228
defaultTrackColor = {'#e3e3e3'}
3329
leftThumbColor = {'red'}
@@ -39,16 +35,37 @@ class MultiSlider extends Component {
3935
onRightValueChange = {(rightValue) => this.setState({rightValue})}
4036
/>
4137
</View>
38+
<TouchableOpacity onPress = {() => this.onPress(true)}>
39+
<View style = {styles.button}>
40+
<Text>Click to disable</Text>
41+
</View>
42+
</TouchableOpacity>
43+
<TouchableOpacity onPress = {() => this.onPress(false)}>
44+
<View style = {styles.button}>
45+
<Text>Click to able</Text>
46+
</View>
47+
</TouchableOpacity>
4248
</View>
4349
);
4450
}
51+
52+
onPress(flag) {
53+
this._ms.setDisable(flag)
54+
}
4555
}
4656

4757
const styles = StyleSheet.create({
4858
container: {
4959
alignItems: 'center',
5060
marginTop: 50,
5161
},
62+
63+
button: {
64+
alignItems: 'center',
65+
padding: 20,
66+
marginHorizontal: 10,
67+
marginVertical: 5,
68+
}
5269
});
5370

5471
AppRegistry.registerComponent('MultiSlider', () => MultiSlider);

Diff for: index.ios.js

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
/**
2-
* Sample React Native App
3-
* https://github.com/facebook/react-native
4-
* @flow
5-
*/
6-
71
import React, { Component } from 'react';
82
import {
93
AppRegistry,
104
StyleSheet,
115
Text,
12-
View
6+
View,
7+
TouchableOpacity
138
} from 'react-native';
149

1510
import MultiSliders from './MultiSlider'
@@ -28,6 +23,7 @@ class MultiSlider extends Component {
2823
<View style = {{flex: 1, backgroundColor: 'white'}}>
2924
<View style = {styles.container}>
3025
<MultiSliders
26+
ref = {(ms) => {this._ms = ms }}
3127
trackWidth = {300}
3228
defaultTrackColor = {'#e3e3e3'}
3329
leftThumbColor = {'red'}
@@ -39,16 +35,37 @@ class MultiSlider extends Component {
3935
onRightValueChange = {(rightValue) => this.setState({rightValue})}
4036
/>
4137
</View>
38+
<TouchableOpacity onPress = {() => this.onPress(true)}>
39+
<View style = {styles.button}>
40+
<Text>Click to disable</Text>
41+
</View>
42+
</TouchableOpacity>
43+
<TouchableOpacity onPress = {() => this.onPress(false)}>
44+
<View style = {styles.button}>
45+
<Text>Click to able</Text>
46+
</View>
47+
</TouchableOpacity>
4248
</View>
4349
);
4450
}
51+
52+
onPress(flag) {
53+
this._ms.setDisable(flag)
54+
}
4555
}
4656

4757
const styles = StyleSheet.create({
4858
container: {
4959
alignItems: 'center',
5060
marginTop: 50,
5161
},
62+
63+
button: {
64+
alignItems: 'center',
65+
padding: 20,
66+
marginHorizontal: 10,
67+
marginVertical: 5,
68+
}
5269
});
5370

5471
AppRegistry.registerComponent('MultiSlider', () => MultiSlider);

0 commit comments

Comments
 (0)