Quellcode durchsuchen

Resolve showOverlay promise after Overlay appeared

Guy Carmeli vor 6 Jahren
Ursprung
Commit
8805f4bda7

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/presentation/OverlayManager.java Datei anzeigen

@@ -12,8 +12,8 @@ public class OverlayManager {
12 12
 
13 13
     public void show(ViewGroup root, ViewController overlay, CommandListener listener) {
14 14
         overlayRegistry.put(overlay.getId(), overlay);
15
+        overlay.setOnAppearedListener(() -> listener.onSuccess(overlay.getId()));
15 16
         root.addView(overlay.getView());
16
-        listener.onSuccess(overlay.getId());
17 17
     }
18 18
 
19 19
     public void dismiss(String componentId, CommandListener listener) {

+ 10
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java Datei anzeigen

@@ -20,6 +20,8 @@ import com.reactnativenavigation.views.Component;
20 20
 
21 21
 public abstract class ViewController<T extends ViewGroup> implements ViewTreeObserver.OnGlobalLayoutListener {
22 22
 
23
+    private Runnable onAppearedListener;
24
+
23 25
     public interface ViewVisibilityListener {
24 26
         /**
25 27
          * @return true if the event is consumed, false otherwise
@@ -52,6 +54,10 @@ public abstract class ViewController<T extends ViewGroup> implements ViewTreeObs
52 54
         options = initialOptions.copy();
53 55
     }
54 56
 
57
+    public void setOnAppearedListener(Runnable onAppearedListener) {
58
+        this.onAppearedListener = onAppearedListener;
59
+    }
60
+
55 61
     protected abstract T createView();
56 62
 
57 63
     public void setViewVisibilityListener(ViewVisibilityListener viewVisibilityListener) {
@@ -162,6 +168,10 @@ public abstract class ViewController<T extends ViewGroup> implements ViewTreeObs
162 168
             parentController.clearOptions();
163 169
             if (getView() instanceof Component) parentController.applyChildOptions(options, (Component) getView());
164 170
         });
171
+        if (onAppearedListener != null) {
172
+            onAppearedListener.run();
173
+            onAppearedListener = null;
174
+        }
165 175
     }
166 176
 
167 177
     public void onViewWillDisappear() {