Comments (16)
Couldn't find version numbers for the following packages in the issue:
react-native
Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.
The versions mentioned in the issue for the following packages differ from the latest versions on npm:
react-native-tab-view
(found:3.0.0
, latest:3.2.1
)react-native-pager-view
(found:4.2.4
, latest:6.0.1
)expo
(found:46.0.0
, latest:46.0.14
)
Can you verify that the issue still exists after upgrading to the latest versions of these packages?
from react-native-tab-view.
Couldn't find version numbers for the following packages in the issue:
react-native
Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.
The versions mentioned in the issue for the following packages differ from the latest versions on npm:
expo
(found:46.0.0
, latest:46.0.14
)
Can you verify that the issue still exists after upgrading to the latest versions of these packages?
from react-native-tab-view.
I also tried replacing the renderScene
by a simple function, but this leads to the same bug:
const renderScene = React.useCallback(({route}: {route: RouteParams}) =>
<Route {...route}/>, []
);
from react-native-tab-view.
The bug also appears with static routes, the following also triggers useless re-renders even though the code uses constants in the Nav
component.
const renderScene = SceneMap({0: Route, 1: Route});
const routes = routesParams(2);
function Nav({nbTabs}:{nbTabs: number}){
const [index, setIndex] = React.useState(0);
return <TabView
navigationState={{ index, routes }}
renderScene={renderScene}
onIndexChange={setIndex}
/>
}
from react-native-tab-view.
https://github.com/satya164/react-native-tab-view#avoid-unnecessary-re-renders
from react-native-tab-view.
If there's a bug with SceneMap
or React.memo
/React.PureComponent
please open a separate issue with repro. Creating components in render/useMemo
/useCallback
aren't for memoing a component.
from react-native-tab-view.
Yes there is a bug with SceneMap
. Render functions passed into it are called multiple times. I provided a reproduction here.
from react-native-tab-view.
SceneMap
doesn't accept render functions. It accepts React components which should be defined outside of other components.
from react-native-tab-view.
Then the documentation is out of date as it clearly states that SceneMap
excpect an objetct with key to function maping.
const FirstRoute = () => (...);
const renderScene = SceneMap({
first: FirstRoute,
});
from react-native-tab-view.
That's a component defined outside of a component, not a regular function. Documentation also explicitly says not to pass a inline function: https://github.com/satya164/react-native-tab-view#renderscene-required
from react-native-tab-view.
Changing the code to:
const renderScene = SceneMap(
Object.fromEntries(
routes.map((c) => [
c.key,
Route,
])
)
);
Doesn't make any difference. The problem is that render functions are called even when the input props (route params for exemple) are untouched.
from react-native-tab-view.
please open a new issue with a minimal repro that uses only SceneMap
/React.memo
if it's not working properly
from react-native-tab-view.
Why a new one? This one shows exactly how it's not working properly.
I think I found the issue in the code, here there is something like:
return (
<>
{
navigationState.routes.map((route, i) => {
renderScene(route);
})
};
</>
);
But it should be something like:
const scenes = useMemo(() => {
navigationState.routes.map((route, i) => {
renderScene(route);
});
}, [navigationState.routes]);
return <>{scenes}</>;
from react-native-tab-view.
This one has incorrect snack and incorrect code in the description. It's better to create a new issue with proper code and repro so the person looking into it doesn't need to read the whole discussion.
from react-native-tab-view.
What do you mean "incorrect snack"? The snack shows an example where route props are not managed properly even when using SceneMap
.
from react-native-tab-view.
But it should be something like:
Memoizing components doesn't work that way. This is also unsafe and will prevent re-renders even if renderScene
refers to a variable in the closure. If renderScene
is used inside useMemo
then it should be in dependency array to be used safely.
What do you mean "incorrect snack"
As I said, you cannot create components inside other components which is what your snack does and the documentation explicitly says not to do. Please create a minimal repro following the docs if there is a bug.
from react-native-tab-view.
Related Issues (20)
- Can we support a sticky tab bar to support render a header component for tab view HOT 7
- Does not scroll to latest content HOT 6
- Tabs switch incorrectly when swipe is released over another element HOT 5
- Tab label gets faded out while swiping HOT 6
- How to not rerender all tabs when swipe to another tab ? HOT 3
- Supporting Reanimated 3 HOT 3
- Can i jumpTo withoutAnimation? HOT 5
- [@react-navigation/material-top-tabs] gestureResponseDistance does not work when top tabs nested within a stack navigator HOT 4
- IOS Not full animation to the pressed tab when keyboard is opened HOT 5
- Tab View inside Flatlist not shown content HOT 5
- Collapsible Header HOT 7
- Color the inactive bar HOT 3
- index in navigationState is ignored HOT 2
- Many useless re-renders HOT 2
- Extra height on tab view with fabric enabled HOT 8
- Migrate to Material You tabs design HOT 2
- Lagging during vertical scroll when using webview on android HOT 2
- The tab header not sync with scene swipe when header is long HOT 2
- Initial tab in child tab view flickers while using react-native-tab-view HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-tab-view.