@react-native-hero/picker 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
} from '@react-native-hero/picker'
|
|
45
45
|
|
|
46
46
|
<Picker
|
|
47
|
+
height={300}
|
|
47
48
|
options={[
|
|
48
49
|
{ text: 'displayed text', value: 'support string or number' },
|
|
49
50
|
{ text: '2', value: 'string' },
|
|
@@ -54,7 +55,6 @@ import {
|
|
|
54
55
|
data.option
|
|
55
56
|
}}
|
|
56
57
|
style={{
|
|
57
|
-
flex: 1,
|
|
58
58
|
backgroundColor: '#eee'
|
|
59
59
|
}}
|
|
60
60
|
|
package/android/build.gradle
CHANGED
|
@@ -36,7 +36,7 @@ android {
|
|
|
36
36
|
dependencies {
|
|
37
37
|
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
|
|
38
38
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${safeExtGet('kotlinVersion', '1.3.40')}"
|
|
39
|
-
implementation 'com.
|
|
39
|
+
implementation 'com.github.LuckyCodeer.Android-PickerView:pickerview:4.2.8'
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
apply plugin: 'kotlin-android'
|
|
@@ -25,7 +25,7 @@ class PickerView(private val reactContext: ThemedReactContext) : WheelView(react
|
|
|
25
25
|
val stringList = arrayListOf<String>()
|
|
26
26
|
|
|
27
27
|
for (i in 0 until value.size()) {
|
|
28
|
-
val map = value.getMap(i)
|
|
28
|
+
val map = value.getMap(i)
|
|
29
29
|
var text = "undefined"
|
|
30
30
|
if (map.hasKey("text")) {
|
|
31
31
|
text = map.getString("text") as String
|
|
@@ -109,8 +109,17 @@ class PickerView(private val reactContext: ThemedReactContext) : WheelView(react
|
|
|
109
109
|
setLineSpacingMultiplier(rowHeight / fontSize)
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
var visibleCount = 6
|
|
113
|
+
|
|
114
|
+
set(value) {
|
|
115
|
+
field = value
|
|
116
|
+
|
|
117
|
+
setItemsVisibleCount(visibleCount)
|
|
118
|
+
}
|
|
119
|
+
|
|
112
120
|
init {
|
|
113
121
|
setCyclic(false)
|
|
122
|
+
setAlphaGradient(true)
|
|
114
123
|
setDividerColor(dividerColor)
|
|
115
124
|
setOnItemSelectedListener {
|
|
116
125
|
selectedIndex = it
|
|
@@ -42,6 +42,11 @@ class RNTPickerManager(private val reactAppContext: ReactApplicationContext) : S
|
|
|
42
42
|
view.rowHeight = rowHeight
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
@ReactProp(name = "visibleCount")
|
|
46
|
+
fun setVisibleCount(view: PickerView, visibleCount: Int) {
|
|
47
|
+
view.visibleCount = visibleCount
|
|
48
|
+
}
|
|
49
|
+
|
|
45
50
|
override fun getExportedCustomBubblingEventTypeConstants(): MutableMap<String, Any> {
|
|
46
51
|
return MapBuilder.builder<String, Any>()
|
|
47
52
|
.put("onChange", MapBuilder.of("phasedRegistrationNames", MapBuilder.of("bubbled", "onChange")))
|
package/index.js
CHANGED
|
@@ -3,11 +3,14 @@ import React, {
|
|
|
3
3
|
} from 'react'
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
+
Platform,
|
|
6
7
|
requireNativeComponent,
|
|
7
8
|
} from 'react-native'
|
|
8
9
|
|
|
9
10
|
import PropTypes from 'prop-types'
|
|
10
11
|
|
|
12
|
+
const isAndroid = Platform.OS === 'android'
|
|
13
|
+
|
|
11
14
|
class PickerComponent extends PureComponent {
|
|
12
15
|
|
|
13
16
|
static propTypes = {
|
|
@@ -17,6 +20,7 @@ class PickerComponent extends PureComponent {
|
|
|
17
20
|
})
|
|
18
21
|
).isRequired,
|
|
19
22
|
selectedIndex: PropTypes.number,
|
|
23
|
+
height: PropTypes.number.isRequired,
|
|
20
24
|
color: PropTypes.string,
|
|
21
25
|
fontSize: PropTypes.number,
|
|
22
26
|
rowHeight: PropTypes.number,
|
|
@@ -32,16 +36,41 @@ class PickerComponent extends PureComponent {
|
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
handleChange = event => {
|
|
35
|
-
|
|
39
|
+
const { onChange } = this.props
|
|
36
40
|
if (onChange) {
|
|
37
41
|
onChange(event.nativeEvent)
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
render() {
|
|
46
|
+
const {
|
|
47
|
+
height,
|
|
48
|
+
rowHeight,
|
|
49
|
+
style,
|
|
50
|
+
...props
|
|
51
|
+
} = this.props
|
|
52
|
+
|
|
53
|
+
const pickerStyle = {
|
|
54
|
+
flex: 1,
|
|
55
|
+
height,
|
|
56
|
+
}
|
|
57
|
+
// 安卓 picker 没有垂直居中
|
|
58
|
+
// 这里支持简单处理,稍微接近 ios 的效果
|
|
59
|
+
if (isAndroid) {
|
|
60
|
+
const gap = Math.floor(height / 100) * 20
|
|
61
|
+
pickerStyle.height -= 2 * gap
|
|
62
|
+
pickerStyle.marginVertical = gap
|
|
63
|
+
}
|
|
42
64
|
return (
|
|
43
65
|
<RNTPicker
|
|
44
|
-
{...
|
|
66
|
+
{...props}
|
|
67
|
+
style={
|
|
68
|
+
style
|
|
69
|
+
? [pickerStyle, style]
|
|
70
|
+
: pickerStyle
|
|
71
|
+
}
|
|
72
|
+
rowHeight={rowHeight}
|
|
73
|
+
visibleCount={Math.ceil(height / rowHeight)}
|
|
45
74
|
onChange={this.handleChange}
|
|
46
75
|
/>
|
|
47
76
|
)
|