Commit d6ad6759 authored by xwenliang's avatar xwenliang

New features for #102 #90 #29

parent cf30fbc6
......@@ -10,22 +10,24 @@
####Params
|Key | Type | Default| Description |
| --- | ---- | ------ | ----------- |
|pickerConfirmBtnText |string |确认 | |
|pickerCancelBtnText |string |取消 | |
|pickerTitleText |string |请选择 | |
|pickerConfirmBtnColor |array |[1, 186, 245, 1] | |
|pickerCancelBtnColor |array |[1, 186, 245, 1] | |
|pickerTitleColor |array |[20, 20, 20, 1]) | |
|pickerToolBarBg |array |[232, 232, 232, 1] | |
|pickerBg |array |[196, 199, 206, 1] | |
|wheelFlex |array |[2, 1, 1] |set width of the three wheels to 2:1:1 |
|pickerData |array | | |
|selectedValue |array | | |
|onPickerConfirm |function| | |
|onPickerCancel |function| | |
|onPickerSelect |function| | |
|Key | Description | Type | Default|
| --- | ----------- | ---- | ------ |
|pickerConfirmBtnText | |string |confirm |
|pickerCancelBtnText | |string |cancel |
|pickerTitleText | |string |pls select |
|pickerConfirmBtnColor | |array |[1, 186, 245, 1] |
|pickerCancelBtnColor | |array |[1, 186, 245, 1] |
|pickerTitleColor | |array |[20, 20, 20, 1]) |
|pickerToolBarBg | |array |[232, 232, 232, 1] |
|pickerBg | |array |[196, 199, 206, 1] |
|pickerToolBarFontSize | |number |16 |
|pickerFontSize | |number |16 |
|pickerFontColor | |array |[31, 31, 31, 1] |
|pickerData | |array | |
|selectedValue | |string | |
|onPickerConfirm | |function| |
|onPickerCancel | |function| |
|onPickerSelect | |function| |
####Methods
......@@ -93,7 +95,7 @@
```javascript
pickerData = [1,2,3,4];
selectedValue = [3];
selectedValue = 3;
```
- two or more wheel:
......
......@@ -19,9 +19,13 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/**
* Edited by shexiaoheng on 2016/10/20
* Edited by <a href="https://github.com/shexiaoheng">heng</a> on 2016/10/20
* 1. Added method getY
* 2. Changed line color 0xffc5c5c5 -> 0xffb8bbc2
*
* Edited by heng on 2016/12/26
* 1. Added setTextColor
* 2. Added setTextSize
*/
public class LoopView extends View {
......@@ -50,10 +54,6 @@ public class LoopView extends View {
private int textSize;
int maxTextHeight;
private int colorGray;
private int colorBlack;
private int colorLightGray;
// 条目间距倍数
float lineSpacingMultiplier;
boolean isLoop;
......@@ -109,37 +109,30 @@ public class LoopView extends View {
lineSpacingMultiplier = 2.0F;
isLoop = true;
itemsVisible = 9;
textSize = 0;
colorGray = 0xffafafaf;
colorBlack = 0xff313131;
colorLightGray = 0xffb8bbc2;
// colorLightGray = 0xffc5c5c5;
textSize = (int) (context.getResources().getDisplayMetrics().density * 16);
totalScrollY = 0;
initPosition = -1;
initPaints();
setTextSize(20F);
}
private void initPaints() {
paintOuterText = new Paint();
paintOuterText.setColor(colorGray);
paintOuterText.setColor(0xffafafaf);
paintOuterText.setAntiAlias(true);
paintOuterText.setTypeface(Typeface.MONOSPACE);
paintOuterText.setTextSize(textSize);
paintCenterText = new Paint();
paintCenterText.setColor(colorBlack);
paintCenterText.setColor(0xff000000);
paintCenterText.setAntiAlias(true);
paintCenterText.setTextScaleX(scaleX);
paintCenterText.setTypeface(Typeface.MONOSPACE);
paintCenterText.setTextSize(textSize);
paintIndicator = new Paint();
paintIndicator.setColor(colorLightGray);
paintIndicator.setColor(0xffb8bbc2);
paintIndicator.setAntiAlias(true);
if (android.os.Build.VERSION.SDK_INT >= 11) {
......@@ -204,15 +197,22 @@ public class LoopView extends View {
}
}
public void setTextColor(int color){
paintCenterText.setColor(color);
invalidate();
}
public final void setNotLoop() {
isLoop = false;
}
public final void setTextSize(float size) {
if (size > 0.0F) {
textSize = (int) (context.getResources().getDisplayMetrics().density * size);
this.textSize = (int) (context.getResources().getDisplayMetrics().density * size);
paintOuterText.setTextSize(textSize);
paintCenterText.setTextSize(textSize);
remeasure();
invalidate();
}
}
......@@ -242,6 +242,7 @@ public class LoopView extends View {
this.initPosition = initPosition;
}
}
selectedIndex = initPosition;
totalScrollY = 0;
cancelFuture();
invalidate();
......
......@@ -8,6 +8,6 @@ import java.util.ArrayList;
public interface OnSelectedListener {
void onSelected(ArrayList<String> selectedList);
void onSelected(ArrayList<ReturnData> selectedList);
}
......@@ -13,10 +13,14 @@ import java.util.ArrayList;
import java.util.Arrays;
/**
* Created by heng on 16/9/6.
* Created by <a href="https://github.com/shexiaoheng">heng</a> on 16/9/6.
* <p>
* Edited by heng on 16/10/09:
* 修复滚动后返回值错误的bug
*
* Edited by heng on 2016/12/26
* 1. Fixed returnData bug
* 2. Added LoopView TextColor and TextSize support
*/
public class PickerViewAlone extends LinearLayout {
......@@ -25,7 +29,7 @@ public class PickerViewAlone extends LinearLayout {
private OnSelectedListener onSelectedListener;
private ArrayList<String> curSelectedList;
private ArrayList<ReturnData> curSelectedList;
public PickerViewAlone(Context context) {
super(context);
......@@ -50,19 +54,19 @@ public class PickerViewAlone extends LinearLayout {
curSelectedList = new ArrayList<>();
switch (array.getType(0).name()) {
case "Array":
setMultipleData(array, curSelectedList, weights);
setMultipleData(array, weights);
break;
default:
setAloneData(array, curSelectedList);
setAloneData(array);
break;
}
}
public ArrayList<String> getSelectedData(){
public ArrayList<ReturnData> getSelectedData() {
return this.curSelectedList;
}
private void setAloneData(ReadableArray array, final ArrayList<String> curSelectedList) {
private void setAloneData(ReadableArray array) {
ArrayList<String> values = arrayToList(array);
final LoopView loopView = new LoopView(getContext());
LayoutParams params = new LayoutParams(
......@@ -71,16 +75,22 @@ public class PickerViewAlone extends LinearLayout {
loopView.setLayoutParams(params);
loopView.setItems(values);
loopView.setSelectedPosition(0);
ReturnData returnData = new ReturnData();
returnData.setItem(values.get(0));
returnData.setIndex(loopView.getSelectedIndex());
if (curSelectedList.size() > 0) {
curSelectedList.set(0, values.get(0));
curSelectedList.set(0, returnData);
} else {
curSelectedList.add(0, values.get(0));
curSelectedList.add(0, returnData);
}
loopView.setListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(String item, int index) {
if (onSelectedListener != null) {
curSelectedList.set(0, item);
ReturnData returnData1 = new ReturnData();
returnData1.setItem(item);
returnData1.setIndex(index);
curSelectedList.set(0, returnData1);
onSelectedListener.onSelected(curSelectedList);
}
}
......@@ -88,8 +98,9 @@ public class PickerViewAlone extends LinearLayout {
pickerViewAloneLayout.addView(loopView);
}
private void setMultipleData(ReadableArray array, final ArrayList<String> curSelectedList, double[] weights) {
private void setMultipleData(ReadableArray array, double[] weights) {
final String[] selectedItems = new String[array.size()];
final int[] selectedIndexes = new int[array.size()];
for (int i = 0; i < array.size(); i++) {
switch (array.getType(i).name()) {
case "Array":
......@@ -110,10 +121,14 @@ public class PickerViewAlone extends LinearLayout {
loopView.setItems(values);
loopView.setTag(i);
loopView.setSelectedPosition(0);
ReturnData returnData = new ReturnData();
returnData.setItem(values.get(0));
returnData.setIndex(loopView.getSelectedIndex());
if (curSelectedList.size() > i) {
curSelectedList.set(i, values.get(0));
curSelectedList.set(i, returnData);
} else {
curSelectedList.add(i, values.get(0));
curSelectedList.add(i, returnData);
}
selectedItems[i] = values.get(0);
loopView.setListener(new OnItemSelectedListener() {
......@@ -125,12 +140,16 @@ public class PickerViewAlone extends LinearLayout {
if (view instanceof LoopView) {
LoopView loop = (LoopView) view;
selectedItems[k] = loop.getSelectedItem();
selectedIndexes[k] = loop.getSelectedIndex();
}
}
if (onSelectedListener != null) {
for (int i = 0; i < selectedItems.length; i++) {
curSelectedList.set(i, selectedItems[i]);
ReturnData returnData1 = new ReturnData();
returnData1.setItem(selectedItems[i]);
returnData1.setIndex(selectedIndexes[i]);
curSelectedList.set(i, returnData1);
}
onSelectedListener.onSelected(curSelectedList);
}
......@@ -155,16 +174,41 @@ public class PickerViewAlone extends LinearLayout {
}
}
private void setSelect(int size, String[] values, ArrayList<String> curSelectedList) {
private void setSelect(int size, String[] values, ArrayList<ReturnData> curSelectedList) {
for (int i = 0; i < size; i++) {
View view = pickerViewAloneLayout.getChildAt(i);
if (view instanceof LoopView) {
LoopView loop = (LoopView) view;
if (loop.hasItem(values[i])) {
loop.setSelectedItem(values[i]);
curSelectedList.set(i, values[i]);
ReturnData returnData = new ReturnData();
returnData.setItem(values[i]);
returnData.setIndex(loop.getSelectedIndex());
curSelectedList.set(i, returnData);
}
}
}
}
public void setTextColor(int color){
int viewCount = pickerViewAloneLayout.getChildCount();
for (int i = 0; i < viewCount; i++) {
View view = pickerViewAloneLayout.getChildAt(i);
if (view instanceof LoopView) {
LoopView loopView = (LoopView) view;
loopView.setTextColor(color);
}
}
}
public void setTextSize(float size){
int viewCount = pickerViewAloneLayout.getChildCount();
for (int i = 0; i < viewCount; i++) {
View view = pickerViewAloneLayout.getChildAt(i);
if (view instanceof LoopView) {
LoopView loopView = (LoopView) view;
loopView.setTextSize(size);
}
}
}
......
package com.beefe.picker.view;
/**
* Created by shexiaoheng on 2016/12/23.
*/
public class ReturnData {
private String item;
private int index;
public String getItem() {
return item;
}
public void setItem(String item) {
this.item = item;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
}
......@@ -19,6 +19,7 @@ class PickerTest extends Component {
constructor(props, context) {
super(props, context);
this._showDatePicker();
}
_createDateData() {
......@@ -78,15 +79,17 @@ class PickerTest extends Component {
_showDatePicker() {
Picker.init({
pickerData: this._createDateData(),
selectedValue: ['2015年', '12月', '12日'],
onPickerConfirm: pickedValue => {
console.log('date', pickedValue);
pickerToolBarFontSize: 16,
pickerFontSize: 16,
pickerFontColor: [255, 0 ,0, 1],
onPickerConfirm: (pickedValue, pickedIndex) => {
console.log('date', pickedValue, pickedIndex);
},
onPickerCancel: pickedValue => {
console.log('date', pickedValue);
onPickerCancel: (pickedValue, pickedIndex) => {
console.log('date', pickedValue, pickedIndex);
},
onPickerSelect: pickedValue => {
console.log('date', pickedValue);
onPickerSelect: (pickedValue, pickedIndex) => {
console.log('date', pickedValue, pickedIndex);
}
});
Picker.show();
......
......@@ -13,17 +13,24 @@ export default {
init(options){
let opt = {
isLoop: false,
pickerConfirmBtnText: '确认',
pickerCancelBtnText: '取消',
pickerTitleText: '请选择',
pickerBg: [196, 199, 206, 1],
pickerToolBarBg: [232, 232, 232, 1],
pickerTitleColor: [20, 20, 20, 1],
pickerCancelBtnColor: [1, 186, 245, 1],
pickerConfirmBtnText: 'confirm',
pickerCancelBtnText: 'cancel',
pickerTitleText: 'pls select',
pickerConfirmBtnColor: [1, 186, 245, 1],
pickerCancelBtnColor: [1, 186, 245, 1],
pickerTitleColor: [20, 20, 20, 1],
pickerToolBarBg: [232, 232, 232, 1],
pickerBg: [196, 199, 206, 1],
wheelFlex: [1, 1, 1],
pickerData: [],
selectedValue: [],
onPickerConfirm(){},
onPickerCancel(){},
onPickerSelect(){},
//4.0.12 add
pickerToolBarFontSize: 16,
pickerFontSize: 16,
pickerFontColor: [31, 31 ,31, 1],
...options
};
let fnConf = {
......@@ -36,14 +43,7 @@ export default {
//there are no `removeListener` for NativeAppEventEmitter & DeviceEventEmitter
this.listener && this.listener.remove();
this.listener = NativeAppEventEmitter.addListener('pickerEvent', event => {
if(ios){
fnConf[event['type']](event['selectedValue']);
}
else if(android){
for (let i in event){
typeof fnConf[i] === 'function' && fnConf[i](event[i]);
}
}
fnConf[event['type']](event['selectedValue'], event['selectedIndex']);
});
},
......
......@@ -39,6 +39,9 @@ typedef void(^backBolock)(NSDictionary * );
@property(strong,nonatomic)NSString *leftStr;
@property(strong,nonatomic)NSString *centStr;
@property(strong,nonatomic)NSString *rightStr;
@property(strong,nonatomic)NSString *pickerToolBarFontSize;
@property(strong,nonatomic)NSString *pickerFontSize;
@property(strong,nonatomic)NSArray*pickerFontColor;
......@@ -61,6 +64,7 @@ typedef void(^backBolock)(NSDictionary * );
@property(strong,nonatomic)NSArray *weightArry;
@property(assign,nonatomic)CGFloat lineWith;
//创建一个下角标记录是第几行 来一进来判断第一行被选中 当进来的是关联两行的逻辑的时候 或者三行关联的时候取第二行做记录
@property(assign,nonatomic)NSInteger num;
......@@ -69,9 +73,12 @@ typedef void(^backBolock)(NSDictionary * );
@property(assign,nonatomic)NSInteger threenum;
@property(assign,nonatomic)NSInteger seleNum;//用来做索引下标用
-(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;
@end
This diff is collapsed.
......@@ -26,7 +26,11 @@ RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){
self.window = [[UIApplication sharedApplication].windows lastObject];
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication].keyWindow endEditing:YES];
});
self.window = [UIApplication sharedApplication].keyWindow;
NSString *pickerConfirmBtnText=indic[@"pickerConfirmBtnText"];
NSString *pickerCancelBtnText=indic[@"pickerCancelBtnText"];
......@@ -38,6 +42,9 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){
NSArray *pickerBg=indic[@"pickerBg"];
NSArray *selectArry=indic[@"selectedValue"];
NSArray *weightArry=indic[@"wheelFlex"];
NSString *pickerToolBarFontSize=[NSString stringWithFormat:@"%@",indic[@"pickerToolBarFontSize"]];
NSString *pickerFontSize=[NSString stringWithFormat:@"%@",indic[@"pickerFontSize"]];
NSArray *pickerFontColor=indic[@"pickerFontColor"];
id pickerData=indic[@"pickerData"];
......@@ -62,7 +69,8 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){
self.height=220;
}
self.pick=[[BzwPicker alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, self.height) dic:dataDic leftStr:pickerCancelBtnText centerStr:pickerTitleText rightStr:pickerConfirmBtnText topbgColor:pickerToolBarBg bottombgColor:pickerBg leftbtnbgColor:pickerCancelBtnColor rightbtnbgColor:pickerConfirmBtnColor centerbtnColor:pickerTitleColor selectValueArry:selectArry weightArry:weightArry];
self.pick=[[BzwPicker alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, self.height) dic:dataDic leftStr:pickerCancelBtnText centerStr:pickerTitleText rightStr:pickerConfirmBtnText topbgColor:pickerToolBarBg bottombgColor:pickerBg leftbtnbgColor:pickerCancelBtnColor rightbtnbgColor:pickerConfirmBtnColor centerbtnColor:pickerTitleColor selectValueArry:selectArry weightArry:weightArry pickerToolBarFontSize:pickerToolBarFontSize pickerFontSize:pickerFontSize pickerFontColor:pickerFontColor];
_pick.bolock=^(NSDictionary *backinfoArry){
......
{
"name": "react-native-picker",
"version": "4.0.11",
"version": "4.0.12",
"description": "",
"main": "index.js",
"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