Skip to content

Commit

Permalink
fix: picker overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
wangshunnn committed Nov 26, 2024
1 parent 19d636f commit cf9fb22
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,

const pickerItemH = useMemo(
() => {
const match = (itemHeight + '').match(/^(\d+)px$/) || [0]
const match = (itemHeight + '').match(/\d+/g) || [0]
return +match[0] || DefaultPickerItemH
},
[itemHeight]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ type OverlayProps = {
overlayContainerStyle?: ViewStyle
}

const Overlay = ({ itemHeight, overlayItemStyle, overlayContainerStyle }: OverlayProps) => {
const itemWidth = overlayItemStyle?.width
if (typeof itemWidth === 'string') {
const match = itemWidth.match(/^(\d+)px$/)
const transPx2Number = (value?: string | number) => {
if (typeof value === 'string') {
const match = value.toString().match(/\d+/g)
if (match) {
overlayItemStyle!.width = +match[1]
return +match[0]
}
}
return value
}

const Overlay = ({ itemHeight, overlayItemStyle, overlayContainerStyle }: OverlayProps) => {
let { width, borderRadius, ...restStyle } = overlayItemStyle || {}
width = transPx2Number(width)
borderRadius = transPx2Number(borderRadius)
return (
<View style={[styles.overlayContainer, overlayContainerStyle]} pointerEvents={'none'}>
<View
style={[{ height: itemHeight }, styles.selection, overlayItemStyle]}
style={[styles.selection, { height: itemHeight, width, borderRadius }, restStyle]}
/>
</View>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,9 @@ export const useStableCallback = <T extends AnyFunc | null | undefined>(

export const usePrevious = <T, >(value: T): T | undefined => {
const ref = useRef<T | undefined>(undefined)
useEffect(() => {
ref.current = value
})
return ref.current
const prev = ref.current
ref.current = value
return prev
}

export interface GestureHandler {
Expand Down

0 comments on commit cf9fb22

Please sign in to comment.