react-native-ui-lib 7.40.1-snapshot.6844 → 7.40.1-snapshot.6845
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import React, { useContext, useCallback, useRef } from 'react';
|
|
1
|
+
import React, { useContext, useCallback, useRef, useState } from 'react';
|
|
2
2
|
import { ActivityIndicator, StyleSheet } from 'react-native';
|
|
3
3
|
import { runOnJS, useAnimatedReaction, useSharedValue } from 'react-native-reanimated';
|
|
4
4
|
import { FlashListPackage } from "../../optionalDependencies";
|
|
5
5
|
import { BorderRadiuses, Colors } from "../../style";
|
|
6
|
+
import { useDidUpdate } from "../../hooks";
|
|
6
7
|
import View from "../../components/view";
|
|
7
8
|
import Text from "../../components/text";
|
|
8
9
|
import { isSameDay, isSameMonth } from "./helpers/DateUtils";
|
|
9
10
|
import { UpdateSource } from "./types";
|
|
10
11
|
import CalendarContext from "./CalendarContext";
|
|
11
12
|
const FlashList = FlashListPackage?.FlashList;
|
|
12
|
-
|
|
13
|
-
// TODO: Fix initial scrolling
|
|
14
13
|
function Agenda(props) {
|
|
15
14
|
const {
|
|
16
15
|
renderEvent,
|
|
17
16
|
renderHeader,
|
|
18
|
-
itemHeight = 50,
|
|
19
17
|
onEndReached,
|
|
20
18
|
showLoader
|
|
21
19
|
} = props;
|
|
@@ -28,18 +26,27 @@ function Agenda(props) {
|
|
|
28
26
|
const flashList = useRef(null);
|
|
29
27
|
const closestSectionHeader = useSharedValue(null);
|
|
30
28
|
const scrolledByUser = useSharedValue(false);
|
|
29
|
+
const [stickyHeaderIndices, setStickyHeaderIndices] = useState([]);
|
|
30
|
+
const lastDateBeforeLoadingNewEvents = useSharedValue(selectedDate.value);
|
|
31
31
|
|
|
32
32
|
/* const keyExtractor = useCallback((item: InternalEvent) => {
|
|
33
33
|
return item.type === 'Event' ? item.id : item.header;
|
|
34
34
|
}, []); */
|
|
35
35
|
|
|
36
|
+
useDidUpdate(() => {
|
|
37
|
+
const result = findClosestDateAfter(lastDateBeforeLoadingNewEvents.value);
|
|
38
|
+
if (result?.index) {
|
|
39
|
+
setTimeout(() => scrollToIndex(result?.index, false), 200);
|
|
40
|
+
}
|
|
41
|
+
const headerIndices = data.map((e, index) => e.type === 'Header' ? index : undefined).filter(i => i !== undefined);
|
|
42
|
+
// @ts-expect-error
|
|
43
|
+
setStickyHeaderIndices(headerIndices);
|
|
44
|
+
}, [data]);
|
|
36
45
|
const _renderEvent = useCallback(eventItem => {
|
|
37
46
|
if (renderEvent) {
|
|
38
|
-
return <View
|
|
39
|
-
{renderEvent(eventItem)}
|
|
40
|
-
</View>;
|
|
47
|
+
return <View style={styles.eventContainer}>{renderEvent(eventItem)}</View>;
|
|
41
48
|
}
|
|
42
|
-
return <View marginV-1 marginH-10 paddingH-10
|
|
49
|
+
return <View marginV-1 marginH-10 paddingH-10 centerV style={styles.event}>
|
|
43
50
|
<Text>
|
|
44
51
|
Item for
|
|
45
52
|
{new Date(eventItem.start).toLocaleString('en-GB', {
|
|
@@ -56,15 +63,15 @@ function Agenda(props) {
|
|
|
56
63
|
})}
|
|
57
64
|
</Text>
|
|
58
65
|
</View>;
|
|
59
|
-
}, [renderEvent
|
|
66
|
+
}, [renderEvent]);
|
|
60
67
|
const _renderHeader = useCallback(headerItem => {
|
|
61
68
|
if (renderHeader) {
|
|
62
|
-
return <View
|
|
69
|
+
return <View>{renderHeader(headerItem)}</View>;
|
|
63
70
|
}
|
|
64
|
-
return <View bottom marginB-5 marginH-20
|
|
71
|
+
return <View bg-$backgroundDefault bottom marginB-5 marginH-20>
|
|
65
72
|
<Text>{headerItem.header}</Text>
|
|
66
73
|
</View>;
|
|
67
|
-
}, [renderHeader
|
|
74
|
+
}, [renderHeader]);
|
|
68
75
|
const renderItem = useCallback(({
|
|
69
76
|
item
|
|
70
77
|
}) => {
|
|
@@ -116,6 +123,10 @@ function Agenda(props) {
|
|
|
116
123
|
const _isSameMonth = isSameMonth(selected, previous);
|
|
117
124
|
runOnJS(scrollToIndex)(index, _isSameMonth);
|
|
118
125
|
}
|
|
126
|
+
} else {
|
|
127
|
+
// Note: We got here because we are missing future agenda events to scroll to.
|
|
128
|
+
// therefor we should expect and new events data load
|
|
129
|
+
lastDateBeforeLoadingNewEvents.value = selectedDate.value;
|
|
119
130
|
}
|
|
120
131
|
}
|
|
121
132
|
}
|
|
@@ -148,6 +159,7 @@ function Agenda(props) {
|
|
|
148
159
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
149
160
|
}, []);
|
|
150
161
|
const _onEndReached = useCallback(() => {
|
|
162
|
+
lastDateBeforeLoadingNewEvents.value = selectedDate.value;
|
|
151
163
|
onEndReached?.(selectedDate.value);
|
|
152
164
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
153
165
|
}, [onEndReached]);
|
|
@@ -155,7 +167,7 @@ function Agenda(props) {
|
|
|
155
167
|
<FlashList ref={flashList} estimatedItemSize={52} data={data}
|
|
156
168
|
// TODO: Not sure we need key extractor in flash list
|
|
157
169
|
// keyExtractor={keyExtractor}
|
|
158
|
-
renderItem={renderItem} getItemType={getItemType} onViewableItemsChanged={onViewableItemsChanged} onMomentumScrollBegin={onMomentumScrollBegin} onScrollBeginDrag={onScrollBeginDrag} initialScrollIndex={findClosestDateAfter(selectedDate.value)?.index ?? 0} onEndReached={_onEndReached} />
|
|
170
|
+
renderItem={renderItem} getItemType={getItemType} stickyHeaderIndices={stickyHeaderIndices} onViewableItemsChanged={onViewableItemsChanged} onMomentumScrollBegin={onMomentumScrollBegin} onScrollBeginDrag={onScrollBeginDrag} initialScrollIndex={findClosestDateAfter(selectedDate.value)?.index ?? 0} onEndReached={_onEndReached} />
|
|
159
171
|
{showLoader && <View absF center style={{
|
|
160
172
|
backgroundColor: Colors.rgba(Colors.grey10, 0.2)
|
|
161
173
|
}}>
|
|
@@ -9,6 +9,16 @@ import { getDateObject, getMonthForIndex, addMonths } from "./helpers/DateUtils"
|
|
|
9
9
|
import { DayNamesFormat, UpdateSource } from "./types";
|
|
10
10
|
import CalendarContext from "./CalendarContext";
|
|
11
11
|
import WeekDaysNames from "./WeekDaysNames";
|
|
12
|
+
|
|
13
|
+
// Note: this fixes the updates on the header month title
|
|
14
|
+
Reanimated.addWhitelistedNativeProps({
|
|
15
|
+
text: true
|
|
16
|
+
});
|
|
17
|
+
const ARROWS_THROTTLE_TIME = 300;
|
|
18
|
+
const ARROWS_THROTTLE_OPTIONS = {
|
|
19
|
+
leading: true,
|
|
20
|
+
trailing: false
|
|
21
|
+
};
|
|
12
22
|
const WEEK_NUMBER_WIDTH = 32;
|
|
13
23
|
const ARROW_NEXT = require("./assets/arrowNext.png");
|
|
14
24
|
const ARROW_BACK = require("./assets/arrowBack.png");
|
|
@@ -31,10 +41,10 @@ const Header = props => {
|
|
|
31
41
|
}, []);
|
|
32
42
|
const onLeftArrowPress = useCallback(throttle(() => {
|
|
33
43
|
setDate(getNewDate(-1), UpdateSource.MONTH_ARROW);
|
|
34
|
-
},
|
|
44
|
+
}, ARROWS_THROTTLE_TIME, ARROWS_THROTTLE_OPTIONS), [setDate, getNewDate]);
|
|
35
45
|
const onRightArrowPress = useCallback(throttle(() => {
|
|
36
46
|
setDate(getNewDate(1), UpdateSource.MONTH_ARROW);
|
|
37
|
-
},
|
|
47
|
+
}, ARROWS_THROTTLE_TIME, ARROWS_THROTTLE_OPTIONS), [setDate, getNewDate]);
|
|
38
48
|
const getTitle = useCallback(date => {
|
|
39
49
|
'worklet';
|
|
40
50
|
|
|
@@ -15,12 +15,11 @@ import { useDidUpdate } from "../../hooks";
|
|
|
15
15
|
const FlashList = FlashListPackage?.FlashList;
|
|
16
16
|
const VIEWABILITY_CONFIG = {
|
|
17
17
|
itemVisiblePercentThreshold: 95,
|
|
18
|
-
minimumViewTime:
|
|
18
|
+
minimumViewTime: 1000
|
|
19
19
|
};
|
|
20
|
-
const YEARS_RANGE =
|
|
20
|
+
const YEARS_RANGE = 5;
|
|
21
21
|
const PAGE_RELOAD_THRESHOLD = 3;
|
|
22
|
-
const NOW = Date.
|
|
23
|
-
|
|
22
|
+
const NOW = new Date().setHours(0, 0, 0, 0);
|
|
24
23
|
function Calendar(props) {
|
|
25
24
|
const {
|
|
26
25
|
data,
|
|
@@ -31,20 +30,20 @@ function Calendar(props) {
|
|
|
31
30
|
staticHeader = false,
|
|
32
31
|
showExtraDays = true
|
|
33
32
|
} = props;
|
|
34
|
-
const [
|
|
33
|
+
const [monthItems] = useState(() => generateMonthItems(initialDate, YEARS_RANGE, YEARS_RANGE));
|
|
35
34
|
const getItemIndex = useCallback(date => {
|
|
36
35
|
'worklet';
|
|
37
36
|
|
|
38
37
|
const dateObject = getDateObject(date);
|
|
39
|
-
for (let i = 0; i <
|
|
40
|
-
if (
|
|
38
|
+
for (let i = 0; i < monthItems.length; i++) {
|
|
39
|
+
if (monthItems[i].month === dateObject.month && monthItems[i].year === dateObject.year) {
|
|
41
40
|
return i;
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
return -1;
|
|
45
|
-
}, [
|
|
44
|
+
}, [monthItems]);
|
|
46
45
|
const flashListRef = useRef();
|
|
47
|
-
const current = useSharedValue(initialDate);
|
|
46
|
+
const current = useSharedValue(new Date(initialDate).setHours(0, 0, 0, 0));
|
|
48
47
|
const initialMonthIndex = useRef(getItemIndex(current.value));
|
|
49
48
|
const lastUpdateSource = useSharedValue(UpdateSource.INIT);
|
|
50
49
|
const processedData = useMemo(() => addHeaders(data), [data]);
|
|
@@ -74,7 +73,7 @@ function Calendar(props) {
|
|
|
74
73
|
console.log('Update items');
|
|
75
74
|
const index = getItemIndex(current.value);
|
|
76
75
|
scrollToIndex(index);
|
|
77
|
-
}, [
|
|
76
|
+
}, [monthItems, getItemIndex]);
|
|
78
77
|
const setHeaderHeight = useCallback(height => {
|
|
79
78
|
headerHeight.value = height;
|
|
80
79
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -116,21 +115,21 @@ function Calendar(props) {
|
|
|
116
115
|
// const newDate = addYears(current.value, prepend ? -1 : 1);
|
|
117
116
|
// const newItems = generateMonthItems(newDate, pastRange, futureRange);
|
|
118
117
|
// const newArray = mergeArrays(prepend, items, newItems);
|
|
119
|
-
//
|
|
118
|
+
// setMonthItems(newArray);
|
|
120
119
|
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
121
|
-
}, [
|
|
120
|
+
}, [monthItems]);
|
|
122
121
|
const shouldAddPages = useCallback(index => {
|
|
123
122
|
'worklet';
|
|
124
123
|
|
|
125
|
-
return index !== -1 && (index < PAGE_RELOAD_THRESHOLD || index >
|
|
124
|
+
return index !== -1 && (index < PAGE_RELOAD_THRESHOLD || index > monthItems.length - PAGE_RELOAD_THRESHOLD);
|
|
126
125
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
127
|
-
}, [
|
|
126
|
+
}, [monthItems]);
|
|
128
127
|
useAnimatedReaction(() => {
|
|
129
128
|
return current.value;
|
|
130
129
|
}, (selected, previous) => {
|
|
131
130
|
const index = getItemIndex(selected);
|
|
132
131
|
if (shouldAddPages(index)) {
|
|
133
|
-
console.log('Add new pages: ', index,
|
|
132
|
+
console.log('Add new pages: ', index, monthItems.length);
|
|
134
133
|
runOnJS(addPages)(/* index */);
|
|
135
134
|
} else if (lastUpdateSource.value !== UpdateSource.MONTH_SCROLL) {
|
|
136
135
|
if (previous && !isSameMonth(selected, previous)) {
|
|
@@ -176,7 +175,7 @@ function Calendar(props) {
|
|
|
176
175
|
}, []);
|
|
177
176
|
return <CalendarContext.Provider value={contextValue}>
|
|
178
177
|
{staticHeader && <Header />}
|
|
179
|
-
<FlashList ref={flashListRef} estimatedItemSize={Constants.screenWidth} data={
|
|
178
|
+
<FlashList ref={flashListRef} estimatedItemSize={Constants.screenWidth} data={monthItems} initialScrollIndex={initialMonthIndex.current} estimatedFirstItemOffset={0} renderItem={renderCalendarItem} horizontal pagingEnabled showsHorizontalScrollIndicator={false}
|
|
180
179
|
// TODO: Consider moving this shared logic with Agenda to a hook
|
|
181
180
|
onViewableItemsChanged={onViewableItemsChanged} viewabilityConfig={VIEWABILITY_CONFIG} onMomentumScrollBegin={onMomentumScrollBegin} onScrollBeginDrag={onScrollBeginDrag} />
|
|
182
181
|
{children}
|
|
@@ -113,7 +113,6 @@ export interface CalendarProps {
|
|
|
113
113
|
export interface AgendaProps {
|
|
114
114
|
renderEvent?: (event: Event) => React.ReactElement | null;
|
|
115
115
|
renderHeader?: (header: DateSectionHeader) => React.ReactElement | null;
|
|
116
|
-
itemHeight?: number;
|
|
117
116
|
showLoader?: boolean;
|
|
118
117
|
onEndReached?: (date: number) => void;
|
|
119
118
|
}
|