Skip to content

Commit 7ff6657

Browse files
kmagierafacebook-github-bot
authored andcommittedDec 21, 2017
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
1 parent 489b98b commit 7ff6657

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed
 

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

+16-2
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)
Please sign in to comment.