Skip to content
This repository was archived by the owner on Feb 25, 2020. It is now read-only.

Commit 163d5ce

Browse files
committed
fix: don't ignore descriptors change
1 parent 256387e commit 163d5ce

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/views/Stack/StackView.tsx

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type State = {
3030
routes: NavigationRoute[];
3131
// Previous routes, to compare whether routes have changed or not
3232
previousRoutes: NavigationRoute[];
33+
// Previous descriptors, to compare whether descriptors have changed or not
34+
previousDescriptors: SceneDescriptorMap;
3335
// List of routes being opened, we need to animate pushing of these new routes
3436
openingRouteKeys: string[];
3537
// List of routes being closed, we need to animate popping of these routes
@@ -56,6 +58,23 @@ class StackView extends React.Component<Props, State> {
5658
navigation.state.routes === state.previousRoutes &&
5759
state.routes.length
5860
) {
61+
if (props.descriptors !== state.previousDescriptors) {
62+
const descriptors = state.routes.reduce<SceneDescriptorMap>(
63+
(acc, route) => {
64+
acc[route.key] =
65+
props.descriptors[route.key] || state.descriptors[route.key];
66+
67+
return acc;
68+
},
69+
{}
70+
);
71+
72+
return {
73+
previousDescriptors: props.descriptors,
74+
descriptors,
75+
};
76+
}
77+
5978
return null;
6079
}
6180

@@ -185,19 +204,17 @@ class StackView extends React.Component<Props, State> {
185204
throw new Error(`There should always be at least one route.`);
186205
}
187206

188-
const descriptors = routes.reduce(
189-
(acc, route) => {
190-
acc[route.key] =
191-
props.descriptors[route.key] || state.descriptors[route.key];
207+
const descriptors = routes.reduce<SceneDescriptorMap>((acc, route) => {
208+
acc[route.key] =
209+
props.descriptors[route.key] || state.descriptors[route.key];
192210

193-
return acc;
194-
},
195-
{} as SceneDescriptorMap
196-
);
211+
return acc;
212+
}, {});
197213

198214
return {
199215
routes,
200216
previousRoutes: navigation.state.routes,
217+
previousDescriptors: props.descriptors,
201218
openingRouteKeys,
202219
closingRouteKeys,
203220
replacingRouteKeys,
@@ -208,6 +225,7 @@ class StackView extends React.Component<Props, State> {
208225
state: State = {
209226
routes: [],
210227
previousRoutes: [],
228+
previousDescriptors: {},
211229
openingRouteKeys: [],
212230
closingRouteKeys: [],
213231
replacingRouteKeys: [],

0 commit comments

Comments
 (0)