소스 검색

indentation

Daniel Zlotin 7 년 전
부모
커밋
236e1d7c68
1개의 변경된 파일174개의 추가작업 그리고 174개의 파일을 삭제
  1. 174
    174
      android/app/src/main/java/com/reactnativenavigation/react/NavigationReactGateway.java

+ 174
- 174
android/app/src/main/java/com/reactnativenavigation/react/NavigationReactGateway.java 파일 보기

@@ -23,178 +23,178 @@ import javax.annotation.Nullable;
23 23
 
24 24
 public class NavigationReactGateway implements ReactGateway {
25 25
 
26
-    private final ReactNativeHost host;
27
-    private NavigationReactEventEmitter reactEventEmitter;
28
-    private JsDevReloadHandler jsDevReloadHandler;
29
-
30
-    public NavigationReactGateway() {
31
-        host = new ReactNativeHostImpl();
32
-        jsDevReloadHandler = new JsDevReloadHandler();
33
-    }
34
-
35
-    @Override
36
-    public void startReactContextOnceInBackgroundAndExecuteJS() {
37
-        getReactInstanceManager().createReactContextInBackground();
38
-    }
39
-
40
-    public boolean isInitialized() {
41
-        return host.hasInstance() && getReactInstanceManager().getCurrentReactContext() != null;
42
-    }
43
-
44
-    @Override
45
-    public boolean hasStartedCreatingContext() {
46
-        return getReactInstanceManager().hasStartedCreatingInitialContext();
47
-    }
48
-
49
-    public ReactContext getReactContext() {
50
-        return getReactInstanceManager().getCurrentReactContext();
51
-    }
52
-
53
-    public NavigationReactEventEmitter getReactEventEmitter() {
54
-        return reactEventEmitter;
55
-    }
56
-
57
-    @Override
58
-    public ReactInstanceManager getReactInstanceManager() {
59
-        return host.getReactInstanceManager();
60
-    }
61
-
62
-    public void onBackPressed() {
63
-        getReactInstanceManager().onBackPressed();
64
-    }
65
-
66
-    public void onDestroyApp() {
67
-        getReactInstanceManager().onHostDestroy();
68
-        host.clear();
69
-    }
70
-
71
-    public void onPauseActivity() {
72
-        getReactInstanceManager().onHostPause();
73
-        jsDevReloadHandler.onPauseActivity();
74
-    }
75
-
76
-    public void onNewIntent(Intent intent) {
77
-        getReactInstanceManager().onNewIntent(intent);
78
-    }
79
-
80
-    @Override
81
-    public boolean onKeyUp(View currentFocus, int keyCode) {
82
-        return jsDevReloadHandler.onKeyUp(currentFocus, keyCode);
83
-    }
84
-
85
-    public void onResumeActivity(Activity activity, DefaultHardwareBackBtnHandler defaultHardwareBackBtnHandler) {
86
-        getReactInstanceManager().onHostResume(activity, defaultHardwareBackBtnHandler);
87
-        jsDevReloadHandler.onResumeActivity();
88
-    }
89
-
90
-    public void onActivityResult(int requestCode, int resultCode, Intent data) {
91
-        ReactContext reactContext = getReactInstanceManager().getCurrentReactContext();
92
-        if (reactContext != null) {
93
-            Activity currentActivity = reactContext.getCurrentActivity();
94
-            getReactInstanceManager().onActivityResult(currentActivity, requestCode, resultCode, data);
95
-        }
96
-    }
97
-
98
-    public ReactNativeHost getReactNativeHost() {
99
-        return host;
100
-    }
101
-
102
-    //TODO temp hack
103
-    private void onReactContextInitialized() {
104
-        reactEventEmitter = new NavigationReactEventEmitter(getReactContext());
105
-    }
106
-
107
-    private static class ReactNativeHostImpl extends ReactNativeHost implements ReactInstanceManager.ReactInstanceEventListener {
108
-
109
-        ReactNativeHostImpl() {
110
-            super(NavigationApplication.instance);
111
-        }
112
-
113
-        @Override
114
-        public boolean getUseDeveloperSupport() {
115
-            return NavigationApplication.instance.isDebug();
116
-        }
117
-
118
-        @Override
119
-        protected List<ReactPackage> getPackages() {
120
-            List<ReactPackage> list = new ArrayList<>();
121
-            list.add(new MainReactPackage());
122
-            list.add(new NavigationReactPackage());
123
-            addAdditionalReactPackagesIfNeeded(list);
124
-            return list;
125
-        }
126
-
127
-        private void addAdditionalReactPackagesIfNeeded(List<ReactPackage> list) {
128
-            List<ReactPackage> additionalReactPackages = NavigationApplication.instance.createAdditionalReactPackages();
129
-            if (additionalReactPackages == null) {
130
-                return;
131
-            }
132
-
133
-            for (ReactPackage reactPackage : additionalReactPackages) {
134
-                if (reactPackage instanceof MainReactPackage)
135
-                    throw new RuntimeException("Do not create a new MainReactPackage. This is created for you.");
136
-                if (reactPackage instanceof NavigationReactPackage)
137
-                    throw new RuntimeException("Do not create a new NavigationReactPackage. This is created for you.");
138
-            }
139
-
140
-            list.addAll(additionalReactPackages);
141
-        }
142
-
143
-        @Override
144
-        protected ReactInstanceManager createReactInstanceManager() {
145
-            ReactInstanceManager manager = super.createReactInstanceManager();
146
-            if (NavigationApplication.instance.isDebug()) {
147
-                replaceJsDevReloadListener(manager);
148
-            }
149
-            manager.addReactInstanceEventListener(this);
150
-            return manager;
151
-        }
152
-
153
-        private void replaceJsDevReloadListener(ReactInstanceManager manager) {
154
-            new JsDevReloadListenerReplacer(manager, new JsDevReloadListenerReplacer.Listener() {
155
-                @Override
156
-                public void onJsDevReload() {
157
-                    EventBus.instance.post(new JsDevReloadEvent());
158
-                }
159
-            }).replace();
160
-        }
161
-
162
-        @Override
163
-        public void onReactContextInitialized(ReactContext context) {
164
-            ((NavigationReactGateway) NavigationApplication.instance.getReactGateway()).onReactContextInitialized();
165
-            NavigationApplication.instance.onReactInitialized(context);
166
-        }
167
-
168
-        @Override
169
-        public void clear() {
170
-            getReactInstanceManager().removeReactInstanceEventListener(this);
171
-            super.clear();
172
-        }
173
-
174
-        @Override
175
-        protected String getJSMainModuleName() {
176
-            String jsMainModuleName = NavigationApplication.instance.getJSMainModuleName();
177
-            if (jsMainModuleName != null)
178
-                return jsMainModuleName;
179
-            return super.getJSMainModuleName();
180
-        }
181
-
182
-        @Nullable
183
-        @Override
184
-        protected String getJSBundleFile() {
185
-            String jsBundleFile = NavigationApplication.instance.getJSBundleFile();
186
-            if (jsBundleFile != null)
187
-                return jsBundleFile;
188
-            return super.getJSBundleFile();
189
-        }
190
-
191
-        @Nullable
192
-        @Override
193
-        protected String getBundleAssetName() {
194
-            String bundleAssetName = NavigationApplication.instance.getBundleAssetName();
195
-            if (bundleAssetName != null)
196
-                return bundleAssetName;
197
-            return super.getBundleAssetName();
198
-        }
199
-    }
26
+	private final ReactNativeHost host;
27
+	private NavigationReactEventEmitter reactEventEmitter;
28
+	private JsDevReloadHandler jsDevReloadHandler;
29
+
30
+	public NavigationReactGateway() {
31
+		host = new ReactNativeHostImpl();
32
+		jsDevReloadHandler = new JsDevReloadHandler();
33
+	}
34
+
35
+	@Override
36
+	public void startReactContextOnceInBackgroundAndExecuteJS() {
37
+		getReactInstanceManager().createReactContextInBackground();
38
+	}
39
+
40
+	public boolean isInitialized() {
41
+		return host.hasInstance() && getReactInstanceManager().getCurrentReactContext() != null;
42
+	}
43
+
44
+	@Override
45
+	public boolean hasStartedCreatingContext() {
46
+		return getReactInstanceManager().hasStartedCreatingInitialContext();
47
+	}
48
+
49
+	public ReactContext getReactContext() {
50
+		return getReactInstanceManager().getCurrentReactContext();
51
+	}
52
+
53
+	public NavigationReactEventEmitter getReactEventEmitter() {
54
+		return reactEventEmitter;
55
+	}
56
+
57
+	@Override
58
+	public ReactInstanceManager getReactInstanceManager() {
59
+		return host.getReactInstanceManager();
60
+	}
61
+
62
+	public void onBackPressed() {
63
+		getReactInstanceManager().onBackPressed();
64
+	}
65
+
66
+	public void onDestroyApp() {
67
+		getReactInstanceManager().onHostDestroy();
68
+		host.clear();
69
+	}
70
+
71
+	public void onPauseActivity() {
72
+		getReactInstanceManager().onHostPause();
73
+		jsDevReloadHandler.onPauseActivity();
74
+	}
75
+
76
+	public void onNewIntent(Intent intent) {
77
+		getReactInstanceManager().onNewIntent(intent);
78
+	}
79
+
80
+	@Override
81
+	public boolean onKeyUp(View currentFocus, int keyCode) {
82
+		return jsDevReloadHandler.onKeyUp(currentFocus, keyCode);
83
+	}
84
+
85
+	public void onResumeActivity(Activity activity, DefaultHardwareBackBtnHandler defaultHardwareBackBtnHandler) {
86
+		getReactInstanceManager().onHostResume(activity, defaultHardwareBackBtnHandler);
87
+		jsDevReloadHandler.onResumeActivity();
88
+	}
89
+
90
+	public void onActivityResult(int requestCode, int resultCode, Intent data) {
91
+		ReactContext reactContext = getReactInstanceManager().getCurrentReactContext();
92
+		if (reactContext != null) {
93
+			Activity currentActivity = reactContext.getCurrentActivity();
94
+			getReactInstanceManager().onActivityResult(currentActivity, requestCode, resultCode, data);
95
+		}
96
+	}
97
+
98
+	public ReactNativeHost getReactNativeHost() {
99
+		return host;
100
+	}
101
+
102
+	//TODO temp hack
103
+	private void onReactContextInitialized() {
104
+		reactEventEmitter = new NavigationReactEventEmitter(getReactContext());
105
+	}
106
+
107
+	private static class ReactNativeHostImpl extends ReactNativeHost implements ReactInstanceManager.ReactInstanceEventListener {
108
+
109
+		ReactNativeHostImpl() {
110
+			super(NavigationApplication.instance);
111
+		}
112
+
113
+		@Override
114
+		public boolean getUseDeveloperSupport() {
115
+			return NavigationApplication.instance.isDebug();
116
+		}
117
+
118
+		@Override
119
+		protected List<ReactPackage> getPackages() {
120
+			List<ReactPackage> list = new ArrayList<>();
121
+			list.add(new MainReactPackage());
122
+			list.add(new NavigationReactPackage());
123
+			addAdditionalReactPackagesIfNeeded(list);
124
+			return list;
125
+		}
126
+
127
+		private void addAdditionalReactPackagesIfNeeded(List<ReactPackage> list) {
128
+			List<ReactPackage> additionalReactPackages = NavigationApplication.instance.createAdditionalReactPackages();
129
+			if (additionalReactPackages == null) {
130
+				return;
131
+			}
132
+
133
+			for (ReactPackage reactPackage : additionalReactPackages) {
134
+				if (reactPackage instanceof MainReactPackage)
135
+					throw new RuntimeException("Do not create a new MainReactPackage. This is created for you.");
136
+				if (reactPackage instanceof NavigationReactPackage)
137
+					throw new RuntimeException("Do not create a new NavigationReactPackage. This is created for you.");
138
+			}
139
+
140
+			list.addAll(additionalReactPackages);
141
+		}
142
+
143
+		@Override
144
+		protected ReactInstanceManager createReactInstanceManager() {
145
+			ReactInstanceManager manager = super.createReactInstanceManager();
146
+			if (NavigationApplication.instance.isDebug()) {
147
+				replaceJsDevReloadListener(manager);
148
+			}
149
+			manager.addReactInstanceEventListener(this);
150
+			return manager;
151
+		}
152
+
153
+		private void replaceJsDevReloadListener(ReactInstanceManager manager) {
154
+			new JsDevReloadListenerReplacer(manager, new JsDevReloadListenerReplacer.Listener() {
155
+				@Override
156
+				public void onJsDevReload() {
157
+					EventBus.instance.post(new JsDevReloadEvent());
158
+				}
159
+			}).replace();
160
+		}
161
+
162
+		@Override
163
+		public void onReactContextInitialized(ReactContext context) {
164
+			((NavigationReactGateway) NavigationApplication.instance.getReactGateway()).onReactContextInitialized();
165
+			NavigationApplication.instance.onReactInitialized(context);
166
+		}
167
+
168
+		@Override
169
+		public void clear() {
170
+			getReactInstanceManager().removeReactInstanceEventListener(this);
171
+			super.clear();
172
+		}
173
+
174
+		@Override
175
+		protected String getJSMainModuleName() {
176
+			String jsMainModuleName = NavigationApplication.instance.getJSMainModuleName();
177
+			if (jsMainModuleName != null)
178
+				return jsMainModuleName;
179
+			return super.getJSMainModuleName();
180
+		}
181
+
182
+		@Nullable
183
+		@Override
184
+		protected String getJSBundleFile() {
185
+			String jsBundleFile = NavigationApplication.instance.getJSBundleFile();
186
+			if (jsBundleFile != null)
187
+				return jsBundleFile;
188
+			return super.getJSBundleFile();
189
+		}
190
+
191
+		@Nullable
192
+		@Override
193
+		protected String getBundleAssetName() {
194
+			String bundleAssetName = NavigationApplication.instance.getBundleAssetName();
195
+			if (bundleAssetName != null)
196
+				return bundleAssetName;
197
+			return super.getBundleAssetName();
198
+		}
199
+	}
200 200
 }