Skip to content

Commit

Permalink
Merge pull request #27 from farhoudshapouran/time-picker-bug
Browse files Browse the repository at this point in the history
fix: time picker values array checked to not be undefined
  • Loading branch information
farhoudshapouran authored Oct 31, 2023
2 parents e46182e + 066a086 commit 80a2124
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
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);

0 comments on commit 80a2124

Please sign in to comment.