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

WheelPickerItem - adding disabled and disabledColor props #3454

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions demo/src/screens/componentScreens/WheelPickerScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const yearItems = _.times(2050, i => i)
.reverse()
.map(item => ({label: `${item}`, value: item}));
const dayItems = _.times(31, i => i + 1).map(day => ({label: `${day}`, value: day}));
const items = _.times(50, i => i + 1).map(i => ({label: `${i}`, value: i, disabled: i % 2 === 0}));

export default () => {
const [showDialog, setShowDialog] = useState(false);
Expand All @@ -48,6 +49,8 @@ export default () => {
<View flex padding-page>
<Text h1>Wheel Picker</Text>

<WheelPicker initialValue={5} items={items}/>

<View row center marginT-30>
<View center>
<Text h3>Months</Text>
Expand Down
13 changes: 10 additions & 3 deletions src/components/WheelPicker/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface WheelPickerItemProps<T = WheelPickerItemValue> {
value: T;
align?: WheelPickerAlign;
disableRTL?: boolean;
disabled?: boolean;
}

interface InternalProps<T> extends WheelPickerItemProps<T> {
Expand All @@ -23,6 +24,7 @@ interface InternalProps<T> extends WheelPickerItemProps<T> {
itemHeight: number;
activeColor?: string;
inactiveColor?: string;
disabledColor?: string;
style?: TextStyle;
onSelect: (index: number) => void;
centerH?: boolean;
Expand All @@ -45,24 +47,29 @@ const WheelPickerItem = <T extends WheelPickerItemValue = number>(props: Interna
offset,
activeColor = Colors.$textPrimary,
inactiveColor = Colors.$textNeutralHeavy,
disabledColor = Colors.$textDisabled,
style,
testID,
centerH = true,
align,
disableRTL
disableRTL,
disabled
} = themeProps;

const selectItem = useCallback(() => onSelect(index), [index]);
const selectItem = useCallback(() => !disabled && onSelect(index), [index, disabled, onSelect]);
const itemOffset = index * itemHeight;
const _activeColor = useRef(activeColor.toString());
const _inactiveColor = useRef(inactiveColor.toString());

const animatedColorStyle = useAnimatedStyle(() => {
if (disabled) {
return {color: disabledColor};
}
const color = interpolateColor(offset.value,
[itemOffset - itemHeight, itemOffset, itemOffset + itemHeight],
[_inactiveColor.current, _activeColor.current, _inactiveColor.current]);
return {color};
}, [itemHeight]);
}, [itemHeight, disabled]);

const containerStyle = useMemo(() => {
return [{height: itemHeight}, styles.container, disableRTL && styles.disableRTL];
Expand Down