소스 검색

throttled navigator & navigation functions

Daniel Zlotin 8 년 전
부모
커밋
7e0d81815a
3개의 변경된 파일23개의 추가작업 그리고 25개의 파일을 삭제
  1. 10
    9
      src/Navigation.js
  2. 11
    8
      src/Screen.js
  3. 2
    8
      src/deprecated/platformSpecificDeprecated.android.js

+ 10
- 9
src/Navigation.js 파일 보기

2
 import {AppRegistry} from 'react-native';
2
 import {AppRegistry} from 'react-native';
3
 import platformSpecific from './deprecated/platformSpecificDeprecated';
3
 import platformSpecific from './deprecated/platformSpecificDeprecated';
4
 import Screen from './Screen';
4
 import Screen from './Screen';
5
+import _ from 'lodash';
5
 
6
 
6
 const registeredScreens = {};
7
 const registeredScreens = {};
7
 
8
 
105
   registerScreen,
106
   registerScreen,
106
   getRegisteredScreen,
107
   getRegisteredScreen,
107
   registerComponent,
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 파일 보기

10
 
10
 
11
 const _allNavigatorEventHandlers = {};
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
 class Navigator {
20
 class Navigator {
14
   constructor(navigatorID, navigatorEventID, screenInstanceID) {
21
   constructor(navigatorID, navigatorEventID, screenInstanceID) {
15
     this.navigatorID = navigatorID;
22
     this.navigatorID = navigatorID;
20
   }
27
   }
21
 
28
 
22
   push(params = {}) {
29
   push(params = {}) {
23
-    return platformSpecific.navigatorPush(this, params);
30
+    return throttledPlatformSpecificFunctions.push(this, params);
24
   }
31
   }
25
 
32
 
26
   pop(params = {}) {
33
   pop(params = {}) {
27
-    return platformSpecific.navigatorPop(this, params);
34
+    return throttledPlatformSpecificFunctions.pop(this, params);
28
   }
35
   }
29
 
36
 
30
   popToRoot(params = {}) {
37
   popToRoot(params = {}) {
31
-    return platformSpecific.navigatorPopToRoot(this, params);
38
+    return throttledPlatformSpecificFunctions.popToRoot(this, params);
32
   }
39
   }
33
 
40
 
34
   resetTo(params = {}) {
41
   resetTo(params = {}) {
35
-    return platformSpecific.navigatorResetTo(this, params);
42
+    return throttledPlatformSpecificFunctions.resetTo(this, params);
36
   }
43
   }
37
 
44
 
38
   showModal(params = {}) {
45
   showModal(params = {}) {
95
     return platformSpecific.navigatorSwitchToTab(this, params);
102
     return platformSpecific.navigatorSwitchToTab(this, params);
96
   }
103
   }
97
 
104
 
98
-  showFAB(params = {}) {
99
-    return platformSpecific.showFAB(params);
100
-  }
101
-
102
   setOnNavigatorEvent(callback) {
105
   setOnNavigatorEvent(callback) {
103
     this.navigatorEventHandler = callback;
106
     this.navigatorEventHandler = callback;
104
     if (!this.navigatorEventSubscription) {
107
     if (!this.navigatorEventSubscription) {

+ 2
- 8
src/deprecated/platformSpecificDeprecated.android.js 파일 보기

122
 
122
 
123
 function startTabBasedApp(params) {
123
 function startTabBasedApp(params) {
124
   if (!params.tabs) {
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
   params.tabs.forEach(function(tab, idx) {
129
   params.tabs.forEach(function(tab, idx) {
328
   return drawer;
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
 export default {
331
 export default {
337
   startTabBasedApp,
332
   startTabBasedApp,
338
   startSingleScreenApp,
333
   startSingleScreenApp,
343
   showModal,
338
   showModal,
344
   dismissModal,
339
   dismissModal,
345
   dismissAllModals,
340
   dismissAllModals,
346
-  showFAB,
347
   navigatorSetButtons,
341
   navigatorSetButtons,
348
   navigatorSetTabBadge,
342
   navigatorSetTabBadge,
349
   navigatorSetTitle,
343
   navigatorSetTitle,