Skip to content

Commit ea52e7d

Browse files
hannarederksch
authored andcommitted
added scale function
1 parent 85c4fb2 commit ea52e7d

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/WheelPicker.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface Props {
2424
itemHeight?: number;
2525
containerStyle?: ViewStyle;
2626
containerProps?: Omit<ViewProps, 'style'>;
27+
scaleFunction?: (x: number) => number;
2728
rotationFunction?: (x: number) => number;
2829
opacityFunction?: (x: number) => number;
2930
visibleRest?: number;
@@ -40,6 +41,7 @@ const WheelPicker: React.FC<Props> = ({
4041
itemStyle = {},
4142
itemTextStyle = {},
4243
itemHeight = 40,
44+
scaleFunction = (x: number) => 0.7 ** x,
4345
rotationFunction = (x: number) => 1 - Math.pow(1 / 2, x),
4446
opacityFunction = (x: number) => Math.pow(1 / 3, x),
4547
visibleRest = 2,
@@ -138,6 +140,7 @@ const WheelPicker: React.FC<Props> = ({
138140
textStyle={itemTextStyle}
139141
height={itemHeight}
140142
currentScrollIndex={currentScrollIndex}
143+
scaleFunction={scaleFunction}
141144
rotationFunction={rotationFunction}
142145
opacityFunction={opacityFunction}
143146
visibleRest={visibleRest}

src/WheelPickerItem.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface ItemProps {
1212
visibleRest: number;
1313
rotationFunction: (x: number) => number;
1414
opacityFunction: (x: number) => number;
15+
scaleFunction: (x: number) => number;
1516
}
1617

1718
const WheelPickerItem: React.FC<ItemProps> = ({
@@ -24,6 +25,7 @@ const WheelPickerItem: React.FC<ItemProps> = ({
2425
currentScrollIndex,
2526
opacityFunction,
2627
rotationFunction,
28+
scaleFunction
2729
}) => {
2830
const relativeScrollIndex = Animated.subtract(index, currentScrollIndex);
2931

@@ -71,6 +73,26 @@ const WheelPickerItem: React.FC<ItemProps> = ({
7173
})(),
7274
});
7375

76+
const scale = relativeScrollIndex.interpolate({
77+
inputRange: (() => {
78+
const range = [0];
79+
for (let i = 1; i <= visibleRest + 1; i++) {
80+
range.unshift(-i);
81+
range.push(i);
82+
}
83+
return range;
84+
})(),
85+
outputRange: (() => {
86+
const range = [1.0];
87+
for (let x = 1; x <= visibleRest + 1; x++) {
88+
const y = scaleFunction(x);
89+
range.unshift(y);
90+
range.push(y);
91+
}
92+
return range;
93+
})(),
94+
});
95+
7496
const rotateX = relativeScrollIndex.interpolate({
7597
inputRange: (() => {
7698
const range = [0];
@@ -96,7 +118,7 @@ const WheelPickerItem: React.FC<ItemProps> = ({
96118
style={[
97119
styles.option,
98120
style,
99-
{ height, opacity, transform: [{ translateY }, { rotateX }] },
121+
{ height, opacity, transform: [{ translateY }, { rotateX }, { scale }]},
100122
]}
101123
>
102124
<Text style={textStyle}>{option}</Text>

0 commit comments

Comments
 (0)