Skip to content

Commit d3e2ff8

Browse files
committed
feat(CascadePicker): limit the Android picker to one line
1 parent 49c939c commit d3e2ff8

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

app/pickerLogic/cascadePicker.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ class CascadePicker extends Component {
277277
{that.passData && that.passData.map((item,index) =>{
278278
if (this.props.loading[index]) {
279279
return (
280-
<View key={index} style={[{flex: 1, alignItems: 'center', backgroundColor: 'red', borderWidth:0}, Platform.OS !== 'ios' && {justifyContent: 'center'}]}>
281-
{Platform.OS === 'ios' && <View style={{position: 'absolute', width: 501, height: 35, borderTopWidth: 0.5, borderBottomWidth: 0.5, borderColor: '#ddd', marginTop: 90.5, borderLeftWidth: 0}} />}
280+
<View key={index} style={[{flex: 1, alignItems: 'center', borderWidth:0}, Platform.OS !== 'ios' && {justifyContent: 'center'}]}>
281+
{Platform.OS === 'ios' && <View style={{position: 'absolute', width: 500, height: 36, borderTopWidth: 1, borderBottomWidth: 1, borderColor: '#ddd', marginTop: 90}} />}
282282
<ActivityIndicator
283283
animating={true}
284284
size="small"
@@ -287,6 +287,7 @@ class CascadePicker extends Component {
287287
</View>
288288
);
289289
}
290+
console.debug(index);
290291
return (
291292
<PickRoll
292293
itemStyle={{fontSize: 16}}

app/pickerLogic/cascadeRoll.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class Pickroll extends Component {
9090
middleItems[index + 2] = <View style={rollStyles.textContainer} key={'mid' + (index + 2)}><Animated.Text
9191
className={'mid' + (index + 2)}
9292
onPress={() => {this._moveTo(index + 2);}}
93+
numberOfLines={1}
9394
style={[rollStyles.middleText, this.props.itemStyle,
9495
{
9596
// todo: when add fontSize, the shaking is too obvious

index.android.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,42 +250,63 @@ class TpickerEx extends Component {
250250
if (index === 0) {
251251
that.state.Cdata1[1] = [];
252252
that.state.Cdata1[2] = [];
253+
that.state.Cdata1[3] = [];
253254
this.forceUpdate();
254255
return;
255256
}
256257
console.debug(cateMap[index - 1]);
257258
let url = ip + cateMap[index - 1];
258-
this.setState({loadingState: [false, true, true]});
259+
this.setState({loadingState: [false, true, true, true]});
259260
fetch(url)
260261
.then((res) => {
261262
return res.json();
262263
}).then((data) => {
263264
that.state.Cdata1[1] = data.data;
264265
that.state.Cdata1[2] = [];
265-
this.state.loadingState = [false, false, false];
266+
that.state.Cdata1[3] = [];
267+
this.state.loadingState = [false, false, false, false];
266268
this.forceUpdate();
267269
});
268270
}
269271
if (wheelNumber === 1) {
270272
if (index === 0) {
271273
that.state.Cdata1[2] = [];
274+
that.state.Cdata1[3] = [];
272275
this.forceUpdate();
273276
return;
274277
}
275278
let url = ip + cateMap[index - 1];
276-
this.setState({loadingState: [false, false, true]});
279+
this.setState({loadingState: [false, false, true, true]});
277280
fetch(url)
278281
.then((res) => {
279282
return res.json();
280283
}).then((data) => {
281284
that.state.Cdata1[2] = data.data;
282-
this.state.loadingState = [false, false, false];
285+
that.state.Cdata1[3] = [];
286+
this.state.loadingState = [false, false, false, false];
287+
this.forceUpdate();
288+
});
289+
}
290+
if (wheelNumber === 2) {
291+
if (index === 0) {
292+
that.state.Cdata1[3] = [];
293+
this.forceUpdate();
294+
return;
295+
}
296+
let url = ip + cateMap[index - 1];
297+
this.setState({loadingState: [false, false, false, true]});
298+
fetch(url)
299+
.then((res) => {
300+
return res.json();
301+
}).then((data) => {
302+
that.state.Cdata1[3] = data.data;
303+
this.state.loadingState = [false, false, false, false];
283304
this.forceUpdate();
284305
});
285306
}
286307
}
287308
_handle(level, data) {
288-
this.setState({Cdata1: [data,[],[]]});
309+
this.setState({Cdata1: [data,[],[],[]]});
289310
}
290311
_handle2(level, data, index) {
291312
this.state.Cdata[1] = data;
@@ -384,7 +405,7 @@ class TpickerEx extends Component {
384405
<Text style={styles.demoValue}>Cascade Picker value: {this.state.str4}</Text>
385406
<CascadePicker
386407
inputValue = {this.state.str5}
387-
level = {3}
408+
level = {4}
388409
selectedValue ={this.state.choseValue}
389410
data = {this.state.Cdata1}
390411
onWheelChange={(value, index, wheelNumber) => {this._getLevel3(value, index, wheelNumber);}}

0 commit comments

Comments
 (0)