Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-native-picker
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
ym
react-native-picker
Commits
92a23c07
Commit
92a23c07
authored
Sep 22, 2016
by
xwenliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
toggle bug
parent
e23e33df
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
77 additions
and
40 deletions
+77
-40
README.md
README.md
+15
-17
android/src/main/java/com/beefe/picker/PickerViewModule.java
android/src/main/java/com/beefe/picker/PickerViewModule.java
+32
-13
android/src/main/java/com/beefe/picker/view/LoopView.java
android/src/main/java/com/beefe/picker/view/LoopView.java
+4
-1
android/src/main/java/com/beefe/picker/view/PickerViewAlone.java
.../src/main/java/com/beefe/picker/view/PickerViewAlone.java
+10
-0
android/src/main/java/com/beefe/picker/view/PickerViewLinkage.java
...rc/main/java/com/beefe/picker/view/PickerViewLinkage.java
+4
-0
android/src/main/res/layout/popup_picker_view.xml
android/src/main/res/layout/popup_picker_view.xml
+1
-6
index.js
index.js
+11
-3
No files found.
README.md
View file @
92a23c07
# react-native-picker
[

](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>
[

](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)

###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
...
...
android/src/main/java/com/beefe/picker/PickerViewModule.java
View file @
92a23c07
...
...
@@ -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
);
...
...
android/src/main/java/com/beefe/picker/view/LoopView.java
View file @
92a23c07
...
...
@@ -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
;
...
...
android/src/main/java/com/beefe/picker/view/PickerViewAlone.java
View file @
92a23c07
...
...
@@ -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
++)
{
...
...
android/src/main/java/com/beefe/picker/view/PickerViewLinkage.java
View file @
92a23c07
...
...
@@ -446,6 +446,10 @@ public class PickerViewLinkage extends LinearLayout {
}
}
public
int
getViewHeight
(){
return
loopViewOne
.
getViewHeight
();
}
public
void
setOnSelectListener
(
OnSelectedListener
listener
)
{
this
.
onSelectedListener
=
listener
;
}
...
...
android/src/main/res/layout/popup_picker_view.xml
View file @
92a23c07
<?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_par
ent"
android:layout_height=
"
wrap_cont
ent"
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"
...
...
index.js
View file @
92a23c07
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment