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

fix: time picker values array checked to not be undefined #27

Merged
merged 1 commit into from
Oct 31, 2023
Merged
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
7 changes: 4 additions & 3 deletions src/components/DaySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ const DaySelector = () => {
const month = utils.getDateMonth(currentDate);
const year = utils.getDateYear(currentDate);
const days = useMemo(
() => utils.getMonthDays(currentDate),
() => {
return utils.getMonthDays(currentDate);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[month, year, utils.displayFullDays]
[month, year, utils.displayFullDays, utils.minimumDate, utils.maximumDate]
);

const handleSelectDate = (date: string) => {
Expand Down Expand Up @@ -135,7 +137,6 @@ const styles = StyleSheet.create({
height: '100%',
flexWrap: 'wrap',
flexDirection: 'row',
justifyContent: 'center',
alignContent: 'flex-start',
},
dayCell: {
Expand Down
14 changes: 8 additions & 6 deletions src/components/TimePicker/Wheel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ViewStyle,
Platform,
} from 'react-native';
import React, { useMemo, useRef } from 'react';
import React, { memo, useMemo, useRef } from 'react';
import { sin } from './AnimatedMath';
import { CALENDAR_HEIGHT } from '../../enums';

Expand All @@ -28,7 +28,7 @@ export interface WheelProps extends WheelStyleProps {
onScroll?: (scrollState: boolean) => void;
}

export default function Wheel({
const Wheel = ({
value,
setValue,
onScroll,
Expand All @@ -40,7 +40,7 @@ export default function Wheel({
disabledColor = 'gray',
wheelHeight,
displayCount = 5,
}: WheelProps) {
}: WheelProps) => {
const translateY = useRef(new Animated.Value(0)).current;
const renderCount =
displayCount * 2 < items.length
Expand Down Expand Up @@ -100,7 +100,7 @@ export default function Wheel({
const displayValues = useMemo(() => {
const centerIndex = Math.floor(renderCount / 2);

return [...Array(renderCount).keys()].map((_, index) => {
return Array.from({ length: renderCount }, (_, index) => {
let targetIndex = valueIndex + index - centerIndex;
if (targetIndex < 0 || targetIndex >= items.length) {
targetIndex = (targetIndex + items.length) % items.length;
Expand Down Expand Up @@ -136,7 +136,7 @@ export default function Wheel({
style={[styles.container, containerStyle]}
{...panResponder.panHandlers}
>
{displayValues.map((displayValue, index) => {
{displayValues?.map((displayValue, index) => {
const animatedAngle = animatedAngles[index];
return (
<Animated.Text
Expand Down Expand Up @@ -178,7 +178,7 @@ export default function Wheel({
})}
</View>
);
}
};

const styles = StyleSheet.create({
container: {
Expand All @@ -199,3 +199,5 @@ const styles = StyleSheet.create({
alignItems: 'center',
},
});

export default memo(Wheel);
Loading