react-native-ui-lib 7.36.0-snapshot.6093 → 7.36.0-snapshot.6094
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-ui-lib",
|
|
3
|
-
"version": "7.36.0-snapshot.
|
|
3
|
+
"version": "7.36.0-snapshot.6094",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"author": "Ethan Sharabi <ethan.shar@gmail.com>",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@formatjs/intl-locale": "^3.0.3",
|
|
71
71
|
"@formatjs/intl-numberformat": "^8.0.4",
|
|
72
72
|
"@formatjs/intl-pluralrules": "^5.0.3",
|
|
73
|
-
"@react-native-community/blur": "4.
|
|
73
|
+
"@react-native-community/blur": "4.3.0",
|
|
74
74
|
"@react-native-community/datetimepicker": "^3.4.6",
|
|
75
75
|
"@react-native-community/netinfo": "^5.6.2",
|
|
76
76
|
"@react-native/babel-preset": "0.73.21",
|
|
@@ -1,21 +1,21 @@
|
|
|
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) {
|
|
14
|
+
// TODO: Consider removing itemHeight if it's not needed
|
|
15
15
|
const {
|
|
16
16
|
renderEvent,
|
|
17
17
|
renderHeader,
|
|
18
|
-
itemHeight
|
|
18
|
+
itemHeight,
|
|
19
19
|
onEndReached,
|
|
20
20
|
showLoader
|
|
21
21
|
} = props;
|
|
@@ -28,11 +28,22 @@ function Agenda(props) {
|
|
|
28
28
|
const flashList = useRef(null);
|
|
29
29
|
const closestSectionHeader = useSharedValue(null);
|
|
30
30
|
const scrolledByUser = useSharedValue(false);
|
|
31
|
+
const [stickyHeaderIndices, setStickyHeaderIndices] = useState([]);
|
|
32
|
+
const lastDateBeforeLoadingNewEvents = useSharedValue(selectedDate.value);
|
|
31
33
|
|
|
32
34
|
/* const keyExtractor = useCallback((item: InternalEvent) => {
|
|
33
35
|
return item.type === 'Event' ? item.id : item.header;
|
|
34
36
|
}, []); */
|
|
35
37
|
|
|
38
|
+
useDidUpdate(() => {
|
|
39
|
+
const result = findClosestDateAfter(lastDateBeforeLoadingNewEvents.value);
|
|
40
|
+
if (result?.index) {
|
|
41
|
+
setTimeout(() => scrollToIndex(result?.index, false), 200);
|
|
42
|
+
}
|
|
43
|
+
const headerIndices = data.map((e, index) => e.type === 'Header' ? index : undefined).filter(i => i !== undefined);
|
|
44
|
+
// @ts-expect-error
|
|
45
|
+
setStickyHeaderIndices(headerIndices);
|
|
46
|
+
}, [data]);
|
|
36
47
|
const _renderEvent = useCallback(eventItem => {
|
|
37
48
|
if (renderEvent) {
|
|
38
49
|
return <View height={itemHeight} style={styles.eventContainer}>
|
|
@@ -61,7 +72,7 @@ function Agenda(props) {
|
|
|
61
72
|
if (renderHeader) {
|
|
62
73
|
return <View height={itemHeight}>{renderHeader(headerItem)}</View>;
|
|
63
74
|
}
|
|
64
|
-
return <View bottom marginB-5 marginH-20 height={itemHeight}>
|
|
75
|
+
return <View bg-$backgroundDefault bottom marginB-5 marginH-20 height={itemHeight}>
|
|
65
76
|
<Text>{headerItem.header}</Text>
|
|
66
77
|
</View>;
|
|
67
78
|
}, [renderHeader, itemHeight]);
|
|
@@ -116,6 +127,10 @@ function Agenda(props) {
|
|
|
116
127
|
const _isSameMonth = isSameMonth(selected, previous);
|
|
117
128
|
runOnJS(scrollToIndex)(index, _isSameMonth);
|
|
118
129
|
}
|
|
130
|
+
} else {
|
|
131
|
+
// Note: We got here because we are missing future agenda events to scroll to.
|
|
132
|
+
// therefor we should expect and new events data load
|
|
133
|
+
lastDateBeforeLoadingNewEvents.value = selectedDate.value;
|
|
119
134
|
}
|
|
120
135
|
}
|
|
121
136
|
}
|
|
@@ -148,6 +163,7 @@ function Agenda(props) {
|
|
|
148
163
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
149
164
|
}, []);
|
|
150
165
|
const _onEndReached = useCallback(() => {
|
|
166
|
+
lastDateBeforeLoadingNewEvents.value = selectedDate.value;
|
|
151
167
|
onEndReached?.(selectedDate.value);
|
|
152
168
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
153
169
|
}, [onEndReached]);
|
|
@@ -155,7 +171,7 @@ function Agenda(props) {
|
|
|
155
171
|
<FlashList ref={flashList} estimatedItemSize={52} data={data}
|
|
156
172
|
// TODO: Not sure we need key extractor in flash list
|
|
157
173
|
// keyExtractor={keyExtractor}
|
|
158
|
-
renderItem={renderItem} getItemType={getItemType} onViewableItemsChanged={onViewableItemsChanged} onMomentumScrollBegin={onMomentumScrollBegin} onScrollBeginDrag={onScrollBeginDrag} initialScrollIndex={findClosestDateAfter(selectedDate.value)?.index ?? 0} onEndReached={_onEndReached} />
|
|
174
|
+
renderItem={renderItem} getItemType={getItemType} stickyHeaderIndices={stickyHeaderIndices} onViewableItemsChanged={onViewableItemsChanged} onMomentumScrollBegin={onMomentumScrollBegin} onScrollBeginDrag={onScrollBeginDrag} initialScrollIndex={findClosestDateAfter(selectedDate.value)?.index ?? 0} onEndReached={_onEndReached} />
|
|
159
175
|
{showLoader && <View absF center style={{
|
|
160
176
|
backgroundColor: Colors.rgba(Colors.grey10, 0.2)
|
|
161
177
|
}}>
|
|
@@ -9,6 +9,12 @@ 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;
|
|
12
18
|
const WEEK_NUMBER_WIDTH = 32;
|
|
13
19
|
const ARROW_NEXT = require("./assets/arrowNext.png");
|
|
14
20
|
const ARROW_BACK = require("./assets/arrowBack.png");
|
|
@@ -31,10 +37,16 @@ const Header = props => {
|
|
|
31
37
|
}, []);
|
|
32
38
|
const onLeftArrowPress = useCallback(throttle(() => {
|
|
33
39
|
setDate(getNewDate(-1), UpdateSource.MONTH_ARROW);
|
|
34
|
-
},
|
|
40
|
+
}, ARROWS_THROTTLE_TIME, {
|
|
41
|
+
leading: true,
|
|
42
|
+
trailing: false
|
|
43
|
+
}), [setDate, getNewDate]);
|
|
35
44
|
const onRightArrowPress = useCallback(throttle(() => {
|
|
36
45
|
setDate(getNewDate(1), UpdateSource.MONTH_ARROW);
|
|
37
|
-
},
|
|
46
|
+
}, ARROWS_THROTTLE_TIME, {
|
|
47
|
+
leading: true,
|
|
48
|
+
trailing: false
|
|
49
|
+
}), [setDate, getNewDate]);
|
|
38
50
|
const getTitle = useCallback(date => {
|
|
39
51
|
'worklet';
|
|
40
52
|
|
|
@@ -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,7 @@ 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;
|
|
116
|
+
itemHeight?: number | null;
|
|
117
117
|
showLoader?: boolean;
|
|
118
118
|
onEndReached?: (date: number) => void;
|
|
119
119
|
}
|