|
@@ -21,7 +21,6 @@ import android.widget.Toast;
|
21
|
21
|
import com.facebook.common.logging.FLog;
|
22
|
22
|
import com.facebook.react.ReactInstanceManager;
|
23
|
23
|
import com.facebook.react.ReactPackage;
|
24
|
|
-import com.facebook.react.ReactRootView;
|
25
|
24
|
import com.facebook.react.bridge.Arguments;
|
26
|
25
|
import com.facebook.react.bridge.ReadableMap;
|
27
|
26
|
import com.facebook.react.bridge.WritableMap;
|
|
@@ -29,13 +28,12 @@ import com.facebook.react.common.ReactConstants;
|
29
|
28
|
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
|
30
|
29
|
import com.facebook.react.shell.MainReactPackage;
|
31
|
30
|
import com.reactnativenavigation.BuildConfig;
|
|
31
|
+import com.reactnativenavigation.bridge.NavigationReactPackage;
|
32
|
32
|
import com.reactnativenavigation.controllers.ModalController;
|
33
|
|
-import com.reactnativenavigation.core.RctManager;
|
34
|
33
|
import com.reactnativenavigation.core.objects.Button;
|
35
|
34
|
import com.reactnativenavigation.core.objects.Drawer;
|
36
|
35
|
import com.reactnativenavigation.core.objects.Screen;
|
37
|
36
|
import com.reactnativenavigation.modal.RnnModal;
|
38
|
|
-import com.reactnativenavigation.bridge.NavigationReactPackage;
|
39
|
37
|
import com.reactnativenavigation.utils.ContextProvider;
|
40
|
38
|
import com.reactnativenavigation.utils.StyleHelper;
|
41
|
39
|
import com.reactnativenavigation.views.RnnToolBar;
|
|
@@ -62,73 +60,13 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
|
62
|
60
|
"Overlay permissions needs to be granted in order for react native apps to run in dev mode";
|
63
|
61
|
|
64
|
62
|
@Nullable
|
65
|
|
- protected ReactInstanceManager mReactInstanceManager;
|
66
|
|
- private boolean mDoRefresh = false;
|
67
|
|
- private Menu mMenu;
|
68
|
|
- protected RnnToolBar mToolbar;
|
69
|
|
- protected ActionBarDrawerToggle mDrawerToggle;
|
70
|
|
- protected DrawerLayout mDrawerLayout;
|
71
|
|
- protected ScreenStack mDrawerStack;
|
72
|
|
-
|
73
|
|
- /**
|
74
|
|
- * Returns the name of the bundle in assets. If this is null, and no file path is specified for
|
75
|
|
- * the bundle, the app will only work with {@code getUseDeveloperSupport} enabled and will
|
76
|
|
- * always try to load the JS bundle from the packager server.
|
77
|
|
- * e.g. "index.android.bundle"
|
78
|
|
- */
|
79
|
|
- @Nullable
|
80
|
|
- public String getBundleAssetName() {
|
81
|
|
- return "index.android.bundle";
|
82
|
|
- }
|
83
|
|
-
|
84
|
|
- /**
|
85
|
|
- * Returns a custom path of the bundle file. This is used in cases the bundle should be loaded
|
86
|
|
- * from a custom path. By default it is loaded from Android assets, from a path specified
|
87
|
|
- * by {getBundleAssetName}.
|
88
|
|
- * e.g. "file://sdcard/myapp_cache/index.android.bundle"
|
89
|
|
- */
|
90
|
|
- @Nullable
|
91
|
|
- public String getJSBundleFile() {
|
92
|
|
- return null;
|
93
|
|
- }
|
94
|
|
-
|
95
|
|
- /**
|
96
|
|
- * Returns the name of the main module. Determines the URL used to fetch the JS bundle
|
97
|
|
- * from the packager server. It is only used when dev support is enabled.
|
98
|
|
- * This is the first file to be executed once the {@link ReactInstanceManager} is created.
|
99
|
|
- * e.g. "index.android"
|
100
|
|
- */
|
101
|
|
- public String getJSMainModuleName() {
|
102
|
|
- return "index.android";
|
103
|
|
- }
|
104
|
|
-
|
105
|
|
- /**
|
106
|
|
- * Returns the launchOptions which will be passed to the {@link ReactInstanceManager}
|
107
|
|
- * when the application is started. By default, this will return null and an empty
|
108
|
|
- * object will be passed to your top level component as its initial props.
|
109
|
|
- * If your React Native application requires props set outside of JS, override
|
110
|
|
- * this method to return the Android.os.Bundle of your desired initial props.
|
111
|
|
- */
|
112
|
|
- @Nullable
|
113
|
|
- protected Bundle getLaunchOptions() {
|
114
|
|
- return null;
|
115
|
|
- }
|
116
|
|
-
|
117
|
|
- /**
|
118
|
|
- * Returns the name of the main component registered from JavaScript.
|
119
|
|
- * This is used to schedule rendering of the component.
|
120
|
|
- * e.g. "MoviesApp"
|
121
|
|
- */
|
122
|
|
- protected String getMainComponentName() {
|
123
|
|
- return "";
|
124
|
|
- }
|
125
|
|
-
|
126
|
|
- /**
|
127
|
|
- * Returns whether dev mode should be enabled. This enables e.g. the dev menu.
|
128
|
|
- */
|
129
|
|
- public boolean getUseDeveloperSupport() {
|
130
|
|
- return BuildConfig.DEBUG;
|
131
|
|
- }
|
|
63
|
+ protected ReactInstanceManager reactInstanceManager;
|
|
64
|
+ private boolean shouldRefreshOnRR = false;
|
|
65
|
+ private Menu menu;
|
|
66
|
+ protected RnnToolBar toolbar;
|
|
67
|
+ protected ActionBarDrawerToggle drawerToggle;
|
|
68
|
+ protected DrawerLayout drawerLayout;
|
|
69
|
+ protected ScreenStack drawerStack;
|
132
|
70
|
|
133
|
71
|
/**
|
134
|
72
|
* Returns a list of {@link ReactPackage} used by the app.
|
|
@@ -143,18 +81,11 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
|
143
|
81
|
);
|
144
|
82
|
}
|
145
|
83
|
|
146
|
|
- /**
|
147
|
|
- * A subclass may override this method if it needs to use a custom {@link ReactRootView}.
|
148
|
|
- */
|
149
|
|
- protected ReactRootView createRootView() {
|
150
|
|
- return new ReactRootView(this);
|
151
|
|
- }
|
152
|
|
-
|
153
|
84
|
@Override
|
154
|
85
|
protected void onCreate(Bundle savedInstanceState) {
|
155
|
86
|
super.onCreate(savedInstanceState);
|
156
|
87
|
ContextProvider.setActivityContext(this);
|
157
|
|
- mReactInstanceManager = createReactInstanceManager();
|
|
88
|
+ reactInstanceManager = createReactInstanceManager();
|
158
|
89
|
handleOnCreate();
|
159
|
90
|
|
160
|
91
|
}
|
|
@@ -180,7 +111,7 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
|
180
|
111
|
}
|
181
|
112
|
|
182
|
113
|
private void permissionToShowRedboxIfNeeded() {
|
183
|
|
- if (getUseDeveloperSupport() && Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(this)) {
|
|
114
|
+ if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(this)) {
|
184
|
115
|
Intent serviceIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
|
185
|
116
|
startActivity(serviceIntent);
|
186
|
117
|
FLog.w(ReactConstants.TAG, REDBOX_PERMISSION_MESSAGE);
|
|
@@ -193,8 +124,8 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
|
193
|
124
|
super.onResume();
|
194
|
125
|
ContextProvider.setActivityContext(this);
|
195
|
126
|
|
196
|
|
- if (mReactInstanceManager != null) {
|
197
|
|
- mReactInstanceManager.onHostResume(this, this);
|
|
127
|
+ if (reactInstanceManager != null) {
|
|
128
|
+ reactInstanceManager.onHostResume(this, this);
|
198
|
129
|
}
|
199
|
130
|
}
|
200
|
131
|
|
|
@@ -202,8 +133,8 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
|
202
|
133
|
protected void onPause() {
|
203
|
134
|
super.onPause();
|
204
|
135
|
|
205
|
|
- if (mReactInstanceManager != null) {
|
206
|
|
- mReactInstanceManager.onHostPause();
|
|
136
|
+ if (reactInstanceManager != null) {
|
|
137
|
+ reactInstanceManager.onHostPause();
|
207
|
138
|
}
|
208
|
139
|
|
209
|
140
|
ContextProvider.clearActivityContext();
|
|
@@ -215,9 +146,9 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
|
215
|
146
|
|
216
|
147
|
// Destroy react instance manager only if there are no resumed react activities
|
217
|
148
|
BaseReactActivity activity = ContextProvider.getActivityContext();
|
218
|
|
- if (mReactInstanceManager != null && (activity == null || activity.isFinishing())) {
|
|
149
|
+ if (reactInstanceManager != null && (activity == null || activity.isFinishing())) {
|
219
|
150
|
Log.i(TAG, "Destroying ReactInstanceManager");
|
220
|
|
- mReactInstanceManager.onHostDestroy();
|
|
151
|
+ reactInstanceManager.onHostDestroy();
|
221
|
152
|
RctManager.getInstance().onDestroy();
|
222
|
153
|
} else {
|
223
|
154
|
Log.d(TAG, "Not destroying ReactInstanceManager");
|
|
@@ -226,23 +157,23 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
|
226
|
157
|
|
227
|
158
|
@CallSuper
|
228
|
159
|
public void push(Screen screen) {
|
229
|
|
- StyleHelper.updateStyles(mToolbar, screen);
|
230
|
|
- if (mToolbar != null) {
|
231
|
|
- mToolbar.update(screen);
|
|
160
|
+ StyleHelper.updateStyles(toolbar, screen);
|
|
161
|
+ if (toolbar != null) {
|
|
162
|
+ toolbar.update(screen);
|
232
|
163
|
|
233
|
164
|
if (getCurrentNavigatorId().equals(screen.navigatorId) &&
|
234
|
165
|
getScreenStackSize() >= 1) {
|
235
|
|
- mToolbar.setNavUpButton(screen);
|
|
166
|
+ toolbar.setNavUpButton(screen);
|
236
|
167
|
}
|
237
|
168
|
}
|
238
|
169
|
}
|
239
|
170
|
|
240
|
171
|
@CallSuper
|
241
|
172
|
public Screen pop(String navigatorId) {
|
242
|
|
- if (mToolbar != null &&
|
|
173
|
+ if (toolbar != null &&
|
243
|
174
|
getCurrentNavigatorId().equals(navigatorId) &&
|
244
|
175
|
getScreenStackSize() <= 2) {
|
245
|
|
- mToolbar.setNavUpButton();
|
|
176
|
+ toolbar.setNavUpButton();
|
246
|
177
|
}
|
247
|
178
|
|
248
|
179
|
return null;
|
|
@@ -250,8 +181,8 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
|
250
|
181
|
|
251
|
182
|
@CallSuper
|
252
|
183
|
public Screen popToRoot(String navigatorId) {
|
253
|
|
- if (mToolbar != null) {
|
254
|
|
- mToolbar.setNavUpButton();
|
|
184
|
+ if (toolbar != null) {
|
|
185
|
+ toolbar.setNavUpButton();
|
255
|
186
|
}
|
256
|
187
|
|
257
|
188
|
return null;
|
|
@@ -259,9 +190,9 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
|
259
|
190
|
|
260
|
191
|
@CallSuper
|
261
|
192
|
public Screen resetTo(Screen screen) {
|
262
|
|
- StyleHelper.updateStyles(mToolbar, screen);
|
263
|
|
- if (mToolbar != null) {
|
264
|
|
- mToolbar.setNavUpButton();
|
|
193
|
+ StyleHelper.updateStyles(toolbar, screen);
|
|
194
|
+ if (toolbar != null) {
|
|
195
|
+ toolbar.setNavUpButton();
|
265
|
196
|
}
|
266
|
197
|
|
267
|
198
|
return null;
|
|
@@ -286,26 +217,26 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
|
286
|
217
|
@Override
|
287
|
218
|
public void onConfigurationChanged(Configuration newConfig) {
|
288
|
219
|
super.onConfigurationChanged(newConfig);
|
289
|
|
- if (mDrawerToggle != null) {
|
290
|
|
- mDrawerToggle.onConfigurationChanged(newConfig);
|
|
220
|
+ if (drawerToggle != null) {
|
|
221
|
+ drawerToggle.onConfigurationChanged(newConfig);
|
291
|
222
|
}
|
292
|
223
|
}
|
293
|
224
|
|
294
|
225
|
@Override
|
295
|
226
|
public boolean onCreateOptionsMenu(Menu menu) {
|
296
|
|
- mMenu = menu;
|
|
227
|
+ this.menu = menu;
|
297
|
228
|
Screen currentScreen = getCurrentScreen();
|
298
|
|
- if (mToolbar != null && currentScreen != null && !isFinishing()) {
|
299
|
|
- mToolbar.setupToolbarButtonsAsync(currentScreen);
|
|
229
|
+ if (toolbar != null && currentScreen != null && !isFinishing()) {
|
|
230
|
+ toolbar.setupToolbarButtonsAsync(currentScreen);
|
300
|
231
|
}
|
301
|
232
|
return super.onCreateOptionsMenu(menu);
|
302
|
233
|
}
|
303
|
234
|
|
304
|
235
|
@Override
|
305
|
236
|
public boolean onOptionsItemSelected(MenuItem item) {
|
306
|
|
- if (mDrawerToggle != null &&
|
|
237
|
+ if (drawerToggle != null &&
|
307
|
238
|
getScreenStackSize() == 1 &&
|
308
|
|
- mDrawerToggle.onOptionsItemSelected(item)) {
|
|
239
|
+ drawerToggle.onOptionsItemSelected(item)) {
|
309
|
240
|
return true;
|
310
|
241
|
}
|
311
|
242
|
|
|
@@ -324,42 +255,42 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
|
324
|
255
|
@Override
|
325
|
256
|
public void onPostCreate(Bundle savedInstanceState) {
|
326
|
257
|
super.onPostCreate(savedInstanceState);
|
327
|
|
- if (mDrawerToggle != null) {
|
328
|
|
- mDrawerToggle.syncState();
|
|
258
|
+ if (drawerToggle != null) {
|
|
259
|
+ drawerToggle.syncState();
|
329
|
260
|
}
|
330
|
261
|
}
|
331
|
262
|
|
332
|
263
|
public Menu getMenu() {
|
333
|
|
- return mMenu;
|
|
264
|
+ return menu;
|
334
|
265
|
}
|
335
|
266
|
|
336
|
267
|
@Override
|
337
|
268
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
338
|
|
- if (mReactInstanceManager != null) {
|
339
|
|
- mReactInstanceManager.onActivityResult(requestCode, resultCode, data);
|
|
269
|
+ if (reactInstanceManager != null) {
|
|
270
|
+ reactInstanceManager.onActivityResult(requestCode, resultCode, data);
|
340
|
271
|
}
|
341
|
272
|
}
|
342
|
273
|
|
343
|
274
|
@Override
|
344
|
275
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
345
|
|
- if (mReactInstanceManager != null &&
|
346
|
|
- mReactInstanceManager.getDevSupportManager().getDevSupportEnabled()) {
|
|
276
|
+ if (reactInstanceManager != null &&
|
|
277
|
+ reactInstanceManager.getDevSupportManager().getDevSupportEnabled()) {
|
347
|
278
|
if (keyCode == KeyEvent.KEYCODE_MENU) {
|
348
|
|
- mReactInstanceManager.showDevOptionsDialog();
|
|
279
|
+ reactInstanceManager.showDevOptionsDialog();
|
349
|
280
|
return true;
|
350
|
281
|
}
|
351
|
282
|
if (keyCode == KeyEvent.KEYCODE_R && !(getCurrentFocus() instanceof EditText)) {
|
352
|
283
|
// Enable double-tap-R-to-reload
|
353
|
|
- if (mDoRefresh) {
|
354
|
|
- mReactInstanceManager.getDevSupportManager().handleReloadJS();
|
355
|
|
- mDoRefresh = false;
|
|
284
|
+ if (shouldRefreshOnRR) {
|
|
285
|
+ reactInstanceManager.getDevSupportManager().handleReloadJS();
|
|
286
|
+ shouldRefreshOnRR = false;
|
356
|
287
|
} else {
|
357
|
|
- mDoRefresh = true;
|
|
288
|
+ shouldRefreshOnRR = true;
|
358
|
289
|
new Handler().postDelayed(
|
359
|
290
|
new Runnable() {
|
360
|
291
|
@Override
|
361
|
292
|
public void run() {
|
362
|
|
- mDoRefresh = false;
|
|
293
|
+ shouldRefreshOnRR = false;
|
363
|
294
|
}
|
364
|
295
|
},
|
365
|
296
|
200);
|
|
@@ -388,8 +319,8 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
|
388
|
319
|
|
389
|
320
|
if (getScreenStackSize() > 1) {
|
390
|
321
|
pop(getCurrentNavigatorId());
|
391
|
|
- } else if (mReactInstanceManager != null) {
|
392
|
|
- mReactInstanceManager.onBackPressed();
|
|
322
|
+ } else if (reactInstanceManager != null) {
|
|
323
|
+ reactInstanceManager.onBackPressed();
|
393
|
324
|
} else {
|
394
|
325
|
super.onBackPressed();
|
395
|
326
|
}
|
|
@@ -405,47 +336,47 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
|
405
|
336
|
return;
|
406
|
337
|
}
|
407
|
338
|
|
408
|
|
- mDrawerStack = new ScreenStack(this);
|
|
339
|
+ drawerStack = new ScreenStack(this);
|
409
|
340
|
FrameLayout drawerFrame = (FrameLayout) findViewById(drawerFrameId);
|
410
|
|
- drawerFrame.addView(mDrawerStack);
|
411
|
|
- mDrawerStack.push(drawer.left);
|
|
341
|
+ drawerFrame.addView(drawerStack);
|
|
342
|
+ drawerStack.push(drawer.left);
|
412
|
343
|
|
413
|
|
- mDrawerLayout = (DrawerLayout) findViewById(drawerLayoutId);
|
414
|
|
- mDrawerToggle = mToolbar.setupDrawer(mDrawerLayout, drawer.left, screen);
|
|
344
|
+ drawerLayout = (DrawerLayout) findViewById(drawerLayoutId);
|
|
345
|
+ drawerToggle = toolbar.setupDrawer(drawerLayout, drawer.left, screen);
|
415
|
346
|
}
|
416
|
347
|
|
417
|
348
|
public void setNavigationButtons(ReadableMap buttons) {
|
418
|
|
- if (mToolbar == null) {
|
|
349
|
+ if (toolbar == null) {
|
419
|
350
|
return;
|
420
|
351
|
}
|
421
|
352
|
getCurrentScreen().setButtons(buttons);
|
422
|
|
- mToolbar.setupToolbarButtonsAsync(getCurrentScreen());
|
|
353
|
+ toolbar.setupToolbarButtonsAsync(getCurrentScreen());
|
423
|
354
|
}
|
424
|
355
|
|
425
|
356
|
public void setNavigationTitle(ReadableMap title) {
|
426
|
|
- if (mToolbar == null) {
|
|
357
|
+ if (toolbar == null) {
|
427
|
358
|
return;
|
428
|
359
|
}
|
429
|
360
|
|
430
|
|
- mToolbar.setTitle(title.getString(KEY_TITLE));
|
|
361
|
+ toolbar.setTitle(title.getString(KEY_TITLE));
|
431
|
362
|
}
|
432
|
363
|
|
433
|
364
|
public void toggleNavigationBar(ReadableMap params) {
|
434
|
|
- if (mToolbar == null) {
|
|
365
|
+ if (toolbar == null) {
|
435
|
366
|
return;
|
436
|
367
|
}
|
437
|
368
|
|
438
|
369
|
boolean hide = params.getBoolean(KEY_HIDDEN);
|
439
|
370
|
boolean animated = params.getBoolean(KEY_ANIMATED);
|
440
|
371
|
if (hide) {
|
441
|
|
- mToolbar.hideToolbar(animated);
|
|
372
|
+ toolbar.hideToolbar(animated);
|
442
|
373
|
} else {
|
443
|
|
- mToolbar.showToolbar(animated);
|
|
374
|
+ toolbar.showToolbar(animated);
|
444
|
375
|
}
|
445
|
376
|
}
|
446
|
377
|
|
447
|
378
|
public void toggleDrawer(ReadableMap params) {
|
448
|
|
- if (mToolbar == null || mDrawerToggle == null) {
|
|
379
|
+ if (toolbar == null || drawerToggle == null) {
|
449
|
380
|
return;
|
450
|
381
|
}
|
451
|
382
|
|
|
@@ -454,13 +385,13 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
|
454
|
385
|
String to = params.getString(KEY_TO);
|
455
|
386
|
switch (to) {
|
456
|
387
|
case "open":
|
457
|
|
- mToolbar.showDrawer(animated);
|
|
388
|
+ toolbar.showDrawer(animated);
|
458
|
389
|
break;
|
459
|
390
|
case "closed":
|
460
|
|
- mToolbar.hideDrawer(animated);
|
|
391
|
+ toolbar.hideDrawer(animated);
|
461
|
392
|
break;
|
462
|
393
|
default:
|
463
|
|
- mToolbar.toggleDrawer(animated);
|
|
394
|
+ toolbar.toggleDrawer(animated);
|
464
|
395
|
break;
|
465
|
396
|
}
|
466
|
397
|
}
|