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

Merged
merged 42 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
42 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
5276929
fix: reset scroll position
wangshunnn Dec 26, 2024
5e304f4
feat: update
wangshunnn Dec 27, 2024
0a577b6
feat: update scales
wangshunnn Dec 30, 2024
249fdea
wip: review
wangshunnn Jan 5, 2025
00803cb
feat: update get rn style
wangshunnn Jan 6, 2025
8ef5c7d
chore: merge master
wangshunnn Jan 6, 2025
f8f43ad
chore: lint fix
wangshunnn Jan 6, 2025
de69fcf
feat: udpate animated style
wangshunnn Jan 7, 2025
9908e15
fix: update
wangshunnn Jan 7, 2025
e8440ba
feat: update
wangshunnn Jan 7, 2025
8b13b4c
feat: clear timer
wangshunnn Jan 8, 2025
da72a3c
feat: review
wangshunnn Jan 9, 2025
cb71dab
feat: review update
wangshunnn Jan 9, 2025
c4a0ae2
Merge branch 'master' into fix-picker-view-1129
wangshunnn Jan 9, 2025
47c1a94
feat: review
wangshunnn Jan 9, 2025
bbb7298
Merge branch 'master' into fix-picker-view-1129
wangshunnn Jan 9, 2025
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 = '100%',
textStyleFromParent,
textStyle,
wangshunnn marked this conversation as resolved.
Show resolved Hide resolved
hasVarDec,
wangshunnn marked this conversation as resolved.
Show resolved Hide resolved
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(
wangshunnn marked this conversation as resolved.
Show resolved Hide resolved
{
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(
wangshunnn marked this conversation as resolved.
Show resolved Hide resolved
{ children: realItem },
{
hasVarDec,
varContext,
textStyle,
textProps
}
)}
</Reanimated.View>
)
}

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