Skip to content

Support old prop in TabPage - lazyLoadTime #1910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generatedTypes/src/components/tabController/TabPage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ export interface TabControllerPageProps {
* @description: TabController's TabPage
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/TabControllerScreen/index.tsx
*/
export default function TabPage({ testID, index, lazy, renderLoading, ...props }: PropsWithChildren<TabControllerPageProps>): JSX.Element;
export default function TabPage({ testID, index, lazy, renderLoading, lazyLoadTime, ...props }: PropsWithChildren<TabControllerPageProps>): JSX.Element;
11 changes: 7 additions & 4 deletions src/components/tabController/TabPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface TabControllerPageProps {
*/
lazy?: boolean;
/**
* How long to wait till lazy load complete (good for showing loader screens)
* How long to wait till lazy load complete (good for showing loader screens and when loading big pages)
*/
lazyLoadTime?: number;
/**
Expand All @@ -36,6 +36,7 @@ export default function TabPage({
index,
lazy,
renderLoading,
lazyLoadTime = 100,
...props
}: PropsWithChildren<TabControllerPageProps>) {
const {currentPage, asCarousel, containerWidth} = useContext(TabBarContext);
Expand All @@ -44,14 +45,16 @@ export default function TabPage({

const lazyLoad = useCallback(() => {
if (lazy && !shouldLoad) {
setLoaded(true);
setTimeout(() => {
setLoaded(true);
}, lazyLoadTime);
}
}, [lazy, shouldLoad]);

useAnimatedReaction(() => {
return currentPage.value;
},
(currentPage/* , previousPage */) => {
(currentPage /* , previousPage */) => {
const isActive = currentPage === index;
// const wasActive = previousPage === index;
// const nearActive = asCarousel && (currentPage - 1 === index || currentPage + 1 === index);
Expand All @@ -68,7 +71,7 @@ export default function TabPage({
// runOnJS(setFocused)(false);
// }
},
[currentPage]);
[currentPage, lazyLoad]);

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