react-native-wheel-pick 1.2.2 → 1.2.4
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 +22 -3
- package/android/build.gradle +16 -0
- package/android/src/main/java/com/tron/ReactWheelCurvedPicker.java +12 -1
- package/android/src/main/java/com/tron/ReactWheelCurvedPickerManager.java +13 -2
- package/package.json +1 -1
- package/src/WheelCurvedPicker.web.js +6 -0
- package/src/date-picker.web.js +52 -0
- package/src/picker.js +32 -2
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
# [react-native-wheel-pick](https://www.npmjs.com/package/react-native-wheel-pick)
|
|
3
3
|
|
|
4
|
-
React native wheel picker for both iOS and android.
|
|
4
|
+
React native wheel picker for both iOS and android.
|
|
5
5
|
|
|
6
6
|
This is not original but inspired by [react-native-wheel-datepicker](https://github.com/pinguinjkeke/react-native-wheel-datepicker)
|
|
7
7
|
|
|
@@ -24,6 +24,8 @@ npm install @react-native-picker/picker --save-dev --legacy-peer-deps
|
|
|
24
24
|
npm install @react-native-community/datetimepicker --save-dev --legacy-peer-deps
|
|
25
25
|
npx pod-install
|
|
26
26
|
|
|
27
|
+
npx react-native start --reset-cache // clear cache
|
|
28
|
+
|
|
27
29
|
npx react-native run-ios // re-build native-code
|
|
28
30
|
npx react-native run-android // re-build native-code for gradle
|
|
29
31
|
```
|
|
@@ -77,7 +79,6 @@ onDateChange={(date: Date) => { console.log(date) }}
|
|
|
77
79
|
maximumDate={new Date('2050-12-31')}
|
|
78
80
|
onDateChange={date => { console.log(date) }}
|
|
79
81
|
/>
|
|
80
|
-
|
|
81
82
|
```
|
|
82
83
|
```jsx
|
|
83
84
|
// pickerData also support array of object. (Optional Way)
|
|
@@ -108,7 +109,7 @@ onDateChange={(date: Date) => { console.log(date) }}
|
|
|
108
109
|
```
|
|
109
110
|
```jsx
|
|
110
111
|
// Android Only.
|
|
111
|
-
// These is special props for Android. (iOS not work)
|
|
112
|
+
// These is special props for Android. (iOS and Web not work)
|
|
112
113
|
// You can also use these props for DatePicker, too.
|
|
113
114
|
<Picker
|
|
114
115
|
textSize={20}
|
|
@@ -127,6 +128,10 @@ onDateChange={(date: Date) => { console.log(date) }}
|
|
|
127
128
|
<DatePicker
|
|
128
129
|
order='D-M-Y' // Default is M-D-Y
|
|
129
130
|
/>
|
|
131
|
+
|
|
132
|
+
// Test on Web (Platform.OS === 'Web')
|
|
133
|
+
<Picker style={{ height: 50 }} />
|
|
134
|
+
// DatePicker still not supported on Web.
|
|
130
135
|
```
|
|
131
136
|
## FYI
|
|
132
137
|
|
|
@@ -140,6 +145,20 @@ You can sponsor me
|
|
|
140
145
|
OR you can fork this project instead.
|
|
141
146
|
|
|
142
147
|
## Release Note
|
|
148
|
+
### 1.2.4 (Feb 17 2025)
|
|
149
|
+
[Web]
|
|
150
|
+
- Test on `Platform.OS === 'web'`
|
|
151
|
+
- Only `<Picker />` can use on Web. `<DatePicker />` still not supported on Web.
|
|
152
|
+
|
|
153
|
+
### 1.2.3 (Feb 15 2024)
|
|
154
|
+
- Fix state is not updating after onValueChange in Picker Component. Thanks to [@spasma
|
|
155
|
+
](https://github.com/TronNatthakorn/react-native-wheel-pick/issues/52)
|
|
156
|
+
- Test on React Native Version 0.77
|
|
157
|
+
|
|
158
|
+
[Android]
|
|
159
|
+
- Support [UIManager New Architecture of React Native](https://github.com/reactwg/react-native-new-architecture/discussions/201)
|
|
160
|
+
- Use Handler for fix 23 index problem. Thanks to [@mykhailoperemitko](https://github.com/TronNatthakorn/react-native-wheel-pick/issues/44) [@A-ANing](https://github.com/A-ANing)
|
|
161
|
+
|
|
143
162
|
### 1.2.2 (June 7 2023)
|
|
144
163
|
[iOS]
|
|
145
164
|
- Now iOS can use `textColor`, too. [Add missing color option for iOS](https://github.com/TronNatthakorn/react-native-wheel-pick/pull/38) [@aurotones](https://github.com/aurotones)
|
package/android/build.gradle
CHANGED
|
@@ -6,9 +6,25 @@ buildscript {
|
|
|
6
6
|
|
|
7
7
|
apply plugin: 'com.android.library'
|
|
8
8
|
|
|
9
|
+
def isNewArchitectureEnabled() {
|
|
10
|
+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (isNewArchitectureEnabled()) {
|
|
14
|
+
apply plugin: 'com.facebook.react'
|
|
15
|
+
}
|
|
16
|
+
|
|
9
17
|
android {
|
|
10
18
|
compileSdkVersion 33
|
|
11
19
|
namespace 'com.tron'
|
|
20
|
+
|
|
21
|
+
defaultConfig {
|
|
22
|
+
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString())
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
buildFeatures {
|
|
26
|
+
buildConfig true
|
|
27
|
+
}
|
|
12
28
|
}
|
|
13
29
|
|
|
14
30
|
dependencies {
|
|
@@ -20,6 +20,11 @@ import com.facebook.react.uimanager.events.Event;
|
|
|
20
20
|
import com.facebook.react.uimanager.events.EventDispatcher;
|
|
21
21
|
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
22
22
|
|
|
23
|
+
import com.facebook.react.uimanager.UIManagerHelper;
|
|
24
|
+
|
|
25
|
+
// UIManagerType;
|
|
26
|
+
import com.facebook.react.uimanager.common.UIManagerType;
|
|
27
|
+
|
|
23
28
|
import java.util.Date;
|
|
24
29
|
import java.util.List;
|
|
25
30
|
|
|
@@ -35,7 +40,13 @@ public class ReactWheelCurvedPicker extends WheelPicker {
|
|
|
35
40
|
|
|
36
41
|
public ReactWheelCurvedPicker(ReactContext reactContext) {
|
|
37
42
|
super(reactContext);
|
|
38
|
-
|
|
43
|
+
|
|
44
|
+
if(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
|
|
45
|
+
mEventDispatcher = (UIManagerHelper.getUIManager(reactContext, 1 /** UIManagerType */)).getEventDispatcher();
|
|
46
|
+
} else {
|
|
47
|
+
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
|
48
|
+
}
|
|
49
|
+
|
|
39
50
|
setOnWheelChangeListener(new OnWheelChangeListener() {
|
|
40
51
|
@Override
|
|
41
52
|
public void onWheelScrolled(int offset) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package com.tron;
|
|
2
2
|
|
|
3
3
|
import android.graphics.Color;
|
|
4
|
+
import android.os.Handler;
|
|
4
5
|
|
|
5
6
|
import com.aigestudio.wheelpicker.WheelPicker;
|
|
6
7
|
import com.facebook.react.bridge.ReadableArray;
|
|
@@ -84,8 +85,18 @@ public class ReactWheelCurvedPickerManager extends SimpleViewManager<ReactWheelC
|
|
|
84
85
|
//if (picker != null && picker.getState() == WheelPicker.SCROLL_STATE_IDLE) {
|
|
85
86
|
// Log.d("Index from React", index + "");
|
|
86
87
|
if (picker != null) {
|
|
87
|
-
picker.setSelectedItemPosition(index);
|
|
88
|
-
picker.invalidate();
|
|
88
|
+
// picker.setSelectedItemPosition(index);
|
|
89
|
+
// picker.invalidate();
|
|
90
|
+
|
|
91
|
+
final Handler handler = new Handler();
|
|
92
|
+
|
|
93
|
+
handler.post(new Runnable() {
|
|
94
|
+
@Override
|
|
95
|
+
public void run() {
|
|
96
|
+
picker.setSelectedItemPosition(index);
|
|
97
|
+
picker.invalidate();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
89
100
|
}
|
|
90
101
|
}
|
|
91
102
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React, { PureComponent } from 'react';
|
|
2
|
+
// import { DatePickerIOS } from 'react-native';
|
|
3
|
+
import DateTimePicker from '@react-native-community/datetimepicker';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
|
|
6
|
+
export default class DatePicker extends PureComponent {
|
|
7
|
+
static propTypes = {
|
|
8
|
+
date: PropTypes.instanceOf(Date),
|
|
9
|
+
maximumDate: PropTypes.instanceOf(Date),
|
|
10
|
+
minimumDate: PropTypes.instanceOf(Date),
|
|
11
|
+
mode: PropTypes.oneOf(['date', 'time', 'datetime']),
|
|
12
|
+
onDateChange: PropTypes.func.isRequired,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
static defaultProps = {
|
|
16
|
+
mode: 'date',
|
|
17
|
+
date: new Date(),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
state = {
|
|
21
|
+
date: new Date(),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// @react-native-community/datetimepicker
|
|
25
|
+
//2022 use value instead of date
|
|
26
|
+
//2022 use onChange instead of onDateChange (and first param not date anymore)
|
|
27
|
+
render() {
|
|
28
|
+
return (
|
|
29
|
+
<DateTimePicker
|
|
30
|
+
{...this.props}
|
|
31
|
+
onChange={(event, date) => this.onDateChange(date)}
|
|
32
|
+
display='spinner'
|
|
33
|
+
value={this.state.date}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
componentDidMount() {
|
|
39
|
+
this.setState({ date: this.props.date })
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
componentDidUpdate(prevProps) {
|
|
43
|
+
if (this.props.date !== prevProps.date) {
|
|
44
|
+
this.setState({ date: this.props.date })
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
onDateChange = (date) => {
|
|
49
|
+
this.setState({ date });
|
|
50
|
+
this.props.onDateChange(date);
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/picker.js
CHANGED
|
@@ -45,6 +45,12 @@ export default class Picker extends Component {
|
|
|
45
45
|
this.props.onValueChange(selectedValue);
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
+
componentDidUpdate(prevProps) {
|
|
49
|
+
if (prevProps.selectedValue !== this.props.selectedValue) {
|
|
50
|
+
this.setState({ selectedValue: this.props.selectedValue });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
48
54
|
validateDeprecateProps = (oldProp = 'curtain', newProp = '') => {
|
|
49
55
|
if(this.props){
|
|
50
56
|
if(typeof this.props[oldProp] !== 'undefined'){
|
|
@@ -76,9 +82,33 @@ export default class Picker extends Component {
|
|
|
76
82
|
this.validateDeprecateProps('indicatorSize', 'selectLineSize');
|
|
77
83
|
}
|
|
78
84
|
|
|
85
|
+
const propsForWeb = { ...props }
|
|
86
|
+
|
|
87
|
+
if(Platform.OS === 'web'){
|
|
88
|
+
propsForWeb.textcolor = propsForWeb.textColor
|
|
89
|
+
propsForWeb.textsize = propsForWeb.textSize
|
|
90
|
+
|
|
91
|
+
propsForWeb.selecttextcolor = propsForWeb.selectTextColor
|
|
92
|
+
propsForWeb.isshowselectbackground = propsForWeb.isShowSelectBackground.toString()
|
|
93
|
+
propsForWeb.selectbackgroundcolor = propsForWeb.selectBackgroundColor
|
|
94
|
+
propsForWeb.isshowselectline = propsForWeb.isShowSelectLine.toString()
|
|
95
|
+
propsForWeb.selectlinecolor = propsForWeb.selectLineColor
|
|
96
|
+
propsForWeb.selectlinesize = propsForWeb.selectLineSize
|
|
97
|
+
|
|
98
|
+
delete propsForWeb.textColor
|
|
99
|
+
delete propsForWeb.textSize
|
|
100
|
+
|
|
101
|
+
delete propsForWeb.selectTextColor
|
|
102
|
+
delete propsForWeb.isShowSelectBackground
|
|
103
|
+
delete propsForWeb.selectBackgroundColor
|
|
104
|
+
delete propsForWeb.isShowSelectLine
|
|
105
|
+
delete propsForWeb.selectLineColor
|
|
106
|
+
delete propsForWeb.selectLineSize
|
|
107
|
+
}
|
|
108
|
+
|
|
79
109
|
return (
|
|
80
110
|
<WheelCurvedPicker
|
|
81
|
-
{...props}
|
|
111
|
+
{...(Platform.OS === 'web'? propsForWeb: props)}
|
|
82
112
|
style={[styles.picker, style]}
|
|
83
113
|
selectedValue={this.state.selectedValue}
|
|
84
114
|
onValueChange={this.handleChange}
|
|
@@ -88,7 +118,7 @@ export default class Picker extends Component {
|
|
|
88
118
|
key={index}
|
|
89
119
|
value={typeof data.value !== 'undefined' ? data.value : data.toString()}
|
|
90
120
|
label={typeof data.label !== 'undefined' ? data.label : data.toString()}
|
|
91
|
-
color={props.textColor}
|
|
121
|
+
color={(Platform.OS === 'web'? propsForWeb.textcolor: props.textColor)}
|
|
92
122
|
/>
|
|
93
123
|
))}
|
|
94
124
|
</WheelCurvedPicker>
|