Skip to content

Commit 850dadb

Browse files
authored
Support old prop in TabPage - lazyLoadTime (#1910)
1 parent 6183f55 commit 850dadb

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

generatedTypes/src/components/tabController/TabPage.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ export interface TabControllerPageProps {
2525
* @description: TabController's TabPage
2626
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/TabControllerScreen/index.tsx
2727
*/
28-
export default function TabPage({ testID, index, lazy, renderLoading, ...props }: PropsWithChildren<TabControllerPageProps>): JSX.Element;
28+
export default function TabPage({ testID, index, lazy, renderLoading, lazyLoadTime, ...props }: PropsWithChildren<TabControllerPageProps>): JSX.Element;

src/components/tabController/TabPage.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface TabControllerPageProps {
1414
*/
1515
lazy?: boolean;
1616
/**
17-
* How long to wait till lazy load complete (good for showing loader screens)
17+
* How long to wait till lazy load complete (good for showing loader screens and when loading big pages)
1818
*/
1919
lazyLoadTime?: number;
2020
/**
@@ -36,6 +36,7 @@ export default function TabPage({
3636
index,
3737
lazy,
3838
renderLoading,
39+
lazyLoadTime = 100,
3940
...props
4041
}: PropsWithChildren<TabControllerPageProps>) {
4142
const {currentPage, asCarousel, containerWidth} = useContext(TabBarContext);
@@ -44,14 +45,16 @@ export default function TabPage({
4445

4546
const lazyLoad = useCallback(() => {
4647
if (lazy && !shouldLoad) {
47-
setLoaded(true);
48+
setTimeout(() => {
49+
setLoaded(true);
50+
}, lazyLoadTime);
4851
}
4952
}, [lazy, shouldLoad]);
5053

5154
useAnimatedReaction(() => {
5255
return currentPage.value;
5356
},
54-
(currentPage/* , previousPage */) => {
57+
(currentPage /* , previousPage */) => {
5558
const isActive = currentPage === index;
5659
// const wasActive = previousPage === index;
5760
// const nearActive = asCarousel && (currentPage - 1 === index || currentPage + 1 === index);
@@ -68,7 +71,7 @@ export default function TabPage({
6871
// runOnJS(setFocused)(false);
6972
// }
7073
},
71-
[currentPage]);
74+
[currentPage, lazyLoad]);
7275

7376
const animatedPageStyle = useAnimatedStyle(() => {
7477
const isActive = Math.round(currentPage.value) === index;

0 commit comments

Comments
 (0)