Commit 92a23c07 authored by xwenliang's avatar xwenliang

toggle bug

parent e23e33df
...@@ -2,28 +2,26 @@ ...@@ -2,28 +2,26 @@
[![npm version](https://img.shields.io/npm/v/react-native-picker.svg?style=flat-square)](https://www.npmjs.com/package/react-native-picker) <a href="https://david-dm.org/beefe/react-native-picker"><img src="https://david-dm.org/beefe/react-native-picker.svg?style=flat-square" alt="dependency status"></a> [![npm version](https://img.shields.io/npm/v/react-native-picker.svg?style=flat-square)](https://www.npmjs.com/package/react-native-picker) <a href="https://david-dm.org/beefe/react-native-picker"><img src="https://david-dm.org/beefe/react-native-picker.svg?style=flat-square" alt="dependency status"></a>
A Native Picker with high performance. ### For pure javascript version -> [v3.0.5](https://github.com/beefe/react-native-picker/tree/pure-javascript-version)
pure javascript version -> [v3.0.5](https://github.com/beefe/react-native-picker/tree/pure-javascript-version)
![ui2](./doc/ui2.jpg) ![ui2](./doc/ui2.jpg)
###Documentation ###Documentation
####Props ####Props
- <b>pickerConfirmBtnText</b> string, 确认按钮文字 - <b>pickerConfirmBtnText</b>(string), 确认按钮文字
- <b>pickerCancelBtnText</b> string, 取消按钮文字 - <b>pickerCancelBtnText</b>(string), 取消按钮文字
- <b>pickerTitleText</b> string, 标题文字 - <b>pickerTitleText</b>(string), 标题文字
- <b>pickerConfirmBtnColor</b> [1, 186, 245, 1], 确认按钮字体颜色 - <b>pickerConfirmBtnColor</b>([1, 186, 245, 1]), 确认按钮字体颜色
- <b>pickerCancelBtnColor</b> [1, 186, 245, 1], 取消按钮字体颜色 - <b>pickerCancelBtnColor</b>([1, 186, 245, 1]), 取消按钮字体颜色
- <b>pickerTitleColor</b> [20, 20, 20, 1], 标题字体颜色 - <b>pickerTitleColor</b>([20, 20, 20, 1]), 标题字体颜色
- <b>pickerToolBarBg</b> [232, 232, 232, 1], 工具栏背景颜色 - <b>pickerToolBarBg</b>([232, 232, 232, 1]), 工具栏背景颜色
- <b>pickerBg</b> [196, 199, 206, 1], picker背景颜色 - <b>pickerBg</b>([196, 199, 206, 1]), picker背景颜色
- <b>pickerData</b> 数组或对象,picker数据 - <b>pickerData</b>(array), picker数据
- <b>selectedValue</b> string,默认选中数据 - <b>selectedValue</b>(string),默认选中数据
- <b>onPickerConfirm</b> function,确认按钮回调 - <b>onPickerConfirm</b>(function),确认按钮回调
- <b>onPickerCancel</b> function,取消按钮回调 - <b>onPickerCancel</b>(function),取消按钮回调
- <b>onPickerSelect</b> function,滚轮滚动时回调 - <b>onPickerSelect</b>(function),滚轮滚动时回调
####Methods ####Methods
- <b>toggle</b> show or hide picker, default to be hiden - <b>toggle</b> show or hide picker, default to be hiden
......
...@@ -30,7 +30,13 @@ import com.facebook.react.modules.core.DeviceEventManagerModule; ...@@ -30,7 +30,13 @@ import com.facebook.react.modules.core.DeviceEventManagerModule;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
* Author: heng <a href="https://github.com/shexiaoheng"/>
*
* Created by heng on 16/9/5. * Created by heng on 16/9/5.
*
* Edited by heng on 16/9/22.
* 1. PopupWindow height : full screen -> assignation
* 2. Added pickerToolBarHeight support
*/ */
public class PickerViewModule extends ReactContextBaseJavaModule { public class PickerViewModule extends ReactContextBaseJavaModule {
...@@ -42,6 +48,7 @@ public class PickerViewModule extends ReactContextBaseJavaModule { ...@@ -42,6 +48,7 @@ public class PickerViewModule extends ReactContextBaseJavaModule {
private static final String IS_LOOP = "isLoop"; private static final String IS_LOOP = "isLoop";
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 TEXT_BAR_COLOR = "pickerToolBarBg";
private static final String TEXT_BAR_HEIGHT = "pickerToolBarHeight";
private static final String CONFIRM_TEXT = "pickerConfirmBtnText"; private static final String CONFIRM_TEXT = "pickerConfirmBtnText";
private static final String CONFIRM_TEXT_COLOR = "pickerConfirmBtnColor"; private static final String CONFIRM_TEXT_COLOR = "pickerConfirmBtnColor";
private static final String CANCEL_TEXT = "pickerCancelBtnText"; private static final String CANCEL_TEXT = "pickerCancelBtnText";
...@@ -73,7 +80,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule { ...@@ -73,7 +80,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule {
private ArrayList<String> curSelectedList = new ArrayList<>(); private ArrayList<String> curSelectedList = new ArrayList<>();
private RelativeLayout pickerParent;
private RelativeLayout barLayout; private RelativeLayout barLayout;
private TextView cancelTV; private TextView cancelTV;
private TextView titleTV; private TextView titleTV;
...@@ -81,6 +87,9 @@ public class PickerViewModule extends ReactContextBaseJavaModule { ...@@ -81,6 +87,9 @@ public class PickerViewModule extends ReactContextBaseJavaModule {
private PickerViewLinkage pickerViewLinkage; private PickerViewLinkage pickerViewLinkage;
private PickerViewAlone pickerViewAlone; private PickerViewAlone pickerViewAlone;
private int pickerViewHeight;
private int barViewHeight;
public PickerViewModule(ReactApplicationContext reactContext) { public PickerViewModule(ReactApplicationContext reactContext) {
super(reactContext); super(reactContext);
} }
...@@ -95,7 +104,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule { ...@@ -95,7 +104,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule {
Activity activity = getCurrentActivity(); Activity activity = getCurrentActivity();
if (activity != null && options.hasKey(PICKER_DATA)) { if (activity != null && options.hasKey(PICKER_DATA)) {
view = activity.getLayoutInflater().inflate(R.layout.popup_picker_view, null); view = activity.getLayoutInflater().inflate(R.layout.popup_picker_view, null);
pickerParent = (RelativeLayout) view.findViewById(R.id.pickerParent);
barLayout = (RelativeLayout) view.findViewById(R.id.barLayout); barLayout = (RelativeLayout) view.findViewById(R.id.barLayout);
cancelTV = (TextView) view.findViewById(R.id.cancel); cancelTV = (TextView) view.findViewById(R.id.cancel);
titleTV = (TextView) view.findViewById(R.id.title); titleTV = (TextView) view.findViewById(R.id.title);
...@@ -103,13 +111,19 @@ public class PickerViewModule extends ReactContextBaseJavaModule { ...@@ -103,13 +111,19 @@ public class PickerViewModule extends ReactContextBaseJavaModule {
pickerViewLinkage = (PickerViewLinkage) view.findViewById(R.id.pickerViewLinkage); pickerViewLinkage = (PickerViewLinkage) view.findViewById(R.id.pickerViewLinkage);
pickerViewAlone = (PickerViewAlone) view.findViewById(R.id.pickerViewAlone); pickerViewAlone = (PickerViewAlone) view.findViewById(R.id.pickerViewAlone);
pickerParent.setOnClickListener(new View.OnClickListener() { if (options.hasKey(TEXT_BAR_HEIGHT)) {
@Override try {
public void onClick(View v) { barViewHeight = options.getInt(TEXT_BAR_HEIGHT);
commonEvent(EVENT_KEY_CANCEL); } catch (Exception e) {
hide(); barViewHeight = (int) options.getDouble(TEXT_BAR_HEIGHT);
} }
}); } else {
barViewHeight = (int) (activity.getResources().getDisplayMetrics().density * 40);
}
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
barViewHeight);
barLayout.setLayoutParams(params);
if (options.hasKey(TEXT_BAR_COLOR)) { if (options.hasKey(TEXT_BAR_COLOR)) {
ReadableArray array = options.getArray(TEXT_BAR_COLOR); ReadableArray array = options.getArray(TEXT_BAR_COLOR);
...@@ -237,7 +251,9 @@ public class PickerViewModule extends ReactContextBaseJavaModule { ...@@ -237,7 +251,9 @@ public class PickerViewModule extends ReactContextBaseJavaModule {
pickerViewAlone.setVisibility(View.GONE); pickerViewAlone.setVisibility(View.GONE);
pickerViewLinkage.setPickerData(pickerData, curSelectedList); pickerViewLinkage.setPickerData(pickerData, curSelectedList);
pickerViewLinkage.setIsLoop(isLoop); pickerViewLinkage.setIsLoop(isLoop);
if (options.hasKey(PICKER_BG_COLOR)) {
pickerViewLinkage.setBackgroundColor(Color.argb(pickerColor[3], pickerColor[0], pickerColor[1], pickerColor[2])); pickerViewLinkage.setBackgroundColor(Color.argb(pickerColor[3], pickerColor[0], pickerColor[1], pickerColor[2]));
}
pickerViewLinkage.setOnSelectListener(new OnSelectedListener() { pickerViewLinkage.setOnSelectListener(new OnSelectedListener() {
@Override @Override
public void onSelected(ArrayList<String> selectedList) { public void onSelected(ArrayList<String> selectedList) {
...@@ -246,6 +262,7 @@ public class PickerViewModule extends ReactContextBaseJavaModule { ...@@ -246,6 +262,7 @@ public class PickerViewModule extends ReactContextBaseJavaModule {
} }
}); });
pickerViewLinkage.setSelectValue(selectValue, curSelectedList); pickerViewLinkage.setSelectValue(selectValue, curSelectedList);
pickerViewHeight = pickerViewLinkage.getViewHeight();
break; break;
default: default:
pickerViewAlone.setVisibility(View.VISIBLE); pickerViewAlone.setVisibility(View.VISIBLE);
...@@ -253,7 +270,9 @@ public class PickerViewModule extends ReactContextBaseJavaModule { ...@@ -253,7 +270,9 @@ public class PickerViewModule extends ReactContextBaseJavaModule {
pickerViewAlone.setPickerData(pickerData, curSelectedList); pickerViewAlone.setPickerData(pickerData, curSelectedList);
pickerViewAlone.setIsLoop(isLoop); pickerViewAlone.setIsLoop(isLoop);
if (options.hasKey(PICKER_BG_COLOR)) {
pickerViewAlone.setBackgroundColor(Color.argb(pickerColor[3], pickerColor[0], pickerColor[1], pickerColor[2])); pickerViewAlone.setBackgroundColor(Color.argb(pickerColor[3], pickerColor[0], pickerColor[1], pickerColor[2]));
}
pickerViewAlone.setOnSelectedListener(new OnSelectedListener() { pickerViewAlone.setOnSelectedListener(new OnSelectedListener() {
@Override @Override
...@@ -264,16 +283,16 @@ public class PickerViewModule extends ReactContextBaseJavaModule { ...@@ -264,16 +283,16 @@ public class PickerViewModule extends ReactContextBaseJavaModule {
}); });
pickerViewAlone.setSelectValue(selectValue, curSelectedList); pickerViewAlone.setSelectValue(selectValue, curSelectedList);
pickerViewHeight = pickerViewAlone.getViewHeight();
break; break;
} }
if (popupWindow == null) { if (popupWindow == null) {
popupWindow = new PopupWindow(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); int height = barViewHeight + pickerViewHeight;
popupWindow = new PopupWindow(WindowManager.LayoutParams.MATCH_PARENT, height);
popupWindow.setBackgroundDrawable(new ColorDrawable()); popupWindow.setBackgroundDrawable(new ColorDrawable());
popupWindow.setFocusable(true);
popupWindow.setAnimationStyle(R.style.PopAnim); popupWindow.setAnimationStyle(R.style.PopAnim);
popupWindow.setOutsideTouchable(true);
} }
popupWindow.setContentView(view); popupWindow.setContentView(view);
popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0); popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
......
...@@ -32,7 +32,6 @@ public class LoopView extends View { ...@@ -32,7 +32,6 @@ public class LoopView extends View {
private GestureDetector gestureDetector; private GestureDetector gestureDetector;
OnItemSelectedListener onItemSelectedListener; OnItemSelectedListener onItemSelectedListener;
// Timer mTimer;
private ScheduledExecutorService mExecutor = Executors.newSingleThreadScheduledExecutor(); private ScheduledExecutorService mExecutor = Executors.newSingleThreadScheduledExecutor();
private ScheduledFuture<?> mFuture; private ScheduledFuture<?> mFuture;
...@@ -224,6 +223,10 @@ public class LoopView extends View { ...@@ -224,6 +223,10 @@ public class LoopView extends View {
return items.indexOf(item); return items.indexOf(item);
} }
public int getViewHeight(){
return measuredHeight;
}
public final void setSelectedPosition(int initPosition) { public final void setSelectedPosition(int initPosition) {
if (initPosition < 0) { if (initPosition < 0) {
this.initPosition = 0; this.initPosition = 0;
......
...@@ -169,6 +169,16 @@ public class PickerViewAlone extends LinearLayout { ...@@ -169,6 +169,16 @@ public class PickerViewAlone extends LinearLayout {
} }
} }
public int getViewHeight(){
int viewHeight = 0;
View view = pickerViewAloneLayout.getChildAt(0);
if (view instanceof LoopView) {
LoopView loopView = (LoopView) view;
viewHeight = loopView.getViewHeight();
}
return viewHeight;
}
private ArrayList<String> arrayToList(ReadableArray array) { private ArrayList<String> arrayToList(ReadableArray array) {
ArrayList<String> values = new ArrayList<>(); ArrayList<String> values = new ArrayList<>();
for (int i = 0; i < array.size(); i++) { for (int i = 0; i < array.size(); i++) {
......
...@@ -446,6 +446,10 @@ public class PickerViewLinkage extends LinearLayout { ...@@ -446,6 +446,10 @@ public class PickerViewLinkage extends LinearLayout {
} }
} }
public int getViewHeight (){
return loopViewOne.getViewHeight();
}
public void setOnSelectListener(OnSelectedListener listener) { public void setOnSelectListener(OnSelectedListener listener) {
this.onSelectedListener = listener; this.onSelectedListener = listener;
} }
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:background="#00000000"> android:background="#00000000">
<RelativeLayout
android:id="@+id/pickerParent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/barLayout" />
<RelativeLayout <RelativeLayout
android:id="@+id/barLayout" android:id="@+id/barLayout"
......
...@@ -67,9 +67,17 @@ export default { ...@@ -67,9 +67,17 @@ export default {
}, },
isPickerShow(fn){ isPickerShow(fn){
//android return show or not, ios return hide or not... //android return two params: err(error massage) and status(show or not)
Picker.isPickerShow(status => { //ios return only one param: hide or not...
fn(android ? status : !status); Picker.isPickerShow((err, status) => {
let returnValue = null;
if(android){
returnValue = err ? false : status;
}
else if(ios){
returnValue = !err;
}
fn(returnValue);
}); });
} }
}; };
\ No newline at end of file
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