Skip to content

Commit

Permalink
Don't cache values for constants() call (#5442)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ItsNoHax authored and guyca committed Sep 5, 2019
1 parent d41f164 commit a99e138
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/docs/constants.md
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
9 changes: 2 additions & 7 deletions lib/src/adapters/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ export interface NavigationConstants {

export class Constants {
static async get(): Promise<NavigationConstants> {
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;
Expand Down

0 comments on commit a99e138

Please sign in to comment.