-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1760 from wangshunnn/fix-picker-view-1129
Feat rn picker-view
- Loading branch information
Showing
11 changed files
with
459 additions
and
291 deletions.
There are no files selected for viewing
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
76 changes: 76 additions & 0 deletions
76
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,76 @@ | ||
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, usePickerViewStyleContext } from './pickerVIewContext' | ||
|
||
interface PickerColumnItemProps { | ||
item: React.ReactElement | ||
index: number | ||
itemHeight: number | ||
itemWidth?: number | '100%' | ||
textStyle: Record<string, any> | ||
visibleCount: number | ||
textProps?: any | ||
onItemLayout?: (e: LayoutChangeEvent) => void | ||
} | ||
|
||
const PickerViewColumnItem: React.FC<PickerColumnItemProps> = ({ | ||
item, | ||
index, | ||
itemHeight, | ||
itemWidth = '100%', | ||
textStyle, | ||
textProps, | ||
visibleCount, | ||
onItemLayout | ||
}) => { | ||
const textStyleFromAncestor = usePickerViewStyleContext() | ||
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: [ | ||
{ translateY: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.offsetY), Extrapolation.EXTEND) }, | ||
{ rotateX: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.deg), Extrapolation.CLAMP) + 'deg' }, | ||
{ 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%' }, | ||
textStyleFromAncestor, | ||
textStyle, | ||
item.props.style | ||
) | ||
}, | ||
textProps, | ||
restProps | ||
) | ||
const realItem = React.cloneElement(item, itemProps) | ||
|
||
return ( | ||
<Reanimated.View | ||
key={strKey} | ||
style={[{ height: itemHeight, width: itemWidth }, animatedStyles]} | ||
> | ||
{realItem} | ||
</Reanimated.View> | ||
) | ||
} | ||
|
||
PickerViewColumnItem.displayName = 'MpxPickerViewColumnItem' | ||
export default PickerViewColumnItem |
Oops, something went wrong.