Commit 9e28d766 authored by zooble's avatar zooble Committed by GitHub

Merge pull request #115 from ltjin/master

Add Picker.select feature
parents f50741fd 2036575a
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
|toggle |show or hide picker | | | |toggle |show or hide picker | | |
|show |show picker | | | |show |show picker | | |
|hide |hide picker | | | |hide |hide picker | | |
|select |select a row |array| |
|isPickerShow |get status of picker, return a boolean | | | |isPickerShow |get status of picker, return a boolean | | |
......
...@@ -107,6 +107,10 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life ...@@ -107,6 +107,10 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
private Dialog dialog = null; private Dialog dialog = null;
private PickerViewLinkage pickerViewLinkage;
private PickerViewAlone pickerViewAlone;
private boolean isAlone = true;
private boolean isLoop = true; private boolean isLoop = true;
private String confirmText; private String confirmText;
...@@ -139,8 +143,8 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life ...@@ -139,8 +143,8 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
TextView titleTV = (TextView) view.findViewById(R.id.title); TextView titleTV = (TextView) view.findViewById(R.id.title);
TextView confirmTV = (TextView) view.findViewById(R.id.confirm); TextView confirmTV = (TextView) view.findViewById(R.id.confirm);
RelativeLayout pickerLayout = (RelativeLayout) view.findViewById(R.id.pickerLayout); RelativeLayout pickerLayout = (RelativeLayout) view.findViewById(R.id.pickerLayout);
final PickerViewLinkage pickerViewLinkage = (PickerViewLinkage) view.findViewById(R.id.pickerViewLinkage); pickerViewLinkage = (PickerViewLinkage) view.findViewById(R.id.pickerViewLinkage);
final PickerViewAlone pickerViewAlone = (PickerViewAlone) view.findViewById(R.id.pickerViewAlone); pickerViewAlone = (PickerViewAlone) view.findViewById(R.id.pickerViewAlone);
int barViewHeight; int barViewHeight;
if (options.hasKey(PICKER_TOOL_BAR_HEIGHT)) { if (options.hasKey(PICKER_TOOL_BAR_HEIGHT)) {
...@@ -309,6 +313,7 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life ...@@ -309,6 +313,7 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
String name = pickerData.getType(0).name(); String name = pickerData.getType(0).name();
switch (name) { switch (name) {
case "Map": case "Map":
isAlone = false;
curStatus = 1; curStatus = 1;
pickerViewLinkage.setVisibility(View.VISIBLE); pickerViewLinkage.setVisibility(View.VISIBLE);
pickerViewAlone.setVisibility(View.GONE); pickerViewAlone.setVisibility(View.GONE);
...@@ -400,6 +405,37 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life ...@@ -400,6 +405,37 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
} }
} }
@ReactMethod
public void select(ReadableArray array) {
if (dialog != null) {
String[] selectValue = new String[array.size()];
String value = "";
for (int i = 0; i < array.size(); i++) {
switch (array.getType(i).name()) {
case "Boolean":
value = String.valueOf(array.getBoolean(i));
break;
case "Number":
try {
value = String.valueOf(array.getInt(i));
} catch (Exception e) {
value = String.valueOf(array.getDouble(i));
}
break;
case "String":
value = array.getString(i);
break;
}
selectValue[i] = value;
}
if(isAlone){
pickerViewAlone.setSelectValue(selectValue);
}else{
pickerViewLinkage.setSelectValue(selectValue);
}
}
}
@ReactMethod @ReactMethod
public void isPickerShow(Callback callback) { public void isPickerShow(Callback callback) {
if (callback == null) if (callback == null)
...@@ -465,6 +501,7 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life ...@@ -465,6 +501,7 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
@Override @Override
public void onHostDestroy() { public void onHostDestroy() {
hide();
dialog = null;
} }
} }
\ No newline at end of file
...@@ -55,6 +55,10 @@ export default { ...@@ -55,6 +55,10 @@ export default {
Picker.hide(); Picker.hide();
}, },
select(data) {
Picker.select(data)
},
toggle(){ toggle(){
this.isPickerShow(show => { this.isPickerShow(show => {
if(show){ if(show){
......
...@@ -80,5 +80,5 @@ typedef void(^backBolock)(NSDictionary * ); ...@@ -80,5 +80,5 @@ 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 weightArry:(NSArray *)weightArry -(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
pickerToolBarFontSize:(NSString *)pickerToolBarFontSize pickerFontSize:(NSString *)pickerFontSize pickerFontColor:(NSArray *)pickerFontColor; pickerToolBarFontSize:(NSString *)pickerToolBarFontSize pickerFontSize:(NSString *)pickerFontSize pickerFontColor:(NSArray *)pickerFontColor;
-(void)selectRow;
@end @end
...@@ -117,6 +117,17 @@ RCT_EXPORT_METHOD(hide){ ...@@ -117,6 +117,17 @@ RCT_EXPORT_METHOD(hide){
}); });
}return; }return;
} }
RCT_EXPORT_METHOD(select: (NSArray*)data){
if (self.pick) {
dispatch_async(dispatch_get_main_queue(), ^{
_pick.selectValueArry = data;
[_pick selectRow];
});
}return;
}
RCT_EXPORT_METHOD(isPickerShow:(RCTResponseSenderBlock)getBack){ RCT_EXPORT_METHOD(isPickerShow:(RCTResponseSenderBlock)getBack){
if (self.pick) { if (self.pick) {
......
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