Created
November 17, 2020 19:31
-
-
Save skaldo/02d053e986b6081374fa5eec6cda3ec1 to your computer and use it in GitHub Desktop.
Notifee - collapse notification drawer / status bar once an action press event has been received
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
diff --git a/node_modules/@notifee/react-native/android/src/main/java/io/invertase/notifee/NotifeeEventSubscriber.java b/node_modules/@notifee/react-native/android/src/main/java/io/invertase/notifee/NotifeeEventSubscriber.java | |
index 00ecd14..af4bf4b 100644 | |
--- a/node_modules/@notifee/react-native/android/src/main/java/io/invertase/notifee/NotifeeEventSubscriber.java | |
+++ b/node_modules/@notifee/react-native/android/src/main/java/io/invertase/notifee/NotifeeEventSubscriber.java | |
@@ -46,6 +46,7 @@ public class NotifeeEventSubscriber implements EventListener { | |
Bundle pressAction = extras.getBundle(KEY_DETAIL_PRESS_ACTION); | |
if (pressAction != null) { | |
eventDetailMap.putMap(KEY_DETAIL_PRESS_ACTION, Arguments.fromBundle(pressAction)); | |
+ NotifeeReactUtils.hideStatusBar(); | |
} | |
String input = extras.getString(KEY_DETAIL_INPUT); | |
diff --git a/node_modules/@notifee/react-native/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java b/node_modules/@notifee/react-native/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java | |
index b5a1a6b..5819e50 100644 | |
--- a/node_modules/@notifee/react-native/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java | |
+++ b/node_modules/@notifee/react-native/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java | |
@@ -27,6 +27,8 @@ import com.facebook.react.jstasks.HeadlessJsTaskContext; | |
import com.facebook.react.jstasks.HeadlessJsTaskEventListener; | |
import com.facebook.react.modules.core.DeviceEventManagerModule; | |
import java.util.List; | |
+import android.os.Build; | |
+import java.lang.reflect.Method; | |
class NotifeeReactUtils { | |
private static final SparseArray<GenericCallback> headlessTasks = new SparseArray<>(); | |
@@ -175,6 +177,21 @@ class NotifeeReactUtils { | |
} | |
} | |
+ static void hideStatusBar() { | |
+ ReactContext reactContext = getReactContext(); | |
+ Context context = EventSubscriber.getContext(); | |
+ | |
+ try { | |
+ Object service = context.getSystemService("statusbar"); | |
+ Class<?> statusbarManager = Class.forName("android.app.StatusBarManager"); | |
+ Method collapse = statusbarManager.getMethod((Build.VERSION.SDK_INT >= 17) ? "collapsePanels" : "collapse"); | |
+ collapse.setAccessible(true); | |
+ collapse.invoke(service); | |
+ } catch (Exception ex) { | |
+ ex.printStackTrace(); | |
+ } | |
+ } | |
+ | |
static void sendEvent(String eventName, WritableMap eventMap) { | |
try { | |
ReactContext reactContext = getReactContext(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment