-
Notifications
You must be signed in to change notification settings - Fork 380
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
wangshunnn
wants to merge
26
commits into
didi:master
Choose a base branch
from
wangshunnn:fix-picker-view-1129
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat rn picker-view #1760
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
460aeb0
feat: update initialOffset
wangshunnn 41015c2
feat: add mask & remove animated value
wangshunnn 81d394c
feat: support mask-style prop
wangshunnn 10ebd1a
fix: default picker item height
wangshunnn 1b897d7
fix: inherit font-related styles from picker-view
wangshunnn 4899726
fix: integerize ScrollView width to prevent snapToOffsets failure
wangshunnn c4d3dd3
perf: remove debounce
wangshunnn e893690
feat: update
wangshunnn bc3b809
feat: update
wangshunnn 791488c
fix: add column normal style
wangshunnn 08efcef
fix: scrollTo animate
wangshunnn ba404be
chore: merge master
wangshunnn 99ffac9
feat: update
wangshunnn 5a5bf92
Merge branch 'master' into fix-picker-view-1129
wangshunnn 050475f
refactor: reanimated
wangshunnn d03eaf4
fix: snapToOffsets
wangshunnn 3a31d17
feat: update style && add vibrate
wangshunnn ad235ac
feat: update vibrate
wangshunnn 6513c60
feat: update style
wangshunnn 539916c
Merge branch 'master' into fix-picker-view-1129
wangshunnn 6fc0894
fix: ts lint
wangshunnn 416aa72
feat: update
wangshunnn 7f032a6
fix: width style
wangshunnn 8395ee1
Merge branch 'master' into fix-picker-view-1129
wangshunnn 6636443
fix: Android config
wangshunnn 948cbf2
fix: padding height
wangshunnn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column-item.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个不用传递下来啊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
理论上这玩意不需要接收样式吧