Skip to content

Commit

Permalink
feat: remove autoRefreshTimezoneOffset and recheckTimezoneOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
howljs committed Mar 7, 2023
1 parent 471df53 commit 6e7ce0b
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 51 deletions.
30 changes: 2 additions & 28 deletions example/src/screens/Calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
import {
EventItem,
HighlightDates,
MomentConfig,
OnChangeProps,
PackedEvent,
RangeTime,
TimelineCalendar,
TimelineCalendarHandle,
UnavailableItemProps,
MomentConfig,
} from '@howljs/calendar-kit';
import type { NavigationProp, RouteProp } from '@react-navigation/native';
import dayjs from 'dayjs';
import React, {
useCallback,
useEffect,
useLayoutEffect,
useMemo,
useRef,
useState,
} from 'react';
import {
AppState,
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { Line, Svg } from 'react-native-svg';
import CustomUnavailableItem from './CustomUnavailableItem';
Expand Down Expand Up @@ -105,25 +98,6 @@ const Calendar = ({ route, navigation }: CalendarProps) => {
const [events, setEvents] = useState<EventItem[]>([]);
const [selectedEvent, setSelectedEvent] = useState<PackedEvent>();

const appState = useRef(AppState.currentState);
// if autoRefreshTimezoneOffset = true, you can remove this useEffect
useEffect(() => {
const subscription = AppState.addEventListener('change', (nextAppState) => {
if (
appState.current.match(/inactive|background/) &&
nextAppState === 'active'
) {
// Recheck timezone offset the app has come to the foreground
calendarRef.current?.recheckTimezoneOffset();
}
appState.current = nextAppState;
});

return () => {
subscription.remove();
};
}, []);

const _renderHeaderRight = useCallback(() => {
return (
<TouchableOpacity
Expand Down
4 changes: 0 additions & 4 deletions src/components/Timeline/NowIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface NowIndicatorProps {
tzOffset: string;
start: number;
updateCurrentDate: () => void;
recheckTimezoneOffset?: () => void;
nowIndicatorInterval: number;
}

Expand All @@ -36,15 +35,13 @@ const NowIndicator = ({
start,
updateCurrentDate,
nowIndicatorInterval,
recheckTimezoneOffset,
}: NowIndicatorProps) => {
const initial = useRef(getCurrentMinutes(tzOffset));
const translateY = useSharedValue(0);
const intervalCallbackId = useRef<any>(null);

const prevMinutes = useRef(initial.current.minutes);
const updateLinePosition = useCallback(() => {
recheckTimezoneOffset?.();
const { date, minutes } = getCurrentMinutes(tzOffset);
if (prevMinutes.current === minutes) {
return;
Expand All @@ -62,7 +59,6 @@ const NowIndicator = ({
duration: 500,
});
}, [
recheckTimezoneOffset,
tzOffset,
start,
timeIntervalHeight.value,
Expand Down
5 changes: 0 additions & 5 deletions src/components/Timeline/TimelinePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ const TimelinePage = ({
updateCurrentDate,
nowIndicatorInterval,
isPinchActive,
recheckTimezoneOffset,
autoRefreshTimezoneOffset,
} = useTimelineCalendarContext();

const eventsByColumns = useMemo(
Expand Down Expand Up @@ -181,9 +179,6 @@ const TimelinePage = ({
tzOffset={tzOffset}
start={start}
updateCurrentDate={updateCurrentDate}
recheckTimezoneOffset={
autoRefreshTimezoneOffset ? recheckTimezoneOffset : undefined
}
nowIndicatorInterval={nowIndicatorInterval}
/>
)}
Expand Down
3 changes: 0 additions & 3 deletions src/components/Timeline/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ const Timeline: React.ForwardRefRenderFunction<
offsetY,
timelineVerticalListRef,
initialTimeIntervalHeight,
recheckTimezoneOffset,
} = useTimelineCalendarContext();
const { goToNextPage, goToPrevPage, goToOffsetY } = useTimelineScroll();

Expand Down Expand Up @@ -143,7 +142,6 @@ const Timeline: React.ForwardRefRenderFunction<
goToOffsetY(Math.max(0, position - 8), animated);
},
forceUpdateNowIndicator: updateCurrentDate,
recheckTimezoneOffset: recheckTimezoneOffset,
zoom: (props?: { scale?: number; height?: number }) => {
let newHeight = props?.height ?? initialTimeIntervalHeight;
if (props?.scale) {
Expand Down Expand Up @@ -179,7 +177,6 @@ const Timeline: React.ForwardRefRenderFunction<
offsetY.value,
timelineVerticalListRef,
initialTimeIntervalHeight,
recheckTimezoneOffset,
]
);

Expand Down
5 changes: 0 additions & 5 deletions src/context/TimelineProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ interface TimelineCalendarContextValue extends CustomTimelineProviderProps {
updateCurrentDate: () => void;
isPinchActive: SharedValue<boolean>;
numOfColumns: number;
recheckTimezoneOffset: () => void;
}

const TimelineCalendarContext = React.createContext<
Expand Down Expand Up @@ -121,7 +120,6 @@ const TimelineProvider: React.FC<TimelineProviderProps> = (props) => {
timeZone = moment.tz.guess(),
nowIndicatorInterval = DEFAULT_PROPS.NOW_INDICATOR_INTERVAL,
navigateDelay = DEFAULT_PROPS.NAVIGATION_DELAY,
autoRefreshTimezoneOffset = false,
calendarWidth,
} = props;

Expand Down Expand Up @@ -264,9 +262,7 @@ const TimelineProvider: React.FC<TimelineProviderProps> = (props) => {
isPinchActive,
navigateDelay,
numOfColumns,
recheckTimezoneOffset: () => {},
initialTimeIntervalHeight,
autoRefreshTimezoneOffset,
};
}, [
pages,
Expand Down Expand Up @@ -312,7 +308,6 @@ const TimelineProvider: React.FC<TimelineProviderProps> = (props) => {
isPinchActive,
navigateDelay,
initialTimeIntervalHeight,
autoRefreshTimezoneOffset,
]);

const mountedRef = useRef(false);
Expand Down
6 changes: 0 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ export interface TimelineCalendarHandle {
* * props is `undefined`: Change `timeIntervalHeight` to initialTimeIntervalHeight
*/
zoom: (props?: { scale?: number; height?: number }) => void;

/** Refresh timezone offset */
recheckTimezoneOffset: () => void;
}

export interface TimelineCalendarProps
Expand Down Expand Up @@ -329,9 +326,6 @@ export interface TimelineProviderProps {
*/
navigateDelay?: number;

/** Auto refresh timezone offset every seconds */
autoRefreshTimezoneOffset?: boolean;

/** Width of calendar */
calendarWidth?: number;
}
Expand Down

0 comments on commit 6e7ce0b

Please sign in to comment.