Skip to content

Commit

Permalink
feat(Picker): add readonly props
Browse files Browse the repository at this point in the history
  • Loading branch information
cuilanxin committed Oct 30, 2021
1 parent 4cb045c commit c11fa05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/Picker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,7 @@ export interface PickerProps {
value?: number,
/** value 改变时触发 */
onChange?: (value: number)=>unknown,
/** 是否只读 不能点击不能滑动但可以通过value控制 */
readonly?: boolean
}
```
6 changes: 6 additions & 0 deletions packages/core/src/Picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export interface PickerProps {
};
/** 选中当前项的下标 */
value?: number;
/** 是否只读 */
readonly?: boolean;
/** value 改变时触发 */
onChange?: (value: number) => unknown;
}
Expand All @@ -57,6 +59,7 @@ const Picker = (props: PickerProps) => {
textStyle = {},
value = 0,
onChange,
readonly = false,
} = props;
const Y = useRef(new Animated.Value(0)).current;
const scrollView = useRef<ScrollView>();
Expand Down Expand Up @@ -143,6 +146,7 @@ const Picker = (props: PickerProps) => {
}, 160);
};
const onTouchEnd = () => {
if (readonly) return;
if (Platform.OS === 'ios') {
if (onPressORonScroll.current === 'onPress') {
setCurrent(currentY.current);
Expand All @@ -163,13 +167,15 @@ const Picker = (props: PickerProps) => {
listener,
useNativeDriver: false,
})}
scrollEnabled={!readonly}
>
{data.map((item, index) => (
<Pressable
onLayout={getItemHeight}
key={index}
onPressOut={Platform.OS === 'android' ? onTouchEnd : undefined}
onPress={() => {
if (readonly) return;
if (timer.current) return;
clearTimeout(onPressTimer.current!);
onPressORonScroll.current = 'onPress';
Expand Down

0 comments on commit c11fa05

Please sign in to comment.