Pārlūkot izejas kodu

throttled navigator & navigation functions

Daniel Zlotin 8 gadus atpakaļ
vecāks
revīzija
7e0d81815a

+ 10
- 9
src/Navigation.js Parādīt failu

@@ -2,6 +2,7 @@ import React from 'react';
2 2
 import {AppRegistry} from 'react-native';
3 3
 import platformSpecific from './deprecated/platformSpecificDeprecated';
4 4
 import Screen from './Screen';
5
+import _ from 'lodash';
5 6
 
6 7
 const registeredScreens = {};
7 8
 
@@ -105,13 +106,13 @@ export default {
105 106
   registerScreen,
106 107
   getRegisteredScreen,
107 108
   registerComponent,
108
-  showModal,
109
-  dismissModal,
110
-  dismissAllModals,
111
-  showLightBox,
112
-  dismissLightBox,
113
-  showInAppNotification,
114
-  dismissInAppNotification,
115
-  startTabBasedApp,
116
-  startSingleScreenApp
109
+  showModal: _.throttle(showModal, 500, {leading: true, trailing: false}),
110
+  dismissModal: _.throttle(dismissModal, 500, {leading: true, trailing: false}),
111
+  dismissAllModals: _.throttle(dismissAllModals, 500, {leading: true, trailing: false}),
112
+  showLightBox: _.throttle(showLightBox, 500, {leading: true, trailing: false}),
113
+  dismissLightBox: _.throttle(dismissLightBox, 500, {leading: true, trailing: false}),
114
+  showInAppNotification: _.throttle(showInAppNotification, 500, {leading: true, trailing: false}),
115
+  dismissInAppNotification: _.throttle(dismissInAppNotification, 500, {leading: true, trailing: false}),
116
+  startTabBasedApp: _.throttle(startTabBasedApp, 500, {leading: true, trailing: false}),
117
+  startSingleScreenApp: _.throttle(startSingleScreenApp, 500, {leading: true, trailing: false})
117 118
 };

+ 11
- 8
src/Screen.js Parādīt failu

@@ -10,6 +10,13 @@ import _ from 'lodash';
10 10
 
11 11
 const _allNavigatorEventHandlers = {};
12 12
 
13
+const throttledPlatformSpecificFunctions = {
14
+  push: _.throttle(platformSpecific.navigatorPush, 500, {leading: true, trailing: false}),
15
+  pop: _.throttle(platformSpecific.navigatorPop, 500, {leading: true, trailing: false}),
16
+  popToRoot: _.throttle(platformSpecific.navigatorPopToRoot, 500, {leading: true, trailing: false}),
17
+  resetTo: _.throttle(platformSpecific.navigatorResetTo, 500, {leading: true, trailing: false})
18
+};
19
+
13 20
 class Navigator {
14 21
   constructor(navigatorID, navigatorEventID, screenInstanceID) {
15 22
     this.navigatorID = navigatorID;
@@ -20,19 +27,19 @@ class Navigator {
20 27
   }
21 28
 
22 29
   push(params = {}) {
23
-    return platformSpecific.navigatorPush(this, params);
30
+    return throttledPlatformSpecificFunctions.push(this, params);
24 31
   }
25 32
 
26 33
   pop(params = {}) {
27
-    return platformSpecific.navigatorPop(this, params);
34
+    return throttledPlatformSpecificFunctions.pop(this, params);
28 35
   }
29 36
 
30 37
   popToRoot(params = {}) {
31
-    return platformSpecific.navigatorPopToRoot(this, params);
38
+    return throttledPlatformSpecificFunctions.popToRoot(this, params);
32 39
   }
33 40
 
34 41
   resetTo(params = {}) {
35
-    return platformSpecific.navigatorResetTo(this, params);
42
+    return throttledPlatformSpecificFunctions.resetTo(this, params);
36 43
   }
37 44
 
38 45
   showModal(params = {}) {
@@ -95,10 +102,6 @@ class Navigator {
95 102
     return platformSpecific.navigatorSwitchToTab(this, params);
96 103
   }
97 104
 
98
-  showFAB(params = {}) {
99
-    return platformSpecific.showFAB(params);
100
-  }
101
-
102 105
   setOnNavigatorEvent(callback) {
103 106
     this.navigatorEventHandler = callback;
104 107
     if (!this.navigatorEventSubscription) {

+ 2
- 8
src/deprecated/platformSpecificDeprecated.android.js Parādīt failu

@@ -122,8 +122,8 @@ function adaptNavigationParams(screen) {
122 122
 
123 123
 function startTabBasedApp(params) {
124 124
   if (!params.tabs) {
125
-   console.error('startTabBasedApp(params): params.tabs is required');
126
-   return;
125
+    console.error('startTabBasedApp(params): params.tabs is required');
126
+    return;
127 127
   }
128 128
 
129 129
   params.tabs.forEach(function(tab, idx) {
@@ -328,11 +328,6 @@ function setupDrawer(drawerParams) {
328 328
   return drawer;
329 329
 }
330 330
 
331
-function showFAB(params) {
332
-  //params.icon = resolveAssetSource(params.icon).uri;
333
-  //RctActivity.showFAB(params);
334
-}
335
-
336 331
 export default {
337 332
   startTabBasedApp,
338 333
   startSingleScreenApp,
@@ -343,7 +338,6 @@ export default {
343 338
   showModal,
344 339
   dismissModal,
345 340
   dismissAllModals,
346
-  showFAB,
347 341
   navigatorSetButtons,
348 342
   navigatorSetTabBadge,
349 343
   navigatorSetTitle,