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
c5cfec35
Commit
c5cfec35
authored
Dec 25, 2015
by
xwenliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue#5
parent
3db45e28
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
22 deletions
+51
-22
index.js
index.js
+50
-21
package.json
package.json
+1
-1
No files found.
index.js
View file @
c5cfec35
...
@@ -41,10 +41,30 @@ export default class PickerAny extends React.Component {
...
@@ -41,10 +41,30 @@ export default class PickerAny extends React.Component {
constructor
(
props
,
context
){
constructor
(
props
,
context
){
super
(
props
,
context
);
super
(
props
,
context
);
}
componentWillMount
(){
this
.
state
=
this
.
_getStateFromProps
(
this
.
props
);
}
componentWillReceiveProps
(
newProps
){
let
newState
=
this
.
_getStateFromProps
(
newProps
);
this
.
setState
(
newState
);
}
_getStateFromProps
(
props
){
//the pickedValue must looks like [wheelone's, wheeltwo's, ...]
//the pickedValue must looks like [wheelone's, wheeltwo's, ...]
//this.state.selectedValue may be the result of the first pickerWheel
//this.state.selectedValue may be the result of the first pickerWheel
let
pickedValue
=
this
.
props
.
selectedValue
;
let
pickerBtnText
=
props
.
pickerBtnText
;
let
pickerData
=
this
.
props
.
pickerData
;
let
pickerBtnStyle
=
props
.
pickerBtnStyle
;
let
pickerToolBarStyle
=
props
.
pickerToolBarStyle
;
let
pickerItemStyle
=
props
.
pickerItemStyle
;
let
pickerHeight
=
props
.
pickerHeight
;
let
showDuration
=
props
.
showDuration
;
let
pickerData
=
props
.
pickerData
;
let
selectedValue
=
props
.
selectedValue
;
let
onPickerDone
=
props
.
onPickerDone
;
let
pickerStyle
=
pickerData
.
constructor
===
Array
?
'
parallel
'
:
'
cascade
'
;
let
pickerStyle
=
pickerData
.
constructor
===
Array
?
'
parallel
'
:
'
cascade
'
;
let
firstWheelData
;
let
firstWheelData
;
let
firstPickedData
;
let
firstPickedData
;
...
@@ -55,8 +75,8 @@ export default class PickerAny extends React.Component {
...
@@ -55,8 +75,8 @@ export default class PickerAny extends React.Component {
let
cascadeData
=
{};
let
cascadeData
=
{};
if
(
pickerStyle
===
'
parallel
'
){
if
(
pickerStyle
===
'
parallel
'
){
//compatible single wheel sence
//compatible single wheel sence
if
(
pick
edValue
.
constructor
!==
Array
){
if
(
select
edValue
.
constructor
!==
Array
){
pickedValue
=
[
pick
edValue
];
selectedValue
=
[
select
edValue
];
}
}
if
(
pickerData
[
0
].
constructor
!==
Array
){
if
(
pickerData
[
0
].
constructor
!==
Array
){
pickerData
=
[
pickerData
];
pickerData
=
[
pickerData
];
...
@@ -65,18 +85,28 @@ export default class PickerAny extends React.Component {
...
@@ -65,18 +85,28 @@ export default class PickerAny extends React.Component {
else
if
(
pickerStyle
===
'
cascade
'
){
else
if
(
pickerStyle
===
'
cascade
'
){
//only support three stage
//only support three stage
firstWheelData
=
Object
.
keys
(
pickerData
);
firstWheelData
=
Object
.
keys
(
pickerData
);
firstPickedData
=
this
.
props
.
selectedValue
[
0
];
firstPickedData
=
props
.
selectedValue
[
0
];
secondPickedData
=
this
.
props
.
selectedValue
[
1
];
secondPickedData
=
props
.
selectedValue
[
1
];
cascadeData
=
this
.
_getCascadeData
(
pickerData
,
pick
edValue
,
firstPickedData
,
secondPickedData
,
true
);
cascadeData
=
this
.
_getCascadeData
(
pickerData
,
select
edValue
,
firstPickedData
,
secondPickedData
,
true
);
}
}
this
.
state
=
{
//保存了已经选择到的数据
slideAnim
:
new
Animated
.
Value
(
-
this
.
props
.
pickerHeight
),
this
.
pickedValue
=
selectedValue
;
this
.
pickerStyle
=
pickerStyle
;
return
{
pickerBtnText
,
pickerBtnStyle
,
pickerToolBarStyle
,
pickerItemStyle
,
pickerHeight
,
showDuration
,
pickerData
,
pickerData
,
selectedValue
:
pickedValue
,
selectedValue
,
onPickerDone
,
//list of first wheel data
//list of first wheel data
firstWheelData
,
firstWheelData
,
//first wheel selected value
//first wheel selected value
firstPickedData
,
firstPickedData
,
slideAnim
:
new
Animated
.
Value
(
-
props
.
pickerHeight
),
//list of second wheel data and pickedDataIndex
//list of second wheel data and pickedDataIndex
secondWheelData
:
cascadeData
.
secondWheelData
,
secondWheelData
:
cascadeData
.
secondWheelData
,
secondPickedDataIndex
:
cascadeData
.
secondPickedDataIndex
,
secondPickedDataIndex
:
cascadeData
.
secondPickedDataIndex
,
...
@@ -84,8 +114,6 @@ export default class PickerAny extends React.Component {
...
@@ -84,8 +114,6 @@ export default class PickerAny extends React.Component {
thirdWheelData
:
cascadeData
.
thirdWheelData
,
thirdWheelData
:
cascadeData
.
thirdWheelData
,
thirdPickedDataIndex
:
cascadeData
.
thirdPickedDataIndex
thirdPickedDataIndex
:
cascadeData
.
thirdPickedDataIndex
};
};
this
.
pickedValue
=
pickedValue
;
this
.
pickerStyle
=
pickerStyle
;
}
}
_slideUp
(){
_slideUp
(){
...
@@ -94,7 +122,7 @@ export default class PickerAny extends React.Component {
...
@@ -94,7 +122,7 @@ export default class PickerAny extends React.Component {
this
.
state
.
slideAnim
,
this
.
state
.
slideAnim
,
{
{
toValue
:
0
,
toValue
:
0
,
duration
:
this
.
props
.
showDuration
,
duration
:
this
.
state
.
showDuration
,
}
}
).
start
((
evt
)
=>
{
).
start
((
evt
)
=>
{
if
(
evt
.
finished
)
{
if
(
evt
.
finished
)
{
...
@@ -109,8 +137,8 @@ export default class PickerAny extends React.Component {
...
@@ -109,8 +137,8 @@ export default class PickerAny extends React.Component {
Animated
.
timing
(
Animated
.
timing
(
this
.
state
.
slideAnim
,
this
.
state
.
slideAnim
,
{
{
toValue
:
-
this
.
props
.
pickerHeight
,
toValue
:
-
this
.
state
.
pickerHeight
,
duration
:
this
.
props
.
showDuration
,
duration
:
this
.
state
.
showDuration
,
}
}
).
start
((
evt
)
=>
{
).
start
((
evt
)
=>
{
if
(
evt
.
finished
)
{
if
(
evt
.
finished
)
{
...
@@ -148,7 +176,8 @@ export default class PickerAny extends React.Component {
...
@@ -148,7 +176,8 @@ export default class PickerAny extends React.Component {
_pickerFinish
(){
_pickerFinish
(){
this
.
_toggle
();
this
.
_toggle
();
this
.
props
.
onPickerDone
(
this
.
pickedValue
);
debugger
;
this
.
state
.
onPickerDone
(
this
.
pickedValue
);
}
}
_renderParallelWheel
(
pickerData
){
_renderParallelWheel
(
pickerData
){
...
@@ -385,14 +414,14 @@ export default class PickerAny extends React.Component {
...
@@ -385,14 +414,14 @@ export default class PickerAny extends React.Component {
let
pickerBtn
=
null
;
let
pickerBtn
=
null
;
return
(
return
(
<
Animated
.
View
style
=
{[
styles
.
picker
,
{
<
Animated
.
View
style
=
{[
styles
.
picker
,
{
height
:
this
.
props
.
pickerHeight
,
height
:
this
.
state
.
pickerHeight
,
bottom
:
this
.
state
.
slideAnim
bottom
:
this
.
state
.
slideAnim
}]}
>
}]}
>
<
View
style
=
{[
styles
.
pickerToolbar
,
this
.
props
.
pickerToolBarStyle
]}
>
<
View
style
=
{[
styles
.
pickerToolbar
,
this
.
state
.
pickerToolBarStyle
]}
>
{
pickerBtn
}
{
pickerBtn
}
<
View
style
=
{
styles
.
pickerFinishBtn
}
>
<
View
style
=
{
styles
.
pickerFinishBtn
}
>
<
Text
style
=
{[
styles
.
pickerFinishBtnText
,
this
.
props
.
pickerBtnStyle
]}
<
Text
style
=
{[
styles
.
pickerFinishBtnText
,
this
.
state
.
pickerBtnStyle
]}
onPress
=
{
this
.
_pickerFinish
.
bind
(
this
)}
>
{
this
.
props
.
pickerBtnText
}
<
/Text
>
onPress
=
{
this
.
_pickerFinish
.
bind
(
this
)}
>
{
this
.
state
.
pickerBtnText
}
<
/Text
>
<
/View
>
<
/View
>
<
/View
>
<
/View
>
<
View
style
=
{
styles
.
pickerWrap
}
>
<
View
style
=
{
styles
.
pickerWrap
}
>
...
...
package.json
View file @
c5cfec35
{
{
"name"
:
"react-native-picker"
,
"name"
:
"react-native-picker"
,
"version"
:
"0.2.
3
"
,
"version"
:
"0.2.
4
"
,
"description"
:
"react-native-picker"
,
"description"
:
"react-native-picker"
,
"main"
:
"index.js"
,
"main"
:
"index.js"
,
"scripts"
:
{
"scripts"
:
{
...
...
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