From d4ad9d48f9fcc4bb4c1743f23fd2dfdf0bcf9a3b Mon Sep 17 00:00:00 2001 From: "satyajit.happy" Date: Sat, 31 Aug 2019 23:10:30 +0200 Subject: [PATCH] refactor: make descriptor.options a getter --- packages/core/src/useDescriptors.tsx | 46 +++++++++++++++------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/packages/core/src/useDescriptors.tsx b/packages/core/src/useDescriptors.tsx index d8778f49..5a791ea7 100644 --- a/packages/core/src/useDescriptors.tsx +++ b/packages/core/src/useDescriptors.tsx @@ -99,13 +99,15 @@ export default function useDescriptors< return state.routes.reduce( (acc, route) => { const screen = screens[route.name]; + const navigation = navigations[route.key]; acc[route.key] = { + navigation, render() { return ( ); }, - options: { - // The default `screenOptions` passed to the navigator - ...(typeof screenOptions === 'object' || screenOptions == null - ? screenOptions - : screenOptions({ - // @ts-ignore - route, - navigation: navigations[route.key], - })), - // The `options` prop passed to `Screen` elements - ...(typeof screen.options === 'object' || screen.options == null - ? screen.options - : screen.options({ - // @ts-ignore - route, - navigation: navigations[route.key], - })), - // The options set via `navigation.setOptions` - ...options[route.key], + get options() { + return { + // The default `screenOptions` passed to the navigator + ...(typeof screenOptions === 'object' || screenOptions == null + ? screenOptions + : screenOptions({ + // @ts-ignore + route, + navigation, + })), + // The `options` prop passed to `Screen` elements + ...(typeof screen.options === 'object' || screen.options == null + ? screen.options + : screen.options({ + // @ts-ignore + route, + navigation, + })), + // The options set via `navigation.setOptions` + ...options[route.key], + }; }, - navigation: navigations[route.key], }; + return acc; }, {} as {