Last active
June 12, 2019 16:25
-
-
Save mykltronn/2906c1c9cd7c09ce15aa47e9af20fb16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// previous imports | |
. . . | |
+ import android.os.Handler; | |
public class ImmersiveMode extends ReactContextBaseJavaModule { | |
// let's declare a handler for our UI thread; | |
+ Handler uiHandler; | |
. . . | |
// our constructor | |
public class ImmersiveMode extends ReactContextBaseJavaModule { | |
super(reactContext); | |
+ // instantiate a handler, tell it to construct a Handler object | |
+ // for our UI thread using reactContext.getMainLooper(); | |
+ this.uiHandler = new Handler(reactContext.getMainLooper()); | |
} | |
@ReactMethod | |
+ public void enterImmersiveMode() { | |
+ // ^^ let's give our fail() method a more optimistic name | |
+ // Handlers have a post() method that schedules a runnable on its thread | |
+ uiHandler.post(runnableEnterImmersiveMode) | |
} | |
// let's take our previous logic from fail() and stick it in a runnable | |
+ private Runnable runnableEnterImmersiveMode = new Runnable() { | |
+ // implement the required run() method of Runnable | |
+ @Override | |
+ public void run() { | |
+ // use the setSystemUIFlags method and the flags we defined for immersive mode | |
+ // our runnable will execute this code on the thread of our choosing | |
+ setSystemUIFlags( | |
+ View.SYSTEM_UI_FLAG_IMMERSIVE | |
+ | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | |
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | |
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | |
+ | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
+ | View.SYSTEM_UI_FLAG_FULLSCREEN | |
+ ); | |
+ } | |
+ }; | |
. . . | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment