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
85c1c118
Commit
85c1c118
authored
Jan 17, 2017
by
xwenliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add TimePicker example for use of Picker.select
parent
5eec07e3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
5 deletions
+84
-5
example/PickerTest/index.js
example/PickerTest/index.js
+75
-1
index.js
index.js
+8
-3
package.json
package.json
+1
-1
No files found.
example/PickerTest/index.js
View file @
85c1c118
...
@@ -19,7 +19,6 @@ class PickerTest extends Component {
...
@@ -19,7 +19,6 @@ class PickerTest extends Component {
constructor
(
props
,
context
)
{
constructor
(
props
,
context
)
{
super
(
props
,
context
);
super
(
props
,
context
);
this
.
_showDatePicker
();
}
}
_createDateData
()
{
_createDateData
()
{
...
@@ -113,6 +112,78 @@ class PickerTest extends Component {
...
@@ -113,6 +112,78 @@ class PickerTest extends Component {
Picker
.
show
();
Picker
.
show
();
}
}
_showTimePicker
()
{
let
years
=
[],
months
=
[],
days
=
[],
hours
=
[],
minutes
=
[];
for
(
let
i
=
1
;
i
<
51
;
i
++
){
years
.
push
(
i
+
1980
);
}
for
(
let
i
=
1
;
i
<
13
;
i
++
){
months
.
push
(
i
);
hours
.
push
(
i
);
}
for
(
let
i
=
1
;
i
<
32
;
i
++
){
days
.
push
(
i
);
}
for
(
let
i
=
1
;
i
<
61
;
i
++
){
minutes
.
push
(
i
);
}
let
pickerData
=
[
years
,
months
,
days
,
[
'
am
'
,
'
pm
'
],
hours
,
minutes
];
let
date
=
new
Date
();
let
selectedValue
=
[
[
date
.
getFullYear
()],
[
date
.
getMonth
()
+
1
],
[
date
.
getDate
()],
[
date
.
getHours
()
>
11
?
'
pm
'
:
'
am
'
],
[
date
.
getHours
()
===
12
?
12
:
date
.
getHours
()
%
12
],
[
date
.
getMinutes
()]
];
Picker
.
init
({
pickerData
,
selectedValue
,
pickerTitleText
:
'
Select Date and Time
'
,
wheelFlex
:
[
2
,
1
,
1
,
2
,
1
,
1
],
onPickerConfirm
:
pickedValue
=>
{
console
.
log
(
'
area
'
,
pickedValue
);
},
onPickerCancel
:
pickedValue
=>
{
console
.
log
(
'
area
'
,
pickedValue
);
},
onPickerSelect
:
pickedValue
=>
{
let
targetValue
=
[...
pickedValue
];
if
(
parseInt
(
targetValue
[
1
])
===
2
){
if
(
targetValue
[
0
]
%
4
===
0
&&
targetValue
[
2
]
>
29
){
targetValue
[
2
]
=
29
;
}
else
if
(
targetValue
[
0
]
%
4
!==
0
&&
targetValue
[
2
]
>
28
){
targetValue
[
2
]
=
28
;
}
}
else
if
(
targetValue
[
1
]
in
{
4
:
1
,
6
:
1
,
9
:
1
,
11
:
1
}
&&
targetValue
[
2
]
>
30
){
targetValue
[
2
]
=
30
;
}
// forbidden some value such as some 2.29, 4.31, 6.31...
if
(
JSON
.
stringify
(
targetValue
)
!==
JSON
.
stringify
(
pickedValue
)){
// android will return String all the time,but we put Number into picker at first
// so we need to convert them to Number again
targetValue
.
map
((
v
,
k
)
=>
{
if
(
k
!==
3
){
targetValue
[
k
]
=
parseInt
(
v
);
}
});
Picker
.
select
(
targetValue
);
pickedValue
=
targetValue
;
}
}
});
Picker
.
show
();
}
_toggle
()
{
_toggle
()
{
Picker
.
toggle
();
Picker
.
toggle
();
}
}
...
@@ -129,6 +200,9 @@ class PickerTest extends Component {
...
@@ -129,6 +200,9 @@ class PickerTest extends Component {
<
TouchableOpacity
style
=
{{
marginTop
:
40
,
marginLeft
:
20
}}
onPress
=
{
this
.
_showDatePicker
.
bind
(
this
)}
>
<
TouchableOpacity
style
=
{{
marginTop
:
40
,
marginLeft
:
20
}}
onPress
=
{
this
.
_showDatePicker
.
bind
(
this
)}
>
<
Text
>
DatePicker
<
/Text
>
<
Text
>
DatePicker
<
/Text
>
<
/TouchableOpacity
>
<
/TouchableOpacity
>
<
TouchableOpacity
style
=
{{
marginTop
:
10
,
marginLeft
:
20
}}
onPress
=
{
this
.
_showTimePicker
.
bind
(
this
)}
>
<
Text
>
TimePicker
<
/Text
>
<
/TouchableOpacity
>
<
TouchableOpacity
style
=
{{
marginTop
:
10
,
marginLeft
:
20
}}
onPress
=
{
this
.
_showAreaPicker
.
bind
(
this
)}
>
<
TouchableOpacity
style
=
{{
marginTop
:
10
,
marginLeft
:
20
}}
onPress
=
{
this
.
_showAreaPicker
.
bind
(
this
)}
>
<
Text
>
AreaPicker
<
/Text
>
<
Text
>
AreaPicker
<
/Text
>
<
/TouchableOpacity
>
<
/TouchableOpacity
>
...
...
index.js
View file @
85c1c118
...
@@ -56,9 +56,14 @@ export default {
...
@@ -56,9 +56,14 @@ export default {
},
},
select
(
arr
,
fn
)
{
select
(
arr
,
fn
)
{
if
(
ios
){
Picker
.
select
(
arr
);
}
else
if
(
android
){
Picker
.
select
(
arr
,
err
=>
{
Picker
.
select
(
arr
,
err
=>
{
typeof
fn
===
'
function
'
&&
fn
(
err
);
typeof
fn
===
'
function
'
&&
fn
(
err
);
});
});
}
},
},
toggle
(){
toggle
(){
...
...
package.json
View file @
85c1c118
{
{
"name"
:
"react-native-picker"
,
"name"
:
"react-native-picker"
,
"version"
:
"4.0.1
7
"
,
"version"
:
"4.0.1
8
"
,
"description"
:
""
,
"description"
:
""
,
"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