Merge pull request #238 from lbryio/hide-navigation-bar-fix
obtain the proper activity reference in the utility module
This commit is contained in:
commit
82a7846e6d
2 changed files with 31 additions and 12 deletions
|
@ -36,6 +36,8 @@ import java.util.Random;
|
||||||
|
|
||||||
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
|
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
|
||||||
|
|
||||||
|
private static Activity currentActivity = null;
|
||||||
|
|
||||||
private static final int OVERLAY_PERMISSION_REQ_CODE = 101;
|
private static final int OVERLAY_PERMISSION_REQ_CODE = 101;
|
||||||
|
|
||||||
private static final int STORAGE_PERMISSION_REQ_CODE = 201;
|
private static final int STORAGE_PERMISSION_REQ_CODE = 201;
|
||||||
|
@ -75,6 +77,7 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
currentActivity = this;
|
||||||
|
|
||||||
// Start the daemon service if it is not started
|
// Start the daemon service if it is not started
|
||||||
serviceRunning = isServiceRunning(LbrynetService.class);
|
serviceRunning = isServiceRunning(LbrynetService.class);
|
||||||
|
@ -110,6 +113,12 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Activity getActivity() {
|
||||||
|
Activity activity = new Activity();
|
||||||
|
activity = currentActivity;
|
||||||
|
return activity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
|
|
|
@ -56,24 +56,34 @@ public class UtilityModule extends ReactContextBaseJavaModule {
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void hideNavigationBar() {
|
public void hideNavigationBar() {
|
||||||
if (context != null && context instanceof Activity) {
|
final Activity activity = MainActivity.getActivity();
|
||||||
Activity activity = (Activity) context;
|
if (activity != null) {
|
||||||
|
activity.runOnUiThread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
View decorView = activity.getWindow().getDecorView();
|
View decorView = activity.getWindow().getDecorView();
|
||||||
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
|
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
|
||||||
View.SYSTEM_UI_FLAG_IMMERSIVE |
|
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void showNavigationBar() {
|
public void showNavigationBar() {
|
||||||
if (context != null && context instanceof Activity) {
|
final Activity activity = MainActivity.getActivity();
|
||||||
Activity activity = (Activity) context;
|
if (activity != null) {
|
||||||
|
activity.runOnUiThread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
View decorView = activity.getWindow().getDecorView();
|
View decorView = activity.getWindow().getDecorView();
|
||||||
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
|
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
|
||||||
View.SYSTEM_UI_FLAG_VISIBLE);
|
View.SYSTEM_UI_FLAG_VISIBLE);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
|
|
Loading…
Reference in a new issue