Skip to content

Commit e56a401

Browse files
committed
Add top offset for react loading view on Kitkat
1 parent 0b5e8b4 commit e56a401

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

ReactAndroid/src/main/java/com/facebook/react/devsupport/DevLoadingViewController.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
import android.app.Activity;
1313
import android.content.Context;
1414
import android.graphics.Color;
15+
import android.graphics.Rect;
16+
import android.os.Build;
1517
import android.view.Gravity;
1618
import android.view.LayoutInflater;
1719
import android.view.ViewGroup;
20+
import android.view.Window;
1821
import android.widget.PopupWindow;
1922
import android.widget.TextView;
2023

@@ -53,7 +56,7 @@ public DevLoadingViewController(Context context, ReactInstanceManagerDevHelper r
5356
}
5457

5558
public void showMessage(final String message, final int color, final int backgroundColor) {
56-
if (!sEnabled ) {
59+
if (!sEnabled) {
5760
return;
5861
}
5962

@@ -147,6 +150,16 @@ private void showInternal() {
147150
return;
148151
}
149152

153+
int topOffset = 0;
154+
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
155+
// On Android SDK <= 19 PopupWindow#showAtLocation uses absolute screen position. In order for
156+
// loading view to be placed below status bar (if the status bar is present) we need to pass
157+
// an appropriate Y offset.
158+
Rect rectangle = new Rect();
159+
currentActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rectangle);
160+
topOffset = rectangle.top;
161+
}
162+
150163
mDevLoadingPopup = new PopupWindow(
151164
mDevLoadingView,
152165
ViewGroup.LayoutParams.MATCH_PARENT,
@@ -156,8 +169,9 @@ private void showInternal() {
156169
mDevLoadingPopup.showAtLocation(
157170
currentActivity.getWindow().getDecorView(),
158171
Gravity.NO_GRAVITY,
172+
159173
0,
160-
0);
174+
topOffset);
161175
}
162176

163177
private void hideInternal() {

0 commit comments

Comments
 (0)