Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit ba51765

Browse files
committed
fix android fit
1 parent 40ba8d0 commit ba51765

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

Runtime/Plugins/platform/android/view/UIWidgetsViewController.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,29 @@ public static UIWidgetsViewController getInstance() {
3434
private UIWidgetsViewMetrics viewMetrics;
3535
private boolean keyboardOpen;
3636

37+
private float statusHeight;
38+
private float navigationBarHeight;
39+
3740
private void setup() {
3841
//Log.i("tag", "On Setup 2");
3942

4043
keyboardOpen = false;
4144
viewMetrics = new UIWidgetsViewMetrics();
42-
45+
setupHeights();
4346
updateViewMetrics();
4447

4548
setupViewMetricsChangedListener();
4649
}
4750

51+
private void setupHeights() {
52+
final View unityView = ((ViewGroup)UnityPlayer.currentActivity.findViewById(android.R.id.content)).getChildAt(0);
53+
Rect rect = new Rect();
54+
unityView.getWindowVisibleDisplayFrame(rect);
55+
56+
statusHeight = rect.top;
57+
navigationBarHeight = unityView.getRootView().getHeight() - rect.bottom;
58+
}
59+
4860
public static UIWidgetsViewMetrics getMetrics() {
4961
UIWidgetsViewController controller = getInstance();
5062
return controller.viewMetrics;
@@ -111,7 +123,7 @@ private boolean hasNavigationBar() {
111123
} catch (Exception e) {
112124
e.printStackTrace();
113125
}
114-
//Log.i("UIWidgetsDebug", " hasBar: " + hasBar);
126+
Log.i("UIWidgetsDebug", " hasBar: " + hasBar);
115127
return hasBar;
116128
}
117129

@@ -120,7 +132,7 @@ public void updateViewMetrics() {
120132
Rect rect = new Rect();
121133
unityView.getWindowVisibleDisplayFrame(rect);
122134

123-
//Log.i("UIWidgetsDebug", "calculation: " + unityView.getRootView().getHeight() + " " + rect.bottom + " " + rect.top);
135+
Log.i("UIWidgetsDebug", "calculation: " + unityView.getRootView().getHeight() + " " + rect.bottom + " " + rect.top);
124136

125137
rect.bottom = unityView.getRootView().getHeight() - (rect.bottom - rect.top) - rect.top;
126138
rect.right = unityView.getRootView().getWidth() - (rect.right - rect.left) - rect.left;
@@ -143,9 +155,13 @@ public void updateViewMetrics() {
143155
viewMetrics.insets_bottom = navigationBarHidden? calculateBottomKeyboardInset(rect) : rect.bottom;
144156
viewMetrics.insets_left = 0;
145157

146-
//Log.i("UIWidgetsDebug", "checks: " + navigationBarHidden + " " + rect.bottom);
147-
//Log.i("UIWidgetsDebug", " padding: " + viewMetrics.padding_top + " " + viewMetrics.padding_right + " " + viewMetrics.padding_bottom + " " + viewMetrics.padding_left);
148-
//Log.i("UIWidgetsDebug", " insets: " + viewMetrics.insets_top + " " + viewMetrics.insets_right + " " + viewMetrics.insets_bottom + " " + viewMetrics.insets_left);
158+
//adjust
159+
viewMetrics.insets_bottom -= navigationBarHeight;
160+
viewMetrics.padding_top -= statusHeight;
161+
162+
Log.i("UIWidgetsDebug", "checks: " + navigationBarHidden + " " + rect.bottom);
163+
Log.i("UIWidgetsDebug", " padding: " + viewMetrics.padding_top + " " + viewMetrics.padding_right + " " + viewMetrics.padding_bottom + " " + viewMetrics.padding_left);
164+
Log.i("UIWidgetsDebug", " insets: " + viewMetrics.insets_top + " " + viewMetrics.insets_right + " " + viewMetrics.insets_bottom + " " + viewMetrics.insets_left);
149165
}
150166

151167
public void setupViewMetricsChangedListener() {

Runtime/engine/UIWidgetsPanel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public class UIWidgetWindowAdapter : WindowAdapter {
2121
protected override void updateSafeArea() {
2222
this._padding = this._uiWidgetsPanel.viewPadding;
2323
this._viewInsets = this._uiWidgetsPanel.viewInsets;
24+
25+
Debug.Log($"update safe area: padding = {this._padding.top}, {this._padding.left}, {this._padding.bottom}, {this._padding.right} ; " +
26+
$"viewInsets = {this._viewInsets.top}, {this._viewInsets.left}, {this._viewInsets.bottom}, {this._viewInsets.right}");
2427
}
2528

2629
protected override bool hasFocus() {

Samples/UIWidgetSample/TextInput.unity

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ Camera:
258258
m_GameObject: {fileID: 244594849}
259259
m_Enabled: 1
260260
serializedVersion: 2
261-
m_ClearFlags: 2
262-
m_BackGroundColor: {r: 1, g: 1, b: 1, a: 1}
261+
m_ClearFlags: 1
262+
m_BackGroundColor: {r: 0.21960786, g: 0.21960786, b: 0.21960786, a: 1}
263263
m_projectionMatrixMode: 1
264264
m_SensorSize: {x: 36, y: 24}
265265
m_LensShift: {x: 0, y: 0}
@@ -299,7 +299,7 @@ Transform:
299299
m_PrefabAsset: {fileID: 0}
300300
m_GameObject: {fileID: 244594849}
301301
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
302-
m_LocalPosition: {x: 0, y: 0, z: -15}
302+
m_LocalPosition: {x: 0, y: 0.3, z: -66.1}
303303
m_LocalScale: {x: 1, y: 1, z: 1}
304304
m_Children: []
305305
m_Father: {fileID: 0}
@@ -390,7 +390,7 @@ Canvas:
390390
m_Enabled: 1
391391
serializedVersion: 3
392392
m_RenderMode: 0
393-
m_Camera: {fileID: 0}
393+
m_Camera: {fileID: 244594851}
394394
m_PlaneDistance: 100
395395
m_PixelPerfect: 0
396396
m_ReceivesEvents: 1
@@ -1311,7 +1311,7 @@ MonoBehaviour:
13111311
m_GameObject: {fileID: 1387978526}
13121312
m_Enabled: 1
13131313
m_EditorHideFlags: 0
1314-
m_Script: {fileID: 11500000, guid: 9c5c86936ca864ae684720ddcd50d759, type: 3}
1314+
m_Script: {fileID: 11500000, guid: 85b678a668e064f5c90ee8a9f7c13f35, type: 3}
13151315
m_Name:
13161316
m_EditorClassIdentifier:
13171317
m_Material: {fileID: 0}
@@ -1330,7 +1330,7 @@ MonoBehaviour:
13301330
width: 1
13311331
height: 1
13321332
devicePixelRatioOverride: 0
1333-
antiAliasingOverride: 0
1333+
antiAliasingOverride: 4
13341334
--- !u!222 &1387978529
13351335
CanvasRenderer:
13361336
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)