Commit f807257e authored by xwenliang's avatar xwenliang

new feature wheelFlex and fix #79

parent cf10cc34
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
|pickerTitleColor | |array |[20, 20, 20, 1]) | |pickerTitleColor | |array |[20, 20, 20, 1]) |
|pickerToolBarBg | |array |[232, 232, 232, 1] | |pickerToolBarBg | |array |[232, 232, 232, 1] |
|pickerBg | |array |[196, 199, 206, 1] | |pickerBg | |array |[196, 199, 206, 1] |
|wheelFlex | |array |[2, 1, 1] |
|pickerData | |array | | |pickerData | |array | |
|selectedValue | |array | | |selectedValue | |array | |
|onPickerConfirm | |function| | |onPickerConfirm | |function| |
......
...@@ -14,7 +14,7 @@ import java.util.Arrays; ...@@ -14,7 +14,7 @@ import java.util.Arrays;
/** /**
* Created by heng on 16/9/6. * Created by heng on 16/9/6.
* * <p>
* Edited by heng on 16/10/09: * Edited by heng on 16/10/09:
* 修复滚动后返回值错误的bug * 修复滚动后返回值错误的bug
*/ */
...@@ -25,6 +25,8 @@ public class PickerViewAlone extends LinearLayout { ...@@ -25,6 +25,8 @@ public class PickerViewAlone extends LinearLayout {
private OnSelectedListener onSelectedListener; private OnSelectedListener onSelectedListener;
private ArrayList<String> curSelectedList;
public PickerViewAlone(Context context) { public PickerViewAlone(Context context) {
super(context); super(context);
init(context); init(context);
...@@ -44,10 +46,11 @@ public class PickerViewAlone extends LinearLayout { ...@@ -44,10 +46,11 @@ public class PickerViewAlone extends LinearLayout {
this.onSelectedListener = listener; this.onSelectedListener = listener;
} }
public void setPickerData(ReadableArray array, final ArrayList<String> curSelectedList) { public void setPickerData(ReadableArray array, double[] weights) {
curSelectedList = new ArrayList<>();
switch (array.getType(0).name()) { switch (array.getType(0).name()) {
case "Array": case "Array":
setMultipleData(array, curSelectedList); setMultipleData(array, curSelectedList, weights);
break; break;
default: default:
setAloneData(array, curSelectedList); setAloneData(array, curSelectedList);
...@@ -55,6 +58,10 @@ public class PickerViewAlone extends LinearLayout { ...@@ -55,6 +58,10 @@ public class PickerViewAlone extends LinearLayout {
} }
} }
public ArrayList<String> getSelectedData(){
return this.curSelectedList;
}
private void setAloneData(ReadableArray array, final ArrayList<String> curSelectedList) { private void setAloneData(ReadableArray array, final ArrayList<String> curSelectedList) {
ArrayList<String> values = arrayToList(array); ArrayList<String> values = arrayToList(array);
final LoopView loopView = new LoopView(getContext()); final LoopView loopView = new LoopView(getContext());
...@@ -81,7 +88,7 @@ public class PickerViewAlone extends LinearLayout { ...@@ -81,7 +88,7 @@ public class PickerViewAlone extends LinearLayout {
pickerViewAloneLayout.addView(loopView); pickerViewAloneLayout.addView(loopView);
} }
private void setMultipleData(ReadableArray array, final ArrayList<String> curSelectedList) { private void setMultipleData(ReadableArray array, final ArrayList<String> curSelectedList, double[] weights) {
final String[] selectedItems = new String[array.size()]; final String[] selectedItems = new String[array.size()];
for (int i = 0; i < array.size(); i++) { for (int i = 0; i < array.size(); i++) {
switch (array.getType(i).name()) { switch (array.getType(i).name()) {
...@@ -89,9 +96,16 @@ public class PickerViewAlone extends LinearLayout { ...@@ -89,9 +96,16 @@ public class PickerViewAlone extends LinearLayout {
ReadableArray childArray = array.getArray(i); ReadableArray childArray = array.getArray(i);
ArrayList<String> values = arrayToList(childArray); ArrayList<String> values = arrayToList(childArray);
final LoopView loopView = new LoopView(getContext()); final LoopView loopView = new LoopView(getContext());
LayoutParams params = new LayoutParams( LayoutParams params = new LayoutParams(0, LayoutParams.MATCH_PARENT);
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); if (weights != null) {
params.weight = 1.0f; if (i < weights.length) {
params.weight = (float) weights[i];
} else {
params.weight = 1.0f;
}
} else {
params.weight = 1.0f;
}
loopView.setLayoutParams(params); loopView.setLayoutParams(params);
loopView.setItems(values); loopView.setItems(values);
loopView.setTag(i); loopView.setTag(i);
...@@ -130,7 +144,7 @@ public class PickerViewAlone extends LinearLayout { ...@@ -130,7 +144,7 @@ public class PickerViewAlone extends LinearLayout {
} }
} }
public void setSelectValue(String[] selectValue, final ArrayList<String> curSelectedList) { public void setSelectValue(String[] selectValue) {
int viewCount = pickerViewAloneLayout.getChildCount(); int viewCount = pickerViewAloneLayout.getChildCount();
int valueCount = selectValue.length; int valueCount = selectValue.length;
if (valueCount <= viewCount) { if (valueCount <= viewCount) {
......
...@@ -77,6 +77,8 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -77,6 +77,8 @@ public class PickerViewLinkage extends LinearLayout {
private int selectOneIndex; private int selectOneIndex;
private int selectTwoIndex; private int selectTwoIndex;
private ArrayList<String> curSelectedList;
private void checkItems(LoopView loopView, ArrayList<String> list) { private void checkItems(LoopView loopView, ArrayList<String> list) {
if (list != null && list.size() > 0) { if (list != null && list.size() > 0) {
loopView.setItems(list); loopView.setItems(list);
...@@ -84,11 +86,57 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -84,11 +86,57 @@ public class PickerViewLinkage extends LinearLayout {
} }
} }
private void setWeights(double[] weights) {
LayoutParams paramsOne = new LayoutParams(0, LayoutParams.MATCH_PARENT);
LayoutParams paramsTwo = new LayoutParams(0, LayoutParams.MATCH_PARENT);
LayoutParams paramsThree = new LayoutParams(0, LayoutParams.MATCH_PARENT);
switch (curRow) {
case 2:
switch (weights.length) {
case 1:
paramsOne.weight = (float) weights[0];
paramsTwo.weight = 1.0f;
break;
default:
paramsOne.weight = (float) weights[0];
paramsTwo.weight = (float) weights[1];
break;
}
loopViewOne.setLayoutParams(paramsOne);
loopViewTwo.setLayoutParams(paramsTwo);
break;
case 3:
switch (weights.length) {
case 1:
paramsOne.weight = (float) weights[0];
paramsTwo.weight = 1.0f;
paramsThree.weight = 1.0f;
break;
case 2:
paramsOne.weight = (float) weights[0];
paramsTwo.weight = (float) weights[1];
paramsThree.weight = 1.0f;
break;
default:
paramsOne.weight = (float) weights[0];
paramsTwo.weight = (float) weights[1];
paramsThree.weight = (float) weights[2];
break;
}
loopViewOne.setLayoutParams(paramsOne);
loopViewTwo.setLayoutParams(paramsTwo);
loopViewThree.setLayoutParams(paramsThree);
break;
}
}
/** /**
* ReadableArray getMap will remove the item. * ReadableArray getMap will remove the item.
* <a href="https://github.com/facebook/react-native/issues/8557"></a> * <a href="https://github.com/facebook/react-native/issues/8557"></a>
* */ */
public void setPickerData(ReadableArray array, final ArrayList<String> curSelectedList) { public void setPickerData(ReadableArray array, double[] weights) {
curSelectedList = new ArrayList<>();
oneList.clear(); oneList.clear();
for (int i = 0; i < array.size(); i++) { for (int i = 0; i < array.size(); i++) {
ReadableMap map = array.getMap(i); ReadableMap map = array.getMap(i);
...@@ -235,6 +283,9 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -235,6 +283,9 @@ public class PickerViewLinkage extends LinearLayout {
} }
}); });
} }
if (weights != null) {
setWeights(weights);
}
} }
private ArrayList<String> arrayToList(ReadableArray array) { private ArrayList<String> arrayToList(ReadableArray array) {
...@@ -265,7 +316,7 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -265,7 +316,7 @@ public class PickerViewLinkage extends LinearLayout {
} }
} }
public void setSelectValue(String[] selectValue, final ArrayList<String> curSelectedList) { public void setSelectValue(String[] selectValue) {
if (curRow <= selectValue.length) { if (curRow <= selectValue.length) {
String[] values = Arrays.copyOf(selectValue, curRow); String[] values = Arrays.copyOf(selectValue, curRow);
selectValues(values, curSelectedList); selectValues(values, curSelectedList);
...@@ -275,7 +326,6 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -275,7 +326,6 @@ public class PickerViewLinkage extends LinearLayout {
selectOneLoop(selectValue, curSelectedList); selectOneLoop(selectValue, curSelectedList);
switch (curRow) { switch (curRow) {
case 3: case 3:
twoList.clear(); twoList.clear();
getTwoListData(); getTwoListData();
loopViewTwo.setItems(twoList); loopViewTwo.setItems(twoList);
...@@ -305,7 +355,7 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -305,7 +355,7 @@ public class PickerViewLinkage extends LinearLayout {
twoList.clear(); twoList.clear();
getTwoListData(); getTwoListData();
selectTwoLoop(selectValue,curSelectedList); selectTwoLoop(selectValue, curSelectedList);
threeList.clear(); threeList.clear();
...@@ -419,9 +469,8 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -419,9 +469,8 @@ public class PickerViewLinkage extends LinearLayout {
/** /**
* 获取第三个滚轮的值 * 获取第三个滚轮的值
* */ */
private void getThreeListData(){ private void getThreeListData() {
//{ NativeMap: {"b":[{"b1":[11,22,33,44]},{"b2":[55,66,77,88]},{"b3":[99,1010,1111,1212]}]} }
ReadableMap childMap = data.get(selectOneIndex).getArray(oneList.get(selectOneIndex)).getMap(selectTwoIndex); ReadableMap childMap = data.get(selectOneIndex).getArray(oneList.get(selectOneIndex)).getMap(selectTwoIndex);
String key = childMap.keySetIterator().nextKey(); String key = childMap.keySetIterator().nextKey();
ReadableArray sunArray = childMap.getArray(key); ReadableArray sunArray = childMap.getArray(key);
...@@ -446,10 +495,14 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -446,10 +495,14 @@ public class PickerViewLinkage extends LinearLayout {
} }
} }
public int getViewHeight (){ public int getViewHeight() {
return loopViewOne.getViewHeight(); return loopViewOne.getViewHeight();
} }
public ArrayList<String> getSelectedData(){
return this.curSelectedList;
}
public void setOnSelectListener(OnSelectedListener listener) { public void setOnSelectListener(OnSelectedListener listener) {
this.onSelectedListener = listener; this.onSelectedListener = listener;
} }
......
...@@ -59,6 +59,8 @@ typedef void(^backBolock)(NSDictionary * ); ...@@ -59,6 +59,8 @@ typedef void(^backBolock)(NSDictionary * );
@property(strong,nonatomic)NSArray *selectValueArry; @property(strong,nonatomic)NSArray *selectValueArry;
@property(strong,nonatomic)NSArray *weightArry;
//创建一个下角标记录是第几行 来一进来判断第一行被选中 当进来的是关联两行的逻辑的时候 或者三行关联的时候取第二行做记录 //创建一个下角标记录是第几行 来一进来判断第一行被选中 当进来的是关联两行的逻辑的时候 或者三行关联的时候取第二行做记录
@property(assign,nonatomic)NSInteger num; @property(assign,nonatomic)NSInteger num;
...@@ -69,7 +71,7 @@ typedef void(^backBolock)(NSDictionary * ); ...@@ -69,7 +71,7 @@ typedef void(^backBolock)(NSDictionary * );
-(instancetype)initWithFrame:(CGRect)frame dic:(NSDictionary *)dic leftStr:(NSString *)leftStr centerStr:(NSString *)centerStr rightStr:(NSString *)rightStr topbgColor:(NSArray *)topbgColor bottombgColor:(NSArray *)bottombgColor leftbtnbgColor:(NSArray *)leftbtnbgColor rightbtnbgColor:(NSArray *)rightbtnbgColor centerbtnColor:(NSArray *)centerbtnColor selectValueArry:(NSArray *)selectValueArry; -(instancetype)initWithFrame:(CGRect)frame dic:(NSDictionary *)dic leftStr:(NSString *)leftStr centerStr:(NSString *)centerStr rightStr:(NSString *)rightStr topbgColor:(NSArray *)topbgColor bottombgColor:(NSArray *)bottombgColor leftbtnbgColor:(NSArray *)leftbtnbgColor rightbtnbgColor:(NSArray *)rightbtnbgColor centerbtnColor:(NSArray *)centerbtnColor selectValueArry:(NSArray *)selectValueArry weightArry:(NSArray *)weightArry;
@end @end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
@implementation BzwPicker @implementation BzwPicker
-(instancetype)initWithFrame:(CGRect)frame dic:(NSDictionary *)dic leftStr:(NSString *)leftStr centerStr:(NSString *)centerStr rightStr:(NSString *)rightStr topbgColor:(NSArray *)topbgColor bottombgColor:(NSArray *)bottombgColor leftbtnbgColor:(NSArray *)leftbtnbgColor rightbtnbgColor:(NSArray *)rightbtnbgColor centerbtnColor:(NSArray *)centerbtnColor selectValueArry:(NSArray *)selectValueArry -(instancetype)initWithFrame:(CGRect)frame dic:(NSDictionary *)dic leftStr:(NSString *)leftStr centerStr:(NSString *)centerStr rightStr:(NSString *)rightStr topbgColor:(NSArray *)topbgColor bottombgColor:(NSArray *)bottombgColor leftbtnbgColor:(NSArray *)leftbtnbgColor rightbtnbgColor:(NSArray *)rightbtnbgColor centerbtnColor:(NSArray *)centerbtnColor selectValueArry:(NSArray *)selectValueArry weightArry:(NSArray *)weightArry
{ {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) if (self)
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
self.provinceArray=[[NSMutableArray alloc]init]; self.provinceArray=[[NSMutableArray alloc]init];
self.cityArray=[[NSMutableArray alloc]init]; self.cityArray=[[NSMutableArray alloc]init];
self.selectValueArry=selectValueArry; self.selectValueArry=selectValueArry;
self.weightArry=weightArry;
self.pickerDic=dic; self.pickerDic=dic;
self.leftStr=leftStr; self.leftStr=leftStr;
self.rightStr=rightStr; self.rightStr=rightStr;
...@@ -186,18 +187,115 @@ ...@@ -186,18 +187,115 @@
if (_Correlation) { if (_Correlation) {
if ([_numberCorrela isEqualToString:@"three"]) { if ([_numberCorrela isEqualToString:@"three"]) {
if (self.weightArry.count>=3) {
return SCREEN_WIDTH/3; NSString *onestr=[NSString stringWithFormat:@"%@",[self.weightArry firstObject]];
NSString *twostr=[NSString stringWithFormat:@"%@",self.weightArry[1]];
NSString *threestr=[NSString stringWithFormat:@"%@",self.weightArry[2]];
double totalweight=onestr.doubleValue+twostr.doubleValue+threestr.doubleValue;
if (component==0) {
return SCREEN_WIDTH*onestr.doubleValue/totalweight;
}else if (component==1){
return SCREEN_WIDTH*twostr.doubleValue/totalweight;
}else{
return SCREEN_WIDTH*threestr.doubleValue/totalweight;
}
}else{
if (self.weightArry.count>0) {
NSInteger totalNum=self.weightArry.count;
double totalweight=0;
for (NSInteger i=0; i<self.weightArry.count; i++) {
NSString *str=[NSString stringWithFormat:@"%@",[self.weightArry objectAtIndex:i]];
totalweight=totalweight+str.doubleValue;
}
if (component>totalNum-1) {
NSString *str=[NSString stringWithFormat:@"%f",totalweight+3-totalNum];
return SCREEN_WIDTH/str.doubleValue;;
}else{
NSString *str=[NSString stringWithFormat:@"%f",totalweight+3-totalNum];
return SCREEN_WIDTH*[NSString stringWithFormat:@"%@",[self.weightArry objectAtIndex:component]].doubleValue/str.doubleValue;
}
}else{
return SCREEN_WIDTH/3;
}
}
}else{ }else{
return SCREEN_WIDTH/2; if (self.weightArry.count>=2) {
NSString *onestr=[NSString stringWithFormat:@"%@",[self.weightArry firstObject]];
NSString *twostr=[NSString stringWithFormat:@"%@",self.weightArry[1]];
double totalweight=onestr.doubleValue+twostr.doubleValue;
if (component==0) {
return SCREEN_WIDTH*onestr.doubleValue/totalweight;
}else{
return SCREEN_WIDTH*twostr.doubleValue/totalweight;
}
}else{
if (self.weightArry.count>0) {
double twonum=[NSString stringWithFormat:@"%@",[self.weightArry firstObject]].doubleValue;
if (component==0) {
NSString *str=[NSString stringWithFormat:@"%f",twonum+1];
return SCREEN_WIDTH*twonum/str.doubleValue;
}else{
NSString *str=[NSString stringWithFormat:@"%f",twonum+1];
return SCREEN_WIDTH/str.doubleValue;
}
}else
{
return SCREEN_WIDTH/2;
}
}
} }
}else{ }else{
if (_noArryElementBool) { if (_noArryElementBool) {
//表示一个数组 特殊情况 //表示一个数组 特殊情况
return SCREEN_WIDTH; return SCREEN_WIDTH;
}else{ }else{
if (self.weightArry.count>=self.dataDry.count) {
return SCREEN_WIDTH/self.dataDry.count;
double totalweight=0;
for (NSInteger i=0; i<self.dataDry.count; i++) {
NSString *str=[NSString stringWithFormat:@"%@",[self.weightArry objectAtIndex:i]];
totalweight=totalweight+str.doubleValue;
}
NSString *comStr=[NSString stringWithFormat:@"%@",[self.weightArry objectAtIndex:component]];
return SCREEN_WIDTH*comStr.doubleValue/totalweight;
}else
{
if (self.weightArry.count>0) {
NSInteger totalNum=self.weightArry.count;
double totalweight=0;
for (NSInteger i=0; i<self.weightArry.count; i++) {
NSString *str=[NSString stringWithFormat:@"%@",[self.weightArry objectAtIndex:i]];
totalweight=totalweight+str.doubleValue;
}
if (component>totalNum-1) {
NSString *str=[NSString stringWithFormat:@"%f",totalweight+self.dataDry.count-totalNum];
return SCREEN_WIDTH/str.doubleValue;
}else{
NSString *str=[NSString stringWithFormat:@"%f",totalweight+self.dataDry.count-totalNum];
return SCREEN_WIDTH*[NSString stringWithFormat:@"%@",[self.weightArry objectAtIndex:component]].doubleValue/str.doubleValue;
}
}else{
return SCREEN_WIDTH/self.dataDry.count;
}
}
} }
} }
} }
......
...@@ -60,6 +60,7 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){ ...@@ -60,6 +60,7 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){
NSArray *pickerToolBarBg=indic[@"pickerToolBarBg"]; NSArray *pickerToolBarBg=indic[@"pickerToolBarBg"];
NSArray *pickerBg=indic[@"pickerBg"]; NSArray *pickerBg=indic[@"pickerBg"];
NSArray *selectArry=indic[@"selectedValue"]; NSArray *selectArry=indic[@"selectedValue"];
NSArray *weightArry=indic[@"wheelFlex"];
id pickerData=indic[@"pickerData"]; id pickerData=indic[@"pickerData"];
...@@ -78,7 +79,7 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){ ...@@ -78,7 +79,7 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){
}]; }];
self.pick=[[BzwPicker alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 250) dic:dataDic leftStr:pickerCancelBtnText centerStr:pickerTitleText rightStr:pickerConfirmBtnText topbgColor:pickerToolBarBg bottombgColor:pickerBg leftbtnbgColor:pickerCancelBtnColor rightbtnbgColor:pickerConfirmBtnColor centerbtnColor:pickerTitleColor selectValueArry:selectArry]; self.pick=[[BzwPicker alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 250) dic:dataDic leftStr:pickerCancelBtnText centerStr:pickerTitleText rightStr:pickerConfirmBtnText topbgColor:pickerToolBarBg bottombgColor:pickerBg leftbtnbgColor:pickerCancelBtnColor rightbtnbgColor:pickerConfirmBtnColor centerbtnColor:pickerTitleColor selectValueArry:selectArry weightArry:weightArry];
_pick.bolock=^(NSDictionary *backinfoArry){ _pick.bolock=^(NSDictionary *backinfoArry){
......
{ {
"name": "react-native-picker", "name": "react-native-picker",
"version": "4.0.5", "version": "4.0.6",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment