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
d6ad6759
Commit
d6ad6759
authored
Dec 26, 2016
by
xwenliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New features for #102 #90 #29
parent
cf30fbc6
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
553 additions
and
266 deletions
+553
-266
README.md
README.md
+19
-17
android/src/main/AndroidManifest.xml
android/src/main/AndroidManifest.xml
+1
-1
android/src/main/java/com/beefe/picker/PickerViewModule.java
android/src/main/java/com/beefe/picker/PickerViewModule.java
+98
-65
android/src/main/java/com/beefe/picker/view/LoopView.java
android/src/main/java/com/beefe/picker/view/LoopView.java
+19
-18
android/src/main/java/com/beefe/picker/view/OnSelectedListener.java
...c/main/java/com/beefe/picker/view/OnSelectedListener.java
+1
-1
android/src/main/java/com/beefe/picker/view/PickerViewAlone.java
.../src/main/java/com/beefe/picker/view/PickerViewAlone.java
+61
-17
android/src/main/java/com/beefe/picker/view/PickerViewLinkage.java
...rc/main/java/com/beefe/picker/view/PickerViewLinkage.java
+156
-48
android/src/main/java/com/beefe/picker/view/ReturnData.java
android/src/main/java/com/beefe/picker/view/ReturnData.java
+27
-0
android/src/main/res/values/styles.xml
android/src/main/res/values/styles.xml
+1
-1
example/PickerTest/index.js
example/PickerTest/index.js
+10
-7
index.js
index.js
+15
-15
ios/RCTBEEPickerManager/BzwPicker.h
ios/RCTBEEPickerManager/BzwPicker.h
+8
-1
ios/RCTBEEPickerManager/BzwPicker.m
ios/RCTBEEPickerManager/BzwPicker.m
+125
-71
ios/RCTBEEPickerManager/RCTBEEPickerManager.m
ios/RCTBEEPickerManager/RCTBEEPickerManager.m
+11
-3
package.json
package.json
+1
-1
No files found.
README.md
View file @
d6ad6759
...
...
@@ -10,22 +10,24 @@
####Params
|Key | Type | Default| Description |
| --- | ---- | ------ | ----------- |
|pickerConfirmBtnText |string |确认 | |
|pickerCancelBtnText |string |取消 | |
|pickerTitleText |string |请选择 | |
|pickerConfirmBtnColor |array |[1, 186, 245, 1] | |
|pickerCancelBtnColor |array |[1, 186, 245, 1] | |
|pickerTitleColor |array |[20, 20, 20, 1]) | |
|pickerToolBarBg |array |[232, 232, 232, 1] | |
|pickerBg |array |[196, 199, 206, 1] | |
|wheelFlex |array |[2, 1, 1] |set width of the three wheels to 2:1:1 |
|pickerData |array | | |
|selectedValue |array | | |
|onPickerConfirm |function| | |
|onPickerCancel |function| | |
|onPickerSelect |function| | |
|Key | Description | Type | Default|
| --- | ----------- | ---- | ------ |
|pickerConfirmBtnText | |string |confirm |
|pickerCancelBtnText | |string |cancel |
|pickerTitleText | |string |pls select |
|pickerConfirmBtnColor | |array |[1, 186, 245, 1] |
|pickerCancelBtnColor | |array |[1, 186, 245, 1] |
|pickerTitleColor | |array |[20, 20, 20, 1]) |
|pickerToolBarBg | |array |[232, 232, 232, 1] |
|pickerBg | |array |[196, 199, 206, 1] |
|pickerToolBarFontSize | |number |16 |
|pickerFontSize | |number |16 |
|pickerFontColor | |array |[31, 31, 31, 1] |
|pickerData | |array | |
|selectedValue | |string | |
|onPickerConfirm | |function| |
|onPickerCancel | |function| |
|onPickerSelect | |function| |
####Methods
...
...
@@ -93,7 +95,7 @@
```
javascript
pickerData
=
[
1
,
2
,
3
,
4
];
selectedValue
=
[
3
]
;
selectedValue
=
3
;
```
-
two or more wheel:
...
...
android/src/main/AndroidManifest.xml
View file @
d6ad6759
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"com.beefe.picker"
>
</manifest>
\ No newline at end of file
</manifest>
android/src/main/java/com/beefe/picker/PickerViewModule.java
View file @
d6ad6759
package
com.beefe.picker
;
import
android.app.Activity
;
import
android.app.Application
;
import
android.app.Dialog
;
import
android.graphics.Color
;
import
android.graphics.PixelFormat
;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.view.Gravity
;
import
android.view.View
;
import
android.view.Window
;
...
...
@@ -18,8 +17,10 @@ import android.widget.TextView;
import
com.beefe.picker.view.OnSelectedListener
;
import
com.beefe.picker.view.PickerViewAlone
;
import
com.beefe.picker.view.PickerViewLinkage
;
import
com.beefe.picker.view.ReturnData
;
import
com.facebook.react.bridge.Arguments
;
import
com.facebook.react.bridge.Callback
;
import
com.facebook.react.bridge.LifecycleEventListener
;
import
com.facebook.react.bridge.ReactApplicationContext
;
import
com.facebook.react.bridge.ReactContext
;
import
com.facebook.react.bridge.ReactContextBaseJavaModule
;
...
...
@@ -32,8 +33,10 @@ import com.facebook.react.modules.core.DeviceEventManagerModule;
import
java.util.ArrayList
;
import
static
android
.
graphics
.
Color
.
argb
;
/**
* Author:
heng <a href="https://github.com/shexiaoheng"/
>
* Author:
<a href="https://github.com/shexiaoheng">heng</a
>
* <p>
* Created by heng on 16/9/5.
* <p>
...
...
@@ -53,9 +56,20 @@ import java.util.ArrayList;
* Edited by heng on 2016/11/17
* 1. Used Dialog replace WindowManger
* 2. Restore method show() isPickerShow()
* <p>
* Edited by heng on 2016/12/23
* 1. Changed returnData type
* 2. Added pickerToolBarFontSize
*
* Edited by heng on 2016/12/26
* 1. Fixed returnData bug
* 2. Added pickerFontColor
* 3. Added pickerFontSize
* 4. Used LifecycleEventListener replace Application.ActivityLifecycleCallbacks
* 5. Fixed other bug
*/
public
class
PickerViewModule
extends
ReactContextBaseJavaModule
implements
Application
.
ActivityLifecycleCallbacks
{
public
class
PickerViewModule
extends
ReactContextBaseJavaModule
implements
LifecycleEventListener
{
private
static
final
String
REACT_CLASS
=
"BEEPickerManager"
;
...
...
@@ -68,17 +82,21 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
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
PICKER_TOOL_BAR_BG
=
"pickerToolBarBg"
;
private
static
final
String
PICKER_TOOL_BAR_HEIGHT
=
"pickerToolBarHeight"
;
private
static
final
String
PICKER_TOOL_BAR_TEXT_SIZE
=
"pickerToolBarFontSize"
;
private
static
final
String
CONFIRM
_TEXT
=
"pickerConfirmBtnText"
;
private
static
final
String
CONFIRM_TEXT
_COLOR
=
"pickerConfirmBtnColor"
;
private
static
final
String
PICKER_CONFIRM_BTN
_TEXT
=
"pickerConfirmBtnText"
;
private
static
final
String
PICKER_CONFIRM_BTN
_COLOR
=
"pickerConfirmBtnColor"
;
private
static
final
String
CANCEL
_TEXT
=
"pickerCancelBtnText"
;
private
static
final
String
CANCEL_TEXT
_COLOR
=
"pickerCancelBtnColor"
;
private
static
final
String
PICKER_CANCEL_BTN
_TEXT
=
"pickerCancelBtnText"
;
private
static
final
String
PICKER_CANCEL_BTN
_COLOR
=
"pickerCancelBtnColor"
;
private
static
final
String
TITLE_TEXT
=
"pickerTitleText"
;
private
static
final
String
TITLE_TEXT_COLOR
=
"pickerTitleColor"
;
private
static
final
String
PICKER_TITLE_TEXT
=
"pickerTitleText"
;
private
static
final
String
PICKER_TITLE_TEXT_COLOR
=
"pickerTitleColor"
;
private
static
final
String
PICKER_TEXT_COLOR
=
"pickerFontColor"
;
private
static
final
String
PICKER_TEXT_SIZE
=
"pickerFontSize"
;
private
static
final
String
PICKER_EVENT_NAME
=
"pickerEvent"
;
private
static
final
String
EVENT_KEY_CONFIRM
=
"confirm"
;
...
...
@@ -97,12 +115,13 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
private
double
[]
weights
;
private
ArrayList
<
String
>
returnData
;
private
ArrayList
<
ReturnData
>
returnData
;
private
int
curStatus
;
public
PickerViewModule
(
ReactApplicationContext
reactContext
)
{
super
(
reactContext
);
reactContext
.
addLifecycleEventListener
(
this
);
}
@Override
...
...
@@ -124,11 +143,11 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
final
PickerViewAlone
pickerViewAlone
=
(
PickerViewAlone
)
view
.
findViewById
(
R
.
id
.
pickerViewAlone
);
int
barViewHeight
;
if
(
options
.
hasKey
(
TEXT
_BAR_HEIGHT
))
{
if
(
options
.
hasKey
(
PICKER_TOOL
_BAR_HEIGHT
))
{
try
{
barViewHeight
=
options
.
getInt
(
TEXT
_BAR_HEIGHT
);
barViewHeight
=
options
.
getInt
(
PICKER_TOOL
_BAR_HEIGHT
);
}
catch
(
Exception
e
)
{
barViewHeight
=
(
int
)
options
.
getDouble
(
TEXT
_BAR_HEIGHT
);
barViewHeight
=
(
int
)
options
.
getDouble
(
PICKER_TOOL
_BAR_HEIGHT
);
}
}
else
{
barViewHeight
=
(
int
)
(
activity
.
getResources
().
getDisplayMetrics
().
density
*
40
);
...
...
@@ -138,22 +157,28 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
barViewHeight
);
barLayout
.
setLayoutParams
(
params
);
if
(
options
.
hasKey
(
TEXT_BAR_COLOR
))
{
ReadableArray
array
=
options
.
getArray
(
TEXT_BAR_COLOR
);
if
(
options
.
hasKey
(
PICKER_TOOL_BAR_BG
))
{
ReadableArray
array
=
options
.
getArray
(
PICKER_TOOL_BAR_BG
);
int
[]
colors
=
getColor
(
array
);
barLayout
.
setBackgroundColor
(
Color
.
argb
(
colors
[
3
],
colors
[
0
],
colors
[
1
],
colors
[
2
]));
barLayout
.
setBackgroundColor
(
argb
(
colors
[
3
],
colors
[
0
],
colors
[
1
],
colors
[
2
]));
}
if
(
options
.
hasKey
(
PICKER_TOOL_BAR_TEXT_SIZE
))
{
int
toolBarTextSize
=
options
.
getInt
(
PICKER_TOOL_BAR_TEXT_SIZE
);
cancelTV
.
setTextSize
(
toolBarTextSize
);
titleTV
.
setTextSize
(
toolBarTextSize
);
confirmTV
.
setTextSize
(
toolBarTextSize
);
}
if
(
options
.
hasKey
(
CONFIRM
_TEXT
))
{
confirmText
=
options
.
getString
(
CONFIRM
_TEXT
);
if
(
options
.
hasKey
(
PICKER_CONFIRM_BTN
_TEXT
))
{
confirmText
=
options
.
getString
(
PICKER_CONFIRM_BTN
_TEXT
);
}
confirmTV
.
setText
(!
TextUtils
.
isEmpty
(
confirmText
)
?
confirmText
:
""
);
if
(
options
.
hasKey
(
CONFIRM_TEXT
_COLOR
))
{
ReadableArray
array
=
options
.
getArray
(
CONFIRM_TEXT
_COLOR
);
if
(
options
.
hasKey
(
PICKER_CONFIRM_BTN
_COLOR
))
{
ReadableArray
array
=
options
.
getArray
(
PICKER_CONFIRM_BTN
_COLOR
);
int
[]
colors
=
getColor
(
array
);
confirmTV
.
setTextColor
(
Color
.
argb
(
colors
[
3
],
colors
[
0
],
colors
[
1
],
colors
[
2
]));
confirmTV
.
setTextColor
(
argb
(
colors
[
3
],
colors
[
0
],
colors
[
1
],
colors
[
2
]));
}
confirmTV
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
...
...
@@ -172,24 +197,24 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
});
if
(
options
.
hasKey
(
TITLE_TEXT
))
{
titleText
=
options
.
getString
(
TITLE_TEXT
);
if
(
options
.
hasKey
(
PICKER_
TITLE_TEXT
))
{
titleText
=
options
.
getString
(
PICKER_
TITLE_TEXT
);
}
titleTV
.
setText
(!
TextUtils
.
isEmpty
(
titleText
)
?
titleText
:
""
);
if
(
options
.
hasKey
(
TITLE_TEXT_COLOR
))
{
ReadableArray
array
=
options
.
getArray
(
TITLE_TEXT_COLOR
);
if
(
options
.
hasKey
(
PICKER_
TITLE_TEXT_COLOR
))
{
ReadableArray
array
=
options
.
getArray
(
PICKER_
TITLE_TEXT_COLOR
);
int
[]
colors
=
getColor
(
array
);
titleTV
.
setTextColor
(
Color
.
argb
(
colors
[
3
],
colors
[
0
],
colors
[
1
],
colors
[
2
]));
titleTV
.
setTextColor
(
argb
(
colors
[
3
],
colors
[
0
],
colors
[
1
],
colors
[
2
]));
}
if
(
options
.
hasKey
(
CANCEL
_TEXT
))
{
cancelText
=
options
.
getString
(
CANCEL
_TEXT
);
if
(
options
.
hasKey
(
PICKER_CANCEL_BTN
_TEXT
))
{
cancelText
=
options
.
getString
(
PICKER_CANCEL_BTN
_TEXT
);
}
cancelTV
.
setText
(!
TextUtils
.
isEmpty
(
cancelText
)
?
cancelText
:
""
);
if
(
options
.
hasKey
(
CANCEL_TEXT
_COLOR
))
{
ReadableArray
array
=
options
.
getArray
(
CANCEL_TEXT
_COLOR
);
if
(
options
.
hasKey
(
PICKER_CANCEL_BTN
_COLOR
))
{
ReadableArray
array
=
options
.
getArray
(
PICKER_CANCEL_BTN
_COLOR
);
int
[]
colors
=
getColor
(
array
);
cancelTV
.
setTextColor
(
Color
.
argb
(
colors
[
3
],
colors
[
0
],
colors
[
1
],
colors
[
2
]));
cancelTV
.
setTextColor
(
argb
(
colors
[
3
],
colors
[
0
],
colors
[
1
],
colors
[
2
]));
}
cancelTV
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
...
...
@@ -262,6 +287,22 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
}
}
int
pickerTextColor
=
0xff000000
;
if
(
options
.
hasKey
(
PICKER_TEXT_COLOR
))
{
ReadableArray
array
=
options
.
getArray
(
PICKER_TEXT_COLOR
);
int
[]
colors
=
getColor
(
array
);
pickerTextColor
=
Color
.
argb
(
colors
[
3
],
colors
[
0
],
colors
[
1
],
colors
[
2
]);
}
int
pickerTextSize
=
16
;
if
(
options
.
hasKey
(
PICKER_TEXT_SIZE
))
{
try
{
pickerTextSize
=
options
.
getInt
(
PICKER_TEXT_SIZE
);
}
catch
(
Exception
e
)
{
pickerTextSize
=
(
int
)
options
.
getDouble
(
PICKER_TEXT_SIZE
);
}
}
ReadableArray
pickerData
=
options
.
getArray
(
PICKER_DATA
);
int
pickerViewHeight
;
...
...
@@ -273,11 +314,13 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
pickerViewAlone
.
setVisibility
(
View
.
GONE
);
pickerViewLinkage
.
setPickerData
(
pickerData
,
weights
);
pickerViewLinkage
.
setTextColor
(
pickerTextColor
);
pickerViewLinkage
.
setTextSize
(
pickerTextSize
);
pickerViewLinkage
.
setIsLoop
(
isLoop
);
pickerViewLinkage
.
setOnSelectListener
(
new
OnSelectedListener
()
{
@Override
public
void
onSelected
(
ArrayList
<
String
>
selectedList
)
{
public
void
onSelected
(
ArrayList
<
ReturnData
>
selectedList
)
{
returnData
=
selectedList
;
commonEvent
(
EVENT_KEY_SELECTED
);
}
...
...
@@ -291,11 +334,13 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
pickerViewLinkage
.
setVisibility
(
View
.
GONE
);
pickerViewAlone
.
setPickerData
(
pickerData
,
weights
);
pickerViewAlone
.
setTextColor
(
pickerTextColor
);
pickerViewAlone
.
setTextSize
(
pickerTextSize
);
pickerViewAlone
.
setIsLoop
(
isLoop
);
pickerViewAlone
.
setOnSelectedListener
(
new
OnSelectedListener
()
{
@Override
public
void
onSelected
(
ArrayList
<
String
>
selectedList
)
{
public
void
onSelected
(
ArrayList
<
ReturnData
>
selectedList
)
{
returnData
=
selectedList
;
commonEvent
(
EVENT_KEY_SELECTED
);
}
...
...
@@ -309,9 +354,10 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
if
(
options
.
hasKey
(
PICKER_BG_COLOR
))
{
ReadableArray
array
=
options
.
getArray
(
PICKER_BG_COLOR
);
int
[]
colors
=
getColor
(
array
);
pickerLayout
.
setBackgroundColor
(
Color
.
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
;
if
(
dialog
==
null
)
{
dialog
=
new
Dialog
(
activity
,
R
.
style
.
Dialog_Full_Screen
);
...
...
@@ -331,7 +377,6 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
dialog
.
dismiss
();
dialog
.
setContentView
(
view
);
}
dialog
.
show
();
}
}
...
...
@@ -357,6 +402,8 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
@ReactMethod
public
void
isPickerShow
(
Callback
callback
)
{
if
(
callback
==
null
)
return
;
if
(
dialog
==
null
)
{
callback
.
invoke
(
ERROR_NOT_INIT
);
}
else
{
...
...
@@ -385,11 +432,15 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
private
void
commonEvent
(
String
eventKey
)
{
WritableMap
map
=
Arguments
.
createMap
();
WritableArray
array
=
Arguments
.
createArray
();
for
(
String
item
:
returnData
)
{
array
.
pushString
(
item
);
map
.
putString
(
"type"
,
eventKey
);
WritableArray
indexes
=
Arguments
.
createArray
();
WritableArray
values
=
Arguments
.
createArray
();
for
(
ReturnData
data
:
returnData
)
{
indexes
.
pushInt
(
data
.
getIndex
());
values
.
pushString
(
data
.
getItem
());
}
map
.
putArray
(
eventKey
,
array
);
map
.
putArray
(
"selectedValue"
,
values
);
map
.
putArray
(
"selectedIndex"
,
indexes
);
sendEvent
(
getReactApplicationContext
(),
PICKER_EVENT_NAME
,
map
);
}
...
...
@@ -402,36 +453,18 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Appl
}
@Override
public
void
on
ActivityCreated
(
Activity
activity
,
Bundle
savedInstanceState
)
{
public
void
on
HostResume
(
)
{
}
@Override
public
void
onActivityStarted
(
Activity
activity
)
{
}
@Override
public
void
onActivityResumed
(
Activity
activity
)
{
}
@Override
public
void
onActivityPaused
(
Activity
activity
)
{
}
@Override
public
void
onActivityStopped
(
Activity
activity
)
{
public
void
onHostPause
()
{
hide
();
dialog
=
null
;
}
@Override
public
void
on
ActivitySaveInstanceState
(
Activity
activity
,
Bundle
outState
)
{
public
void
on
HostDestroy
(
)
{
}
@Override
public
void
onActivityDestroyed
(
Activity
activity
)
{
}
}
}
\ No newline at end of file
android/src/main/java/com/beefe/picker/view/LoopView.java
View file @
d6ad6759
...
...
@@ -19,9 +19,13 @@ import java.util.concurrent.ScheduledFuture;
import
java.util.concurrent.TimeUnit
;
/**
* Edited by
shexiaoheng
on 2016/10/20
* Edited by
<a href="https://github.com/shexiaoheng">heng</a>
on 2016/10/20
* 1. Added method getY
* 2. Changed line color 0xffc5c5c5 -> 0xffb8bbc2
*
* Edited by heng on 2016/12/26
* 1. Added setTextColor
* 2. Added setTextSize
*/
public
class
LoopView
extends
View
{
...
...
@@ -50,10 +54,6 @@ public class LoopView extends View {
private
int
textSize
;
int
maxTextHeight
;
private
int
colorGray
;
private
int
colorBlack
;
private
int
colorLightGray
;
// 条目间距倍数
float
lineSpacingMultiplier
;
boolean
isLoop
;
...
...
@@ -109,37 +109,30 @@ public class LoopView extends View {
lineSpacingMultiplier
=
2.0
F
;
isLoop
=
true
;
itemsVisible
=
9
;
textSize
=
0
;
colorGray
=
0xffafafaf
;
colorBlack
=
0xff313131
;
colorLightGray
=
0xffb8bbc2
;
// colorLightGray = 0xffc5c5c5;
textSize
=
(
int
)
(
context
.
getResources
().
getDisplayMetrics
().
density
*
16
);
totalScrollY
=
0
;
initPosition
=
-
1
;
initPaints
();
setTextSize
(
20
F
);
}
private
void
initPaints
()
{
paintOuterText
=
new
Paint
();
paintOuterText
.
setColor
(
colorGray
);
paintOuterText
.
setColor
(
0xffafafaf
);
paintOuterText
.
setAntiAlias
(
true
);
paintOuterText
.
setTypeface
(
Typeface
.
MONOSPACE
);
paintOuterText
.
setTextSize
(
textSize
);
paintCenterText
=
new
Paint
();
paintCenterText
.
setColor
(
colorBlack
);
paintCenterText
.
setColor
(
0xff000000
);
paintCenterText
.
setAntiAlias
(
true
);
paintCenterText
.
setTextScaleX
(
scaleX
);
paintCenterText
.
setTypeface
(
Typeface
.
MONOSPACE
);
paintCenterText
.
setTextSize
(
textSize
);
paintIndicator
=
new
Paint
();
paintIndicator
.
setColor
(
colorLightGray
);
paintIndicator
.
setColor
(
0xffb8bbc2
);
paintIndicator
.
setAntiAlias
(
true
);
if
(
android
.
os
.
Build
.
VERSION
.
SDK_INT
>=
11
)
{
...
...
@@ -204,15 +197,22 @@ public class LoopView extends View {
}
}
public
void
setTextColor
(
int
color
){
paintCenterText
.
setColor
(
color
);
invalidate
();
}
public
final
void
setNotLoop
()
{
isLoop
=
false
;
}
public
final
void
setTextSize
(
float
size
)
{
if
(
size
>
0.0
F
)
{
textSize
=
(
int
)
(
context
.
getResources
().
getDisplayMetrics
().
density
*
size
);
t
his
.
t
extSize
=
(
int
)
(
context
.
getResources
().
getDisplayMetrics
().
density
*
size
);
paintOuterText
.
setTextSize
(
textSize
);
paintCenterText
.
setTextSize
(
textSize
);
remeasure
();
invalidate
();
}
}
...
...
@@ -242,6 +242,7 @@ public class LoopView extends View {
this
.
initPosition
=
initPosition
;
}
}
selectedIndex
=
initPosition
;
totalScrollY
=
0
;
cancelFuture
();
invalidate
();
...
...
@@ -450,4 +451,4 @@ public class LoopView extends View {
invalidate
();
return
true
;
}
}
}
\ No newline at end of file
android/src/main/java/com/beefe/picker/view/OnSelectedListener.java
View file @
d6ad6759
...
...
@@ -8,6 +8,6 @@ import java.util.ArrayList;
public
interface
OnSelectedListener
{
void
onSelected
(
ArrayList
<
String
>
selectedList
);
void
onSelected
(
ArrayList
<
ReturnData
>
selectedList
);
}
android/src/main/java/com/beefe/picker/view/PickerViewAlone.java
View file @
d6ad6759
...
...
@@ -13,10 +13,14 @@ import java.util.ArrayList;
import
java.util.Arrays
;
/**
* Created by
heng
on 16/9/6.
* Created by
<a href="https://github.com/shexiaoheng">heng</a>
on 16/9/6.
* <p>
* Edited by heng on 16/10/09:
* 修复滚动后返回值错误的bug
*
* Edited by heng on 2016/12/26
* 1. Fixed returnData bug
* 2. Added LoopView TextColor and TextSize support
*/
public
class
PickerViewAlone
extends
LinearLayout
{
...
...
@@ -25,7 +29,7 @@ public class PickerViewAlone extends LinearLayout {
private
OnSelectedListener
onSelectedListener
;
private
ArrayList
<
String
>
curSelectedList
;
private
ArrayList
<
ReturnData
>
curSelectedList
;
public
PickerViewAlone
(
Context
context
)
{
super
(
context
);
...
...
@@ -46,23 +50,23 @@ public class PickerViewAlone extends LinearLayout {
this
.
onSelectedListener
=
listener
;
}
public
void
setPickerData
(
ReadableArray
array
,
double
[]
weights
)
{
public
void
setPickerData
(
ReadableArray
array
,
double
[]
weights
)
{
curSelectedList
=
new
ArrayList
<>();
switch
(
array
.
getType
(
0
).
name
())
{
case
"Array"
:
setMultipleData
(
array
,
curSelectedList
,
weights
);
setMultipleData
(
array
,
weights
);
break
;
default
:
setAloneData
(
array
,
curSelectedList
);
setAloneData
(
array
);
break
;
}
}
public
ArrayList
<
String
>
getSelectedData
()
{
public
ArrayList
<
ReturnData
>
getSelectedData
()
{
return
this
.
curSelectedList
;
}
private
void
setAloneData
(
ReadableArray
array
,
final
ArrayList
<
String
>
curSelectedList
)
{
private
void
setAloneData
(
ReadableArray
array
)
{
ArrayList
<
String
>
values
=
arrayToList
(
array
);
final
LoopView
loopView
=
new
LoopView
(
getContext
());
LayoutParams
params
=
new
LayoutParams
(
...
...
@@ -71,16 +75,22 @@ public class PickerViewAlone extends LinearLayout {
loopView
.
setLayoutParams
(
params
);
loopView
.
setItems
(
values
);
loopView
.
setSelectedPosition
(
0
);
ReturnData
returnData
=
new
ReturnData
();
returnData
.
setItem
(
values
.
get
(
0
));
returnData
.
setIndex
(
loopView
.
getSelectedIndex
());
if
(
curSelectedList
.
size
()
>
0
)
{
curSelectedList
.
set
(
0
,
values
.
get
(
0
)
);
curSelectedList
.
set
(
0
,
returnData
);
}
else
{
curSelectedList
.
add
(
0
,
values
.
get
(
0
)
);
curSelectedList
.
add
(
0
,
returnData
);
}
loopView
.
setListener
(
new
OnItemSelectedListener
()
{
@Override
public
void
onItemSelected
(
String
item
,
int
index
)
{
if
(
onSelectedListener
!=
null
)
{
curSelectedList
.
set
(
0
,
item
);
ReturnData
returnData1
=
new
ReturnData
();
returnData1
.
setItem
(
item
);
returnData1
.
setIndex
(
index
);
curSelectedList
.
set
(
0
,
returnData1
);
onSelectedListener
.
onSelected
(
curSelectedList
);
}
}
...
...
@@ -88,8 +98,9 @@ public class PickerViewAlone extends LinearLayout {
pickerViewAloneLayout
.
addView
(
loopView
);
}
private
void
setMultipleData
(
ReadableArray
array
,
final
ArrayList
<
String
>
curSelectedList
,
double
[]
weights
)
{
private
void
setMultipleData
(
ReadableArray
array
,
double
[]
weights
)
{
final
String
[]
selectedItems
=
new
String
[
array
.
size
()];
final
int
[]
selectedIndexes
=
new
int
[
array
.
size
()];
for
(
int
i
=
0
;
i
<
array
.
size
();
i
++)
{
switch
(
array
.
getType
(
i
).
name
())
{
case
"Array"
:
...
...
@@ -110,10 +121,14 @@ public class PickerViewAlone extends LinearLayout {
loopView
.
setItems
(
values
);
loopView
.
setTag
(
i
);
loopView
.
setSelectedPosition
(
0
);
ReturnData
returnData
=
new
ReturnData
();
returnData
.
setItem
(
values
.
get
(
0
));
returnData
.
setIndex
(
loopView
.
getSelectedIndex
());
if
(
curSelectedList
.
size
()
>
i
)
{
curSelectedList
.
set
(
i
,
values
.
get
(
0
)
);
curSelectedList
.
set
(
i
,
returnData
);
}
else
{
curSelectedList
.
add
(
i
,
values
.
get
(
0
)
);
curSelectedList
.
add
(
i
,
returnData
);
}
selectedItems
[
i
]
=
values
.
get
(
0
);
loopView
.
setListener
(
new
OnItemSelectedListener
()
{
...
...
@@ -125,12 +140,16 @@ public class PickerViewAlone extends LinearLayout {
if
(
view
instanceof
LoopView
)
{
LoopView
loop
=
(
LoopView
)
view
;
selectedItems
[
k
]
=
loop
.
getSelectedItem
();
selectedIndexes
[
k
]
=
loop
.
getSelectedIndex
();
}
}
if
(
onSelectedListener
!=
null
)
{
for
(
int
i
=
0
;
i
<
selectedItems
.
length
;
i
++)
{
curSelectedList
.
set
(
i
,
selectedItems
[
i
]);
ReturnData
returnData1
=
new
ReturnData
();
returnData1
.
setItem
(
selectedItems
[
i
]);
returnData1
.
setIndex
(
selectedIndexes
[
i
]);
curSelectedList
.
set
(
i
,
returnData1
);
}
onSelectedListener
.
onSelected
(
curSelectedList
);
}
...
...
@@ -155,19 +174,44 @@ public class PickerViewAlone extends LinearLayout {
}
}
private
void
setSelect
(
int
size
,
String
[]
values
,
ArrayList
<
String
>
curSelectedList
)
{
private
void
setSelect
(
int
size
,
String
[]
values
,
ArrayList
<
ReturnData
>
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
]);
ReturnData
returnData
=
new
ReturnData
();
returnData
.
setItem
(
values
[
i
]);
returnData
.
setIndex
(
loop
.
getSelectedIndex
());
curSelectedList
.
set
(
i
,
returnData
);
}
}
}
}
public
void
setTextColor
(
int
color
){
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
.
setTextColor
(
color
);
}
}
}
public
void
setTextSize
(
float
size
){
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
.
setTextSize
(
size
);
}
}
}
public
void
setIsLoop
(
boolean
isLoop
)
{
if
(!
isLoop
)
{
int
viewCount
=
pickerViewAloneLayout
.
getChildCount
();
...
...
@@ -215,4 +259,4 @@ public class PickerViewAlone extends LinearLayout {
return
values
;
}
}
}
\ No newline at end of file
android/src/main/java/com/beefe/picker/view/PickerViewLinkage.java
View file @
d6ad6759
...
...
@@ -15,7 +15,11 @@ import java.util.ArrayList;
import
java.util.Arrays
;
/**
* Created by heng on 16/9/1.
* Created by <a href="https://github.com/shexiaoheng">heng</a> on 2016/09/01
*
* Edited by heng on 2016/12/26
* 1. Fixed returnData bug
* 2. Added LoopView TextColor and TextSize support
*/
public
class
PickerViewLinkage
extends
LinearLayout
{
...
...
@@ -77,7 +81,11 @@ public class PickerViewLinkage extends LinearLayout {
private
int
selectOneIndex
;
private
int
selectTwoIndex
;
private
ArrayList
<
String
>
curSelectedList
;
private
ArrayList
<
ReturnData
>
curSelectedList
;
private
ReturnData
returnData
;
private
ReturnData
returnData1
;
private
ReturnData
returnData2
;
private
void
checkItems
(
LoopView
loopView
,
ArrayList
<
String
>
list
)
{
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
...
...
@@ -137,6 +145,9 @@ public class PickerViewLinkage extends LinearLayout {
*/
public
void
setPickerData
(
ReadableArray
array
,
double
[]
weights
)
{
curSelectedList
=
new
ArrayList
<>();
returnData
=
new
ReturnData
();
returnData1
=
new
ReturnData
();
returnData2
=
new
ReturnData
();
oneList
.
clear
();
for
(
int
i
=
0
;
i
<
array
.
size
();
i
++)
{
ReadableMap
map
=
array
.
getMap
(
i
);
...
...
@@ -148,10 +159,13 @@ public class PickerViewLinkage extends LinearLayout {
}
}
checkItems
(
loopViewOne
,
oneList
);
returnData
.
setItem
(
oneList
.
get
(
0
));
returnData
.
setIndex
(
loopViewOne
.
getSelectedIndex
());
if
(
curSelectedList
.
size
()
>
0
)
{
curSelectedList
.
set
(
0
,
oneList
.
get
(
0
)
);
curSelectedList
.
set
(
0
,
returnData
);
}
else
{
curSelectedList
.
add
(
0
,
oneList
.
get
(
0
)
);
curSelectedList
.
add
(
0
,
returnData
);
}
ReadableArray
childArray
=
data
.
get
(
0
).
getArray
(
oneList
.
get
(
0
));
...
...
@@ -162,10 +176,12 @@ public class PickerViewLinkage extends LinearLayout {
twoList
.
clear
();
getTwoListData
();
checkItems
(
loopViewTwo
,
twoList
);
returnData1
.
setItem
(
twoList
.
get
(
0
));
returnData1
.
setIndex
(
loopViewTwo
.
getSelectedIndex
());
if
(
curSelectedList
.
size
()
>
1
)
{
curSelectedList
.
set
(
1
,
twoList
.
get
(
0
)
);
curSelectedList
.
set
(
1
,
returnData1
);
}
else
{
curSelectedList
.
add
(
1
,
twoList
.
get
(
0
)
);
curSelectedList
.
add
(
1
,
returnData1
);
}
ReadableMap
childMap
=
data
.
get
(
0
).
getArray
(
oneList
.
get
(
0
)).
getMap
(
0
);
...
...
@@ -174,17 +190,22 @@ public class PickerViewLinkage extends LinearLayout {
threeList
.
clear
();
threeList
=
arrayToList
(
sunArray
);
checkItems
(
loopViewThree
,
threeList
);
returnData2
.
setItem
(
threeList
.
get
(
0
));
returnData2
.
setIndex
(
loopViewThree
.
getSelectedIndex
());
if
(
curSelectedList
.
size
()
>
2
)
{
curSelectedList
.
set
(
2
,
threeList
.
get
(
0
)
);
curSelectedList
.
set
(
2
,
returnData2
);
}
else
{
curSelectedList
.
add
(
2
,
threeList
.
get
(
0
)
);
curSelectedList
.
add
(
2
,
returnData2
);
}
loopViewOne
.
setListener
(
new
OnItemSelectedListener
()
{
@Override
public
void
onItemSelected
(
String
item
,
int
index
)
{
selectOneIndex
=
index
;
curSelectedList
.
set
(
0
,
item
);
returnData
=
new
ReturnData
();
returnData
.
setIndex
(
index
);
returnData
.
setItem
(
item
);
curSelectedList
.
set
(
0
,
returnData
);
twoList
.
clear
();
ReadableArray
arr
=
data
.
get
(
index
).
getArray
(
item
);
for
(
int
i
=
0
;
i
<
arr
.
size
();
i
++)
{
...
...
@@ -195,7 +216,10 @@ public class PickerViewLinkage extends LinearLayout {
}
}
checkItems
(
loopViewTwo
,
twoList
);
curSelectedList
.
set
(
1
,
twoList
.
get
(
0
));
returnData1
=
new
ReturnData
();
returnData1
.
setItem
(
twoList
.
get
(
0
));
returnData1
.
setIndex
(
loopViewTwo
.
getSelectedIndex
());
curSelectedList
.
set
(
1
,
returnData1
);
ReadableArray
ar
=
data
.
get
(
index
).
getArray
(
item
);
...
...
@@ -205,7 +229,10 @@ public class PickerViewLinkage extends LinearLayout {
threeList
.
clear
();
threeList
=
arrayToList
(
sunArray
);
checkItems
(
loopViewThree
,
threeList
);
curSelectedList
.
set
(
2
,
threeList
.
get
(
0
));
returnData2
=
new
ReturnData
();
returnData2
.
setItem
(
threeList
.
get
(
0
));
returnData2
.
setIndex
(
loopViewThree
.
getSelectedIndex
());
curSelectedList
.
set
(
2
,
returnData2
);
if
(
onSelectedListener
!=
null
)
{
onSelectedListener
.
onSelected
(
curSelectedList
);
...
...
@@ -226,9 +253,20 @@ public class PickerViewLinkage extends LinearLayout {
threeList
=
arrayToList
(
sunArray
);
checkItems
(
loopViewThree
,
threeList
);
curSelectedList
.
set
(
0
,
oneList
.
get
(
selectOneIndex
));
curSelectedList
.
set
(
1
,
item
);
curSelectedList
.
set
(
2
,
threeList
.
get
(
0
));
returnData
=
new
ReturnData
();
returnData
.
setItem
(
oneList
.
get
(
selectOneIndex
));
returnData
.
setIndex
(
loopViewOne
.
getSelectedIndex
());
curSelectedList
.
set
(
0
,
returnData
);
returnData1
=
new
ReturnData
();
returnData1
.
setItem
(
item
);
returnData1
.
setIndex
(
index
);
curSelectedList
.
set
(
1
,
returnData1
);
returnData2
=
new
ReturnData
();
returnData2
.
setItem
(
threeList
.
get
(
0
));
returnData2
.
setIndex
(
loopViewThree
.
getSelectedIndex
());
curSelectedList
.
set
(
2
,
returnData2
);
if
(
onSelectedListener
!=
null
)
{
onSelectedListener
.
onSelected
(
curSelectedList
);
}
...
...
@@ -238,9 +276,20 @@ public class PickerViewLinkage extends LinearLayout {
loopViewThree
.
setListener
(
new
OnItemSelectedListener
()
{
@Override
public
void
onItemSelected
(
String
item
,
int
index
)
{
curSelectedList
.
set
(
0
,
oneList
.
get
(
selectOneIndex
));
curSelectedList
.
set
(
1
,
twoList
.
get
(
selectTwoIndex
));
curSelectedList
.
set
(
2
,
item
);
returnData
=
new
ReturnData
();
returnData
.
setItem
(
oneList
.
get
(
selectOneIndex
));
returnData
.
setIndex
(
loopViewOne
.
getSelectedIndex
());
curSelectedList
.
set
(
0
,
returnData
);
returnData1
=
new
ReturnData
();
returnData1
.
setItem
(
twoList
.
get
(
selectTwoIndex
));
returnData1
.
setIndex
(
loopViewTwo
.
getSelectedIndex
());
curSelectedList
.
set
(
1
,
returnData1
);
returnData2
=
new
ReturnData
();
returnData2
.
setItem
(
item
);
returnData2
.
setIndex
(
index
);
curSelectedList
.
set
(
2
,
returnData2
);
if
(
onSelectedListener
!=
null
)
{
onSelectedListener
.
onSelected
(
curSelectedList
);
}
...
...
@@ -256,8 +305,14 @@ public class PickerViewLinkage extends LinearLayout {
twoList
.
clear
();
twoList
=
arrayToList
(
arr
);
checkItems
(
loopViewTwo
,
twoList
);
curSelectedList
.
set
(
0
,
item
);
curSelectedList
.
set
(
1
,
twoList
.
get
(
0
));
returnData
=
new
ReturnData
();
returnData
.
setItem
(
item
);
returnData
.
setIndex
(
index
);
curSelectedList
.
set
(
0
,
returnData
);
returnData1
=
new
ReturnData
();
returnData1
.
setItem
(
twoList
.
get
(
0
));
returnData1
.
setIndex
(
loopViewTwo
.
getSelectedIndex
());
curSelectedList
.
set
(
1
,
returnData1
);
if
(
onSelectedListener
!=
null
)
{
onSelectedListener
.
onSelected
(
curSelectedList
);
}
...
...
@@ -267,16 +322,26 @@ public class PickerViewLinkage extends LinearLayout {
twoList
.
clear
();
twoList
=
arrayToList
(
childArray
);
checkItems
(
loopViewTwo
,
twoList
);
returnData1
=
new
ReturnData
();
returnData1
.
setItem
(
twoList
.
get
(
0
));
returnData1
.
setIndex
(
loopViewTwo
.
getSelectedIndex
());
if
(
curSelectedList
.
size
()
>
1
)
{
curSelectedList
.
set
(
1
,
twoList
.
get
(
0
)
);
curSelectedList
.
set
(
1
,
returnData1
);
}
else
{
curSelectedList
.
add
(
1
,
twoList
.
get
(
0
)
);
curSelectedList
.
add
(
1
,
returnData1
);
}
loopViewTwo
.
setListener
(
new
OnItemSelectedListener
()
{
@Override
public
void
onItemSelected
(
String
item
,
int
index
)
{
curSelectedList
.
set
(
0
,
oneList
.
get
(
selectOneIndex
));
curSelectedList
.
set
(
1
,
item
);
returnData
=
new
ReturnData
();
returnData
.
setItem
(
oneList
.
get
(
selectOneIndex
));
returnData
.
setIndex
(
loopViewOne
.
getSelectedIndex
());
curSelectedList
.
set
(
0
,
returnData
);
returnData1
=
new
ReturnData
();
returnData1
.
setIndex
(
index
);
returnData1
.
setItem
(
item
);
curSelectedList
.
set
(
1
,
returnData1
);
if
(
onSelectedListener
!=
null
)
{
onSelectedListener
.
onSelected
(
curSelectedList
);
}
...
...
@@ -330,13 +395,19 @@ public class PickerViewLinkage extends LinearLayout {
getTwoListData
();
loopViewTwo
.
setItems
(
twoList
);
loopViewTwo
.
setSelectedPosition
(
0
);
curSelectedList
.
set
(
1
,
loopViewTwo
.
getIndexItem
(
0
));
returnData1
=
new
ReturnData
();
returnData1
.
setItem
(
loopViewTwo
.
getIndexItem
(
0
));
returnData1
.
setIndex
(
loopViewTwo
.
getSelectedIndex
());
curSelectedList
.
set
(
1
,
returnData1
);
threeList
.
clear
();
getThreeListData
();
loopViewThree
.
setItems
(
threeList
);
loopViewThree
.
setSelectedPosition
(
0
);
curSelectedList
.
set
(
2
,
loopViewThree
.
getIndexItem
(
0
));
returnData2
=
new
ReturnData
();
returnData2
.
setItem
(
loopViewThree
.
getIndexItem
(
0
));
returnData2
.
setIndex
(
loopViewThree
.
getSelectedIndex
());
curSelectedList
.
set
(
2
,
returnData2
);
break
;
case
2
:
...
...
@@ -344,7 +415,10 @@ public class PickerViewLinkage extends LinearLayout {
getAllTwoListData
();
loopViewTwo
.
setItems
(
twoList
);
loopViewTwo
.
setSelectedPosition
(
0
);
curSelectedList
.
set
(
1
,
loopViewTwo
.
getIndexItem
(
0
));
returnData1
=
new
ReturnData
();
returnData1
.
setItem
(
loopViewTwo
.
getIndexItem
(
0
));
returnData1
.
setIndex
(
loopViewTwo
.
getSelectedIndex
());
curSelectedList
.
set
(
1
,
returnData1
);
break
;
}
break
;
...
...
@@ -362,7 +436,10 @@ public class PickerViewLinkage extends LinearLayout {
getThreeListData
();
loopViewThree
.
setItems
(
threeList
);
loopViewThree
.
setSelectedPosition
(
0
);
curSelectedList
.
set
(
2
,
loopViewThree
.
getIndexItem
(
0
));
returnData2
=
new
ReturnData
();
returnData2
.
setItem
(
loopViewThree
.
getIndexItem
(
0
));
returnData2
.
setIndex
(
loopViewThree
.
getSelectedIndex
());
curSelectedList
.
set
(
2
,
returnData2
);
break
;
}
break
;
...
...
@@ -372,7 +449,7 @@ public class PickerViewLinkage extends LinearLayout {
}
}
private
void
selectValues
(
String
[]
values
,
final
ArrayList
<
String
>
curSelectedList
)
{
private
void
selectValues
(
String
[]
values
,
final
ArrayList
<
ReturnData
>
curSelectedList
)
{
switch
(
values
.
length
)
{
case
3
:
selectOneLoop
(
values
,
curSelectedList
);
...
...
@@ -400,47 +477,53 @@ public class PickerViewLinkage extends LinearLayout {
/**
* 设置第一个滚轮选中的值
*/
private
void
selectOneLoop
(
String
[]
values
,
final
ArrayList
<
String
>
curSelectedList
)
{
private
void
selectOneLoop
(
String
[]
values
,
final
ArrayList
<
ReturnData
>
curSelectedList
)
{
if
(
loopViewOne
.
hasItem
(
values
[
0
]))
{
selectOneIndex
=
loopViewOne
.
getItemPosition
(
values
[
0
]);
loopViewOne
.
setSelectedPosition
(
selectOneIndex
);
curSelectedList
.
set
(
0
,
loopViewOne
.
getIndexItem
(
selectOneIndex
));
}
else
{
selectOneIndex
=
0
;
loopViewOne
.
setSelectedPosition
(
0
);
curSelectedList
.
set
(
0
,
loopViewOne
.
getIndexItem
(
0
));
}
loopViewOne
.
setSelectedPosition
(
selectOneIndex
);
returnData
=
new
ReturnData
();
returnData
.
setItem
(
loopViewOne
.
getIndexItem
(
selectOneIndex
));
returnData
.
setIndex
(
loopViewOne
.
getSelectedIndex
());
curSelectedList
.
set
(
0
,
returnData
);
}
/**
* 设置第二个滚轮选中的值
*/
private
void
selectTwoLoop
(
String
[]
values
,
final
ArrayList
<
String
>
curSelectedList
)
{
private
void
selectTwoLoop
(
String
[]
values
,
final
ArrayList
<
ReturnData
>
curSelectedList
)
{
loopViewTwo
.
setItems
(
twoList
);
if
(
loopViewTwo
.
hasItem
(
values
[
1
]))
{
selectTwoIndex
=
loopViewTwo
.
getItemPosition
(
values
[
1
]);
loopViewTwo
.
setSelectedPosition
(
selectTwoIndex
);
curSelectedList
.
set
(
1
,
loopViewTwo
.
getIndexItem
(
selectTwoIndex
));
}
else
{
selectTwoIndex
=
0
;
loopViewTwo
.
setSelectedPosition
(
0
);
curSelectedList
.
set
(
1
,
loopViewTwo
.
getIndexItem
(
0
));
}
returnData1
=
new
ReturnData
();
loopViewTwo
.
setSelectedPosition
(
selectTwoIndex
);
returnData1
.
setItem
(
loopViewTwo
.
getIndexItem
(
selectTwoIndex
));
returnData1
.
setIndex
(
loopViewTwo
.
getSelectedIndex
());
curSelectedList
.
set
(
1
,
returnData1
);
}
/**
* 设置第三个滚轮选中的值
*/
private
void
selectThreeLoop
(
String
[]
values
,
final
ArrayList
<
String
>
curSelectedList
)
{
private
void
selectThreeLoop
(
String
[]
values
,
final
ArrayList
<
ReturnData
>
curSelectedList
)
{
loopViewThree
.
setItems
(
threeList
);
int
selectThreeIndex
;
if
(
loopViewThree
.
hasItem
(
values
[
2
]))
{
int
selectThreeIndex
=
loopViewThree
.
getItemPosition
(
values
[
2
]);
loopViewThree
.
setSelectedPosition
(
selectThreeIndex
);
curSelectedList
.
set
(
2
,
loopViewThree
.
getIndexItem
(
selectThreeIndex
));
selectThreeIndex
=
loopViewThree
.
getItemPosition
(
values
[
2
]);
}
else
{
loopViewThree
.
setSelectedPosition
(
0
);
curSelectedList
.
set
(
2
,
loopViewThree
.
getIndexItem
(
0
));
selectThreeIndex
=
0
;
}
returnData2
=
new
ReturnData
();
loopViewThree
.
setSelectedPosition
(
selectThreeIndex
);
returnData2
.
setItem
(
loopViewThree
.
getIndexItem
(
selectThreeIndex
));
returnData2
.
setIndex
(
loopViewThree
.
getSelectedIndex
());
curSelectedList
.
set
(
2
,
returnData2
);
}
/**
...
...
@@ -477,6 +560,33 @@ public class PickerViewLinkage extends LinearLayout {
threeList
=
arrayToList
(
sunArray
);
}
public
void
setTextSize
(
float
size
){
switch
(
curRow
)
{
case
2
:
loopViewOne
.
setTextSize
(
size
);
loopViewTwo
.
setTextSize
(
size
);
break
;
case
3
:
loopViewOne
.
setTextSize
(
size
);
loopViewTwo
.
setTextSize
(
size
);
loopViewThree
.
setTextSize
(
size
);
break
;
}
}
public
void
setTextColor
(
int
color
){
switch
(
curRow
)
{
case
2
:
loopViewOne
.
setTextColor
(
color
);
loopViewTwo
.
setTextColor
(
color
);
break
;
case
3
:
loopViewOne
.
setTextColor
(
color
);
loopViewTwo
.
setTextColor
(
color
);
loopViewThree
.
setTextColor
(
color
);
break
;
}
}
public
void
setIsLoop
(
boolean
isLoop
)
{
if
(!
isLoop
)
{
...
...
@@ -491,7 +601,6 @@ public class PickerViewLinkage extends LinearLayout {
loopViewThree
.
setNotLoop
();
break
;
}
}
}
...
...
@@ -499,12 +608,11 @@ public class PickerViewLinkage extends LinearLayout {
return
loopViewOne
.
getViewHeight
();
}
public
ArrayList
<
String
>
getSelectedData
()
{
public
ArrayList
<
ReturnData
>
getSelectedData
()
{
return
this
.
curSelectedList
;
}
public
void
setOnSelectListener
(
OnSelectedListener
listener
)
{
this
.
onSelectedListener
=
listener
;
}
}
}
\ No newline at end of file
android/src/main/java/com/beefe/picker/view/ReturnData.java
0 → 100644
View file @
d6ad6759
package
com.beefe.picker.view
;
/**
* Created by shexiaoheng on 2016/12/23.
*/
public
class
ReturnData
{
private
String
item
;
private
int
index
;
public
String
getItem
()
{
return
item
;
}
public
void
setItem
(
String
item
)
{
this
.
item
=
item
;
}
public
int
getIndex
()
{
return
index
;
}
public
void
setIndex
(
int
index
)
{
this
.
index
=
index
;
}
}
android/src/main/res/values/styles.xml
View file @
d6ad6759
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style
name=
"Dialog_Full_Screen"
>
<style
name=
"Dialog_Full_Screen"
>
<item
name=
"android:windowIsFloating"
>
true
</item>
<item
name=
"android:windowFullscreen"
>
true
</item>
<item
name=
"android:windowNoTitle"
>
true
</item>
...
...
example/PickerTest/index.js
View file @
d6ad6759
...
...
@@ -19,6 +19,7 @@ class PickerTest extends Component {
constructor
(
props
,
context
)
{
super
(
props
,
context
);
this
.
_showDatePicker
();
}
_createDateData
()
{
...
...
@@ -78,15 +79,17 @@ class PickerTest extends Component {
_showDatePicker
()
{
Picker
.
init
({
pickerData
:
this
.
_createDateData
(),
selectedValue
:
[
'
2015年
'
,
'
12月
'
,
'
12日
'
],
onPickerConfirm
:
pickedValue
=>
{
console
.
log
(
'
date
'
,
pickedValue
);
pickerToolBarFontSize
:
16
,
pickerFontSize
:
16
,
pickerFontColor
:
[
255
,
0
,
0
,
1
],
onPickerConfirm
:
(
pickedValue
,
pickedIndex
)
=>
{
console
.
log
(
'
date
'
,
pickedValue
,
pickedIndex
);
},
onPickerCancel
:
pickedValue
=>
{
console
.
log
(
'
date
'
,
pickedValue
);
onPickerCancel
:
(
pickedValue
,
pickedIndex
)
=>
{
console
.
log
(
'
date
'
,
pickedValue
,
pickedIndex
);
},
onPickerSelect
:
pickedValue
=>
{
console
.
log
(
'
date
'
,
pickedValue
);
onPickerSelect
:
(
pickedValue
,
pickedIndex
)
=>
{
console
.
log
(
'
date
'
,
pickedValue
,
pickedIndex
);
}
});
Picker
.
show
();
...
...
index.js
View file @
d6ad6759
...
...
@@ -13,17 +13,24 @@ export default {
init
(
options
){
let
opt
=
{
isLoop
:
false
,
pickerConfirmBtnText
:
'
确认
'
,
pickerCancelBtnText
:
'
取消
'
,
pickerTitleText
:
'
请选择
'
,
pickerBg
:
[
196
,
199
,
206
,
1
],
pickerToolBarBg
:
[
232
,
232
,
232
,
1
],
pickerTitleColor
:
[
20
,
20
,
20
,
1
],
pickerCancelBtnColor
:
[
1
,
186
,
245
,
1
],
pickerConfirmBtnText
:
'
confirm
'
,
pickerCancelBtnText
:
'
cancel
'
,
pickerTitleText
:
'
pls select
'
,
pickerConfirmBtnColor
:
[
1
,
186
,
245
,
1
],
pickerCancelBtnColor
:
[
1
,
186
,
245
,
1
],
pickerTitleColor
:
[
20
,
20
,
20
,
1
],
pickerToolBarBg
:
[
232
,
232
,
232
,
1
],
pickerBg
:
[
196
,
199
,
206
,
1
],
wheelFlex
:
[
1
,
1
,
1
],
pickerData
:
[],
selectedValue
:
[],
onPickerConfirm
(){},
onPickerCancel
(){},
onPickerSelect
(){},
//4.0.12 add
pickerToolBarFontSize
:
16
,
pickerFontSize
:
16
,
pickerFontColor
:
[
31
,
31
,
31
,
1
],
...
options
};
let
fnConf
=
{
...
...
@@ -36,14 +43,7 @@ export default {
//there are no `removeListener` for NativeAppEventEmitter & DeviceEventEmitter
this
.
listener
&&
this
.
listener
.
remove
();
this
.
listener
=
NativeAppEventEmitter
.
addListener
(
'
pickerEvent
'
,
event
=>
{
if
(
ios
){
fnConf
[
event
[
'
type
'
]](
event
[
'
selectedValue
'
]);
}
else
if
(
android
){
for
(
let
i
in
event
){
typeof
fnConf
[
i
]
===
'
function
'
&&
fnConf
[
i
](
event
[
i
]);
}
}
fnConf
[
event
[
'
type
'
]](
event
[
'
selectedValue
'
],
event
[
'
selectedIndex
'
]);
});
},
...
...
ios/RCTBEEPickerManager/BzwPicker.h
View file @
d6ad6759
...
...
@@ -39,6 +39,9 @@ typedef void(^backBolock)(NSDictionary * );
@property
(
strong
,
nonatomic
)
NSString
*
leftStr
;
@property
(
strong
,
nonatomic
)
NSString
*
centStr
;
@property
(
strong
,
nonatomic
)
NSString
*
rightStr
;
@property
(
strong
,
nonatomic
)
NSString
*
pickerToolBarFontSize
;
@property
(
strong
,
nonatomic
)
NSString
*
pickerFontSize
;
@property
(
strong
,
nonatomic
)
NSArray
*
pickerFontColor
;
...
...
@@ -61,6 +64,7 @@ typedef void(^backBolock)(NSDictionary * );
@property
(
strong
,
nonatomic
)
NSArray
*
weightArry
;
@property
(
assign
,
nonatomic
)
CGFloat
lineWith
;
//创建一个下角标记录是第几行 来一进来判断第一行被选中 当进来的是关联两行的逻辑的时候 或者三行关联的时候取第二行做记录
@property
(
assign
,
nonatomic
)
NSInteger
num
;
...
...
@@ -69,9 +73,12 @@ typedef void(^backBolock)(NSDictionary * );
@property
(
assign
,
nonatomic
)
NSInteger
threenum
;
@property
(
assign
,
nonatomic
)
NSInteger
seleNum
;
//用来做索引下标用
-
(
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
weightArry
:(
NSArray
*
)
weightArry
;
-
(
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
weightArry
:(
NSArray
*
)
weightArry
pickerToolBarFontSize
:(
NSString
*
)
pickerToolBarFontSize
pickerFontSize
:(
NSString
*
)
pickerFontSize
pickerFontColor
:(
NSArray
*
)
pickerFontColor
;
@end
ios/RCTBEEPickerManager/BzwPicker.m
View file @
d6ad6759
...
...
@@ -7,10 +7,13 @@
//
#import "BzwPicker.h"
#define linSpace 5
@implementation
BzwPicker
-
(
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
weightArry
:(
NSArray
*
)
weightArry
pickerToolBarFontSize
:(
NSString
*
)
pickerToolBarFontSize
pickerFontSize
:(
NSString
*
)
pickerFontSize
pickerFontColor
:(
NSArray
*
)
pickerFontColor
{
self
=
[
super
initWithFrame
:
frame
];
if
(
self
)
...
...
@@ -24,10 +27,13 @@
self
.
leftStr
=
leftStr
;
self
.
rightStr
=
rightStr
;
self
.
centStr
=
centerStr
;
self
.
pickerToolBarFontSize
=
pickerToolBarFontSize
;
self
.
pickerFontSize
=
pickerFontSize
;
self
.
pickerFontColor
=
pickerFontColor
;
[
self
getStyle
];
[
self
getnumStyle
];
dispatch_async
(
dispatch_get_main_queue
(),
^
{
[
self
makeuiWith
:
topbgColor
With
:
bottombgColor
With
:
leftbtnbgColor
With
:
rightbtnbgColor
With
:
centerbtnColor
];
[
self
makeuiWith
:
topbgColor
With
:
bottombgColor
With
:
leftbtnbgColor
With
:
rightbtnbgColor
With
:
centerbtnColor
];
[
self
selectRow
];
});
}
...
...
@@ -44,7 +50,7 @@
self
.
leftBtn
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
self
.
leftBtn
.
frame
=
CGRectMake
(
10
,
5
,
90
,
30
);
[
self
.
leftBtn
setTitle
:
self
.
leftStr
forState
:
UIControlStateNormal
];
[
self
.
leftBtn
setFont
:[
UIFont
systemFontOfSize
:
16
]];
[
self
.
leftBtn
setFont
:[
UIFont
systemFontOfSize
:
[
_pickerToolBarFontSize
integerValue
]
]];
self
.
leftBtn
.
contentHorizontalAlignment
=
UIControlContentHorizontalAlignmentLeft
;
[
self
.
leftBtn
addTarget
:
self
action
:
@selector
(
cancleAction
)
forControlEvents
:
UIControlEventTouchUpInside
];
...
...
@@ -54,9 +60,8 @@
view
.
backgroundColor
=
[
self
colorWith
:
topbgColor
];
self
.
rightBtn
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
self
.
rightBtn
.
frame
=
CGRectMake
(
view
.
frame
.
size
.
width
-
100
,
5
,
90
,
30
);
self
.
rightBtn
.
frame
=
CGRectMake
(
view
.
frame
.
size
.
width
-
100
,
5
,
90
,
30
);
[
self
.
rightBtn
setTitle
:
self
.
rightStr
forState
:
UIControlStateNormal
];
self
.
rightBtn
.
contentHorizontalAlignment
=
UIControlContentHorizontalAlignmentRight
;
...
...
@@ -64,7 +69,7 @@
[
view
addSubview
:
self
.
rightBtn
];
[
self
.
rightBtn
setFont
:[
UIFont
systemFontOfSize
:
16
]];
[
self
.
rightBtn
setFont
:[
UIFont
systemFontOfSize
:
[
_pickerToolBarFontSize
integerValue
]
]];
[
self
.
rightBtn
addTarget
:
self
action
:
@selector
(
cfirmAction
)
forControlEvents
:
UIControlEventTouchUpInside
];
...
...
@@ -72,15 +77,19 @@
cenLabel
.
textAlignment
=
NSTextAlignmentCenter
;
[
cenLabel
setFont
:[
UIFont
systemFontOfSize
:
16
]];
[
cenLabel
setFont
:[
UIFont
systemFontOfSize
:
[
_pickerToolBarFontSize
integerValue
]
]];
cenLabel
.
text
=
self
.
centStr
;
[
cenLabel
setTextColor
:[
self
colorWith
:
centerbtnColor
]];
[
view
addSubview
:
cenLabel
];
self
.
pick
=
[[
UIPickerView
alloc
]
initWithFrame
:
CGRectMake
(
-
15
,
40
,
self
.
frame
.
size
.
width
+
15
,
self
.
frame
.
size
.
height
-
40
)];
<<<<<<<
HEAD
self
.
pick
=
[[
UIPickerView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
40
,
self
.
frame
.
size
.
width
,
self
.
frame
.
size
.
height
-
40
)];
=======
self
.
pick
=
[[
UIPickerView
alloc
]
initWithFrame
:
CGRectMake
(
-
5
,
40
,
self
.
frame
.
size
.
width
+
5
,
self
.
frame
.
size
.
height
-
40
)];
>>>>>>>
dfafe73491181099295072df68b4d0ebb18d38a8
self
.
pick
.
delegate
=
self
;
self
.
pick
.
dataSource
=
self
;
...
...
@@ -93,13 +102,13 @@
-
(
NSInteger
)
numberOfComponentsInPickerView
:(
UIPickerView
*
)
pickerView
{
if
(
_Correlation
)
{
//这里是关联的
//这里是关联的
if
([
_numberCorrela
isEqualToString
:
@"three"
])
{
return
3
;
}
else
if
([
_numberCorrela
isEqualToString
:
@"two"
]){
return
2
;
}
...
...
@@ -111,7 +120,7 @@
}
else
{
return
self
.
noCorreArry
.
count
;
return
self
.
noCorreArry
.
count
;
}
}
//返回当前列显示的行数
...
...
@@ -119,18 +128,18 @@
{
if
(
_Correlation
)
{
if
(
component
==
0
)
{
return
self
.
provinceArray
.
count
;
}
else
if
(
component
==
1
)
{
return
self
.
cityArray
.
count
;
}
else
{
return
self
.
townArray
.
count
;
}
if
(
component
==
0
)
{
return
self
.
provinceArray
.
count
;
}
else
if
(
component
==
1
)
{
return
self
.
cityArray
.
count
;
}
else
{
return
self
.
townArray
.
count
;
}
}
//NSLog(@"%@",[self.noCorreArry objectAtIndex:component]);
...
...
@@ -148,9 +157,9 @@
}
return
[[
self
.
noCorreArry
objectAtIndex
:
component
]
count
];
return
[[
self
.
noCorreArry
objectAtIndex
:
component
]
count
];
}
}
#pragma mark Picker Delegate Methods
...
...
@@ -160,25 +169,25 @@
{
if
(
_Correlation
)
{
if
(
component
==
0
)
{
return
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
provinceArray
objectAtIndex
:
row
]];
}
else
if
(
component
==
1
)
{
return
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
cityArray
objectAtIndex
:
row
]];
}
else
{
return
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
townArray
objectAtIndex
:
row
]];
}
if
(
component
==
0
)
{
return
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
provinceArray
objectAtIndex
:
row
]];
}
else
if
(
component
==
1
)
{
return
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
cityArray
objectAtIndex
:
row
]];
}
else
{
return
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
townArray
objectAtIndex
:
row
]];
}
}
else
{
if
(
_noArryElementBool
)
{
return
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
noCorreArry
objectAtIndex
:
row
]];
}
else
{
return
[
NSString
stringWithFormat
:
@"%@"
,[[
self
.
noCorreArry
objectAtIndex
:
component
]
objectAtIndex
:
row
]];
return
[
NSString
stringWithFormat
:
@"%@"
,[[
self
.
noCorreArry
objectAtIndex
:
component
]
objectAtIndex
:
row
]];
}
}
...
...
@@ -187,22 +196,23 @@
if
(
_Correlation
)
{
if
([
_numberCorrela
isEqualToString
:
@"three"
])
{
_lineWith
=
SCREEN_WIDTH
-
2
*
linSpace
;
if
(
self
.
weightArry
.
count
>=
3
)
{
NSString
*
onestr
=
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
weightArry
firstObject
]];
NSString
*
twostr
=
[
NSString
stringWithFormat
:
@"%@"
,
self
.
weightArry
[
1
]];
NSString
*
threestr
=
[
NSString
stringWithFormat
:
@"%@"
,
self
.
weightArry
[
2
]];
double
totalweight
=
onestr
.
doubleValue
+
twostr
.
doubleValue
+
threestr
.
doubleValue
;
if
(
component
==
0
)
{
return
SCREEN_WIDTH
*
onestr
.
doubleValue
/
totalweight
;
return
_lineWith
*
onestr
.
doubleValue
/
totalweight
;
}
else
if
(
component
==
1
){
return
SCREEN_WIDTH
*
twostr
.
doubleValue
/
totalweight
;
return
_lineWith
*
twostr
.
doubleValue
/
totalweight
;
}
else
{
return
SCREEN_WIDTH
*
threestr
.
doubleValue
/
totalweight
;
return
_lineWith
*
threestr
.
doubleValue
/
totalweight
;
}
}
else
{
if
(
self
.
weightArry
.
count
>
0
)
{
NSInteger
totalNum
=
self
.
weightArry
.
count
;
double
totalweight
=
0
;
for
(
NSInteger
i
=
0
;
i
<
self
.
weightArry
.
count
;
i
++
)
{
...
...
@@ -211,46 +221,50 @@
}
if
(
component
>
totalNum
-
1
)
{
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%f"
,
totalweight
+
3
-
totalNum
];
return
SCREEN_WIDTH
/
str
.
doubleValue
;;
return
_lineWith
/
str
.
doubleValue
;;
}
else
{
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%f"
,
totalweight
+
3
-
totalNum
];
return
SCREEN_WIDTH
*
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
weightArry
objectAtIndex
:
component
]].
doubleValue
/
str
.
doubleValue
;
return
_lineWith
*
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
weightArry
objectAtIndex
:
component
]].
doubleValue
/
str
.
doubleValue
;
}
}
else
{
return
SCREEN_WIDTH
/
3
;
return
_lineWith
/
3
;
}
}
}
else
{
}
else
{
_lineWith
=
SCREEN_WIDTH
-
linSpace
;
if
(
self
.
weightArry
.
count
>=
2
)
{
NSString
*
onestr
=
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
weightArry
firstObject
]];
NSString
*
twostr
=
[
NSString
stringWithFormat
:
@"%@"
,
self
.
weightArry
[
1
]];
double
totalweight
=
onestr
.
doubleValue
+
twostr
.
doubleValue
;
if
(
component
==
0
)
{
return
SCREEN_WIDTH
*
onestr
.
doubleValue
/
totalweight
;
return
_lineWith
*
onestr
.
doubleValue
/
totalweight
;
}
else
{
return
SCREEN_WIDTH
*
twostr
.
doubleValue
/
totalweight
;
return
_lineWith
*
twostr
.
doubleValue
/
totalweight
;
}
}
else
{
}
else
{
if
(
self
.
weightArry
.
count
>
0
)
{
double
twonum
=
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
weightArry
firstObject
]].
doubleValue
;
if
(
component
==
0
)
{
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%f"
,
twonum
+
1
];
return
SCREEN_WIDTH
*
twonum
/
str
.
doubleValue
;
return
_lineWith
*
twonum
/
str
.
doubleValue
;
}
else
{
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%f"
,
twonum
+
1
];
return
SCREEN_WIDTH
/
str
.
doubleValue
;
return
_lineWith
/
str
.
doubleValue
;
}
}
else
{
return
SCREEN_WIDTH
/
2
;
}
else
{
return
_lineWith
/
2
;
}
}
}
...
...
@@ -259,6 +273,9 @@
//表示一个数组 特殊情况
return
SCREEN_WIDTH
;
}
else
{
_lineWith
=
(
SCREEN_WIDTH
-
linSpace
*
(
self
.
dataDry
.
count
-
1
));
if
(
self
.
weightArry
.
count
>=
self
.
dataDry
.
count
)
{
double
totalweight
=
0
;
...
...
@@ -269,15 +286,12 @@
}
NSString
*
comStr
=
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
weightArry
objectAtIndex
:
component
]];
return
SCREEN_WIDTH
*
comStr
.
doubleValue
/
totalweight
;
return
_lineWith
*
comStr
.
doubleValue
/
totalweight
;
}
else
{
if
(
self
.
weightArry
.
count
>
0
)
{
NSInteger
totalNum
=
self
.
weightArry
.
count
;
double
totalweight
=
0
;
for
(
NSInteger
i
=
0
;
i
<
self
.
weightArry
.
count
;
i
++
)
{
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
weightArry
objectAtIndex
:
i
]];
totalweight
=
totalweight
+
str
.
doubleValue
;
...
...
@@ -285,15 +299,14 @@
if
(
component
>
totalNum
-
1
)
{
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%f"
,
totalweight
+
self
.
dataDry
.
count
-
totalNum
];
return
SCREEN_WIDTH
/
str
.
doubleValue
;
return
_lineWith
/
str
.
doubleValue
;
}
else
{
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%f"
,
totalweight
+
self
.
dataDry
.
count
-
totalNum
];
return
SCREEN_WIDTH
*
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
weightArry
objectAtIndex
:
component
]].
doubleValue
/
str
.
doubleValue
;
return
_lineWith
*
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
weightArry
objectAtIndex
:
component
]].
doubleValue
/
str
.
doubleValue
;
}
}
else
{
return
SCREEN_WIDTH
/
self
.
dataDry
.
count
;
return
_lineWith
/
self
.
dataDry
.
count
;
}
}
}
...
...
@@ -447,7 +460,6 @@
NSArray
*
eachAry
=
self
.
noCorreArry
[
i
];
[
self
.
backArry
addObject
:[
eachAry
objectAtIndex
:[
self
.
pick
selectedRowInComponent
:
i
]]];
}
...
...
@@ -456,8 +468,11 @@
NSMutableDictionary
*
dic
=
[[
NSMutableDictionary
alloc
]
init
];
[
dic
setValue
:
self
.
backArry
forKey
:
@"selectedValue"
];
[
dic
setValue
:
@"select"
forKey
:
@"type"
];
[
dic
setValue
:[
self
getselectIndexArry
]
forKey
:
@"selectedIndex"
];
self
.
bolock
(
dic
);
}
//判断进来的类型是那种
...
...
@@ -470,6 +485,8 @@
if
([
firstobject
isKindOfClass
:[
NSArray
class
]])
{
_seleNum
=
self
.
dataDry
.
count
;
_Correlation
=
NO
;
}
else
if
([
firstobject
isKindOfClass
:[
NSDictionary
class
]]){
...
...
@@ -487,10 +504,11 @@
if
([
scendObjct
isKindOfClass
:[
NSDictionary
class
]])
{
_numberCorrela
=
@"three"
;
_seleNum
=
3
;
}
else
{
_numberCorrela
=
@"two"
;
_seleNum
=
2
;
}
}
}
...
...
@@ -574,17 +592,19 @@
[
dic
setValue
:
self
.
backArry
forKey
:
@"selectedValue"
];
[
dic
setValue
:
@"cancel"
forKey
:
@"type"
];
[
dic
setValue
:[
self
getselectIndexArry
]
forKey
:
@"selectedIndex"
];
self
.
bolock
(
dic
);
}
else
{
[
self
getNOselectinfo
];
[
dic
setValue
:
self
.
backArry
forKey
:
@"selectedValue"
];
[
dic
setValue
:
@"cancel"
forKey
:
@"type"
];
[
dic
setValue
:[
self
getselectIndexArry
]
forKey
:
@"selectedIndex"
];
self
.
bolock
(
dic
);
}
dispatch_async
(
dispatch_get_main_queue
(),
^
{
[
UIView
animateWithDuration
:.
2
f
animations
:
^
{
...
...
@@ -602,6 +622,9 @@
[
dic
setValue
:
self
.
backArry
forKey
:
@"selectedValue"
];
[
dic
setValue
:
@"confirm"
forKey
:
@"type"
];
NSMutableArray
*
arry
=
[[
NSMutableArray
alloc
]
init
];
[
dic
setValue
:[
self
getselectIndexArry
]
forKey
:
@"selectedIndex"
];
[
dic
setValue
:
arry
forKey
:
@"selectedIndex"
];
self
.
bolock
(
dic
);
...
...
@@ -610,6 +633,8 @@
[
dic
setValue
:
self
.
backArry
forKey
:
@"selectedValue"
];
[
dic
setValue
:
@"confirm"
forKey
:
@"type"
];
[
dic
setValue
:[
self
getselectIndexArry
]
forKey
:
@"selectedIndex"
];
self
.
bolock
(
dic
);
}
...
...
@@ -870,8 +895,8 @@
NSString
*
selectStr
=
[
NSString
stringWithFormat
:
@"%@"
,[
self
.
selectValueArry
firstObject
]];
[
self
.
backArry
addObject
:
selectStr
];
}
else
{
[
self
.
backArry
addObject
:[
self
.
noCorreArry
objectAtIndex
:
0
]];
[
self
.
backArry
addObject
:[
self
.
noCorreArry
objectAtIndex
:
0
]];
}
}
else
{
...
...
@@ -897,5 +922,34 @@
UIColor
*
color
=
[[
UIColor
alloc
]
initWithRed
:[
ColorA
integerValue
]
/
255
.
0
green
:[
ColorB
integerValue
]
/
255
.
0
blue
:
[
ColorC
integerValue
]
/
255
.
0
alpha
:
[
ColorD
floatValue
]];
return
color
;
}
-
(
NSArray
*
)
getselectIndexArry
{
NSMutableArray
*
arry
=
[[
NSMutableArray
alloc
]
init
];
for
(
NSInteger
i
=
0
;
i
<
_seleNum
;
i
++
)
{
NSNumber
*
num
=
[[
NSNumber
alloc
]
initWithInteger
:[
self
.
pick
selectedRowInComponent
:
i
]];
[
arry
addObject
:
num
];
}
return
arry
;
}
-
(
UIView
*
)
pickerView
:(
UIPickerView
*
)
pickerView
viewForRow
:(
NSInteger
)
row
forComponent
:(
NSInteger
)
component
reusingView
:(
UIView
*
)
view
{
UILabel
*
lbl
=
(
UILabel
*
)
view
;
if
(
lbl
==
nil
)
{
lbl
=
[[
UILabel
alloc
]
init
];
//在这里设置字体相关属性
lbl
.
font
=
[
UIFont
systemFontOfSize
:[
_pickerFontSize
integerValue
]];
lbl
.
textColor
=
[
self
colorWith
:
_pickerFontColor
];
lbl
.
textAlignment
=
UITextAlignmentCenter
;
}
//重新加载lbl的文字内容
lbl
.
text
=
[
self
pickerView
:
pickerView
titleForRow
:
row
forComponent
:
component
];
return
lbl
;
}
@end
ios/RCTBEEPickerManager/RCTBEEPickerManager.m
View file @
d6ad6759
...
...
@@ -26,7 +26,11 @@ RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD
(
_init
:
(
NSDictionary
*
)
indic
){
self
.
window
=
[[
UIApplication
sharedApplication
].
windows
lastObject
];
dispatch_async
(
dispatch_get_main_queue
(),
^
{
[[
UIApplication
sharedApplication
].
keyWindow
endEditing
:
YES
];
});
self
.
window
=
[
UIApplication
sharedApplication
].
keyWindow
;
NSString
*
pickerConfirmBtnText
=
indic
[
@"pickerConfirmBtnText"
];
NSString
*
pickerCancelBtnText
=
indic
[
@"pickerCancelBtnText"
];
...
...
@@ -38,6 +42,9 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){
NSArray
*
pickerBg
=
indic
[
@"pickerBg"
];
NSArray
*
selectArry
=
indic
[
@"selectedValue"
];
NSArray
*
weightArry
=
indic
[
@"wheelFlex"
];
NSString
*
pickerToolBarFontSize
=
[
NSString
stringWithFormat
:
@"%@"
,
indic
[
@"pickerToolBarFontSize"
]];
NSString
*
pickerFontSize
=
[
NSString
stringWithFormat
:
@"%@"
,
indic
[
@"pickerFontSize"
]];
NSArray
*
pickerFontColor
=
indic
[
@"pickerFontColor"
];
id
pickerData
=
indic
[
@"pickerData"
];
...
...
@@ -62,7 +69,8 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){
self
.
height
=
220
;
}
self
.
pick
=
[[
BzwPicker
alloc
]
initWithFrame
:
CGRectMake
(
0
,
SCREEN_HEIGHT
,
SCREEN_WIDTH
,
self
.
height
)
dic
:
dataDic
leftStr
:
pickerCancelBtnText
centerStr
:
pickerTitleText
rightStr
:
pickerConfirmBtnText
topbgColor
:
pickerToolBarBg
bottombgColor
:
pickerBg
leftbtnbgColor
:
pickerCancelBtnColor
rightbtnbgColor
:
pickerConfirmBtnColor
centerbtnColor
:
pickerTitleColor
selectValueArry
:
selectArry
weightArry
:
weightArry
];
self
.
pick
=
[[
BzwPicker
alloc
]
initWithFrame
:
CGRectMake
(
0
,
SCREEN_HEIGHT
,
SCREEN_WIDTH
,
self
.
height
)
dic
:
dataDic
leftStr
:
pickerCancelBtnText
centerStr
:
pickerTitleText
rightStr
:
pickerConfirmBtnText
topbgColor
:
pickerToolBarBg
bottombgColor
:
pickerBg
leftbtnbgColor
:
pickerCancelBtnColor
rightbtnbgColor
:
pickerConfirmBtnColor
centerbtnColor
:
pickerTitleColor
selectValueArry
:
selectArry
weightArry
:
weightArry
pickerToolBarFontSize
:
pickerToolBarFontSize
pickerFontSize
:
pickerFontSize
pickerFontColor
:
pickerFontColor
];
_pick
.
bolock
=^
(
NSDictionary
*
backinfoArry
){
...
...
@@ -74,7 +82,7 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){
dispatch_async
(
dispatch_get_main_queue
(),
^
{
[
self
.
window
addSubview
:
_pick
];
[
self
.
window
addSubview
:
_pick
];
[
UIView
animateWithDuration
:.
3
animations
:
^
{
...
...
package.json
View file @
d6ad6759
{
"name"
:
"react-native-picker"
,
"version"
:
"4.0.1
1
"
,
"version"
:
"4.0.1
2
"
,
"description"
:
""
,
"main"
:
"index.js"
,
"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