Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat rn picker-view #1760

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
460aeb0
feat: update initialOffset
wangshunnn Nov 27, 2024
41015c2
feat: add mask & remove animated value
wangshunnn Nov 29, 2024
81d394c
feat: support mask-style prop
wangshunnn Nov 29, 2024
10ebd1a
fix: default picker item height
wangshunnn Nov 29, 2024
1b897d7
fix: inherit font-related styles from picker-view
wangshunnn Dec 2, 2024
4899726
fix: integerize ScrollView width to prevent snapToOffsets failure
wangshunnn Dec 3, 2024
c4d3dd3
perf: remove debounce
wangshunnn Dec 4, 2024
e893690
feat: update
wangshunnn Dec 4, 2024
bc3b809
feat: update
wangshunnn Dec 4, 2024
791488c
fix: add column normal style
wangshunnn Dec 7, 2024
08efcef
fix: scrollTo animate
wangshunnn Dec 12, 2024
ba404be
chore: merge master
wangshunnn Dec 13, 2024
99ffac9
feat: update
wangshunnn Dec 16, 2024
5a5bf92
Merge branch 'master' into fix-picker-view-1129
wangshunnn Dec 16, 2024
050475f
refactor: reanimated
wangshunnn Dec 17, 2024
d03eaf4
fix: snapToOffsets
wangshunnn Dec 17, 2024
3a31d17
feat: update style && add vibrate
wangshunnn Dec 18, 2024
ad235ac
feat: update vibrate
wangshunnn Dec 18, 2024
6513c60
feat: update style
wangshunnn Dec 19, 2024
539916c
Merge branch 'master' into fix-picker-view-1129
wangshunnn Dec 19, 2024
6fc0894
fix: ts lint
wangshunnn Dec 19, 2024
416aa72
feat: update
wangshunnn Dec 19, 2024
7f032a6
fix: width style
wangshunnn Dec 20, 2024
8395ee1
Merge branch 'master' into fix-picker-view-1129
wangshunnn Dec 23, 2024
6636443
fix: Android config
wangshunnn Dec 23, 2024
948cbf2
fix: padding height
wangshunnn Dec 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React, { useEffect } from 'react'
import { LayoutChangeEvent } from 'react-native'
import Reanimated, { Extrapolation, interpolate, useAnimatedStyle, useSharedValue } from 'react-native-reanimated'
import { wrapChildren, extendObject } from './utils'
import { createFaces } from './pickerFaces'
import { usePickerViewColumnAnimationContext } from './pickerVIewContext'

interface PickerColumnItemProps {
item: React.ReactElement
index: number
itemHeight: number
itemWidth: number | '100%'
textStyleFromParent: Record<string, any>
textStyle: Record<string, any>
hasVarDec: boolean
varContext: Record<string, any>
visibleCount: number
textProps?: any
onItemLayout?: (e: LayoutChangeEvent) => void
}

const _PickerViewColumnItem: React.FC<PickerColumnItemProps> = ({
item,
index,
itemHeight,
itemWidth,
textStyleFromParent,
textStyle,
hasVarDec,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个不用传递下来啊

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

理论上这玩意不需要接收样式吧

varContext,
textProps,
visibleCount,
onItemLayout
}) => {
const offsetYShared = usePickerViewColumnAnimationContext()
const facesShared = useSharedValue(createFaces(itemHeight, visibleCount))

useEffect(() => {
facesShared.value = createFaces(itemHeight, visibleCount)
}, [itemHeight])

const animatedStyles = useAnimatedStyle(() => {
const inputRange = facesShared.value.map((f) => itemHeight * (index + f.index))
return {
opacity: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.opacity), Extrapolation.CLAMP),
transform: [
{ rotateX: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.deg), Extrapolation.CLAMP) + 'deg' },
{ translateY: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.offsetY), Extrapolation.EXTEND) },
{ scale: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.scale), Extrapolation.EXTEND) }
]
}
})

const strKey = `picker-column-item-${index}`
const restProps = index === 0 ? { onLayout: onItemLayout } : {}
const itemProps = extendObject(
{
style: extendObject(
{ height: itemHeight, width: '100%' },
textStyleFromParent,
textStyle,
item.props.style
)
},
restProps
)
const realItem = React.cloneElement(item, itemProps)

return (
<Reanimated.View
key={strKey}
style={[{ height: itemHeight, width: itemWidth }, animatedStyles]}
>
{wrapChildren(
{ children: realItem },
{
hasVarDec,
varContext,
textStyle,
textProps
}
)}
</Reanimated.View>
)
}

_PickerViewColumnItem.displayName = 'MpxPickerViewColumnItem'
export default _PickerViewColumnItem
Loading
Loading