瀏覽代碼

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
Alberto Blanco 5 年之前
父節點
當前提交
a99e138839
共有 2 個檔案被更改,包括 4 行新增7 行删除
  1. 2
    0
      docs/docs/constants.md
  2. 2
    7
      lib/src/adapters/Constants.ts

+ 2
- 0
docs/docs/constants.md 查看文件

@@ -1,5 +1,7 @@
1 1
 # Constants
2 2
 
3
+!> 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.
4
+
3 5
 ## statusBarHeight
4 6
 ```js
5 7
 const constants = await Navigation.constants();

+ 2
- 7
lib/src/adapters/Constants.ts 查看文件

@@ -9,15 +9,10 @@ export interface NavigationConstants {
9 9
 
10 10
 export class Constants {
11 11
   static async get(): Promise<NavigationConstants> {
12
-    if (!this.instance) {
13
-      const constants: NavigationConstants = await NativeModules.RNNBridgeModule.getConstants();
14
-      this.instance = new Constants(constants);
15
-    }
16
-    return this.instance;
12
+    const constants: NavigationConstants = await NativeModules.RNNBridgeModule.getConstants();
13
+    return new Constants(constants);
17 14
   }
18 15
 
19
-  private static instance: Constants;
20
-
21 16
   public readonly statusBarHeight: number;
22 17
   public readonly backButtonId: string;
23 18
   public readonly topBarHeight: number;