Skip to content

Commit 758aa5c

Browse files
authored
Add FlashList to optional dependencies (#2454)
1 parent f261494 commit 758aa5c

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

src/incubator/Calendar/Agenda.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import React, {useContext, useCallback, useRef} from 'react';
22
import {runOnJS, useAnimatedReaction, useSharedValue} from 'react-native-reanimated';
3-
import {FlashList, ViewToken} from '@shopify/flash-list';
3+
import {FlashListPackage} from 'optionalDeps';
4+
import type {FlashList as FlashListType, ViewToken} from '@shopify/flash-list';
45
import {BorderRadiuses} from 'style';
56
import View from '../../components/view';
67
import Text from '../../components/text';
78
import {isSameDay, isSameMonth} from './helpers/DateUtils';
89
import {InternalEvent, Event, DateSectionHeader, UpdateSource} from './types';
910
import CalendarContext from './CalendarContext';
1011

12+
const {FlashList} = FlashListPackage;
13+
1114
// TODO: Fix initial scrolling
1215
function Agenda() {
1316
const {data, selectedDate, setDate, updateSource} = useContext(CalendarContext);
14-
const flashList = useRef<FlashList<InternalEvent>>(null);
17+
const flashList = useRef<FlashListType<InternalEvent>>(null);
1518
const closestSectionHeader = useSharedValue<DateSectionHeader | null>(null);
1619
const scrolledByUser = useSharedValue<boolean>(false);
1720

src/incubator/Calendar/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import findIndex from 'lodash/findIndex';
22
import React, {PropsWithChildren, useCallback, useMemo, useRef, useEffect} from 'react';
33
import {useSharedValue, useAnimatedReaction, runOnJS} from 'react-native-reanimated';
4-
import {FlashList} from '@shopify/flash-list';
4+
import {FlashListPackage} from 'optionalDeps';
55
import {Constants} from '../../commons/new';
66
import {generateMonthItems} from './helpers/CalendarProcessor';
77
import {addHeaders} from './helpers/DataProcessor';
@@ -13,6 +13,8 @@ import Agenda from './Agenda';
1313
import TodayButton from './TodayButton';
1414
import Header from './Header';
1515

16+
const {FlashList} = FlashListPackage;
17+
1618
// TODO: Move this logic elsewhere to pre-generate on install?
1719
const MONTH_ITEMS = generateMonthItems(2);
1820
const getIndex = (date: number) => {
@@ -105,7 +107,6 @@ function Calendar(props: PropsWithChildren<CalendarProps>) {
105107
<CalendarContext.Provider value={contextValue}>
106108
{staticHeader && <Header/>}
107109
<FlashList
108-
// @ts-expect-error
109110
ref={flashListRef}
110111
estimatedItemSize={calendarWidth}
111112
data={MONTH_ITEMS}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let FlashListPackage: any;
2+
try {
3+
FlashListPackage = require('@shopify/flash-list');
4+
} catch (error) {}
5+
6+
export default FlashListPackage;

src/optionalDependencies/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export {default as DateTimePickerPackage} from './DateTimePickerPackage';
2+
export {default as FlashListPackage} from './FlashListPackage';
23
export {default as BlurViewPackage} from './BlurViewPackage';
34
export {default as NetInfoPackage} from './NetInfoPackage';
45
export {default as HapticFeedbackPackage} from './HapticFeedbackPackage';

0 commit comments

Comments
 (0)