Skip to content

Commit

Permalink
Add top offset for react loading view on Kitkat
Browse files Browse the repository at this point in the history
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 7ff6657
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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,
Expand All @@ -156,8 +169,9 @@ private void showInternal() {
mDevLoadingPopup.showAtLocation(
currentActivity.getWindow().getDecorView(),
Gravity.NO_GRAVITY,

0,
0);
topOffset);
}

private void hideInternal() {
Expand Down

0 comments on commit 7ff6657

Please sign in to comment.