Skip to content

Remove optimization attempt with react-freeze in TabController.TabPage #1784

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 1 commit into from
Jan 18, 2022
Merged
Changes from all commits
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
28 changes: 14 additions & 14 deletions src/components/tabController/TabPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {PropsWithChildren, useCallback, useContext, useState, useMemo} from 'react';
import {StyleSheet} from 'react-native';
import Reanimated, {useAnimatedStyle, useAnimatedReaction, runOnJS} from 'react-native-reanimated';
import {Freeze} from 'react-freeze';
// import {Freeze} from 'react-freeze';
import TabBarContext from './TabBarContext';

export interface TabControllerPageProps {
Expand Down Expand Up @@ -40,7 +40,7 @@ export default function TabPage({
}: PropsWithChildren<TabControllerPageProps>) {
const {currentPage, asCarousel, containerWidth} = useContext(TabBarContext);
const [shouldLoad, setLoaded] = useState(!lazy);
const [focused, setFocused] = useState(false);
// const [focused, setFocused] = useState(false);

const lazyLoad = useCallback(() => {
if (lazy && !shouldLoad) {
Expand All @@ -51,22 +51,22 @@ export default function TabPage({
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);
const wasNearActive =
asCarousel && previousPage !== null && (previousPage - 1 === index || previousPage + 1 === index);
// const wasActive = previousPage === index;
// const nearActive = asCarousel && (currentPage - 1 === index || currentPage + 1 === index);
// const wasNearActive =
// asCarousel && previousPage !== null && (previousPage - 1 === index || previousPage + 1 === index);

if (isActive) {
runOnJS(lazyLoad)();
}

if (isActive || nearActive) {
runOnJS(setFocused)(true);
} else if (wasActive || wasNearActive) {
runOnJS(setFocused)(false);
}
// if (isActive || nearActive) {
// runOnJS(setFocused)(true);
// } else if (wasActive || wasNearActive) {
// runOnJS(setFocused)(false);
// }
},
[currentPage]);

Expand All @@ -85,8 +85,8 @@ export default function TabPage({
return (
<Reanimated.View style={style} testID={testID}>
{!shouldLoad && renderLoading?.()}
{/* {shouldLoad && props.children} */}
<Freeze freeze={!shouldLoad || !focused}>{props.children}</Freeze>
{shouldLoad && props.children}
{/* <Freeze freeze={!shouldLoad || !focused}>{props.children}</Freeze> */}
</Reanimated.View>
);
}
Expand Down