Skip to content

Commit

Permalink
feat(CascadePicker): Compatible with iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
lulutia committed Mar 27, 2017
1 parent 90d1ee7 commit 2bd28b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
13 changes: 11 additions & 2 deletions app/pickerLogic/cascadePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class CascadePicker extends Component {
this.state.animatedHeight = new Animated.Value(height);

this.choseNumber = [];
this.choseValue = [];
}

componentDidMount(){
Expand Down Expand Up @@ -141,6 +142,8 @@ class CascadePicker extends Component {
*/
_cancelChose(){
this.choseNumber = this.beforeOpe.slice();
this.choseValue = this.beforeValue.slice();

this._setModalVisible(false,'cancel');
}

Expand All @@ -153,6 +156,8 @@ class CascadePicker extends Component {
if (this.props.enable){
this.beforeData = this.props.data.slice();
this.beforeOpe = this.choseNumber.slice();
this.beforeValue = this.choseValue.slice();

this._setModalVisible(true);
} else {
this.state.visible = false;
Expand Down Expand Up @@ -213,8 +218,12 @@ class CascadePicker extends Component {
_changeLayout(value,index, wheelNumber){
this.choseNumber[wheelNumber] = index;
this.choseNumber.length = (wheelNumber + 1);
this.choseValue[wheelNumber] = value;
this.choseValue.length = (wheelNumber + 1);
if (Platform.OS === 'ios') {
this.forceUpdate();
}
this.props.onWheelChange && this.props.onWheelChange(value, index, wheelNumber);
console.debug(value, index, wheelNumber);
}

_handleData() {
Expand Down Expand Up @@ -242,7 +251,6 @@ class CascadePicker extends Component {
let that = this;

this._handleData();
console.debug(this.props.data);
return (
<View style={styles.container}>
<Modal
Expand Down Expand Up @@ -278,6 +286,7 @@ class CascadePicker extends Component {
data = {that.passData[index]}
passData = {that.passData}
selectedIndex = {that.choseNumber[index]}
selectedValue = {that.choseValue[index]}
onValueChange={(newValue, newIndex) => {
that._changeLayout(newValue,newIndex, index);}}
>
Expand Down
12 changes: 7 additions & 5 deletions index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class TpickerEx extends Component {

_getLevel() {
let that = this;
fetch('http://10.5.234.227:8282/crm/app/category/r/list?parentId=0&bdId=2020529&ua=20200_android&token=623b9e9f6ae38444e945ae53ced523efefed447b3c4c610af6d94d47469cf37f48d192760aef1cc66b06a2e648fa5dcabefe4ff9fafde8fc6d0b275dc76a8ea750a350c95091f814009e635c84fd78f58eadfef564b26c6e3cb223564577486a')
fetch('http://10.5.236.249:8282/crm/app/category/r/list?parentId=0&ua=20200_android&token=716f9d734ba5ee52b11b2088f43e6fcba85f005f6e57066840de2d63d58cc5b948d192760aef1cc66b06a2e648fa5dca965014e78c59985f600ee67b33261fcf2c546b6518e5fb436cf4428ecdb9d5c6c7a2214ccb3b91cbaef7a0951d603648')
.then((res) => {
return res.json();
}).then((data) => {
Expand All @@ -218,7 +218,7 @@ class TpickerEx extends Component {
return;
}
console.debug(cateMap[index - 1]);
let url = 'http://10.5.234.227:8282/crm/app/category/r/list?parentId=' + cateMap[index - 1] + '&bdId=2020529&ua=20200_android&token=623b9e9f6ae38444e945ae53ced523efefed447b3c4c610af6d94d47469cf37f48d192760aef1cc66b06a2e648fa5dcabefe4ff9fafde8fc6d0b275dc76a8ea750a350c95091f814009e635c84fd78f58eadfef564b26c6e3cb223564577486a';
let url = 'http://10.5.236.249:8282/crm/app/category/r/list?parentId=' + cateMap[index - 1] + '&ua=20200_android&token=716f9d734ba5ee52b11b2088f43e6fcba85f005f6e57066840de2d63d58cc5b948d192760aef1cc66b06a2e648fa5dca965014e78c59985f600ee67b33261fcf2c546b6518e5fb436cf4428ecdb9d5c6c7a2214ccb3b91cbaef7a0951d603648';
fetch(url)
.then((res) => {
return res.json();
Expand All @@ -230,6 +230,7 @@ class TpickerEx extends Component {

_getLevel3(value, index, wheelNumber) {
let that = this;
console.debug('trigger');
let cateMap = [10003,10002,10004,10000,10005,10001,10006,10007,10008,10009];
if (wheelNumber === 0) {
if (index === 0) {
Expand All @@ -239,7 +240,7 @@ class TpickerEx extends Component {
return;
}
console.debug(cateMap[index - 1]);
let url = 'http://10.5.234.227:8282/crm/app/category/r/list?parentId=' + cateMap[index - 1] + '&bdId=2020529&ua=20200_android&token=623b9e9f6ae38444e945ae53ced523efefed447b3c4c610af6d94d47469cf37f48d192760aef1cc66b06a2e648fa5dcabefe4ff9fafde8fc6d0b275dc76a8ea750a350c95091f814009e635c84fd78f58eadfef564b26c6e3cb223564577486a';
let url = 'http://10.5.236.249:8282/crm/app/category/r/list?parentId=' + cateMap[index - 1] + '&ua=20200_android&token=716f9d734ba5ee52b11b2088f43e6fcba85f005f6e57066840de2d63d58cc5b948d192760aef1cc66b06a2e648fa5dca965014e78c59985f600ee67b33261fcf2c546b6518e5fb436cf4428ecdb9d5c6c7a2214ccb3b91cbaef7a0951d603648';
fetch(url)
.then((res) => {
return res.json();
Expand All @@ -255,7 +256,7 @@ class TpickerEx extends Component {
this.forceUpdate();
return;
}
let url = 'http://10.5.234.227:8282/crm/app/category/r/list?parentId=' + cateMap[index - 1] + '&bdId=2020529&ua=20200_android&token=623b9e9f6ae38444e945ae53ced523efefed447b3c4c610af6d94d47469cf37f48d192760aef1cc66b06a2e648fa5dcabefe4ff9fafde8fc6d0b275dc76a8ea750a350c95091f814009e635c84fd78f58eadfef564b26c6e3cb223564577486a';
let url = 'http://10.5.236.249:8282/crm/app/category/r/list?parentId=' + cateMap[index - 1] + '&ua=20200_android&token=716f9d734ba5ee52b11b2088f43e6fcba85f005f6e57066840de2d63d58cc5b948d192760aef1cc66b06a2e648fa5dca965014e78c59985f600ee67b33261fcf2c546b6518e5fb436cf4428ecdb9d5c6c7a2214ccb3b91cbaef7a0951d603648';
fetch(url)
.then((res) => {
return res.json();
Expand Down Expand Up @@ -295,7 +296,7 @@ class TpickerEx extends Component {
<Text style={{color:'#fff'}}>获取数据</Text>
</View>
</TouchableWithoutFeedback>
<View>
{/* <View>
<Text style={styles.demoValue}>Basic Picker value: {this.state.str1}</Text>
<Test3
inputValue ={this.state.str1}
Expand Down Expand Up @@ -356,6 +357,7 @@ class TpickerEx extends Component {
onCancel = {() => {this.state.Cdata[1] = [];}}
/>
</View>
*/}
<View>
<Text style={styles.demoValue}>Cascade Picker value: {this.state.str4}</Text>
<CascadePicker
Expand Down

0 comments on commit 2bd28b8

Please sign in to comment.