Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ const App = () => {
<View style={styles.pickerContainer}>
<Picker
values={years}
containerWidth={120}
defaultValue={defaultValue}
withTranslateZ={true}
withOpacity={true}
withScale={true}
visibleItems={5}
itemHeight={32}
deviderStyle={styles.pickerDevider}
containerStyle={styles.containerStyle}
dividerStyle={styles.pickerDivider}
labelStyle={styles.pickerItemLabel}
onChange={handelPickerChange}
/>
Expand All @@ -81,7 +81,10 @@ const styles = StyleSheet.create({
justifyContent: 'center',
alignItems: 'center',
},
pickerDevider: {
containerStyle: {
width: 120,
},
pickerDivider: {
borderColor: 'rgba(0,0,0,0.1)',
borderTopWidth: 1,
borderBottomWidth: 1,
Expand All @@ -106,5 +109,6 @@ const styles = StyleSheet.create({
| withTranslateZ | no | false | Enable |
| withScale | no | false | |
| withOpacity | no | false | |
| deviderStyle | no | | Styles for the Devider |
| containerStyle | no | | Styles for the outer container |
| dividerStyle | no | | Styles for the Divider |
| labelStyle | no | | Styles for label Items |
32 changes: 16 additions & 16 deletions src/picker.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo } from 'react';
import { View, StyleSheet, Text } from 'react-native';
import {View, StyleSheet, Text, ViewStyle, TextStyle} from 'react-native';
import Animated, {
interpolateNode,
Extrapolate,
Expand All @@ -18,29 +18,29 @@ const perspective = 1600;

interface PickerProps {
values: { value: number | string; label: string }[];
containerWidth: number;
visibleItems: number;
itemHeight: number;
defaultValue?: number | string;
onChange?: (value: number | string) => void;
withTranslateZ?: boolean;
withScale?: boolean;
withOpacity?: boolean;
deviderStyle?: any;
labelStyle?: any;
containerStyle?: ViewStyle;
dividerStyle?: ViewStyle;
labelStyle?: TextStyle;
}

const Picker = ({
containerWidth,
values,
defaultValue,
visibleItems,
itemHeight,
onChange,
const Picker = ({
values,
defaultValue,
visibleItems,
itemHeight,
onChange,
withTranslateZ,
withScale,
withOpacity,
deviderStyle,
containerStyle,
dividerStyle,
labelStyle,
}: PickerProps) => {
const translateY = useValue(0);
Expand Down Expand Up @@ -72,7 +72,7 @@ const Picker = ({
extrapolate: Extrapolate.CLAMP,
}
);

transform.push({ scale });
}

Expand Down Expand Up @@ -114,15 +114,15 @@ const Picker = ({
), []);

return (
<View style={[styles.container, { width: containerWidth, height: itemHeight * visibleItems }]}>
<View style={[styles.container, { height: itemHeight * visibleItems }, containerStyle]}>
<View style={StyleSheet.absoluteFill}>
<View
style={
[{
top: itemHeight * roundedItems,
height: itemHeight,
},
deviderStyle,
dividerStyle,
]}
/>
</View>
Expand Down Expand Up @@ -156,4 +156,4 @@ const styles = StyleSheet.create({
textAlign: 'center',
textAlignVertical: 'center',
},
});
});