From a99e138839abc8ab84b67489ef9a83a6874778da Mon Sep 17 00:00:00 2001 From: Alberto Blanco Date: Thu, 5 Sep 2019 10:43:25 +0200 Subject: [PATCH] Don't cache values for constants() call (#5442) * Don't cache values for constants() call The reason we can not cache the values is because the implementation differs per OS. Android returns static values while iOS will actually crawl the layout and return it's heights. The caching mechanism here meant that iOS would only return the heights of the layout it calculated the first time. * Update docs regarding inconsistencies in Constants --- docs/docs/constants.md | 2 ++ lib/src/adapters/Constants.ts | 9 ++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/docs/docs/constants.md b/docs/docs/constants.md index 36a89976b09..48374cd8c52 100644 --- a/docs/docs/constants.md +++ b/docs/docs/constants.md @@ -1,5 +1,7 @@ # Constants +!> Note! iOS resolves the values from the currently displayed root. If the current root doesn't contain BottomTabs - it will return 0 as the BottomTabs height while Android will always return a static value. + ## statusBarHeight ```js const constants = await Navigation.constants(); diff --git a/lib/src/adapters/Constants.ts b/lib/src/adapters/Constants.ts index a942ec7fae1..56a78b0a8e3 100644 --- a/lib/src/adapters/Constants.ts +++ b/lib/src/adapters/Constants.ts @@ -9,15 +9,10 @@ export interface NavigationConstants { export class Constants { static async get(): Promise { - if (!this.instance) { - const constants: NavigationConstants = await NativeModules.RNNBridgeModule.getConstants(); - this.instance = new Constants(constants); - } - return this.instance; + const constants: NavigationConstants = await NativeModules.RNNBridgeModule.getConstants(); + return new Constants(constants); } - private static instance: Constants; - public readonly statusBarHeight: number; public readonly backButtonId: string; public readonly topBarHeight: number;