File tree Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -92,5 +92,7 @@ export interface PickerProps {
92
92
value? : number ,
93
93
/** value 改变时触发 */
94
94
onChange? : (value : number )=> unknown ,
95
+ /** 是否只读 不能点击不能滑动但可以通过value控制 */
96
+ readonly? : boolean
95
97
}
96
98
```
Original file line number Diff line number Diff line change @@ -44,6 +44,8 @@ export interface PickerProps {
44
44
} ;
45
45
/** 选中当前项的下标 */
46
46
value ?: number ;
47
+ /** 是否只读 */
48
+ readonly ?: boolean ;
47
49
/** value 改变时触发 */
48
50
onChange ?: ( value : number ) => unknown ;
49
51
}
@@ -57,6 +59,7 @@ const Picker = (props: PickerProps) => {
57
59
textStyle = { } ,
58
60
value = 0 ,
59
61
onChange,
62
+ readonly = false ,
60
63
} = props ;
61
64
const Y = useRef ( new Animated . Value ( 0 ) ) . current ;
62
65
const scrollView = useRef < ScrollView > ( ) ;
@@ -143,6 +146,7 @@ const Picker = (props: PickerProps) => {
143
146
} , 160 ) ;
144
147
} ;
145
148
const onTouchEnd = ( ) => {
149
+ if ( readonly ) return ;
146
150
if ( Platform . OS === 'ios' ) {
147
151
if ( onPressORonScroll . current === 'onPress' ) {
148
152
setCurrent ( currentY . current ) ;
@@ -163,13 +167,15 @@ const Picker = (props: PickerProps) => {
163
167
listener,
164
168
useNativeDriver : false ,
165
169
} ) }
170
+ scrollEnabled = { ! readonly }
166
171
>
167
172
{ data . map ( ( item , index ) => (
168
173
< Pressable
169
174
onLayout = { getItemHeight }
170
175
key = { index }
171
176
onPressOut = { Platform . OS === 'android' ? onTouchEnd : undefined }
172
177
onPress = { ( ) => {
178
+ if ( readonly ) return ;
173
179
if ( timer . current ) return ;
174
180
clearTimeout ( onPressTimer . current ! ) ;
175
181
onPressORonScroll . current = 'onPress' ;
You can’t perform that action at this time.
0 commit comments