react-native-ui-lib 7.36.0-snapshot.6094 → 7.36.0-snapshot.6098
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 +2 -2
- package/src/components/floatingButton/index.js +0 -1
- package/src/components/tabController/TabBar.js +2 -1
- package/src/components/tabController/TabBarContext.d.ts +1 -0
- package/src/components/tabController/TabBarItem.js +5 -2
- package/src/components/tabController/index.js +4 -1
- package/src/incubator/calendar/Agenda.js +6 -22
- package/src/incubator/calendar/Header.js +2 -14
- package/src/incubator/calendar/index.js +16 -15
- package/src/incubator/calendar/types.d.ts +1 -1
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.6098",
|
|
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.4.1",
|
|
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",
|
|
@@ -149,7 +149,8 @@ const TabBar = props => {
|
|
|
149
149
|
}, [labelColor, selectedLabelColor]);
|
|
150
150
|
return <View style={_containerStyle} key={key} bg-$backgroundElevated>
|
|
151
151
|
<FadedScrollView ref={tabBar} horizontal showsHorizontalScrollIndicator={false} showStartFader startFaderProps={faderProps} showEndFader endFaderProps={faderProps} contentContainerStyle={scrollViewContainerStyle} testID={testID} onContentSizeChange={onContentSizeChange} onLayout={onLayout}>
|
|
152
|
-
|
|
152
|
+
{/* TODO: Might need to change role to tablist, when upgrading rn77. It didn't work now (rn73) */}
|
|
153
|
+
<View style={tabBarContainerStyle} accessibilityRole="tabbar">{tabBarItems}</View>
|
|
153
154
|
{itemsCount > 1 && <Reanimated.View style={[styles.selectedIndicator, indicatorStyle, _indicatorTransitionStyle]} />}
|
|
154
155
|
</FadedScrollView>
|
|
155
156
|
</View>;
|
|
@@ -13,6 +13,7 @@ interface TabControllerContext {
|
|
|
13
13
|
/** transition page index (can be a fraction when transitioning between pages) */
|
|
14
14
|
targetPage: Reanimated.SharedValue<number>;
|
|
15
15
|
setCurrentIndex: (index: number) => void;
|
|
16
|
+
selectedIndex: number;
|
|
16
17
|
}
|
|
17
18
|
declare const TabBarContext: React.Context<TabControllerContext>;
|
|
18
19
|
export default TabBarContext;
|
|
@@ -44,7 +44,8 @@ export default function TabBarItem({
|
|
|
44
44
|
}) {
|
|
45
45
|
const {
|
|
46
46
|
currentPage,
|
|
47
|
-
setCurrentIndex
|
|
47
|
+
setCurrentIndex,
|
|
48
|
+
selectedIndex
|
|
48
49
|
} = useContext(TabBarContext);
|
|
49
50
|
const itemRef = useRef();
|
|
50
51
|
const itemWidth = useRef(props.width);
|
|
@@ -133,7 +134,9 @@ export default function TabBarItem({
|
|
|
133
134
|
return <GestureDetector gesture={gesture}>
|
|
134
135
|
<View reanimated
|
|
135
136
|
// @ts-expect-error
|
|
136
|
-
ref={itemRef} style={_style} onLayout={onLayout} testID={testID}
|
|
137
|
+
ref={itemRef} style={_style} onLayout={onLayout} testID={testID} accessible accessibilityRole="tab" accessibilityState={{
|
|
138
|
+
selected: selectedIndex === index
|
|
139
|
+
}}>
|
|
137
140
|
{leadingAccessory}
|
|
138
141
|
{icon && <Reanimated.Image source={icon} style={[!_isUndefined(label) && styles.tabItemIconWithLabel, animatedIconStyle]} />}
|
|
139
142
|
{!_isEmpty(label) && <Reanimated.Text {...labelProps} fsTagName={'unmask'} style={[styles.tabItemLabel, labelStyle, animatedLabelStyle, animatedLabelColorStyle]}>
|
|
@@ -38,6 +38,7 @@ const TabController = React.forwardRef((props, ref) => {
|
|
|
38
38
|
children
|
|
39
39
|
} = themeProps;
|
|
40
40
|
const [screenWidth, setScreenWidth] = useState(getScreenWidth(useSafeArea));
|
|
41
|
+
const [selectedIndex, setSelectedIndex] = useState(initialIndex);
|
|
41
42
|
if (items?.length < 2) {
|
|
42
43
|
console.warn('TabController component expect a minimum of 2 items');
|
|
43
44
|
}
|
|
@@ -61,6 +62,7 @@ const TabController = React.forwardRef((props, ref) => {
|
|
|
61
62
|
'worklet';
|
|
62
63
|
|
|
63
64
|
currentPage.value = index;
|
|
65
|
+
runOnJS(setSelectedIndex)(index);
|
|
64
66
|
}, []);
|
|
65
67
|
useEffect(() => {
|
|
66
68
|
setCurrentIndex(initialIndex);
|
|
@@ -88,12 +90,13 @@ const TabController = React.forwardRef((props, ref) => {
|
|
|
88
90
|
/* Animated Values */
|
|
89
91
|
targetPage,
|
|
90
92
|
currentPage,
|
|
93
|
+
selectedIndex,
|
|
91
94
|
containerWidth: screenWidth,
|
|
92
95
|
/* Callbacks */
|
|
93
96
|
onChangeIndex,
|
|
94
97
|
setCurrentIndex
|
|
95
98
|
};
|
|
96
|
-
}, [initialIndex, asCarousel, items, onChangeIndex, screenWidth, nestedInScrollView]);
|
|
99
|
+
}, [initialIndex, asCarousel, items, onChangeIndex, screenWidth, nestedInScrollView, selectedIndex]);
|
|
97
100
|
return <TabBarContext.Provider value={context}>{children}</TabBarContext.Provider>;
|
|
98
101
|
});
|
|
99
102
|
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import React, { useContext, useCallback, useRef
|
|
1
|
+
import React, { useContext, useCallback, useRef } 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";
|
|
7
6
|
import View from "../../components/view";
|
|
8
7
|
import Text from "../../components/text";
|
|
9
8
|
import { isSameDay, isSameMonth } from "./helpers/DateUtils";
|
|
10
9
|
import { UpdateSource } from "./types";
|
|
11
10
|
import CalendarContext from "./CalendarContext";
|
|
12
11
|
const FlashList = FlashListPackage?.FlashList;
|
|
12
|
+
|
|
13
|
+
// TODO: Fix initial scrolling
|
|
13
14
|
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 = 50,
|
|
19
19
|
onEndReached,
|
|
20
20
|
showLoader
|
|
21
21
|
} = props;
|
|
@@ -28,22 +28,11 @@ 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);
|
|
33
31
|
|
|
34
32
|
/* const keyExtractor = useCallback((item: InternalEvent) => {
|
|
35
33
|
return item.type === 'Event' ? item.id : item.header;
|
|
36
34
|
}, []); */
|
|
37
35
|
|
|
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]);
|
|
47
36
|
const _renderEvent = useCallback(eventItem => {
|
|
48
37
|
if (renderEvent) {
|
|
49
38
|
return <View height={itemHeight} style={styles.eventContainer}>
|
|
@@ -72,7 +61,7 @@ function Agenda(props) {
|
|
|
72
61
|
if (renderHeader) {
|
|
73
62
|
return <View height={itemHeight}>{renderHeader(headerItem)}</View>;
|
|
74
63
|
}
|
|
75
|
-
return <View
|
|
64
|
+
return <View bottom marginB-5 marginH-20 height={itemHeight}>
|
|
76
65
|
<Text>{headerItem.header}</Text>
|
|
77
66
|
</View>;
|
|
78
67
|
}, [renderHeader, itemHeight]);
|
|
@@ -127,10 +116,6 @@ function Agenda(props) {
|
|
|
127
116
|
const _isSameMonth = isSameMonth(selected, previous);
|
|
128
117
|
runOnJS(scrollToIndex)(index, _isSameMonth);
|
|
129
118
|
}
|
|
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;
|
|
134
119
|
}
|
|
135
120
|
}
|
|
136
121
|
}
|
|
@@ -163,7 +148,6 @@ function Agenda(props) {
|
|
|
163
148
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
164
149
|
}, []);
|
|
165
150
|
const _onEndReached = useCallback(() => {
|
|
166
|
-
lastDateBeforeLoadingNewEvents.value = selectedDate.value;
|
|
167
151
|
onEndReached?.(selectedDate.value);
|
|
168
152
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
169
153
|
}, [onEndReached]);
|
|
@@ -171,7 +155,7 @@ function Agenda(props) {
|
|
|
171
155
|
<FlashList ref={flashList} estimatedItemSize={52} data={data}
|
|
172
156
|
// TODO: Not sure we need key extractor in flash list
|
|
173
157
|
// keyExtractor={keyExtractor}
|
|
174
|
-
renderItem={renderItem} getItemType={getItemType}
|
|
158
|
+
renderItem={renderItem} getItemType={getItemType} onViewableItemsChanged={onViewableItemsChanged} onMomentumScrollBegin={onMomentumScrollBegin} onScrollBeginDrag={onScrollBeginDrag} initialScrollIndex={findClosestDateAfter(selectedDate.value)?.index ?? 0} onEndReached={_onEndReached} />
|
|
175
159
|
{showLoader && <View absF center style={{
|
|
176
160
|
backgroundColor: Colors.rgba(Colors.grey10, 0.2)
|
|
177
161
|
}}>
|
|
@@ -9,12 +9,6 @@ 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
12
|
const WEEK_NUMBER_WIDTH = 32;
|
|
19
13
|
const ARROW_NEXT = require("./assets/arrowNext.png");
|
|
20
14
|
const ARROW_BACK = require("./assets/arrowBack.png");
|
|
@@ -37,16 +31,10 @@ const Header = props => {
|
|
|
37
31
|
}, []);
|
|
38
32
|
const onLeftArrowPress = useCallback(throttle(() => {
|
|
39
33
|
setDate(getNewDate(-1), UpdateSource.MONTH_ARROW);
|
|
40
|
-
},
|
|
41
|
-
leading: true,
|
|
42
|
-
trailing: false
|
|
43
|
-
}), [setDate, getNewDate]);
|
|
34
|
+
}, 300), [setDate, getNewDate]);
|
|
44
35
|
const onRightArrowPress = useCallback(throttle(() => {
|
|
45
36
|
setDate(getNewDate(1), UpdateSource.MONTH_ARROW);
|
|
46
|
-
},
|
|
47
|
-
leading: true,
|
|
48
|
-
trailing: false
|
|
49
|
-
}), [setDate, getNewDate]);
|
|
37
|
+
}, 300), [setDate, getNewDate]);
|
|
50
38
|
const getTitle = useCallback(date => {
|
|
51
39
|
'worklet';
|
|
52
40
|
|
|
@@ -15,11 +15,12 @@ import { useDidUpdate } from "../../hooks";
|
|
|
15
15
|
const FlashList = FlashListPackage?.FlashList;
|
|
16
16
|
const VIEWABILITY_CONFIG = {
|
|
17
17
|
itemVisiblePercentThreshold: 95,
|
|
18
|
-
minimumViewTime:
|
|
18
|
+
minimumViewTime: 200
|
|
19
19
|
};
|
|
20
|
-
const YEARS_RANGE =
|
|
20
|
+
const YEARS_RANGE = 1;
|
|
21
21
|
const PAGE_RELOAD_THRESHOLD = 3;
|
|
22
|
-
const NOW =
|
|
22
|
+
const NOW = Date.now(); // so the 'initialDate' effect won't get called since the now different on every rerender
|
|
23
|
+
|
|
23
24
|
function Calendar(props) {
|
|
24
25
|
const {
|
|
25
26
|
data,
|
|
@@ -30,20 +31,20 @@ function Calendar(props) {
|
|
|
30
31
|
staticHeader = false,
|
|
31
32
|
showExtraDays = true
|
|
32
33
|
} = props;
|
|
33
|
-
const [
|
|
34
|
+
const [items] = useState(() => generateMonthItems(initialDate, YEARS_RANGE, YEARS_RANGE));
|
|
34
35
|
const getItemIndex = useCallback(date => {
|
|
35
36
|
'worklet';
|
|
36
37
|
|
|
37
38
|
const dateObject = getDateObject(date);
|
|
38
|
-
for (let i = 0; i <
|
|
39
|
-
if (
|
|
39
|
+
for (let i = 0; i < items.length; i++) {
|
|
40
|
+
if (items[i].month === dateObject.month && items[i].year === dateObject.year) {
|
|
40
41
|
return i;
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
return -1;
|
|
44
|
-
}, [
|
|
45
|
+
}, [items]);
|
|
45
46
|
const flashListRef = useRef();
|
|
46
|
-
const current = useSharedValue(
|
|
47
|
+
const current = useSharedValue(initialDate);
|
|
47
48
|
const initialMonthIndex = useRef(getItemIndex(current.value));
|
|
48
49
|
const lastUpdateSource = useSharedValue(UpdateSource.INIT);
|
|
49
50
|
const processedData = useMemo(() => addHeaders(data), [data]);
|
|
@@ -73,7 +74,7 @@ function Calendar(props) {
|
|
|
73
74
|
console.log('Update items');
|
|
74
75
|
const index = getItemIndex(current.value);
|
|
75
76
|
scrollToIndex(index);
|
|
76
|
-
}, [
|
|
77
|
+
}, [items, getItemIndex]);
|
|
77
78
|
const setHeaderHeight = useCallback(height => {
|
|
78
79
|
headerHeight.value = height;
|
|
79
80
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -115,21 +116,21 @@ function Calendar(props) {
|
|
|
115
116
|
// const newDate = addYears(current.value, prepend ? -1 : 1);
|
|
116
117
|
// const newItems = generateMonthItems(newDate, pastRange, futureRange);
|
|
117
118
|
// const newArray = mergeArrays(prepend, items, newItems);
|
|
118
|
-
//
|
|
119
|
+
// setItems(newArray);
|
|
119
120
|
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
120
|
-
}, [
|
|
121
|
+
}, [items]);
|
|
121
122
|
const shouldAddPages = useCallback(index => {
|
|
122
123
|
'worklet';
|
|
123
124
|
|
|
124
|
-
return index !== -1 && (index < PAGE_RELOAD_THRESHOLD || index >
|
|
125
|
+
return index !== -1 && (index < PAGE_RELOAD_THRESHOLD || index > items.length - PAGE_RELOAD_THRESHOLD);
|
|
125
126
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
126
|
-
}, [
|
|
127
|
+
}, [items]);
|
|
127
128
|
useAnimatedReaction(() => {
|
|
128
129
|
return current.value;
|
|
129
130
|
}, (selected, previous) => {
|
|
130
131
|
const index = getItemIndex(selected);
|
|
131
132
|
if (shouldAddPages(index)) {
|
|
132
|
-
console.log('Add new pages: ', index,
|
|
133
|
+
console.log('Add new pages: ', index, items.length);
|
|
133
134
|
runOnJS(addPages)(/* index */);
|
|
134
135
|
} else if (lastUpdateSource.value !== UpdateSource.MONTH_SCROLL) {
|
|
135
136
|
if (previous && !isSameMonth(selected, previous)) {
|
|
@@ -175,7 +176,7 @@ function Calendar(props) {
|
|
|
175
176
|
}, []);
|
|
176
177
|
return <CalendarContext.Provider value={contextValue}>
|
|
177
178
|
{staticHeader && <Header />}
|
|
178
|
-
<FlashList ref={flashListRef} estimatedItemSize={Constants.screenWidth} data={
|
|
179
|
+
<FlashList ref={flashListRef} estimatedItemSize={Constants.screenWidth} data={items} initialScrollIndex={initialMonthIndex.current} estimatedFirstItemOffset={0} renderItem={renderCalendarItem} horizontal pagingEnabled showsHorizontalScrollIndicator={false}
|
|
179
180
|
// TODO: Consider moving this shared logic with Agenda to a hook
|
|
180
181
|
onViewableItemsChanged={onViewableItemsChanged} viewabilityConfig={VIEWABILITY_CONFIG} onMomentumScrollBegin={onMomentumScrollBegin} onScrollBeginDrag={onScrollBeginDrag} />
|
|
181
182
|
{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;
|
|
117
117
|
showLoader?: boolean;
|
|
118
118
|
onEndReached?: (date: number) => void;
|
|
119
119
|
}
|