Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(constants): add navigationBarHeight to getConstants() #7809

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public class Constants {
public static final String STATUS_BAR_HEIGHT_KEY = "statusBarHeight";
public static final String TOP_BAR_HEIGHT_KEY = "topBarHeight";
public static final String BOTTOM_TABS_HEIGHT_KEY = "bottomTabsHeight";
public static final String NAVIGATION_BAR_HEIGHT_KEY = "navigationBarHeight";
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ private WritableMap createNavigationConstantsMap() {
constants.putDouble(Constants.BOTTOM_TABS_HEIGHT_KEY, pxToDp(ctx, UiUtils.getBottomTabsHeight(ctx)));
constants.putDouble(Constants.STATUS_BAR_HEIGHT_KEY, pxToDp(ctx, SystemUiUtils.getStatusBarHeight(currentActivity)));
constants.putDouble(Constants.TOP_BAR_HEIGHT_KEY, pxToDp(ctx, UiUtils.getTopBarHeight(ctx)));
constants.putDouble(Constants.NAVIGATION_BAR_HEIGHT_KEY,
pxToDp(ctx, UiUtils.getNavigationBarHeight(ctx)));
return constants;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
public class UiUtils {
private static final int DEFAULT_TOOLBAR_HEIGHT = 56;
private static final int DEFAULT_BOTTOM_TABS_HEIGHT = 56;
private static final int DEFAULT_NAVIGATION_BAR_HEIGHT = 0;

private static int topBarHeight = -1;
private static int bottomTabsHeight = -1;
private static int navigationBarHeight = -1;

public static <T extends View> void runOnPreDrawOnce(@Nullable final T view, final Functions.Func1<T> task) {
if (view == null) return;
Expand Down Expand Up @@ -134,6 +136,17 @@ public static int getBottomTabsHeight(Context context) {
return bottomTabsHeight;
}

public static int getNavigationBarHeight(Context context) {
if (navigationBarHeight > 0) {
return navigationBarHeight;
}
final Resources resources = context.getResources();
final int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
navigationBarHeight = resourceId > 0 ? resources.getDimensionPixelSize(resourceId)
: dpToPx(context, DEFAULT_NAVIGATION_BAR_HEIGHT);
return navigationBarHeight;
}

public static float dpToPx(Context context, float dp) {
Resources resources = context.getResources();
return dpToPx(resources.getDisplayMetrics(), dp);
Expand Down
3 changes: 2 additions & 1 deletion lib/ios/Constants.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ + (NSDictionary *)getConstants {
return @{
@"topBarHeight" : @([self topBarHeight]),
@"statusBarHeight" : @([self statusBarHeight]),
@"bottomTabsHeight" : @([self bottomTabsHeight])
@"bottomTabsHeight" : @([self bottomTabsHeight]),
@"navigationBarHeight" : @(0)
};
}

Expand Down
3 changes: 3 additions & 0 deletions lib/src/adapters/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface NavigationConstants {
backButtonId: string;
topBarHeight: number;
bottomTabsHeight: number;
navigationBarHeight: number;
}

export class Constants {
Expand All @@ -22,11 +23,13 @@ export class Constants {
public readonly backButtonId: string;
public readonly topBarHeight: number;
public readonly bottomTabsHeight: number;
public readonly navigationBarHeight: number;

private constructor(constants: NavigationConstants) {
this.statusBarHeight = constants.statusBarHeight;
this.topBarHeight = constants.topBarHeight;
this.backButtonId = constants.backButtonId;
this.bottomTabsHeight = constants.bottomTabsHeight;
this.navigationBarHeight = constants.navigationBarHeight;
}
}
Loading