Commit 92a23c07 authored by xwenliang's avatar xwenliang

toggle bug

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