Skip to content

Commit fd49245

Browse files
authored
[#578]优化menubar坐标返回基于页面参数返回 (#579)
1 parent dbffb15 commit fd49245

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

core/runtime/android/runtime/src/main/java/org/hapjs/render/Display.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,7 @@ private void scrollBy(int y, boolean isSmooth) {
20072007
}
20082008
}
20092009

2010-
Rect getContentInsets() {
2010+
public Rect getContentInsets() {
20112011
int topCutoutHeight = mTopCutoutView != null ? mTopCutoutView.getLayoutParams().height : 0;
20122012
int leftCutouWidth = mLeftCutoutView != null ? mLeftCutoutView.getLayoutParams().width : 0;
20132013
int titleHeight = mToolbar == null ? 0 : mToolbar.getLayoutParams().height;

core/runtime/android/runtime/src/main/java/org/hapjs/render/jsruntime/module/PageModule.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public class PageModule extends ModuleExtension {
5252
protected static final String RESULT_MENU_BAR_TOP = "menuBarTop";
5353
protected static final String RESULT_MENU_BAR_RIGHT = "menuBarRight";
5454
protected static final String RESULT_MENU_BAR_BOTTOM = "menuBarBottom";
55+
protected static final String RESULT_MENU_BAR_PAGE_LEFT = "menuBarPageLeft";
56+
protected static final String RESULT_MENU_BAR_PAGE_RIGHT = "menuBarPageRight";
57+
protected static final String RESULT_MENU_BAR_PAGE_TOP = "menuBarPageTop";
58+
protected static final String RESULT_MENU_BAR_PAGE_BOTTOM = "menuBarPageBottom";
5559
protected static final String ACTION_SET_MENUBAR_DATA = "setMenubarData";
5660
protected static final String ACTION_SET_MENUBAR_TIPS = "setMenubarTips";
5761
protected static final String ACTION_SET_TABBAR_ITEM = "setTabBarItem";
@@ -135,12 +139,17 @@ private Response getMenuBarBoundingRect(Request request) throws JSONException {
135139
JSONObject result = new JSONObject();
136140
Display display = getDisPlay(request);
137141
View menubarView = null;
142+
Rect contentInsets = null;
138143
if (null != display) {
139144
menubarView = display.getMenuBar();
145+
contentInsets = display.getContentInsets();
140146
}
141147
Rect rect = new Rect();
148+
int[] positionWindow = null;
142149
if (null != menubarView) {
143150
menubarView.getGlobalVisibleRect(rect);
151+
positionWindow = new int[2];
152+
menubarView.getLocationInWindow(positionWindow);
144153
}
145154
int designWidth = -1;
146155
HapEngine hapEngine = null;
@@ -157,6 +166,12 @@ private Response getMenuBarBoundingRect(Request request) throws JSONException {
157166
result.put(RESULT_MENU_BAR_TOP, DisplayUtil.getDesignPxByWidth(rect.top, designWidth));
158167
result.put(RESULT_MENU_BAR_RIGHT, DisplayUtil.getDesignPxByWidth(rect.right, designWidth));
159168
result.put(RESULT_MENU_BAR_BOTTOM, DisplayUtil.getDesignPxByWidth(rect.bottom, designWidth));
169+
if (null != positionWindow && positionWindow.length == 2) {
170+
result.put(RESULT_MENU_BAR_PAGE_LEFT, DisplayUtil.getDesignPxByWidth(positionWindow[0], designWidth));
171+
result.put(RESULT_MENU_BAR_PAGE_TOP, DisplayUtil.getDesignPxByWidth(positionWindow[1] - (null != contentInsets ? contentInsets.top : 0), designWidth));
172+
result.put(RESULT_MENU_BAR_PAGE_RIGHT, DisplayUtil.getDesignPxByWidth(positionWindow[0] + menubarView.getWidth(), designWidth));
173+
result.put(RESULT_MENU_BAR_PAGE_BOTTOM, DisplayUtil.getDesignPxByWidth(positionWindow[1] + menubarView.getHeight() - (null != contentInsets ? contentInsets.top : 0), designWidth));
174+
}
160175
} else {
161176
result.put(RESULT_MENU_BAR_WIDTH, -1);
162177
result.put(RESULT_MENU_BAR_HEIGHT, -1);

0 commit comments

Comments
 (0)