Parcourir la source

Notification auto dismiss timer (#696)

* Add showInAppNotification autoDismissTimerSec param

* Default autoDismissTimerSec of notification to 5, like on iOS

* Add param to disable notification auto-dismiss behaviour.

* Update showInAppNotification example with optional params
Royce Townsend il y a 7 ans
Parent
révision
20dd48480f

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/SlidingOverlayParams.java Voir le fichier

@@ -17,5 +17,6 @@ public class SlidingOverlayParams {
17 17
 
18 18
     public String screenInstanceId;
19 19
     public NavigationParams navigationParams;
20
+    public Integer autoDismissTimerSec;
20 21
     public Position position;
21 22
 }

+ 3
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/SlidingOverlayParamsParser.java Voir le fichier

@@ -11,6 +11,9 @@ public class SlidingOverlayParamsParser extends Parser {
11 11
         final SlidingOverlayParams result = new SlidingOverlayParams();
12 12
         result.screenInstanceId = bundle.getString("screen");
13 13
         result.navigationParams = new NavigationParams(bundle.getBundle("navigationParams"));
14
+        result.autoDismissTimerSec = bundle.containsKey("autoDismissTimerSec")
15
+                ? bundle.getInt("autoDismissTimerSec")
16
+                : null;
14 17
         result.position = SlidingOverlayParams.Position.fromString(bundle.getString("position", "top"));
15 18
         return result;
16 19
     }

+ 4
- 0
android/app/src/main/java/com/reactnativenavigation/views/slidingOverlay/SlidingOverlay.java Voir le fichier

@@ -40,6 +40,10 @@ public class SlidingOverlay {
40 40
         this.listener = listener;
41 41
     }
42 42
 
43
+    public Integer getAutoDismissTimerSec() {
44
+        return params.autoDismissTimerSec;
45
+    }
46
+
43 47
     public void show() {
44 48
         parent.addView(view);
45 49
 

+ 20
- 17
android/app/src/main/java/com/reactnativenavigation/views/slidingOverlay/SlidingOverlaysQueue.java Voir le fichier

@@ -9,7 +9,6 @@ import java.util.TimerTask;
9 9
 
10 10
 public class SlidingOverlaysQueue implements SlidingOverlay.SlidingListener{
11 11
 
12
-    private static final int SUSTAIN_DURATION = 3000;
13 12
     private static final int SHORT_SUSTAIN_DURATION = 500;
14 13
 
15 14
     protected Timer autoDismissTimer = null;
@@ -60,23 +59,27 @@ public class SlidingOverlaysQueue implements SlidingOverlay.SlidingListener{
60 59
 
61 60
     @Override
62 61
     public void onSlidingOverlayShown() {
63
-        int autoDismissDuration = pendingHide || queue.size() > 1
64
-                ? SHORT_SUSTAIN_DURATION
65
-                : SUSTAIN_DURATION;
66
-        pendingHide = false;
62
+        Integer autoDismissTimerSec = queue.peek().getAutoDismissTimerSec();
67 63
 
68
-        autoDismissTimer = new Timer();
69
-        autoDismissTimer.schedule(new TimerTask() {
70
-            @Override
71
-            public void run() {
72
-                NavigationApplication.instance.runOnMainThread(new Runnable() {
73
-                    @Override
74
-                    public void run() {
75
-                        queue.peek().hide();
76
-                    }
77
-                });
78
-            }
79
-        }, autoDismissDuration);
64
+        if (autoDismissTimerSec != null || pendingHide || queue.size() > 1) {
65
+            int autoDismissDuration = autoDismissTimerSec != null
66
+                    ? autoDismissTimerSec * 1000
67
+                    : SHORT_SUSTAIN_DURATION;
68
+            pendingHide = false;
69
+
70
+            autoDismissTimer = new Timer();
71
+            autoDismissTimer.schedule(new TimerTask() {
72
+                @Override
73
+                public void run() {
74
+                    NavigationApplication.instance.runOnMainThread(new Runnable() {
75
+                        @Override
76
+                        public void run() {
77
+                            queue.peek().hide();
78
+                        }
79
+                    });
80
+                }
81
+            }, autoDismissDuration);
82
+        }
80 83
     }
81 84
 
82 85
     @Override

+ 3
- 1
example/src/screens/SideMenu.js Voir le fichier

@@ -54,7 +54,9 @@ export default class SideMenu extends Component {
54 54
     this._toggleDrawer();
55 55
     this.props.navigator.showInAppNotification({
56 56
       screen: "example.InAppNotification",
57
-      //position: "bottom",
57
+      // autoDismiss: false,
58
+      // autoDismissTimerSec: 1,
59
+      // position: "bottom",
58 60
     });
59 61
   }
60 62
 

+ 4
- 0
src/deprecated/platformSpecificDeprecated.android.js Voir le fichier

@@ -378,6 +378,10 @@ function dismissAllModals(params) {
378 378
 function showInAppNotification(params) {
379 379
   params.navigationParams = {};
380 380
   addNavigatorParams(params.navigationParams);
381
+
382
+  params.autoDismissTimerSec = params.autoDismissTimerSec || 5;
383
+  if (params.autoDismiss === false) delete params.autoDismissTimerSec;
384
+
381 385
   newPlatformSpecific.showInAppNotification(params);
382 386
 }
383 387
 

+ 4
- 2
src/deprecated/platformSpecificDeprecated.ios.js Voir le fichier

@@ -518,7 +518,7 @@ function showInAppNotification(params) {
518 518
   
519 519
   savePassProps(params);
520 520
 
521
-  Notification.show({
521
+  let args = {
522 522
     component: params.screen,
523 523
     passProps: passProps,
524 524
     style: params.style,
@@ -527,7 +527,9 @@ function showInAppNotification(params) {
527 527
     shadowRadius: params.shadowRadius,
528 528
     dismissWithSwipe: params.dismissWithSwipe || true,
529 529
     autoDismissTimerSec: params.autoDismissTimerSec || 5
530
-  });
530
+  };
531
+  if (params.autoDismiss === false) delete args.autoDismissTimerSec;
532
+  Notification.show(args);
531 533
 }
532 534
 
533 535
 function dismissInAppNotification(params) {