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
5eec07e3
Commit
5eec07e3
authored
Jan 17, 2017
by
xwenliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Picker.select feature
parent
9e28d766
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
73 deletions
+70
-73
android/src/main/java/com/beefe/picker/PickerViewModule.java
android/src/main/java/com/beefe/picker/PickerViewModule.java
+64
-70
example/PickerTest/index.js
example/PickerTest/index.js
+1
-0
index.js
index.js
+4
-2
package.json
package.json
+1
-1
No files found.
android/src/main/java/com/beefe/picker/PickerViewModule.java
View file @
5eec07e3
...
@@ -6,7 +6,6 @@ import android.graphics.Color;
...
@@ -6,7 +6,6 @@ import android.graphics.Color;
import
android.graphics.PixelFormat
;
import
android.graphics.PixelFormat
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.Nullable
;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.view.Gravity
;
import
android.view.Gravity
;
import
android.view.View
;
import
android.view.View
;
import
android.view.Window
;
import
android.view.Window
;
...
@@ -60,13 +59,17 @@ import static android.graphics.Color.argb;
...
@@ -60,13 +59,17 @@ import static android.graphics.Color.argb;
* Edited by heng on 2016/12/23
* Edited by heng on 2016/12/23
* 1. Changed returnData type
* 1. Changed returnData type
* 2. Added pickerToolBarFontSize
* 2. Added pickerToolBarFontSize
*
*
<p>
* Edited by heng on 2016/12/26
* Edited by heng on 2016/12/26
* 1. Fixed returnData bug
* 1. Fixed returnData bug
* 2. Added pickerFontColor
* 2. Added pickerFontColor
* 3. Added pickerFontSize
* 3. Added pickerFontSize
* 4. Used LifecycleEventListener replace Application.ActivityLifecycleCallbacks
* 4. Used LifecycleEventListener replace Application.ActivityLifecycleCallbacks
* 5. Fixed other bug
* 5. Fixed other bug
*
* Edited by heng on 2017/01/17
* 1. Added select(ReadableArray array, Callback callback)
* 2. Optimization code
*/
*/
public
class
PickerViewModule
extends
ReactContextBaseJavaModule
implements
LifecycleEventListener
{
public
class
PickerViewModule
extends
ReactContextBaseJavaModule
implements
LifecycleEventListener
{
...
@@ -103,14 +106,10 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
...
@@ -103,14 +106,10 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
private
static
final
String
EVENT_KEY_CANCEL
=
"cancel"
;
private
static
final
String
EVENT_KEY_CANCEL
=
"cancel"
;
private
static
final
String
EVENT_KEY_SELECTED
=
"select"
;
private
static
final
String
EVENT_KEY_SELECTED
=
"select"
;
private
static
final
String
ERROR_NOT_INIT
=
"please initialize"
;
private
static
final
String
ERROR_NOT_INIT
=
"please initialize
the component first
"
;
private
Dialog
dialog
=
null
;
private
Dialog
dialog
=
null
;
private
PickerViewLinkage
pickerViewLinkage
;
private
PickerViewAlone
pickerViewAlone
;
private
boolean
isAlone
=
true
;
private
boolean
isLoop
=
true
;
private
boolean
isLoop
=
true
;
private
String
confirmText
;
private
String
confirmText
;
...
@@ -123,6 +122,9 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
...
@@ -123,6 +122,9 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
private
int
curStatus
;
private
int
curStatus
;
private
PickerViewLinkage
pickerViewLinkage
;
private
PickerViewAlone
pickerViewAlone
;
public
PickerViewModule
(
ReactApplicationContext
reactContext
)
{
public
PickerViewModule
(
ReactApplicationContext
reactContext
)
{
super
(
reactContext
);
super
(
reactContext
);
reactContext
.
addLifecycleEventListener
(
this
);
reactContext
.
addLifecycleEventListener
(
this
);
...
@@ -266,31 +268,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
...
@@ -266,31 +268,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
}
}
}
}
String
[]
selectValue
=
{};
if
(
options
.
hasKey
(
SELECTED_VALUE
))
{
ReadableArray
array
=
options
.
getArray
(
SELECTED_VALUE
);
selectValue
=
new
String
[
array
.
size
()];
String
value
=
""
;
for
(
int
i
=
0
;
i
<
array
.
size
();
i
++)
{
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
;
}
selectValue
[
i
]
=
value
;
}
}
int
pickerTextColor
=
0xff000000
;
int
pickerTextColor
=
0xff000000
;
if
(
options
.
hasKey
(
PICKER_TEXT_COLOR
))
{
if
(
options
.
hasKey
(
PICKER_TEXT_COLOR
))
{
ReadableArray
array
=
options
.
getArray
(
PICKER_TEXT_COLOR
);
ReadableArray
array
=
options
.
getArray
(
PICKER_TEXT_COLOR
);
...
@@ -313,7 +290,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
...
@@ -313,7 +290,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
String
name
=
pickerData
.
getType
(
0
).
name
();
String
name
=
pickerData
.
getType
(
0
).
name
();
switch
(
name
)
{
switch
(
name
)
{
case
"Map"
:
case
"Map"
:
isAlone
=
false
;
curStatus
=
1
;
curStatus
=
1
;
pickerViewLinkage
.
setVisibility
(
View
.
VISIBLE
);
pickerViewLinkage
.
setVisibility
(
View
.
VISIBLE
);
pickerViewAlone
.
setVisibility
(
View
.
GONE
);
pickerViewAlone
.
setVisibility
(
View
.
GONE
);
...
@@ -330,7 +306,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
...
@@ -330,7 +306,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
commonEvent
(
EVENT_KEY_SELECTED
);
commonEvent
(
EVENT_KEY_SELECTED
);
}
}
});
});
pickerViewLinkage
.
setSelectValue
(
selectValue
);
pickerViewHeight
=
pickerViewLinkage
.
getViewHeight
();
pickerViewHeight
=
pickerViewLinkage
.
getViewHeight
();
break
;
break
;
default
:
default
:
...
@@ -351,18 +326,22 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
...
@@ -351,18 +326,22 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
}
}
});
});
pickerViewAlone
.
setSelectValue
(
selectValue
);
pickerViewHeight
=
pickerViewAlone
.
getViewHeight
();
pickerViewHeight
=
pickerViewAlone
.
getViewHeight
();
break
;
break
;
}
}
if
(
options
.
hasKey
(
SELECTED_VALUE
))
{
ReadableArray
array
=
options
.
getArray
(
SELECTED_VALUE
);
String
[]
selectedValue
=
getSelectedValue
(
array
);
select
(
selectedValue
);
}
if
(
options
.
hasKey
(
PICKER_BG_COLOR
))
{
if
(
options
.
hasKey
(
PICKER_BG_COLOR
))
{
ReadableArray
array
=
options
.
getArray
(
PICKER_BG_COLOR
);
ReadableArray
array
=
options
.
getArray
(
PICKER_BG_COLOR
);
int
[]
colors
=
getColor
(
array
);
int
[]
colors
=
getColor
(
array
);
pickerLayout
.
setBackgroundColor
(
argb
(
colors
[
3
],
colors
[
0
],
colors
[
1
],
colors
[
2
]));
pickerLayout
.
setBackgroundColor
(
argb
(
colors
[
3
],
colors
[
0
],
colors
[
1
],
colors
[
2
]));
}
}
Log
.
d
(
"PickerView"
,
"pickerViewHeight = "
+
pickerViewHeight
);
int
height
=
barViewHeight
+
pickerViewHeight
;
int
height
=
barViewHeight
+
pickerViewHeight
;
if
(
dialog
==
null
)
{
if
(
dialog
==
null
)
{
dialog
=
new
Dialog
(
activity
,
R
.
style
.
Dialog_Full_Screen
);
dialog
=
new
Dialog
(
activity
,
R
.
style
.
Dialog_Full_Screen
);
...
@@ -385,6 +364,18 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
...
@@ -385,6 +364,18 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
}
}
}
}
@ReactMethod
public
void
select
(
ReadableArray
array
,
Callback
callback
)
{
if
(
dialog
==
null
)
{
if
(
callback
!=
null
)
{
callback
.
invoke
(
ERROR_NOT_INIT
);
}
return
;
}
String
[]
selectedValue
=
getSelectedValue
(
array
);
select
(
selectedValue
);
}
@ReactMethod
@ReactMethod
public
void
show
()
{
public
void
show
()
{
if
(
dialog
==
null
)
{
if
(
dialog
==
null
)
{
...
@@ -405,37 +396,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
...
@@ -405,37 +396,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
}
}
}
}
@ReactMethod
public
void
select
(
ReadableArray
array
)
{
if
(
dialog
!=
null
)
{
String
[]
selectValue
=
new
String
[
array
.
size
()];
String
value
=
""
;
for
(
int
i
=
0
;
i
<
array
.
size
();
i
++)
{
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
;
}
selectValue
[
i
]
=
value
;
}
if
(
isAlone
){
pickerViewAlone
.
setSelectValue
(
selectValue
);
}
else
{
pickerViewLinkage
.
setSelectValue
(
selectValue
);
}
}
}
@ReactMethod
@ReactMethod
public
void
isPickerShow
(
Callback
callback
)
{
public
void
isPickerShow
(
Callback
callback
)
{
if
(
callback
==
null
)
if
(
callback
==
null
)
...
@@ -466,6 +426,41 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
...
@@ -466,6 +426,41 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
return
colors
;
return
colors
;
}
}
private
String
[]
getSelectedValue
(
ReadableArray
array
)
{
String
[]
selectValue
=
new
String
[
array
.
size
()];
String
value
=
""
;
for
(
int
i
=
0
;
i
<
array
.
size
();
i
++)
{
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
;
}
selectValue
[
i
]
=
value
;
}
return
selectValue
;
}
private
void
select
(
String
[]
selectedValue
)
{
switch
(
curStatus
)
{
case
0
:
pickerViewAlone
.
setSelectValue
(
selectedValue
);
break
;
case
1
:
pickerViewLinkage
.
setSelectValue
(
selectedValue
);
break
;
}
}
private
void
commonEvent
(
String
eventKey
)
{
private
void
commonEvent
(
String
eventKey
)
{
WritableMap
map
=
Arguments
.
createMap
();
WritableMap
map
=
Arguments
.
createMap
();
map
.
putString
(
"type"
,
eventKey
);
map
.
putString
(
"type"
,
eventKey
);
...
@@ -501,7 +496,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
...
@@ -501,7 +496,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
@Override
@Override
public
void
onHostDestroy
()
{
public
void
onHostDestroy
()
{
hide
();
dialog
=
null
;
}
}
}
}
example/PickerTest/index.js
View file @
5eec07e3
...
@@ -106,6 +106,7 @@ class PickerTest extends Component {
...
@@ -106,6 +106,7 @@ class PickerTest extends Component {
console
.
log
(
'
area
'
,
pickedValue
);
console
.
log
(
'
area
'
,
pickedValue
);
},
},
onPickerSelect
:
pickedValue
=>
{
onPickerSelect
:
pickedValue
=>
{
//Picker.select(['山东', '青岛', '黄岛区'])
console
.
log
(
'
area
'
,
pickedValue
);
console
.
log
(
'
area
'
,
pickedValue
);
}
}
});
});
...
...
index.js
View file @
5eec07e3
...
@@ -55,8 +55,10 @@ export default {
...
@@ -55,8 +55,10 @@ export default {
Picker
.
hide
();
Picker
.
hide
();
},
},
select
(
data
)
{
select
(
arr
,
fn
)
{
Picker
.
select
(
data
)
Picker
.
select
(
arr
,
err
=>
{
typeof
fn
===
'
function
'
&&
fn
(
err
);
});
},
},
toggle
(){
toggle
(){
...
...
package.json
View file @
5eec07e3
{
{
"name"
:
"react-native-picker"
,
"name"
:
"react-native-picker"
,
"version"
:
"4.0.1
6
"
,
"version"
:
"4.0.1
7
"
,
"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