Commit d6ad6759 authored by xwenliang's avatar xwenliang

New features for #102 #90 #29

parent cf30fbc6
...@@ -10,22 +10,24 @@ ...@@ -10,22 +10,24 @@
####Params ####Params
|Key | Type | Default| Description | |Key | Description | Type | Default|
| --- | ---- | ------ | ----------- | | --- | ----------- | ---- | ------ |
|pickerConfirmBtnText |string |确认 | | |pickerConfirmBtnText | |string |confirm |
|pickerCancelBtnText |string |取消 | | |pickerCancelBtnText | |string |cancel |
|pickerTitleText |string |请选择 | | |pickerTitleText | |string |pls select |
|pickerConfirmBtnColor |array |[1, 186, 245, 1] | | |pickerConfirmBtnColor | |array |[1, 186, 245, 1] |
|pickerCancelBtnColor |array |[1, 186, 245, 1] | | |pickerCancelBtnColor | |array |[1, 186, 245, 1] |
|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] |set width of the three wheels to 2:1:1 | |pickerToolBarFontSize | |number |16 |
|pickerData |array | | | |pickerFontSize | |number |16 |
|selectedValue |array | | | |pickerFontColor | |array |[31, 31, 31, 1] |
|onPickerConfirm |function| | | |pickerData | |array | |
|onPickerCancel |function| | | |selectedValue | |string | |
|onPickerSelect |function| | | |onPickerConfirm | |function| |
|onPickerCancel | |function| |
|onPickerSelect | |function| |
####Methods ####Methods
...@@ -93,7 +95,7 @@ ...@@ -93,7 +95,7 @@
```javascript ```javascript
pickerData = [1,2,3,4]; pickerData = [1,2,3,4];
selectedValue = [3]; selectedValue = 3;
``` ```
- two or more wheel: - two or more wheel:
......
package com.beefe.picker; package com.beefe.picker;
import android.app.Activity; import android.app.Activity;
import android.app.Application;
import android.app.Dialog; import android.app.Dialog;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
...@@ -18,8 +17,10 @@ import android.widget.TextView; ...@@ -18,8 +17,10 @@ import android.widget.TextView;
import com.beefe.picker.view.OnSelectedListener; import com.beefe.picker.view.OnSelectedListener;
import com.beefe.picker.view.PickerViewAlone; import com.beefe.picker.view.PickerViewAlone;
import com.beefe.picker.view.PickerViewLinkage; import com.beefe.picker.view.PickerViewLinkage;
import com.beefe.picker.view.ReturnData;
import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactContextBaseJavaModule;
...@@ -32,8 +33,10 @@ import com.facebook.react.modules.core.DeviceEventManagerModule; ...@@ -32,8 +33,10 @@ import com.facebook.react.modules.core.DeviceEventManagerModule;
import java.util.ArrayList; import java.util.ArrayList;
import static android.graphics.Color.argb;
/** /**
* Author: heng <a href="https://github.com/shexiaoheng"/> * Author: <a href="https://github.com/shexiaoheng">heng</a>
* <p> * <p>
* Created by heng on 16/9/5. * Created by heng on 16/9/5.
* <p> * <p>
...@@ -53,9 +56,20 @@ import java.util.ArrayList; ...@@ -53,9 +56,20 @@ import java.util.ArrayList;
* Edited by heng on 2016/11/17 * Edited by heng on 2016/11/17
* 1. Used Dialog replace WindowManger * 1. Used Dialog replace WindowManger
* 2. Restore method show() isPickerShow() * 2. Restore method show() isPickerShow()
* <p>
* Edited by heng on 2016/12/23
* 1. Changed returnData type
* 2. Added pickerToolBarFontSize
*
* Edited by heng on 2016/12/26
* 1. Fixed returnData bug
* 2. Added pickerFontColor
* 3. Added pickerFontSize
* 4. Used LifecycleEventListener replace Application.ActivityLifecycleCallbacks
* 5. Fixed other bug
*/ */
public class PickerViewModule extends ReactContextBaseJavaModule implements Application.ActivityLifecycleCallbacks { public class PickerViewModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
private static final String REACT_CLASS = "BEEPickerManager"; private static final String REACT_CLASS = "BEEPickerManager";
...@@ -68,17 +82,21 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl ...@@ -68,17 +82,21 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
private static final String PICKER_BG_COLOR = "pickerBg"; private static final String PICKER_BG_COLOR = "pickerBg";
private static final String TEXT_BAR_COLOR = "pickerToolBarBg"; private static final String PICKER_TOOL_BAR_BG = "pickerToolBarBg";
private static final String TEXT_BAR_HEIGHT = "pickerToolBarHeight"; private static final String PICKER_TOOL_BAR_HEIGHT = "pickerToolBarHeight";
private static final String PICKER_TOOL_BAR_TEXT_SIZE = "pickerToolBarFontSize";
private static final String CONFIRM_TEXT = "pickerConfirmBtnText"; private static final String PICKER_CONFIRM_BTN_TEXT = "pickerConfirmBtnText";
private static final String CONFIRM_TEXT_COLOR = "pickerConfirmBtnColor"; private static final String PICKER_CONFIRM_BTN_COLOR = "pickerConfirmBtnColor";
private static final String CANCEL_TEXT = "pickerCancelBtnText"; private static final String PICKER_CANCEL_BTN_TEXT = "pickerCancelBtnText";
private static final String CANCEL_TEXT_COLOR = "pickerCancelBtnColor"; private static final String PICKER_CANCEL_BTN_COLOR = "pickerCancelBtnColor";
private static final String TITLE_TEXT = "pickerTitleText"; private static final String PICKER_TITLE_TEXT = "pickerTitleText";
private static final String TITLE_TEXT_COLOR = "pickerTitleColor"; private static final String PICKER_TITLE_TEXT_COLOR = "pickerTitleColor";
private static final String PICKER_TEXT_COLOR = "pickerFontColor";
private static final String PICKER_TEXT_SIZE = "pickerFontSize";
private static final String PICKER_EVENT_NAME = "pickerEvent"; private static final String PICKER_EVENT_NAME = "pickerEvent";
private static final String EVENT_KEY_CONFIRM = "confirm"; private static final String EVENT_KEY_CONFIRM = "confirm";
...@@ -97,12 +115,13 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl ...@@ -97,12 +115,13 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
private double[] weights; private double[] weights;
private ArrayList<String> returnData; private ArrayList<ReturnData> returnData;
private int curStatus; private int curStatus;
public PickerViewModule(ReactApplicationContext reactContext) { public PickerViewModule(ReactApplicationContext reactContext) {
super(reactContext); super(reactContext);
reactContext.addLifecycleEventListener(this);
} }
@Override @Override
...@@ -124,11 +143,11 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl ...@@ -124,11 +143,11 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
final PickerViewAlone pickerViewAlone = (PickerViewAlone) view.findViewById(R.id.pickerViewAlone); final PickerViewAlone pickerViewAlone = (PickerViewAlone) view.findViewById(R.id.pickerViewAlone);
int barViewHeight; int barViewHeight;
if (options.hasKey(TEXT_BAR_HEIGHT)) { if (options.hasKey(PICKER_TOOL_BAR_HEIGHT)) {
try { try {
barViewHeight = options.getInt(TEXT_BAR_HEIGHT); barViewHeight = options.getInt(PICKER_TOOL_BAR_HEIGHT);
} catch (Exception e) { } catch (Exception e) {
barViewHeight = (int) options.getDouble(TEXT_BAR_HEIGHT); barViewHeight = (int) options.getDouble(PICKER_TOOL_BAR_HEIGHT);
} }
} else { } else {
barViewHeight = (int) (activity.getResources().getDisplayMetrics().density * 40); barViewHeight = (int) (activity.getResources().getDisplayMetrics().density * 40);
...@@ -138,22 +157,28 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl ...@@ -138,22 +157,28 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
barViewHeight); barViewHeight);
barLayout.setLayoutParams(params); barLayout.setLayoutParams(params);
if (options.hasKey(TEXT_BAR_COLOR)) { if (options.hasKey(PICKER_TOOL_BAR_BG)) {
ReadableArray array = options.getArray(TEXT_BAR_COLOR); ReadableArray array = options.getArray(PICKER_TOOL_BAR_BG);
int[] colors = getColor(array); int[] colors = getColor(array);
barLayout.setBackgroundColor(Color.argb(colors[3], colors[0], colors[1], colors[2])); barLayout.setBackgroundColor(argb(colors[3], colors[0], colors[1], colors[2]));
} }
if (options.hasKey(PICKER_TOOL_BAR_TEXT_SIZE)) {
int toolBarTextSize = options.getInt(PICKER_TOOL_BAR_TEXT_SIZE);
cancelTV.setTextSize(toolBarTextSize);
titleTV.setTextSize(toolBarTextSize);
confirmTV.setTextSize(toolBarTextSize);
}
if (options.hasKey(CONFIRM_TEXT)) { if (options.hasKey(PICKER_CONFIRM_BTN_TEXT)) {
confirmText = options.getString(CONFIRM_TEXT); confirmText = options.getString(PICKER_CONFIRM_BTN_TEXT);
} }
confirmTV.setText(!TextUtils.isEmpty(confirmText) ? confirmText : ""); confirmTV.setText(!TextUtils.isEmpty(confirmText) ? confirmText : "");
if (options.hasKey(CONFIRM_TEXT_COLOR)) { if (options.hasKey(PICKER_CONFIRM_BTN_COLOR)) {
ReadableArray array = options.getArray(CONFIRM_TEXT_COLOR); ReadableArray array = options.getArray(PICKER_CONFIRM_BTN_COLOR);
int[] colors = getColor(array); int[] colors = getColor(array);
confirmTV.setTextColor(Color.argb(colors[3], colors[0], colors[1], colors[2])); confirmTV.setTextColor(argb(colors[3], colors[0], colors[1], colors[2]));
} }
confirmTV.setOnClickListener(new View.OnClickListener() { confirmTV.setOnClickListener(new View.OnClickListener() {
@Override @Override
...@@ -172,24 +197,24 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl ...@@ -172,24 +197,24 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
}); });
if (options.hasKey(TITLE_TEXT)) { if (options.hasKey(PICKER_TITLE_TEXT)) {
titleText = options.getString(TITLE_TEXT); titleText = options.getString(PICKER_TITLE_TEXT);
} }
titleTV.setText(!TextUtils.isEmpty(titleText) ? titleText : ""); titleTV.setText(!TextUtils.isEmpty(titleText) ? titleText : "");
if (options.hasKey(TITLE_TEXT_COLOR)) { if (options.hasKey(PICKER_TITLE_TEXT_COLOR)) {
ReadableArray array = options.getArray(TITLE_TEXT_COLOR); ReadableArray array = options.getArray(PICKER_TITLE_TEXT_COLOR);
int[] colors = getColor(array); int[] colors = getColor(array);
titleTV.setTextColor(Color.argb(colors[3], colors[0], colors[1], colors[2])); titleTV.setTextColor(argb(colors[3], colors[0], colors[1], colors[2]));
} }
if (options.hasKey(CANCEL_TEXT)) { if (options.hasKey(PICKER_CANCEL_BTN_TEXT)) {
cancelText = options.getString(CANCEL_TEXT); cancelText = options.getString(PICKER_CANCEL_BTN_TEXT);
} }
cancelTV.setText(!TextUtils.isEmpty(cancelText) ? cancelText : ""); cancelTV.setText(!TextUtils.isEmpty(cancelText) ? cancelText : "");
if (options.hasKey(CANCEL_TEXT_COLOR)) { if (options.hasKey(PICKER_CANCEL_BTN_COLOR)) {
ReadableArray array = options.getArray(CANCEL_TEXT_COLOR); ReadableArray array = options.getArray(PICKER_CANCEL_BTN_COLOR);
int[] colors = getColor(array); int[] colors = getColor(array);
cancelTV.setTextColor(Color.argb(colors[3], colors[0], colors[1], colors[2])); cancelTV.setTextColor(argb(colors[3], colors[0], colors[1], colors[2]));
} }
cancelTV.setOnClickListener(new View.OnClickListener() { cancelTV.setOnClickListener(new View.OnClickListener() {
@Override @Override
...@@ -262,6 +287,22 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl ...@@ -262,6 +287,22 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
} }
} }
int pickerTextColor = 0xff000000;
if (options.hasKey(PICKER_TEXT_COLOR)) {
ReadableArray array = options.getArray(PICKER_TEXT_COLOR);
int[] colors = getColor(array);
pickerTextColor = Color.argb(colors[3], colors[0], colors[1], colors[2]);
}
int pickerTextSize = 16;
if (options.hasKey(PICKER_TEXT_SIZE)) {
try {
pickerTextSize = options.getInt(PICKER_TEXT_SIZE);
} catch (Exception e) {
pickerTextSize = (int) options.getDouble(PICKER_TEXT_SIZE);
}
}
ReadableArray pickerData = options.getArray(PICKER_DATA); ReadableArray pickerData = options.getArray(PICKER_DATA);
int pickerViewHeight; int pickerViewHeight;
...@@ -273,11 +314,13 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl ...@@ -273,11 +314,13 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
pickerViewAlone.setVisibility(View.GONE); pickerViewAlone.setVisibility(View.GONE);
pickerViewLinkage.setPickerData(pickerData, weights); pickerViewLinkage.setPickerData(pickerData, weights);
pickerViewLinkage.setTextColor(pickerTextColor);
pickerViewLinkage.setTextSize(pickerTextSize);
pickerViewLinkage.setIsLoop(isLoop); pickerViewLinkage.setIsLoop(isLoop);
pickerViewLinkage.setOnSelectListener(new OnSelectedListener() { pickerViewLinkage.setOnSelectListener(new OnSelectedListener() {
@Override @Override
public void onSelected(ArrayList<String> selectedList) { public void onSelected(ArrayList<ReturnData> selectedList) {
returnData = selectedList; returnData = selectedList;
commonEvent(EVENT_KEY_SELECTED); commonEvent(EVENT_KEY_SELECTED);
} }
...@@ -291,11 +334,13 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl ...@@ -291,11 +334,13 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
pickerViewLinkage.setVisibility(View.GONE); pickerViewLinkage.setVisibility(View.GONE);
pickerViewAlone.setPickerData(pickerData, weights); pickerViewAlone.setPickerData(pickerData, weights);
pickerViewAlone.setTextColor(pickerTextColor);
pickerViewAlone.setTextSize(pickerTextSize);
pickerViewAlone.setIsLoop(isLoop); pickerViewAlone.setIsLoop(isLoop);
pickerViewAlone.setOnSelectedListener(new OnSelectedListener() { pickerViewAlone.setOnSelectedListener(new OnSelectedListener() {
@Override @Override
public void onSelected(ArrayList<String> selectedList) { public void onSelected(ArrayList<ReturnData> selectedList) {
returnData = selectedList; returnData = selectedList;
commonEvent(EVENT_KEY_SELECTED); commonEvent(EVENT_KEY_SELECTED);
} }
...@@ -309,9 +354,10 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl ...@@ -309,9 +354,10 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
if (options.hasKey(PICKER_BG_COLOR)) { if (options.hasKey(PICKER_BG_COLOR)) {
ReadableArray array = options.getArray(PICKER_BG_COLOR); ReadableArray array = options.getArray(PICKER_BG_COLOR);
int[] colors = getColor(array); int[] colors = getColor(array);
pickerLayout.setBackgroundColor(Color.argb(colors[3], colors[0], colors[1], colors[2])); pickerLayout.setBackgroundColor(argb(colors[3], colors[0], colors[1], colors[2]));
} }
Log.d("PickerView", "pickerViewHeight = " + pickerViewHeight);
int height = barViewHeight + pickerViewHeight; int height = barViewHeight + pickerViewHeight;
if (dialog == null) { if (dialog == null) {
dialog = new Dialog(activity, R.style.Dialog_Full_Screen); dialog = new Dialog(activity, R.style.Dialog_Full_Screen);
...@@ -331,7 +377,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl ...@@ -331,7 +377,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
dialog.dismiss(); dialog.dismiss();
dialog.setContentView(view); dialog.setContentView(view);
} }
dialog.show();
} }
} }
...@@ -357,6 +402,8 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl ...@@ -357,6 +402,8 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
@ReactMethod @ReactMethod
public void isPickerShow(Callback callback) { public void isPickerShow(Callback callback) {
if (callback == null)
return;
if (dialog == null) { if (dialog == null) {
callback.invoke(ERROR_NOT_INIT); callback.invoke(ERROR_NOT_INIT);
} else { } else {
...@@ -385,11 +432,15 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl ...@@ -385,11 +432,15 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
private void commonEvent(String eventKey) { private void commonEvent(String eventKey) {
WritableMap map = Arguments.createMap(); WritableMap map = Arguments.createMap();
WritableArray array = Arguments.createArray(); map.putString("type", eventKey);
for (String item : returnData) { WritableArray indexes = Arguments.createArray();
array.pushString(item); WritableArray values = Arguments.createArray();
} for (ReturnData data : returnData) {
map.putArray(eventKey, array); indexes.pushInt(data.getIndex());
values.pushString(data.getItem());
}
map.putArray("selectedValue", values);
map.putArray("selectedIndex", indexes);
sendEvent(getReactApplicationContext(), PICKER_EVENT_NAME, map); sendEvent(getReactApplicationContext(), PICKER_EVENT_NAME, map);
} }
...@@ -402,36 +453,18 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl ...@@ -402,36 +453,18 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
} }
@Override @Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) { public void onHostResume() {
} }
@Override @Override
public void onActivityStarted(Activity activity) { public void onHostPause() {
}
@Override
public void onActivityResumed(Activity activity) {
}
@Override
public void onActivityPaused(Activity activity) {
}
@Override
public void onActivityStopped(Activity activity) {
hide(); hide();
dialog = null;
} }
@Override @Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) { public void onHostDestroy() {
} }
@Override
public void onActivityDestroyed(Activity activity) {
}
} }
\ No newline at end of file
...@@ -19,9 +19,13 @@ import java.util.concurrent.ScheduledFuture; ...@@ -19,9 +19,13 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; 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 * 1. Added method getY
* 2. Changed line color 0xffc5c5c5 -> 0xffb8bbc2 * 2. Changed line color 0xffc5c5c5 -> 0xffb8bbc2
*
* Edited by heng on 2016/12/26
* 1. Added setTextColor
* 2. Added setTextSize
*/ */
public class LoopView extends View { public class LoopView extends View {
...@@ -50,10 +54,6 @@ public class LoopView extends View { ...@@ -50,10 +54,6 @@ public class LoopView extends View {
private int textSize; private int textSize;
int maxTextHeight; int maxTextHeight;
private int colorGray;
private int colorBlack;
private int colorLightGray;
// 条目间距倍数 // 条目间距倍数
float lineSpacingMultiplier; float lineSpacingMultiplier;
boolean isLoop; boolean isLoop;
...@@ -109,37 +109,30 @@ public class LoopView extends View { ...@@ -109,37 +109,30 @@ public class LoopView extends View {
lineSpacingMultiplier = 2.0F; lineSpacingMultiplier = 2.0F;
isLoop = true; isLoop = true;
itemsVisible = 9; itemsVisible = 9;
textSize = 0; textSize = (int) (context.getResources().getDisplayMetrics().density * 16);
colorGray = 0xffafafaf;
colorBlack = 0xff313131;
colorLightGray = 0xffb8bbc2;
// colorLightGray = 0xffc5c5c5;
totalScrollY = 0; totalScrollY = 0;
initPosition = -1; initPosition = -1;
initPaints(); initPaints();
setTextSize(20F);
} }
private void initPaints() { private void initPaints() {
paintOuterText = new Paint(); paintOuterText = new Paint();
paintOuterText.setColor(colorGray); paintOuterText.setColor(0xffafafaf);
paintOuterText.setAntiAlias(true); paintOuterText.setAntiAlias(true);
paintOuterText.setTypeface(Typeface.MONOSPACE); paintOuterText.setTypeface(Typeface.MONOSPACE);
paintOuterText.setTextSize(textSize); paintOuterText.setTextSize(textSize);
paintCenterText = new Paint(); paintCenterText = new Paint();
paintCenterText.setColor(colorBlack); paintCenterText.setColor(0xff000000);
paintCenterText.setAntiAlias(true); paintCenterText.setAntiAlias(true);
paintCenterText.setTextScaleX(scaleX); paintCenterText.setTextScaleX(scaleX);
paintCenterText.setTypeface(Typeface.MONOSPACE); paintCenterText.setTypeface(Typeface.MONOSPACE);
paintCenterText.setTextSize(textSize); paintCenterText.setTextSize(textSize);
paintIndicator = new Paint(); paintIndicator = new Paint();
paintIndicator.setColor(colorLightGray); paintIndicator.setColor(0xffb8bbc2);
paintIndicator.setAntiAlias(true); paintIndicator.setAntiAlias(true);
if (android.os.Build.VERSION.SDK_INT >= 11) { if (android.os.Build.VERSION.SDK_INT >= 11) {
...@@ -204,15 +197,22 @@ public class LoopView extends View { ...@@ -204,15 +197,22 @@ public class LoopView extends View {
} }
} }
public void setTextColor(int color){
paintCenterText.setColor(color);
invalidate();
}
public final void setNotLoop() { public final void setNotLoop() {
isLoop = false; isLoop = false;
} }
public final void setTextSize(float size) { public final void setTextSize(float size) {
if (size > 0.0F) { if (size > 0.0F) {
textSize = (int) (context.getResources().getDisplayMetrics().density * size); this.textSize = (int) (context.getResources().getDisplayMetrics().density * size);
paintOuterText.setTextSize(textSize); paintOuterText.setTextSize(textSize);
paintCenterText.setTextSize(textSize); paintCenterText.setTextSize(textSize);
remeasure();
invalidate();
} }
} }
...@@ -242,6 +242,7 @@ public class LoopView extends View { ...@@ -242,6 +242,7 @@ public class LoopView extends View {
this.initPosition = initPosition; this.initPosition = initPosition;
} }
} }
selectedIndex = initPosition;
totalScrollY = 0; totalScrollY = 0;
cancelFuture(); cancelFuture();
invalidate(); invalidate();
......
...@@ -8,6 +8,6 @@ import java.util.ArrayList; ...@@ -8,6 +8,6 @@ import java.util.ArrayList;
public interface OnSelectedListener { public interface OnSelectedListener {
void onSelected(ArrayList<String> selectedList); void onSelected(ArrayList<ReturnData> selectedList);
} }
...@@ -13,10 +13,14 @@ import java.util.ArrayList; ...@@ -13,10 +13,14 @@ import java.util.ArrayList;
import java.util.Arrays; 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> * <p>
* Edited by heng on 16/10/09: * Edited by heng on 16/10/09:
* 修复滚动后返回值错误的bug * 修复滚动后返回值错误的bug
*
* Edited by heng on 2016/12/26
* 1. Fixed returnData bug
* 2. Added LoopView TextColor and TextSize support
*/ */
public class PickerViewAlone extends LinearLayout { public class PickerViewAlone extends LinearLayout {
...@@ -25,7 +29,7 @@ public class PickerViewAlone extends LinearLayout { ...@@ -25,7 +29,7 @@ public class PickerViewAlone extends LinearLayout {
private OnSelectedListener onSelectedListener; private OnSelectedListener onSelectedListener;
private ArrayList<String> curSelectedList; private ArrayList<ReturnData> curSelectedList;
public PickerViewAlone(Context context) { public PickerViewAlone(Context context) {
super(context); super(context);
...@@ -50,19 +54,19 @@ public class PickerViewAlone extends LinearLayout { ...@@ -50,19 +54,19 @@ public class PickerViewAlone extends LinearLayout {
curSelectedList = new ArrayList<>(); curSelectedList = new ArrayList<>();
switch (array.getType(0).name()) { switch (array.getType(0).name()) {
case "Array": case "Array":
setMultipleData(array, curSelectedList, weights); setMultipleData(array, weights);
break; break;
default: default:
setAloneData(array, curSelectedList); setAloneData(array);
break; break;
} }
} }
public ArrayList<String> getSelectedData(){ public ArrayList<ReturnData> getSelectedData() {
return this.curSelectedList; return this.curSelectedList;
} }
private void setAloneData(ReadableArray array, final ArrayList<String> curSelectedList) { private void setAloneData(ReadableArray array) {
ArrayList<String> values = arrayToList(array); ArrayList<String> values = arrayToList(array);
final LoopView loopView = new LoopView(getContext()); final LoopView loopView = new LoopView(getContext());
LayoutParams params = new LayoutParams( LayoutParams params = new LayoutParams(
...@@ -71,16 +75,22 @@ public class PickerViewAlone extends LinearLayout { ...@@ -71,16 +75,22 @@ public class PickerViewAlone extends LinearLayout {
loopView.setLayoutParams(params); loopView.setLayoutParams(params);
loopView.setItems(values); loopView.setItems(values);
loopView.setSelectedPosition(0); loopView.setSelectedPosition(0);
ReturnData returnData = new ReturnData();
returnData.setItem(values.get(0));
returnData.setIndex(loopView.getSelectedIndex());
if (curSelectedList.size() > 0) { if (curSelectedList.size() > 0) {
curSelectedList.set(0, values.get(0)); curSelectedList.set(0, returnData);
} else { } else {
curSelectedList.add(0, values.get(0)); curSelectedList.add(0, returnData);
} }
loopView.setListener(new OnItemSelectedListener() { loopView.setListener(new OnItemSelectedListener() {
@Override @Override
public void onItemSelected(String item, int index) { public void onItemSelected(String item, int index) {
if (onSelectedListener != null) { if (onSelectedListener != null) {
curSelectedList.set(0, item); ReturnData returnData1 = new ReturnData();
returnData1.setItem(item);
returnData1.setIndex(index);
curSelectedList.set(0, returnData1);
onSelectedListener.onSelected(curSelectedList); onSelectedListener.onSelected(curSelectedList);
} }
} }
...@@ -88,8 +98,9 @@ public class PickerViewAlone extends LinearLayout { ...@@ -88,8 +98,9 @@ public class PickerViewAlone extends LinearLayout {
pickerViewAloneLayout.addView(loopView); 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 String[] selectedItems = new String[array.size()];
final int[] selectedIndexes = new int[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()) {
case "Array": case "Array":
...@@ -110,10 +121,14 @@ public class PickerViewAlone extends LinearLayout { ...@@ -110,10 +121,14 @@ public class PickerViewAlone extends LinearLayout {
loopView.setItems(values); loopView.setItems(values);
loopView.setTag(i); loopView.setTag(i);
loopView.setSelectedPosition(0); loopView.setSelectedPosition(0);
ReturnData returnData = new ReturnData();
returnData.setItem(values.get(0));
returnData.setIndex(loopView.getSelectedIndex());
if (curSelectedList.size() > i) { if (curSelectedList.size() > i) {
curSelectedList.set(i, values.get(0)); curSelectedList.set(i, returnData);
} else { } else {
curSelectedList.add(i, values.get(0)); curSelectedList.add(i, returnData);
} }
selectedItems[i] = values.get(0); selectedItems[i] = values.get(0);
loopView.setListener(new OnItemSelectedListener() { loopView.setListener(new OnItemSelectedListener() {
...@@ -125,12 +140,16 @@ public class PickerViewAlone extends LinearLayout { ...@@ -125,12 +140,16 @@ public class PickerViewAlone extends LinearLayout {
if (view instanceof LoopView) { if (view instanceof LoopView) {
LoopView loop = (LoopView) view; LoopView loop = (LoopView) view;
selectedItems[k] = loop.getSelectedItem(); selectedItems[k] = loop.getSelectedItem();
selectedIndexes[k] = loop.getSelectedIndex();
} }
} }
if (onSelectedListener != null) { if (onSelectedListener != null) {
for (int i = 0; i < selectedItems.length; i++) { 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); onSelectedListener.onSelected(curSelectedList);
} }
...@@ -155,16 +174,41 @@ public class PickerViewAlone extends LinearLayout { ...@@ -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++) { for (int i = 0; i < size; i++) {
View view = pickerViewAloneLayout.getChildAt(i); View view = pickerViewAloneLayout.getChildAt(i);
if (view instanceof LoopView) { if (view instanceof LoopView) {
LoopView loop = (LoopView) view; LoopView loop = (LoopView) view;
if (loop.hasItem(values[i])) { if (loop.hasItem(values[i])) {
loop.setSelectedItem(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);
}
} }
} }
......
...@@ -15,7 +15,11 @@ import java.util.ArrayList; ...@@ -15,7 +15,11 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
/** /**
* Created by heng on 16/9/1. * Created by <a href="https://github.com/shexiaoheng">heng</a> on 2016/09/01
*
* Edited by heng on 2016/12/26
* 1. Fixed returnData bug
* 2. Added LoopView TextColor and TextSize support
*/ */
public class PickerViewLinkage extends LinearLayout { public class PickerViewLinkage extends LinearLayout {
...@@ -77,7 +81,11 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -77,7 +81,11 @@ public class PickerViewLinkage extends LinearLayout {
private int selectOneIndex; private int selectOneIndex;
private int selectTwoIndex; private int selectTwoIndex;
private ArrayList<String> curSelectedList; private ArrayList<ReturnData> curSelectedList;
private ReturnData returnData;
private ReturnData returnData1;
private ReturnData returnData2;
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) {
...@@ -137,6 +145,9 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -137,6 +145,9 @@ public class PickerViewLinkage extends LinearLayout {
*/ */
public void setPickerData(ReadableArray array, double[] weights) { public void setPickerData(ReadableArray array, double[] weights) {
curSelectedList = new ArrayList<>(); curSelectedList = new ArrayList<>();
returnData = new ReturnData();
returnData1 = new ReturnData();
returnData2 = new ReturnData();
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);
...@@ -148,10 +159,13 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -148,10 +159,13 @@ public class PickerViewLinkage extends LinearLayout {
} }
} }
checkItems(loopViewOne, oneList); checkItems(loopViewOne, oneList);
returnData.setItem(oneList.get(0));
returnData.setIndex(loopViewOne.getSelectedIndex());
if (curSelectedList.size() > 0) { if (curSelectedList.size() > 0) {
curSelectedList.set(0, oneList.get(0)); curSelectedList.set(0, returnData);
} else { } else {
curSelectedList.add(0, oneList.get(0)); curSelectedList.add(0, returnData);
} }
ReadableArray childArray = data.get(0).getArray(oneList.get(0)); ReadableArray childArray = data.get(0).getArray(oneList.get(0));
...@@ -162,10 +176,12 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -162,10 +176,12 @@ public class PickerViewLinkage extends LinearLayout {
twoList.clear(); twoList.clear();
getTwoListData(); getTwoListData();
checkItems(loopViewTwo, twoList); checkItems(loopViewTwo, twoList);
returnData1.setItem(twoList.get(0));
returnData1.setIndex(loopViewTwo.getSelectedIndex());
if (curSelectedList.size() > 1) { if (curSelectedList.size() > 1) {
curSelectedList.set(1, twoList.get(0)); curSelectedList.set(1, returnData1);
} else { } else {
curSelectedList.add(1, twoList.get(0)); curSelectedList.add(1, returnData1);
} }
ReadableMap childMap = data.get(0).getArray(oneList.get(0)).getMap(0); ReadableMap childMap = data.get(0).getArray(oneList.get(0)).getMap(0);
...@@ -174,17 +190,22 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -174,17 +190,22 @@ public class PickerViewLinkage extends LinearLayout {
threeList.clear(); threeList.clear();
threeList = arrayToList(sunArray); threeList = arrayToList(sunArray);
checkItems(loopViewThree, threeList); checkItems(loopViewThree, threeList);
returnData2.setItem(threeList.get(0));
returnData2.setIndex(loopViewThree.getSelectedIndex());
if (curSelectedList.size() > 2) { if (curSelectedList.size() > 2) {
curSelectedList.set(2, threeList.get(0)); curSelectedList.set(2, returnData2);
} else { } else {
curSelectedList.add(2, threeList.get(0)); curSelectedList.add(2, returnData2);
} }
loopViewOne.setListener(new OnItemSelectedListener() { loopViewOne.setListener(new OnItemSelectedListener() {
@Override @Override
public void onItemSelected(String item, int index) { public void onItemSelected(String item, int index) {
selectOneIndex = index; selectOneIndex = index;
curSelectedList.set(0, item); returnData = new ReturnData();
returnData.setIndex(index);
returnData.setItem(item);
curSelectedList.set(0, returnData);
twoList.clear(); twoList.clear();
ReadableArray arr = data.get(index).getArray(item); ReadableArray arr = data.get(index).getArray(item);
for (int i = 0; i < arr.size(); i++) { for (int i = 0; i < arr.size(); i++) {
...@@ -195,7 +216,10 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -195,7 +216,10 @@ public class PickerViewLinkage extends LinearLayout {
} }
} }
checkItems(loopViewTwo, twoList); checkItems(loopViewTwo, twoList);
curSelectedList.set(1, twoList.get(0)); returnData1 = new ReturnData();
returnData1.setItem(twoList.get(0));
returnData1.setIndex(loopViewTwo.getSelectedIndex());
curSelectedList.set(1, returnData1);
ReadableArray ar = data.get(index).getArray(item); ReadableArray ar = data.get(index).getArray(item);
...@@ -205,7 +229,10 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -205,7 +229,10 @@ public class PickerViewLinkage extends LinearLayout {
threeList.clear(); threeList.clear();
threeList = arrayToList(sunArray); threeList = arrayToList(sunArray);
checkItems(loopViewThree, threeList); checkItems(loopViewThree, threeList);
curSelectedList.set(2, threeList.get(0)); returnData2 = new ReturnData();
returnData2.setItem(threeList.get(0));
returnData2.setIndex(loopViewThree.getSelectedIndex());
curSelectedList.set(2, returnData2);
if (onSelectedListener != null) { if (onSelectedListener != null) {
onSelectedListener.onSelected(curSelectedList); onSelectedListener.onSelected(curSelectedList);
...@@ -226,9 +253,20 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -226,9 +253,20 @@ public class PickerViewLinkage extends LinearLayout {
threeList = arrayToList(sunArray); threeList = arrayToList(sunArray);
checkItems(loopViewThree, threeList); checkItems(loopViewThree, threeList);
curSelectedList.set(0, oneList.get(selectOneIndex)); returnData = new ReturnData();
curSelectedList.set(1, item); returnData.setItem(oneList.get(selectOneIndex));
curSelectedList.set(2, threeList.get(0)); returnData.setIndex(loopViewOne.getSelectedIndex());
curSelectedList.set(0, returnData);
returnData1 = new ReturnData();
returnData1.setItem(item);
returnData1.setIndex(index);
curSelectedList.set(1, returnData1);
returnData2 = new ReturnData();
returnData2.setItem(threeList.get(0));
returnData2.setIndex(loopViewThree.getSelectedIndex());
curSelectedList.set(2, returnData2);
if (onSelectedListener != null) { if (onSelectedListener != null) {
onSelectedListener.onSelected(curSelectedList); onSelectedListener.onSelected(curSelectedList);
} }
...@@ -238,9 +276,20 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -238,9 +276,20 @@ public class PickerViewLinkage extends LinearLayout {
loopViewThree.setListener(new OnItemSelectedListener() { loopViewThree.setListener(new OnItemSelectedListener() {
@Override @Override
public void onItemSelected(String item, int index) { public void onItemSelected(String item, int index) {
curSelectedList.set(0, oneList.get(selectOneIndex)); returnData = new ReturnData();
curSelectedList.set(1, twoList.get(selectTwoIndex)); returnData.setItem(oneList.get(selectOneIndex));
curSelectedList.set(2, item); returnData.setIndex(loopViewOne.getSelectedIndex());
curSelectedList.set(0, returnData);
returnData1 = new ReturnData();
returnData1.setItem(twoList.get(selectTwoIndex));
returnData1.setIndex(loopViewTwo.getSelectedIndex());
curSelectedList.set(1, returnData1);
returnData2 = new ReturnData();
returnData2.setItem(item);
returnData2.setIndex(index);
curSelectedList.set(2, returnData2);
if (onSelectedListener != null) { if (onSelectedListener != null) {
onSelectedListener.onSelected(curSelectedList); onSelectedListener.onSelected(curSelectedList);
} }
...@@ -256,8 +305,14 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -256,8 +305,14 @@ public class PickerViewLinkage extends LinearLayout {
twoList.clear(); twoList.clear();
twoList = arrayToList(arr); twoList = arrayToList(arr);
checkItems(loopViewTwo, twoList); checkItems(loopViewTwo, twoList);
curSelectedList.set(0, item); returnData = new ReturnData();
curSelectedList.set(1, twoList.get(0)); returnData.setItem(item);
returnData.setIndex(index);
curSelectedList.set(0, returnData);
returnData1 = new ReturnData();
returnData1.setItem(twoList.get(0));
returnData1.setIndex(loopViewTwo.getSelectedIndex());
curSelectedList.set(1, returnData1);
if (onSelectedListener != null) { if (onSelectedListener != null) {
onSelectedListener.onSelected(curSelectedList); onSelectedListener.onSelected(curSelectedList);
} }
...@@ -267,16 +322,26 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -267,16 +322,26 @@ public class PickerViewLinkage extends LinearLayout {
twoList.clear(); twoList.clear();
twoList = arrayToList(childArray); twoList = arrayToList(childArray);
checkItems(loopViewTwo, twoList); checkItems(loopViewTwo, twoList);
returnData1 = new ReturnData();
returnData1.setItem(twoList.get(0));
returnData1.setIndex(loopViewTwo.getSelectedIndex());
if (curSelectedList.size() > 1) { if (curSelectedList.size() > 1) {
curSelectedList.set(1, twoList.get(0)); curSelectedList.set(1, returnData1);
} else { } else {
curSelectedList.add(1, twoList.get(0)); curSelectedList.add(1, returnData1);
} }
loopViewTwo.setListener(new OnItemSelectedListener() { loopViewTwo.setListener(new OnItemSelectedListener() {
@Override @Override
public void onItemSelected(String item, int index) { public void onItemSelected(String item, int index) {
curSelectedList.set(0, oneList.get(selectOneIndex)); returnData = new ReturnData();
curSelectedList.set(1, item); returnData.setItem(oneList.get(selectOneIndex));
returnData.setIndex(loopViewOne.getSelectedIndex());
curSelectedList.set(0, returnData);
returnData1 = new ReturnData();
returnData1.setIndex(index);
returnData1.setItem(item);
curSelectedList.set(1, returnData1);
if (onSelectedListener != null) { if (onSelectedListener != null) {
onSelectedListener.onSelected(curSelectedList); onSelectedListener.onSelected(curSelectedList);
} }
...@@ -330,13 +395,19 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -330,13 +395,19 @@ public class PickerViewLinkage extends LinearLayout {
getTwoListData(); getTwoListData();
loopViewTwo.setItems(twoList); loopViewTwo.setItems(twoList);
loopViewTwo.setSelectedPosition(0); loopViewTwo.setSelectedPosition(0);
curSelectedList.set(1, loopViewTwo.getIndexItem(0)); returnData1 = new ReturnData();
returnData1.setItem(loopViewTwo.getIndexItem(0));
returnData1.setIndex(loopViewTwo.getSelectedIndex());
curSelectedList.set(1, returnData1);
threeList.clear(); threeList.clear();
getThreeListData(); getThreeListData();
loopViewThree.setItems(threeList); loopViewThree.setItems(threeList);
loopViewThree.setSelectedPosition(0); loopViewThree.setSelectedPosition(0);
curSelectedList.set(2, loopViewThree.getIndexItem(0)); returnData2 = new ReturnData();
returnData2.setItem(loopViewThree.getIndexItem(0));
returnData2.setIndex(loopViewThree.getSelectedIndex());
curSelectedList.set(2, returnData2);
break; break;
case 2: case 2:
...@@ -344,7 +415,10 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -344,7 +415,10 @@ public class PickerViewLinkage extends LinearLayout {
getAllTwoListData(); getAllTwoListData();
loopViewTwo.setItems(twoList); loopViewTwo.setItems(twoList);
loopViewTwo.setSelectedPosition(0); loopViewTwo.setSelectedPosition(0);
curSelectedList.set(1, loopViewTwo.getIndexItem(0)); returnData1 = new ReturnData();
returnData1.setItem(loopViewTwo.getIndexItem(0));
returnData1.setIndex(loopViewTwo.getSelectedIndex());
curSelectedList.set(1, returnData1);
break; break;
} }
break; break;
...@@ -362,7 +436,10 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -362,7 +436,10 @@ public class PickerViewLinkage extends LinearLayout {
getThreeListData(); getThreeListData();
loopViewThree.setItems(threeList); loopViewThree.setItems(threeList);
loopViewThree.setSelectedPosition(0); loopViewThree.setSelectedPosition(0);
curSelectedList.set(2, loopViewThree.getIndexItem(0)); returnData2 = new ReturnData();
returnData2.setItem(loopViewThree.getIndexItem(0));
returnData2.setIndex(loopViewThree.getSelectedIndex());
curSelectedList.set(2, returnData2);
break; break;
} }
break; break;
...@@ -372,7 +449,7 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -372,7 +449,7 @@ public class PickerViewLinkage extends LinearLayout {
} }
} }
private void selectValues(String[] values, final ArrayList<String> curSelectedList) { private void selectValues(String[] values, final ArrayList<ReturnData> curSelectedList) {
switch (values.length) { switch (values.length) {
case 3: case 3:
selectOneLoop(values, curSelectedList); selectOneLoop(values, curSelectedList);
...@@ -400,47 +477,53 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -400,47 +477,53 @@ public class PickerViewLinkage extends LinearLayout {
/** /**
* 设置第一个滚轮选中的值 * 设置第一个滚轮选中的值
*/ */
private void selectOneLoop(String[] values, final ArrayList<String> curSelectedList) { private void selectOneLoop(String[] values, final ArrayList<ReturnData> curSelectedList) {
if (loopViewOne.hasItem(values[0])) { if (loopViewOne.hasItem(values[0])) {
selectOneIndex = loopViewOne.getItemPosition(values[0]); selectOneIndex = loopViewOne.getItemPosition(values[0]);
loopViewOne.setSelectedPosition(selectOneIndex);
curSelectedList.set(0, loopViewOne.getIndexItem(selectOneIndex));
} else { } else {
selectOneIndex = 0; selectOneIndex = 0;
loopViewOne.setSelectedPosition(0);
curSelectedList.set(0, loopViewOne.getIndexItem(0));
} }
loopViewOne.setSelectedPosition(selectOneIndex);
returnData = new ReturnData();
returnData.setItem(loopViewOne.getIndexItem(selectOneIndex));
returnData.setIndex(loopViewOne.getSelectedIndex());
curSelectedList.set(0, returnData);
} }
/** /**
* 设置第二个滚轮选中的值 * 设置第二个滚轮选中的值
*/ */
private void selectTwoLoop(String[] values, final ArrayList<String> curSelectedList) { private void selectTwoLoop(String[] values, final ArrayList<ReturnData> curSelectedList) {
loopViewTwo.setItems(twoList); loopViewTwo.setItems(twoList);
if (loopViewTwo.hasItem(values[1])) { if (loopViewTwo.hasItem(values[1])) {
selectTwoIndex = loopViewTwo.getItemPosition(values[1]); selectTwoIndex = loopViewTwo.getItemPosition(values[1]);
loopViewTwo.setSelectedPosition(selectTwoIndex);
curSelectedList.set(1, loopViewTwo.getIndexItem(selectTwoIndex));
} else { } else {
selectTwoIndex = 0; selectTwoIndex = 0;
loopViewTwo.setSelectedPosition(0);
curSelectedList.set(1, loopViewTwo.getIndexItem(0));
} }
returnData1 = new ReturnData();
loopViewTwo.setSelectedPosition(selectTwoIndex);
returnData1.setItem(loopViewTwo.getIndexItem(selectTwoIndex));
returnData1.setIndex(loopViewTwo.getSelectedIndex());
curSelectedList.set(1, returnData1);
} }
/** /**
* 设置第三个滚轮选中的值 * 设置第三个滚轮选中的值
*/ */
private void selectThreeLoop(String[] values, final ArrayList<String> curSelectedList) { private void selectThreeLoop(String[] values, final ArrayList<ReturnData> curSelectedList) {
loopViewThree.setItems(threeList); loopViewThree.setItems(threeList);
int selectThreeIndex;
if (loopViewThree.hasItem(values[2])) { if (loopViewThree.hasItem(values[2])) {
int selectThreeIndex = loopViewThree.getItemPosition(values[2]); selectThreeIndex = loopViewThree.getItemPosition(values[2]);
loopViewThree.setSelectedPosition(selectThreeIndex);
curSelectedList.set(2, loopViewThree.getIndexItem(selectThreeIndex));
} else { } else {
loopViewThree.setSelectedPosition(0); selectThreeIndex = 0;
curSelectedList.set(2, loopViewThree.getIndexItem(0));
} }
returnData2 = new ReturnData();
loopViewThree.setSelectedPosition(selectThreeIndex);
returnData2.setItem(loopViewThree.getIndexItem(selectThreeIndex));
returnData2.setIndex(loopViewThree.getSelectedIndex());
curSelectedList.set(2, returnData2);
} }
/** /**
...@@ -477,6 +560,33 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -477,6 +560,33 @@ public class PickerViewLinkage extends LinearLayout {
threeList = arrayToList(sunArray); threeList = arrayToList(sunArray);
} }
public void setTextSize(float size){
switch (curRow) {
case 2:
loopViewOne.setTextSize(size);
loopViewTwo.setTextSize(size);
break;
case 3:
loopViewOne.setTextSize(size);
loopViewTwo.setTextSize(size);
loopViewThree.setTextSize(size);
break;
}
}
public void setTextColor(int color){
switch (curRow) {
case 2:
loopViewOne.setTextColor(color);
loopViewTwo.setTextColor(color);
break;
case 3:
loopViewOne.setTextColor(color);
loopViewTwo.setTextColor(color);
loopViewThree.setTextColor(color);
break;
}
}
public void setIsLoop(boolean isLoop) { public void setIsLoop(boolean isLoop) {
if (!isLoop) { if (!isLoop) {
...@@ -491,7 +601,6 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -491,7 +601,6 @@ public class PickerViewLinkage extends LinearLayout {
loopViewThree.setNotLoop(); loopViewThree.setNotLoop();
break; break;
} }
} }
} }
...@@ -499,12 +608,11 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -499,12 +608,11 @@ public class PickerViewLinkage extends LinearLayout {
return loopViewOne.getViewHeight(); return loopViewOne.getViewHeight();
} }
public ArrayList<String> getSelectedData(){ public ArrayList<ReturnData> getSelectedData() {
return this.curSelectedList; return this.curSelectedList;
} }
public void setOnSelectListener(OnSelectedListener listener) { public void setOnSelectListener(OnSelectedListener listener) {
this.onSelectedListener = listener; this.onSelectedListener = listener;
} }
} }
\ No newline at end of file
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 { ...@@ -19,6 +19,7 @@ class PickerTest extends Component {
constructor(props, context) { constructor(props, context) {
super(props, context); super(props, context);
this._showDatePicker();
} }
_createDateData() { _createDateData() {
...@@ -78,15 +79,17 @@ class PickerTest extends Component { ...@@ -78,15 +79,17 @@ class PickerTest extends Component {
_showDatePicker() { _showDatePicker() {
Picker.init({ Picker.init({
pickerData: this._createDateData(), pickerData: this._createDateData(),
selectedValue: ['2015年', '12月', '12日'], pickerToolBarFontSize: 16,
onPickerConfirm: pickedValue => { pickerFontSize: 16,
console.log('date', pickedValue); pickerFontColor: [255, 0 ,0, 1],
onPickerConfirm: (pickedValue, pickedIndex) => {
console.log('date', pickedValue, pickedIndex);
}, },
onPickerCancel: pickedValue => { onPickerCancel: (pickedValue, pickedIndex) => {
console.log('date', pickedValue); console.log('date', pickedValue, pickedIndex);
}, },
onPickerSelect: pickedValue => { onPickerSelect: (pickedValue, pickedIndex) => {
console.log('date', pickedValue); console.log('date', pickedValue, pickedIndex);
} }
}); });
Picker.show(); Picker.show();
......
...@@ -13,17 +13,24 @@ export default { ...@@ -13,17 +13,24 @@ export default {
init(options){ init(options){
let opt = { let opt = {
isLoop: false, isLoop: false,
pickerConfirmBtnText: '确认', pickerConfirmBtnText: 'confirm',
pickerCancelBtnText: '取消', pickerCancelBtnText: 'cancel',
pickerTitleText: '请选择', pickerTitleText: 'pls select',
pickerBg: [196, 199, 206, 1],
pickerToolBarBg: [232, 232, 232, 1],
pickerTitleColor: [20, 20, 20, 1],
pickerCancelBtnColor: [1, 186, 245, 1],
pickerConfirmBtnColor: [1, 186, 245, 1], 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(){}, onPickerConfirm(){},
onPickerCancel(){}, onPickerCancel(){},
onPickerSelect(){}, onPickerSelect(){},
//4.0.12 add
pickerToolBarFontSize: 16,
pickerFontSize: 16,
pickerFontColor: [31, 31 ,31, 1],
...options ...options
}; };
let fnConf = { let fnConf = {
...@@ -36,14 +43,7 @@ export default { ...@@ -36,14 +43,7 @@ export default {
//there are no `removeListener` for NativeAppEventEmitter & DeviceEventEmitter //there are no `removeListener` for NativeAppEventEmitter & DeviceEventEmitter
this.listener && this.listener.remove(); this.listener && this.listener.remove();
this.listener = NativeAppEventEmitter.addListener('pickerEvent', event => { this.listener = NativeAppEventEmitter.addListener('pickerEvent', event => {
if(ios){ fnConf[event['type']](event['selectedValue'], event['selectedIndex']);
fnConf[event['type']](event['selectedValue']);
}
else if(android){
for (let i in event){
typeof fnConf[i] === 'function' && fnConf[i](event[i]);
}
}
}); });
}, },
......
...@@ -39,6 +39,9 @@ typedef void(^backBolock)(NSDictionary * ); ...@@ -39,6 +39,9 @@ typedef void(^backBolock)(NSDictionary * );
@property(strong,nonatomic)NSString *leftStr; @property(strong,nonatomic)NSString *leftStr;
@property(strong,nonatomic)NSString *centStr; @property(strong,nonatomic)NSString *centStr;
@property(strong,nonatomic)NSString *rightStr; @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 * ); ...@@ -61,6 +64,7 @@ typedef void(^backBolock)(NSDictionary * );
@property(strong,nonatomic)NSArray *weightArry; @property(strong,nonatomic)NSArray *weightArry;
@property(assign,nonatomic)CGFloat lineWith;
//创建一个下角标记录是第几行 来一进来判断第一行被选中 当进来的是关联两行的逻辑的时候 或者三行关联的时候取第二行做记录 //创建一个下角标记录是第几行 来一进来判断第一行被选中 当进来的是关联两行的逻辑的时候 或者三行关联的时候取第二行做记录
@property(assign,nonatomic)NSInteger num; @property(assign,nonatomic)NSInteger num;
...@@ -69,9 +73,12 @@ typedef void(^backBolock)(NSDictionary * ); ...@@ -69,9 +73,12 @@ typedef void(^backBolock)(NSDictionary * );
@property(assign,nonatomic)NSInteger threenum; @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 @end
...@@ -7,10 +7,13 @@ ...@@ -7,10 +7,13 @@
// //
#import "BzwPicker.h" #import "BzwPicker.h"
#define linSpace 5
@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 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
{ {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) if (self)
...@@ -24,6 +27,9 @@ ...@@ -24,6 +27,9 @@
self.leftStr=leftStr; self.leftStr=leftStr;
self.rightStr=rightStr; self.rightStr=rightStr;
self.centStr=centerStr; self.centStr=centerStr;
self.pickerToolBarFontSize=pickerToolBarFontSize;
self.pickerFontSize=pickerFontSize;
self.pickerFontColor=pickerFontColor;
[self getStyle]; [self getStyle];
[self getnumStyle]; [self getnumStyle];
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
...@@ -44,7 +50,7 @@ ...@@ -44,7 +50,7 @@
self.leftBtn = [UIButton buttonWithType:UIButtonTypeCustom]; self.leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.leftBtn.frame = CGRectMake(10, 5, 90, 30); self.leftBtn.frame = CGRectMake(10, 5, 90, 30);
[self.leftBtn setTitle:self.leftStr forState:UIControlStateNormal]; [self.leftBtn setTitle:self.leftStr forState:UIControlStateNormal];
[self.leftBtn setFont:[UIFont systemFontOfSize:16]]; [self.leftBtn setFont:[UIFont systemFontOfSize:[_pickerToolBarFontSize integerValue]]];
self.leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; self.leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[self.leftBtn addTarget:self action:@selector(cancleAction) forControlEvents:UIControlEventTouchUpInside]; [self.leftBtn addTarget:self action:@selector(cancleAction) forControlEvents:UIControlEventTouchUpInside];
...@@ -54,7 +60,6 @@ ...@@ -54,7 +60,6 @@
view.backgroundColor=[self colorWith:topbgColor]; view.backgroundColor=[self colorWith:topbgColor];
self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom]; self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.rightBtn.frame = CGRectMake(view.frame.size.width-100,5, 90, 30); self.rightBtn.frame = CGRectMake(view.frame.size.width-100,5, 90, 30);
[self.rightBtn setTitle:self.rightStr forState:UIControlStateNormal]; [self.rightBtn setTitle:self.rightStr forState:UIControlStateNormal];
...@@ -64,7 +69,7 @@ ...@@ -64,7 +69,7 @@
[view addSubview:self.rightBtn]; [view addSubview:self.rightBtn];
[self.rightBtn setFont:[UIFont systemFontOfSize:16]]; [self.rightBtn setFont:[UIFont systemFontOfSize:[_pickerToolBarFontSize integerValue]]];
[self.rightBtn addTarget:self action:@selector(cfirmAction) forControlEvents:UIControlEventTouchUpInside]; [self.rightBtn addTarget:self action:@selector(cfirmAction) forControlEvents:UIControlEventTouchUpInside];
...@@ -72,7 +77,7 @@ ...@@ -72,7 +77,7 @@
cenLabel.textAlignment=NSTextAlignmentCenter; cenLabel.textAlignment=NSTextAlignmentCenter;
[cenLabel setFont:[UIFont systemFontOfSize:16]]; [cenLabel setFont:[UIFont systemFontOfSize:[_pickerToolBarFontSize integerValue]]];
cenLabel.text=self.centStr; cenLabel.text=self.centStr;
...@@ -80,7 +85,11 @@ ...@@ -80,7 +85,11 @@
[view addSubview:cenLabel]; [view addSubview:cenLabel];
self.pick = [[UIPickerView alloc] initWithFrame:CGRectMake(-15, 40, self.frame.size.width+15, self.frame.size.height - 40)]; <<<<<<< HEAD
self.pick = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, self.frame.size.width, self.frame.size.height - 40)];
=======
self.pick = [[UIPickerView alloc] initWithFrame:CGRectMake(-5, 40, self.frame.size.width+5, self.frame.size.height - 40)];
>>>>>>> dfafe73491181099295072df68b4d0ebb18d38a8
self.pick.delegate = self; self.pick.delegate = self;
self.pick.dataSource = self; self.pick.dataSource = self;
...@@ -187,22 +196,23 @@ ...@@ -187,22 +196,23 @@
if (_Correlation) { if (_Correlation) {
if ([_numberCorrela isEqualToString:@"three"]) { if ([_numberCorrela isEqualToString:@"three"]) {
_lineWith=SCREEN_WIDTH-2*linSpace;
if (self.weightArry.count>=3) { if (self.weightArry.count>=3) {
NSString *onestr=[NSString stringWithFormat:@"%@",[self.weightArry firstObject]]; NSString *onestr=[NSString stringWithFormat:@"%@",[self.weightArry firstObject]];
NSString *twostr=[NSString stringWithFormat:@"%@",self.weightArry[1]]; NSString *twostr=[NSString stringWithFormat:@"%@",self.weightArry[1]];
NSString *threestr=[NSString stringWithFormat:@"%@",self.weightArry[2]]; NSString *threestr=[NSString stringWithFormat:@"%@",self.weightArry[2]];
double totalweight=onestr.doubleValue+twostr.doubleValue+threestr.doubleValue; double totalweight=onestr.doubleValue+twostr.doubleValue+threestr.doubleValue;
if (component==0) { if (component==0) {
return SCREEN_WIDTH*onestr.doubleValue/totalweight; return _lineWith*onestr.doubleValue/totalweight;
}else if (component==1){ }else if (component==1){
return SCREEN_WIDTH*twostr.doubleValue/totalweight; return _lineWith*twostr.doubleValue/totalweight;
}else{ }else{
return SCREEN_WIDTH*threestr.doubleValue/totalweight; return _lineWith*threestr.doubleValue/totalweight;
} }
}else{ }else{
if (self.weightArry.count>0) { if (self.weightArry.count>0) {
NSInteger totalNum=self.weightArry.count; NSInteger totalNum=self.weightArry.count;
double totalweight=0; double totalweight=0;
for (NSInteger i=0; i<self.weightArry.count; i++) { for (NSInteger i=0; i<self.weightArry.count; i++) {
...@@ -211,46 +221,50 @@ ...@@ -211,46 +221,50 @@
} }
if (component>totalNum-1) { if (component>totalNum-1) {
NSString *str=[NSString stringWithFormat:@"%f",totalweight+3-totalNum]; NSString *str=[NSString stringWithFormat:@"%f",totalweight+3-totalNum];
return SCREEN_WIDTH/str.doubleValue;; return _lineWith/str.doubleValue;;
}else{ }else{
NSString *str=[NSString stringWithFormat:@"%f",totalweight+3-totalNum]; NSString *str=[NSString stringWithFormat:@"%f",totalweight+3-totalNum];
return SCREEN_WIDTH*[NSString stringWithFormat:@"%@",[self.weightArry objectAtIndex:component]].doubleValue/str.doubleValue; return _lineWith*[NSString stringWithFormat:@"%@",[self.weightArry objectAtIndex:component]].doubleValue/str.doubleValue;
} }
}else{ }else{
return SCREEN_WIDTH/3; return _lineWith/3;
} }
} }
}else{ }
else{
_lineWith=SCREEN_WIDTH-linSpace;
if (self.weightArry.count>=2) { if (self.weightArry.count>=2) {
NSString *onestr=[NSString stringWithFormat:@"%@",[self.weightArry firstObject]]; NSString *onestr=[NSString stringWithFormat:@"%@",[self.weightArry firstObject]];
NSString *twostr=[NSString stringWithFormat:@"%@",self.weightArry[1]]; NSString *twostr=[NSString stringWithFormat:@"%@",self.weightArry[1]];
double totalweight=onestr.doubleValue+twostr.doubleValue; double totalweight=onestr.doubleValue+twostr.doubleValue;
if (component==0) { if (component==0) {
return SCREEN_WIDTH*onestr.doubleValue/totalweight; return _lineWith*onestr.doubleValue/totalweight;
}else{ }else{
return SCREEN_WIDTH*twostr.doubleValue/totalweight; return _lineWith*twostr.doubleValue/totalweight;
} }
}else{ }
else{
if (self.weightArry.count>0) { if (self.weightArry.count>0) {
double twonum=[NSString stringWithFormat:@"%@",[self.weightArry firstObject]].doubleValue; double twonum=[NSString stringWithFormat:@"%@",[self.weightArry firstObject]].doubleValue;
if (component==0) { if (component==0) {
NSString *str=[NSString stringWithFormat:@"%f",twonum+1]; NSString *str=[NSString stringWithFormat:@"%f",twonum+1];
return SCREEN_WIDTH*twonum/str.doubleValue; return _lineWith*twonum/str.doubleValue;
}else{ }else{
NSString *str=[NSString stringWithFormat:@"%f",twonum+1]; NSString *str=[NSString stringWithFormat:@"%f",twonum+1];
return SCREEN_WIDTH/str.doubleValue; return _lineWith/str.doubleValue;
} }
}else }
{ else{
return SCREEN_WIDTH/2; return _lineWith/2;
} }
} }
} }
...@@ -259,6 +273,9 @@ ...@@ -259,6 +273,9 @@
//表示一个数组 特殊情况 //表示一个数组 特殊情况
return SCREEN_WIDTH; return SCREEN_WIDTH;
}else{ }else{
_lineWith=(SCREEN_WIDTH-linSpace*(self.dataDry.count-1));
if (self.weightArry.count>=self.dataDry.count) { if (self.weightArry.count>=self.dataDry.count) {
double totalweight=0; double totalweight=0;
...@@ -269,15 +286,12 @@ ...@@ -269,15 +286,12 @@
} }
NSString *comStr=[NSString stringWithFormat:@"%@",[self.weightArry objectAtIndex:component]]; NSString *comStr=[NSString stringWithFormat:@"%@",[self.weightArry objectAtIndex:component]];
return SCREEN_WIDTH*comStr.doubleValue/totalweight; return _lineWith*comStr.doubleValue/totalweight;
}else }else
{ {
if (self.weightArry.count>0) { if (self.weightArry.count>0) {
NSInteger totalNum=self.weightArry.count; NSInteger totalNum=self.weightArry.count;
double totalweight=0; double totalweight=0;
for (NSInteger i=0; i<self.weightArry.count; i++) { for (NSInteger i=0; i<self.weightArry.count; i++) {
NSString *str=[NSString stringWithFormat:@"%@",[self.weightArry objectAtIndex:i]]; NSString *str=[NSString stringWithFormat:@"%@",[self.weightArry objectAtIndex:i]];
totalweight=totalweight+str.doubleValue; totalweight=totalweight+str.doubleValue;
...@@ -285,15 +299,14 @@ ...@@ -285,15 +299,14 @@
if (component>totalNum-1) { if (component>totalNum-1) {
NSString *str=[NSString stringWithFormat:@"%f",totalweight+self.dataDry.count-totalNum]; NSString *str=[NSString stringWithFormat:@"%f",totalweight+self.dataDry.count-totalNum];
return SCREEN_WIDTH/str.doubleValue; return _lineWith/str.doubleValue;
}else{ }else{
NSString *str=[NSString stringWithFormat:@"%f",totalweight+self.dataDry.count-totalNum]; NSString *str=[NSString stringWithFormat:@"%f",totalweight+self.dataDry.count-totalNum];
return SCREEN_WIDTH*[NSString stringWithFormat:@"%@",[self.weightArry objectAtIndex:component]].doubleValue/str.doubleValue; return _lineWith*[NSString stringWithFormat:@"%@",[self.weightArry objectAtIndex:component]].doubleValue/str.doubleValue;
} }
}else{ }else{
return SCREEN_WIDTH/self.dataDry.count; return _lineWith/self.dataDry.count;
} }
} }
} }
...@@ -447,7 +460,6 @@ ...@@ -447,7 +460,6 @@
NSArray *eachAry=self.noCorreArry[i]; NSArray *eachAry=self.noCorreArry[i];
[self.backArry addObject:[eachAry objectAtIndex:[self.pick selectedRowInComponent:i]]]; [self.backArry addObject:[eachAry objectAtIndex:[self.pick selectedRowInComponent:i]]];
} }
...@@ -456,8 +468,11 @@ ...@@ -456,8 +468,11 @@
NSMutableDictionary *dic=[[NSMutableDictionary alloc]init]; NSMutableDictionary *dic=[[NSMutableDictionary alloc]init];
[dic setValue:self.backArry forKey:@"selectedValue"]; [dic setValue:self.backArry forKey:@"selectedValue"];
[dic setValue:@"select" forKey:@"type"]; [dic setValue:@"select" forKey:@"type"];
[dic setValue:[self getselectIndexArry] forKey:@"selectedIndex"];
self.bolock(dic); self.bolock(dic);
} }
//判断进来的类型是那种 //判断进来的类型是那种
...@@ -470,6 +485,8 @@ ...@@ -470,6 +485,8 @@
if ([firstobject isKindOfClass:[NSArray class]]) { if ([firstobject isKindOfClass:[NSArray class]]) {
_seleNum=self.dataDry.count;
_Correlation=NO; _Correlation=NO;
}else if ([firstobject isKindOfClass:[NSDictionary class]]){ }else if ([firstobject isKindOfClass:[NSDictionary class]]){
...@@ -487,10 +504,11 @@ ...@@ -487,10 +504,11 @@
if ([scendObjct isKindOfClass:[NSDictionary class]]) { if ([scendObjct isKindOfClass:[NSDictionary class]]) {
_numberCorrela=@"three"; _numberCorrela=@"three";
_seleNum=3;
}else{ }else{
_numberCorrela=@"two"; _numberCorrela=@"two";
_seleNum=2;
} }
} }
} }
...@@ -574,13 +592,15 @@ ...@@ -574,13 +592,15 @@
[dic setValue:self.backArry forKey:@"selectedValue"]; [dic setValue:self.backArry forKey:@"selectedValue"];
[dic setValue:@"cancel" forKey:@"type"]; [dic setValue:@"cancel" forKey:@"type"];
[dic setValue:[self getselectIndexArry] forKey:@"selectedIndex"];
self.bolock(dic); self.bolock(dic);
}else{ }else{
[self getNOselectinfo]; [self getNOselectinfo];
[dic setValue:self.backArry forKey:@"selectedValue"]; [dic setValue:self.backArry forKey:@"selectedValue"];
[dic setValue:@"cancel" forKey:@"type"]; [dic setValue:@"cancel" forKey:@"type"];
[dic setValue:[self getselectIndexArry] forKey:@"selectedIndex"];
self.bolock(dic); self.bolock(dic);
} }
...@@ -602,6 +622,9 @@ ...@@ -602,6 +622,9 @@
[dic setValue:self.backArry forKey:@"selectedValue"]; [dic setValue:self.backArry forKey:@"selectedValue"];
[dic setValue:@"confirm" forKey:@"type"]; [dic setValue:@"confirm" forKey:@"type"];
NSMutableArray *arry=[[NSMutableArray alloc]init];
[dic setValue:[self getselectIndexArry] forKey:@"selectedIndex"];
[dic setValue:arry forKey:@"selectedIndex"];
self.bolock(dic); self.bolock(dic);
...@@ -610,6 +633,8 @@ ...@@ -610,6 +633,8 @@
[dic setValue:self.backArry forKey:@"selectedValue"]; [dic setValue:self.backArry forKey:@"selectedValue"];
[dic setValue:@"confirm" forKey:@"type"]; [dic setValue:@"confirm" forKey:@"type"];
[dic setValue:[self getselectIndexArry] forKey:@"selectedIndex"];
self.bolock(dic); self.bolock(dic);
} }
...@@ -897,5 +922,34 @@ ...@@ -897,5 +922,34 @@
UIColor *color=[[UIColor alloc]initWithRed:[ColorA integerValue]/255.0 green:[ColorB integerValue]/255.0 blue:[ColorC integerValue]/255.0 alpha:[ColorD floatValue]]; UIColor *color=[[UIColor alloc]initWithRed:[ColorA integerValue]/255.0 green:[ColorB integerValue]/255.0 blue:[ColorC integerValue]/255.0 alpha:[ColorD floatValue]];
return color; return color;
} }
-(NSArray *)getselectIndexArry{
NSMutableArray *arry=[[NSMutableArray alloc]init];
for (NSInteger i=0; i<_seleNum; i++) {
NSNumber *num=[[NSNumber alloc]initWithInteger:[self.pick selectedRowInComponent:i]];
[arry addObject:num];
}
return arry;
}
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel *lbl = (UILabel *)view;
if (lbl == nil) {
lbl = [[UILabel alloc]init];
//在这里设置字体相关属性
lbl.font = [UIFont systemFontOfSize:[_pickerFontSize integerValue]];
lbl.textColor = [self colorWith:_pickerFontColor];
lbl.textAlignment = UITextAlignmentCenter;
}
//重新加载lbl的文字内容
lbl.text = [self pickerView:pickerView titleForRow:row forComponent:component];
return lbl;
}
@end @end
...@@ -26,7 +26,11 @@ RCT_EXPORT_MODULE(); ...@@ -26,7 +26,11 @@ RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){ 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 *pickerConfirmBtnText=indic[@"pickerConfirmBtnText"];
NSString *pickerCancelBtnText=indic[@"pickerCancelBtnText"]; NSString *pickerCancelBtnText=indic[@"pickerCancelBtnText"];
...@@ -38,6 +42,9 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){ ...@@ -38,6 +42,9 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){
NSArray *pickerBg=indic[@"pickerBg"]; NSArray *pickerBg=indic[@"pickerBg"];
NSArray *selectArry=indic[@"selectedValue"]; NSArray *selectArry=indic[@"selectedValue"];
NSArray *weightArry=indic[@"wheelFlex"]; NSArray *weightArry=indic[@"wheelFlex"];
NSString *pickerToolBarFontSize=[NSString stringWithFormat:@"%@",indic[@"pickerToolBarFontSize"]];
NSString *pickerFontSize=[NSString stringWithFormat:@"%@",indic[@"pickerFontSize"]];
NSArray *pickerFontColor=indic[@"pickerFontColor"];
id pickerData=indic[@"pickerData"]; id pickerData=indic[@"pickerData"];
...@@ -62,7 +69,8 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){ ...@@ -62,7 +69,8 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){
self.height=220; 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){ _pick.bolock=^(NSDictionary *backinfoArry){
......
{ {
"name": "react-native-picker", "name": "react-native-picker",
"version": "4.0.11", "version": "4.0.12",
"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