Commit 0be959c1 authored by xwenliang's avatar xwenliang

native picker

parent ba944ad4
......@@ -2,13 +2,7 @@
[![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 Picker written in pure javascript for cross-platform support.
It was most likely an example of how to build a cross-platform Picker Component use [react-native-picker-android](https://github.com/beefe/react-native-picker-android).
###Warn
if 0.14.2 <= react-native <=0.24 `npm install react-native-picker@2.0.5 --save`
if 0.24 < react-native `npm install react-native-picker --save`
A Native Picker with high performance
####Demo
......@@ -23,21 +17,19 @@ if 0.24 < react-native `npm install react-native-picker --save`
###Documentation
####Props
- <b>style</b> style of picker, you can set width and height of picker in this prop
- <b>pickerElevation</b> elevation of picker (for issue https://github.com/beefe/react-native-picker/issues/27)
- <b>pickerBtnText</b> string, tool bar's confirm btn text
- <b>pickerCancelBtnText</b> string, tool bar's cancel ben text
- <b>pickerBtnStyle</b> textStylePropType, tool bar's btn style
- <b>pickerToolBarStyle</b> viewStylePropType, tool bar's style
- <b>showDuration</b> number, animation of picker
- <b>showMask</b> boolean, default to be false, cancel the picker by tapping in the rest of the screen support when setted to be true
- <b>pickerTitle</b> string, title of picker
- <b>pickerTitleStyle</b> textStylePropType, style of title
- <b>pickerData</b> array
- <b>selectedValue</b> any
- <b>onPickerDone</b> function
- <b>onPickerCancel</b> function
- <b>onValueChange</b> function
- <b>pickerConfirmBtnText</b> string, 确认按钮文字
- <b>pickerCancelBtnText</b> string, 取消按钮文字
- <b>pickerTitleText</b> string, 标题文字
- <b>pickerConfirmBtnColor</b> ['255', '66', '00', 0.5], 确认按钮字体颜色
- <b>pickerCancelBtnColor</b> ['255', '66', '00', 0.5], 取消按钮字体颜色
- <b>pickerTitleColor</b> ['255', '66', '00', 0.5], 标题字体颜色
- <b>pickerToolBarBg</b> ['255', '66', '00', 0.5], 工具栏背景颜色
- <b>pickerBg</b> ['255', '66', '00', 0.5], picker背景颜色
- <b>pickerData</b> 数组或对象,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
......@@ -53,21 +45,37 @@ if 0.24 < react-native `npm install react-native-picker --save`
npm install react-native-picker --save
```
####Step 2 - import and use in project
####Step 2 - link
```
react-native link
```
####Step 3 - import and use in project
```javascript
import Picker from 'react-native-picker'
import Picker from 'react-native-picker';
let data = [];
for(var i=0;i<100;i++){
data.push(i);
}
Picker.init({
pickerData: data,
selectedValue: [59],
onPickerConfirm: data => {
console.log(data);
},
onPickerCancel: data => {
console.log(data);
},
onPickerSelect: data => {
console.log(data);
}
});
Picker.show();
<Picker
style={{
height: 300
}}
showDuration={300}
showMask={true}
pickerData={}//picker`s value List
selectedValue={}//default to be selected value
onPickerDone={}//when confirm your choice
/>
```
###Notice
......@@ -104,11 +112,9 @@ if 0.24 < react-native `npm install react-native-picker --save`
```javascript
pickerData = {
{
a: [1,2,3,4],
b: [5,6,7,8],
...
}
a: [1,2,3,4],
b: [5,6,7,8],
...
};
selectedValue = ['a', 2];
```
......
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.facebook.react:react-native:0.20.1'
}
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/heng/Desktop/android-sdk-macosx/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.beefe.picker">
</manifest>
This diff is collapsed.
package com.beefe.picker;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* Created by heng on 16/9/5.
*/
public class PickerViewPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(new PickerViewModule(reactContext));
}
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
package com.beefe.picker.view;
import java.util.TimerTask;
final class InertiaTimerTask extends TimerTask {
float a;
final float velocityY;
final LoopView loopView;
InertiaTimerTask(LoopView loopview, float velocityY) {
super();
loopView = loopview;
this.velocityY = velocityY;
a = Integer.MAX_VALUE;
}
@Override
public final void run() {
if (a == Integer.MAX_VALUE) {
if (Math.abs(velocityY) > 2000F) {
if (velocityY > 0.0F) {
a = 2000F;
} else {
a = -2000F;
}
} else {
a = velocityY;
}
}
if (Math.abs(a) >= 0.0F && Math.abs(a) <= 20F) {
loopView.cancelFuture();
loopView.handler.sendEmptyMessage(MessageHandler.WHAT_SMOOTH_SCROLL);
return;
}
int i = (int) ((a * 10F) / 1000F);
LoopView loopview = loopView;
loopview.totalScrollY = loopview.totalScrollY - i;
if (!loopView.isLoop) {
float itemHeight = loopView.lineSpacingMultiplier * loopView.maxTextHeight;
if (loopView.totalScrollY <= (int) ((float) (-loopView.initPosition) * itemHeight)) {
a = 40F;
loopView.totalScrollY = (int) ((float) (-loopView.initPosition) * itemHeight);
} else if (loopView.totalScrollY >= (int) ((float) (loopView.items.size() - 1 - loopView.initPosition) * itemHeight)) {
loopView.totalScrollY = (int) ((float) (loopView.items.size() - 1 - loopView.initPosition) * itemHeight);
a = -40F;
}
}
if (a < 0.0F) {
a = a + 20F;
} else {
a = a - 20F;
}
loopView.handler.sendEmptyMessage(MessageHandler.WHAT_INVALIDATE_LOOP_VIEW);
}
}
This diff is collapsed.
package com.beefe.picker.view;
import android.view.MotionEvent;
final class LoopViewGestureListener extends android.view.GestureDetector.SimpleOnGestureListener {
final LoopView loopView;
LoopViewGestureListener(LoopView loopview) {
loopView = loopview;
}
@Override
public final boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
loopView.scrollBy(velocityY);
return true;
}
}
package com.beefe.picker.view;
import android.os.Handler;
import android.os.Message;
final class MessageHandler extends Handler {
public static final int WHAT_INVALIDATE_LOOP_VIEW = 1000;
public static final int WHAT_SMOOTH_SCROLL = 2000;
public static final int WHAT_ITEM_SELECTED = 3000;
final LoopView loopview;
MessageHandler(LoopView loopview) {
this.loopview = loopview;
}
@Override
public final void handleMessage(Message msg) {
switch (msg.what) {
case WHAT_INVALIDATE_LOOP_VIEW:
loopview.invalidate();
break;
case WHAT_SMOOTH_SCROLL:
loopview.smoothScroll(LoopView.ACTION.FLING);
break;
case WHAT_ITEM_SELECTED:
loopview.onItemSelected();
break;
}
}
}
package com.beefe.picker.view;
public interface OnItemSelectedListener {
void onItemSelected(String item, int index);
}
package com.beefe.picker.view;
final class OnItemSelectedRunnable implements Runnable {
final LoopView loopView;
OnItemSelectedRunnable(LoopView loopview) {
loopView = loopview;
}
@Override
public final void run() {
loopView.onItemSelectedListener.onItemSelected(loopView.getSelectedItem(),loopView.getSelectedIndex());
}
}
package com.beefe.picker.view;
import java.util.ArrayList;
/**
* Created by heng on 16/9/6.
*/
public interface OnSelectedListener {
void onSelected(ArrayList<String> selectedList);
}
package com.beefe.picker.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import com.beefe.picker.R;
import com.facebook.react.bridge.ReadableArray;
import java.util.ArrayList;
import java.util.Arrays;
/**
* Created by heng on 16/9/6.
*/
public class PickerViewAlone extends LinearLayout {
private LinearLayout pickerViewAloneLayout;
private OnSelectedListener onSelectedListener;
private int position;
public PickerViewAlone(Context context) {
super(context);
init(context);
}
public PickerViewAlone(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
private void init(Context context) {
View view = LayoutInflater.from(context).inflate(R.layout.picker_view_alone, this);
pickerViewAloneLayout = (LinearLayout) view.findViewById(R.id.pickerViewAloneLayout);
}
public void setOnSelectedListener(OnSelectedListener listener) {
this.onSelectedListener = listener;
}
public void setAloneData(ReadableArray array, final ArrayList<String> curSelectedList) {
ArrayList<String> values = arrayToList(array);
final LoopView loopView = new LoopView(getContext());
LayoutParams params = new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
params.weight = 1.0f;
loopView.setLayoutParams(params);
loopView.setItems(values);
loopView.setSelectedPosition(0);
if (curSelectedList.size() > 0) {
curSelectedList.set(0, values.get(0));
} else {
curSelectedList.add(0, values.get(0));
}
loopView.setListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(String item, int index) {
if (onSelectedListener != null) {
curSelectedList.set(0, item);
onSelectedListener.onSelected(curSelectedList);
}
}
});
pickerViewAloneLayout.addView(loopView);
}
public void setPickerViewDta(ReadableArray array, final ArrayList<String> curSelectedList) {
final String[] selectedItems = new String[array.size()];
for (int i = 0; i < array.size(); i++) {
switch (array.getType(i).name()) {
case "Array":
ReadableArray childArray = array.getArray(i);
ArrayList<String> values = arrayToList(childArray);
final LoopView loopView = new LoopView(getContext());
LayoutParams params = new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
params.weight = 1.0f;
loopView.setLayoutParams(params);
loopView.setItems(values);
loopView.setTag(i);
loopView.setSelectedPosition(0);
if (curSelectedList.size() > i) {
curSelectedList.set(i, values.get(0));
} else {
curSelectedList.add(i, values.get(0));
}
selectedItems[i] = values.get(0);
loopView.setListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(String item, int index) {
int viewCount = pickerViewAloneLayout.getChildCount();
for (int j = 0; j < viewCount; j++) {
View view = pickerViewAloneLayout.getChildAt(j);
if (view instanceof LoopView) {
LoopView loop = (LoopView) view;
if (loop.getTag() == loopView.getTag()) {
position = j;
break;
}
}
}
selectedItems[position] = item;
if (onSelectedListener != null) {
for (int i = 0; i < selectedItems.length; i++) {
curSelectedList.set(i, selectedItems[i]);
}
onSelectedListener.onSelected(curSelectedList);
}
}
});
pickerViewAloneLayout.addView(loopView);
break;
default:
break;
}
}
}
public void setSelectValue(String[] selectValue, final ArrayList<String> curSelectedList) {
int viewCount = pickerViewAloneLayout.getChildCount();
int valueCount = selectValue.length;
if (valueCount <= viewCount) {
setSelect(valueCount, selectValue, curSelectedList);
} else {
String[] values = Arrays.copyOf(selectValue, viewCount);
setSelect(viewCount, values, curSelectedList);
}
}
private void setSelect(int size, String[] values, ArrayList<String> curSelectedList) {
for (int i = 0; i < size; i++) {
View view = pickerViewAloneLayout.getChildAt(i);
if (view instanceof LoopView) {
LoopView loop = (LoopView) view;
if (loop.hasItem(values[i])) {
loop.setSelectedItem(values[i]);
curSelectedList.set(i, values[i]);
}
}
}
}
public void setIsLoop(boolean isLoop) {
if (!isLoop) {
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.setNotLoop();
}
}
}
}
private ArrayList<String> arrayToList(ReadableArray array) {
ArrayList<String> values = new ArrayList<>();
for (int i = 0; i < array.size(); i++) {
String value = "";
switch (array.getType(i).name()) {
case "Boolean":
value = String.valueOf(array.getBoolean(i));
break;
case "Number":
try {
value = String.valueOf(array.getInt(i));
} catch (Exception e) {
value = String.valueOf(array.getDouble(i));
}
break;
case "String":
value = array.getString(i);
break;
}
values.add(value);
}
return values;
}
}
package com.beefe.picker.view;
import java.util.TimerTask;
final class SmoothScrollTimerTask extends TimerTask {
int realTotalOffset;
int realOffset;
int offset;
final LoopView loopView;
SmoothScrollTimerTask(LoopView loopview, int offset) {
this.loopView = loopview;
this.offset = offset;
realTotalOffset = Integer.MAX_VALUE;
realOffset = 0;
}
@Override
public final void run() {
if (realTotalOffset == Integer.MAX_VALUE) {
realTotalOffset = offset;
}
realOffset = (int) ((float) realTotalOffset * 0.1F);
if (realOffset == 0) {
if (realTotalOffset < 0) {
realOffset = -1;
} else {
realOffset = 1;
}
}
if (Math.abs(realTotalOffset) <= 0) {
loopView.cancelFuture();
loopView.handler.sendEmptyMessage(MessageHandler.WHAT_ITEM_SELECTED);
} else {
loopView.totalScrollY = loopView.totalScrollY + realOffset;
loopView.handler.sendEmptyMessage(MessageHandler.WHAT_INVALIDATE_LOOP_VIEW);
realTotalOffset = realTotalOffset - realOffset;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromXDelta="0"
android:fromYDelta="100%"
android:toXDelta="0"
android:toYDelta="0" />
<!--<alpha-->
<!--android:fromAlpha="0.5"-->
<!--android:duration="500"-->
<!--android:toAlpha="1.0"-->
<!--/>-->
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:fromYDelta="0"
android:duration="300"
android:toXDelta="0"
android:toYDelta="100%" />
<!--<alpha-->
<!--android:fromAlpha="1.0"-->
<!--android:duration="800"-->
<!--android:toAlpha="0.5"-->
<!--/>-->
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:id="@+id/pickerViewAloneLayout"
android:layout_height="match_parent">
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<com.beefe.picker.view.LoopView
android:id="@+id/loopViewOne"
android:layout_width="0dp"
android:layout_weight="1.0"
android:layout_height="match_parent" />
<com.beefe.picker.view.LoopView
android:id="@+id/loopViewTwo"
android:layout_width="0dp"
android:layout_weight="1.0"
android:layout_height="match_parent" />
<com.beefe.picker.view.LoopView
android:id="@+id/loopViewThree"
android:layout_width="0dp"
android:layout_weight="1.0"
android:layout_height="match_parent" />
</LinearLayout>
\ No newline at end of file
<?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: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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/pickerLayout">
<TextView
android:id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="9dp" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="9dp" />
<TextView
android:id="@+id/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="9dp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/pickerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<com.beefe.picker.view.PickerViewLinkage
android:id="@+id/pickerViewLinkage"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<com.beefe.picker.view.PickerViewAlone
android:id="@+id/pickerViewAlone"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
</RelativeLayout>
\ No newline at end of file
<resources>
<string name="app_name">react-native-picker</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="PopAnim">
<item name="android:windowEnterAnimation">@anim/popup_enter</item>
<item name="android:windowExitAnimation">@anim/popup_exit</item>
</style>
</resources>
\ No newline at end of file
......@@ -50,7 +50,23 @@ class PickerTest extends Component {
}
_onPressHandle() {
this.picker.toggle();
Picker.init({
pickerData: createDateData(),
selectedValue: ['2015年', '12月', '12日'],
onPickerConfirm: pickedValue => {
alert(JSON.stringify(pickedValue));
console.log(pickedValue);
},
onPickerCancel: pickedValue => {
alert(JSON.stringify(pickedValue));
console.log(pickedValue);
},
onPickerSelect: pickedValue => {
alert(JSON.stringify(pickedValue));
console.log(pickedValue);
}
});
Picker.show();
}
render() {
......@@ -59,18 +75,6 @@ class PickerTest extends Component {
<TouchableOpacity style={{marginTop: 20}} onPress={this._onPressHandle.bind(this)}>
<Text>Click Me</Text>
</TouchableOpacity>
<Picker
ref={picker => this.picker = picker}
style={{height: 260}}
showDuration={300}
showMask={true}
pickerData={createDateData()}
selectedValue={['2015年', '12月', '12日']}
onPickerDone={(pickedValue) => {
alert(JSON.stringify(pickedValue));
console.log(pickedValue);
}}
/>
</View>
);
}
......
......@@ -8,6 +8,6 @@
"dependencies": {
"react": "15.0.2",
"react-native": "^0.26.1",
"react-native-picker": "^3.0.3"
"react-native-picker": "beefe/react-native-picker"
}
}
This diff is collapsed.
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
17D41E591D7EE0CA0031415E /* RCTBEEPickerManager.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 17D41E581D7EE0CA0031415E /* RCTBEEPickerManager.h */; };
17D41E5B1D7EE0CA0031415E /* RCTBEEPickerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 17D41E5A1D7EE0CA0031415E /* RCTBEEPickerManager.m */; };
17D41E631D7EE0EE0031415E /* BzwPicker.m in Sources */ = {isa = PBXBuildFile; fileRef = 17D41E621D7EE0EE0031415E /* BzwPicker.m */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
17D41E531D7EE0CA0031415E /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "include/$(PRODUCT_NAME)";
dstSubfolderSpec = 16;
files = (
17D41E591D7EE0CA0031415E /* RCTBEEPickerManager.h in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
17D41E551D7EE0CA0031415E /* libRCTBEEPickerManager.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTBEEPickerManager.a; sourceTree = BUILT_PRODUCTS_DIR; };
17D41E581D7EE0CA0031415E /* RCTBEEPickerManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTBEEPickerManager.h; sourceTree = "<group>"; };
17D41E5A1D7EE0CA0031415E /* RCTBEEPickerManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RCTBEEPickerManager.m; sourceTree = "<group>"; };
17D41E611D7EE0EE0031415E /* BzwPicker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BzwPicker.h; sourceTree = "<group>"; };
17D41E621D7EE0EE0031415E /* BzwPicker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BzwPicker.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
17D41E521D7EE0CA0031415E /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
17D41E4C1D7EE0CA0031415E = {
isa = PBXGroup;
children = (
17D41E571D7EE0CA0031415E /* RCTBEEPickerManager */,
17D41E561D7EE0CA0031415E /* Products */,
);
sourceTree = "<group>";
};
17D41E561D7EE0CA0031415E /* Products */ = {
isa = PBXGroup;
children = (
17D41E551D7EE0CA0031415E /* libRCTBEEPickerManager.a */,
);
name = Products;
sourceTree = "<group>";
};
17D41E571D7EE0CA0031415E /* RCTBEEPickerManager */ = {
isa = PBXGroup;
children = (
17D41E611D7EE0EE0031415E /* BzwPicker.h */,
17D41E621D7EE0EE0031415E /* BzwPicker.m */,
17D41E581D7EE0CA0031415E /* RCTBEEPickerManager.h */,
17D41E5A1D7EE0CA0031415E /* RCTBEEPickerManager.m */,
);
path = RCTBEEPickerManager;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
17D41E541D7EE0CA0031415E /* RCTBEEPickerManager */ = {
isa = PBXNativeTarget;
buildConfigurationList = 17D41E5E1D7EE0CA0031415E /* Build configuration list for PBXNativeTarget "RCTBEEPickerManager" */;
buildPhases = (
17D41E511D7EE0CA0031415E /* Sources */,
17D41E521D7EE0CA0031415E /* Frameworks */,
17D41E531D7EE0CA0031415E /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = RCTBEEPickerManager;
productName = RCTBEEPickerManager;
productReference = 17D41E551D7EE0CA0031415E /* libRCTBEEPickerManager.a */;
productType = "com.apple.product-type.library.static";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
17D41E4D1D7EE0CA0031415E /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0720;
ORGANIZATIONNAME = "MFHJ-DZ-001-417";
TargetAttributes = {
17D41E541D7EE0CA0031415E = {
CreatedOnToolsVersion = 7.2.1;
};
};
};
buildConfigurationList = 17D41E501D7EE0CA0031415E /* Build configuration list for PBXProject "RCTBEEPickerManager" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = 17D41E4C1D7EE0CA0031415E;
productRefGroup = 17D41E561D7EE0CA0031415E /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
17D41E541D7EE0CA0031415E /* RCTBEEPickerManager */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
17D41E511D7EE0CA0031415E /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
17D41E5B1D7EE0CA0031415E /* RCTBEEPickerManager.m in Sources */,
17D41E631D7EE0EE0031415E /* BzwPicker.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
17D41E5C1D7EE0CA0031415E /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
name = Debug;
};
17D41E5D1D7EE0CA0031415E /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
17D41E5F1D7EE0CA0031415E /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../../react-native/React/**",
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
name = Debug;
};
17D41E601D7EE0CA0031415E /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../../react-native/React/**",
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
17D41E501D7EE0CA0031415E /* Build configuration list for PBXProject "RCTBEEPickerManager" */ = {
isa = XCConfigurationList;
buildConfigurations = (
17D41E5C1D7EE0CA0031415E /* Debug */,
17D41E5D1D7EE0CA0031415E /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
17D41E5E1D7EE0CA0031415E /* Build configuration list for PBXNativeTarget "RCTBEEPickerManager" */ = {
isa = XCConfigurationList;
buildConfigurations = (
17D41E5F1D7EE0CA0031415E /* Debug */,
17D41E601D7EE0CA0031415E /* Release */,
);
defaultConfigurationIsVisible = 0;
};
/* End XCConfigurationList section */
};
rootObject = 17D41E4D1D7EE0CA0031415E /* Project object */;
}
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:RCTBEEPickerManager.xcodeproj">
</FileRef>
</Workspace>
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "17D41E541D7EE0CA0031415E"
BuildableName = "libRCTBEEPickerManager.a"
BlueprintName = "RCTBEEPickerManager"
ReferencedContainer = "container:RCTBEEPickerManager.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "17D41E541D7EE0CA0031415E"
BuildableName = "libRCTBEEPickerManager.a"
BlueprintName = "RCTBEEPickerManager"
ReferencedContainer = "container:RCTBEEPickerManager.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "17D41E541D7EE0CA0031415E"
BuildableName = "libRCTBEEPickerManager.a"
BlueprintName = "RCTBEEPickerManager"
ReferencedContainer = "container:RCTBEEPickerManager.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>RCTBEEPickerManager.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>17D41E541D7EE0CA0031415E</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
//
// BzwPicker.h
// PickerView
//
// Created by Bao on 15/12/14.
// Copyright © 2015年 Microlink. All rights reserved.
//
#import <UIKit/UIKit.h>
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
typedef void(^backBolock)(NSDictionary * );
@interface BzwPicker : UIView<UIPickerViewDataSource,UIPickerViewDelegate>
@property (strong,nonatomic)UIPickerView *pick;
@property(nonatomic,copy)backBolock bolock;
@property (strong, nonatomic) NSDictionary *pickerDic;//一开始进来的字典
@property (strong, nonatomic) NSArray *provinceArray;//省、市
@property (strong, nonatomic) NSArray *cityArray;//市,县
@property (strong, nonatomic) NSArray *townArray;//县,区
@property (strong, nonatomic) NSDictionary *selectedDic;//3级联动时候用到的
@property (strong,nonatomic)NSArray *selectArry;//2级联动时候用的
@property (strong,nonatomic)UIButton *leftBtn;//取消
@property (strong,nonatomic)UIButton *rightBtn;
@property(strong,nonatomic)NSString *leftStr;
@property(strong,nonatomic)NSString *centStr;
@property(strong,nonatomic)NSString *rightStr;
//用来判断进来的类型
@property(strong,nonatomic)id value;
@property(assign,nonatomic)BOOL Correlation;//判断有没有没有关联
@property(nonatomic,strong)NSString *numberCorrela;//关联是2行 还是3行
@property(nonatomic,strong)NSArray *noCorreArry;
//创建一个数组来传递返回的值
@property(nonatomic,strong)NSMutableArray *backArry;
@property(assign,nonatomic)BOOL noArryElementBool;
//创建一个数组 接收进来的选择Value
@property(strong,nonatomic)NSArray *selectValueArry;
-(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;
@end
This diff is collapsed.
//
// RCTBEEPickerManager.h
// RCTBEEPickerManager
//
// Created by MFHJ-DZ-001-417 on 16/9/6.
// Copyright © 2016年 MFHJ-DZ-001-417. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "RCTBridgeModule.h"
@interface RCTBEEPickerManager : NSObject<RCTBridgeModule>
@end
//
// RCTBEEPickerManager.m
// RCTBEEPickerManager
//
// Created by MFHJ-DZ-001-417 on 16/9/6.
// Copyright © 2016年 MFHJ-DZ-001-417. All rights reserved.
//
#import "RCTBEEPickerManager.h"
#import "BzwPicker.h"
#import "RCTEventDispatcher.h"
@interface RCTBEEPickerManager()
@property(nonatomic,strong)BzwPicker *pick;
@end
@implementation RCTBEEPickerManager
@synthesize bridge = _bridge;
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){
UIViewController *result = nil;
UIWindow * window = [[UIApplication sharedApplication] keyWindow];
if (window.windowLevel != UIWindowLevelNormal)
{
NSArray *windows = [[UIApplication sharedApplication] windows];
for(UIWindow * tmpWin in windows)
{
if (tmpWin.windowLevel == UIWindowLevelNormal)
{
window = tmpWin;
break;
}
}
}
UIView *frontView = [[window subviews] objectAtIndex:0];
id nextResponder = [frontView nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]])
result = nextResponder;
else
result = window.rootViewController;
NSString *pickerConfirmBtnText=indic[@"pickerConfirmBtnText"];
NSString *pickerCancelBtnText=indic[@"pickerCancelBtnText"];
NSString *pickerTitleText=indic[@"pickerTitleText"];
NSArray *pickerConfirmBtnColor=indic[@"pickerConfirmBtnColor"];
NSArray *pickerCancelBtnColor=indic[@"pickerCancelBtnColor"];
NSArray *pickerTitleColor=indic[@"pickerTitleColor"];
NSArray *pickerToolBarBg=indic[@"pickerToolBarBg"];
NSArray *pickerBg=indic[@"pickerBg"];
NSArray *selectArry=indic[@"selectedValue"];
id pickerData=indic[@"pickerData"];
NSMutableDictionary *dataDic=[[NSMutableDictionary alloc]init];
dataDic[@"pickerData"]=pickerData;
[result.view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[BzwPicker class]]) {
dispatch_async(dispatch_get_main_queue(), ^{
[obj removeFromSuperview];
});
}
}];
self.pick=[[BzwPicker alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 250) dic:dataDic leftStr:pickerCancelBtnText centerStr:pickerTitleText rightStr:pickerConfirmBtnText topbgColor:pickerToolBarBg bottombgColor:pickerBg leftbtnbgColor:pickerCancelBtnColor rightbtnbgColor:pickerConfirmBtnColor centerbtnColor:pickerTitleColor selectValueArry:selectArry];
_pick.bolock=^(NSDictionary *backinfoArry){
dispatch_async(dispatch_get_main_queue(), ^{
[self.bridge.eventDispatcher sendAppEventWithName:@"pickerEvent" body:backinfoArry];
});
};
dispatch_async(dispatch_get_main_queue(), ^{
[result.view addSubview:_pick];
[UIView animateWithDuration:.3 animations:^{
[_pick setFrame:CGRectMake(0, SCREEN_HEIGHT-250, SCREEN_WIDTH, 250)];
}];
});
}
RCT_EXPORT_METHOD(show){
if (self.pick) {
dispatch_async(dispatch_get_main_queue(), ^{
[UIView animateWithDuration:.3 animations:^{
[_pick setFrame:CGRectMake(0, SCREEN_HEIGHT-250, SCREEN_WIDTH, 250)];
}];
});
}return;
}
RCT_EXPORT_METHOD(hide){
if (self.pick) {
dispatch_async(dispatch_get_main_queue(), ^{
[UIView animateWithDuration:.3 animations:^{
[_pick setFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 250)];
}];
});
}return;
}
RCT_EXPORT_METHOD(isPickerShow:(RCTResponseSenderBlock)getBack){
if (self.pick) {
CGFloat pickY=_pick.frame.origin.y;
if (pickY==SCREEN_HEIGHT) {
getBack(@[@YES]);
}else
{
getBack(@[@NO]);
}
}else{
getBack(@[@"picker不存在"]);
}
}
@end
{
"name": "react-native-picker",
"version": "3.0.5",
"description": "react-native-picker",
"version": "4.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/beefe/react-native-picker.git"
"url": "git@github.com:beefe/react-native-picker.git"
},
"keywords": [
"react-native",
"picker"
],
"author": {
"name": "zooble",
"email": "wenliang.web@gmail.com"
},
"dependencies": {
"react-native-picker-android": "~1.0.3"
},
"engines": {
"node": ">=4"
},
"license": "ISC",
"bugs": {
"url": "https://github.com/beefe/react-native-picker/issues"
},
"homepage": "https://github.com/beefe/react-native-picker#readme"
}
\ No newline at end of file
"author": "zooble",
"license": "MIT"
}
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