Permalink
Browse files

Add top offset for react loading view on Kitkat

Summary:
This PR fixes the problem with dev loading view on KitKat and older Android devices after #16596

Install RNTester app on Android API 19 or lower device. See green loading view show up under status bar. Do the same with full screen theme set and see it show up correctly at the top of the screen.
Verify the green loading bar displays correctly on devices with API > 19 too.

This fixes an issue introduced in #16596

[ANDROID][MINOR][DevSupport] - Fix green dev loading bar on Android Kitkat and below
Closes #17305

Differential Revision: D6621077

Pulled By: achen1

fbshipit-source-id: 3b4216af535d7db5c96d137f20004fe2651b1dc9
  • Loading branch information...
kmagiera authored and facebook-github-bot committed Dec 21, 2017
1 parent 489b98b commit 7ff6657985a09bd2572615d16403fba3af709859
@@ -12,9 +12,12 @@
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Build;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.PopupWindow;
import android.widget.TextView;
@@ -53,7 +56,7 @@ public DevLoadingViewController(Context context, ReactInstanceManagerDevHelper r
}
public void showMessage(final String message, final int color, final int backgroundColor) {
if (!sEnabled ) {
if (!sEnabled) {
return;
}
@@ -147,6 +150,16 @@ private void showInternal() {
return;
}
int topOffset = 0;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
// On Android SDK <= 19 PopupWindow#showAtLocation uses absolute screen position. In order for
// loading view to be placed below status bar (if the status bar is present) we need to pass
// an appropriate Y offset.
Rect rectangle = new Rect();
currentActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rectangle);
topOffset = rectangle.top;
}
mDevLoadingPopup = new PopupWindow(
mDevLoadingView,
ViewGroup.LayoutParams.MATCH_PARENT,
@@ -156,8 +169,9 @@ private void showInternal() {
mDevLoadingPopup.showAtLocation(
currentActivity.getWindow().getDecorView(),
Gravity.NO_GRAVITY,
0,
0);
topOffset);
}
private void hideInternal() {

0 comments on commit 7ff6657

Please sign in to comment.