forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NavigationApplication.java
89 lines (73 loc) · 3.05 KB
/
NavigationApplication.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.reactnativenavigation;
import android.app.Application;
import androidx.annotation.Nullable;
import androidx.annotation.NonNull;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.reactnativenavigation.react.NavigationReactNativeHost;
import com.reactnativenavigation.react.ReactGateway;
import com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentCreator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public abstract class NavigationApplication extends Application implements ReactApplication {
private ReactGateway reactGateway;
public static NavigationApplication instance;
final Map<String, ExternalComponentCreator> externalComponents = new HashMap<>();
@Override
public void onCreate() {
super.onCreate();
instance = this;
reactGateway = createReactGateway();
}
/**
* Subclasses of NavigationApplication may override this method to create the singleton instance
* of {@link ReactGateway}. For example, subclasses may wish to provide a custom {@link ReactNativeHost}
* with the ReactGateway. This method will be called exactly once, in the application's {@link #onCreate()} method.
*
* Custom {@link ReactNativeHost}s must be sure to include {@link com.reactnativenavigation.react.NavigationPackage}
*
* @return a singleton {@link ReactGateway}
*/
protected ReactGateway createReactGateway() {
return new ReactGateway(this, isDebug(), createReactNativeHost());
}
protected ReactNativeHost createReactNativeHost() {
return new NavigationReactNativeHost(this);
}
public ReactGateway getReactGateway() {
return reactGateway;
}
@Override
public ReactNativeHost getReactNativeHost() {
return getReactGateway().getReactNativeHost();
}
/**
* Generally no need to override this; override for custom permission handling.
*/
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
}
public abstract boolean isDebug();
/**
* Create a list of additional {@link ReactPackage}s to include. This method will only be called by
* the default implementation of {@link #createReactGateway()}
*/
@Nullable
public abstract List<ReactPackage> createAdditionalReactPackages();
/**
* Register a native View which can be displayed using the given {@code name}
* @param name Unique name used to register the native view
* @param creator Used to create the view at runtime
*/
@SuppressWarnings("unused")
public void registerExternalComponent(String name, ExternalComponentCreator creator) {
if (externalComponents.containsKey(name)) {
throw new RuntimeException("A component has already been registered with this name: " + name);
}
externalComponents.put(name, creator);
}
public final Map<String, ExternalComponentCreator> getExternalComponents() {
return externalComponents;
}
}