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 {
9292 value? : number ,
9393 /** value 改变时触发 */
9494 onChange? : (value : number )=> unknown ,
95+ /** 是否只读 不能点击不能滑动但可以通过value控制 */
96+ readonly? : boolean
9597}
9698```
Original file line number Diff line number Diff line change @@ -44,6 +44,8 @@ export interface PickerProps {
4444 } ;
4545 /** 选中当前项的下标 */
4646 value ?: number ;
47+ /** 是否只读 */
48+ readonly ?: boolean ;
4749 /** value 改变时触发 */
4850 onChange ?: ( value : number ) => unknown ;
4951}
@@ -57,6 +59,7 @@ const Picker = (props: PickerProps) => {
5759 textStyle = { } ,
5860 value = 0 ,
5961 onChange,
62+ readonly = false ,
6063 } = props ;
6164 const Y = useRef ( new Animated . Value ( 0 ) ) . current ;
6265 const scrollView = useRef < ScrollView > ( ) ;
@@ -143,6 +146,7 @@ const Picker = (props: PickerProps) => {
143146 } , 160 ) ;
144147 } ;
145148 const onTouchEnd = ( ) => {
149+ if ( readonly ) return ;
146150 if ( Platform . OS === 'ios' ) {
147151 if ( onPressORonScroll . current === 'onPress' ) {
148152 setCurrent ( currentY . current ) ;
@@ -163,13 +167,15 @@ const Picker = (props: PickerProps) => {
163167 listener,
164168 useNativeDriver : false ,
165169 } ) }
170+ scrollEnabled = { ! readonly }
166171 >
167172 { data . map ( ( item , index ) => (
168173 < Pressable
169174 onLayout = { getItemHeight }
170175 key = { index }
171176 onPressOut = { Platform . OS === 'android' ? onTouchEnd : undefined }
172177 onPress = { ( ) => {
178+ if ( readonly ) return ;
173179 if ( timer . current ) return ;
174180 clearTimeout ( onPressTimer . current ! ) ;
175181 onPressORonScroll . current = 'onPress' ;
You can’t perform that action at this time.
0 commit comments