expo 44.0.4 → 45.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/android/.gitignore +261 -0
  3. package/android/build.gradle +73 -34
  4. package/android/proguard-rules.pro +4 -1
  5. package/android/src/legacyReactNativeHostWrapper/expo/modules/ReactNativeHostWrapper.kt +9 -0
  6. package/android/src/main/java/expo/modules/ReactActivityDelegateWrapper.kt +65 -19
  7. package/android/src/main/java/expo/modules/{ReactNativeHostWrapper.kt → ReactNativeHostWrapperBase.kt} +7 -5
  8. package/android/src/reactNativeHostWrapper/expo/modules/ReactNativeHostWrapper.kt +32 -0
  9. package/android/src/test/AndroidManifest.xml +18 -0
  10. package/bin/cli.js +12 -6
  11. package/build/Expo.d.ts +1 -0
  12. package/build/Expo.d.ts.map +1 -0
  13. package/build/Expo.fx.d.ts +1 -0
  14. package/build/Expo.fx.d.ts.map +1 -0
  15. package/build/Expo.fx.web.d.ts +1 -0
  16. package/build/Expo.fx.web.d.ts.map +1 -0
  17. package/build/environment/DevAppContainer.d.ts +1 -0
  18. package/build/environment/DevAppContainer.d.ts.map +1 -0
  19. package/build/environment/DevLoadingView.d.ts +1 -0
  20. package/build/environment/DevLoadingView.d.ts.map +1 -0
  21. package/build/environment/DevLoadingView.js +4 -4
  22. package/build/environment/DevLoadingView.js.map +1 -1
  23. package/build/environment/getInstallationIdAsync.android.d.ts +1 -0
  24. package/build/environment/getInstallationIdAsync.android.d.ts.map +1 -0
  25. package/build/environment/getInstallationIdAsync.d.ts +1 -0
  26. package/build/environment/getInstallationIdAsync.d.ts.map +1 -0
  27. package/build/environment/getInstallationIdAsync.web.d.ts +1 -0
  28. package/build/environment/getInstallationIdAsync.web.d.ts.map +1 -0
  29. package/build/environment/getInstallationIdAsync.web.js +1 -1
  30. package/build/environment/getInstallationIdAsync.web.js.map +1 -1
  31. package/build/environment/logging.fx.d.ts +1 -0
  32. package/build/environment/logging.fx.d.ts.map +1 -0
  33. package/build/environment/logging.fx.js +6 -13
  34. package/build/environment/logging.fx.js.map +1 -1
  35. package/build/environment/react-native-logs.fx.d.ts +1 -0
  36. package/build/environment/react-native-logs.fx.d.ts.map +1 -0
  37. package/build/environment/react-native-logs.fx.js +1 -1
  38. package/build/environment/react-native-logs.fx.js.map +1 -1
  39. package/build/environment/validate.fx.d.ts +1 -0
  40. package/build/environment/validate.fx.d.ts.map +1 -0
  41. package/build/environment/validate.fx.js +3 -3
  42. package/build/environment/validate.fx.js.map +1 -1
  43. package/build/environment/validatorState.d.ts +1 -0
  44. package/build/environment/validatorState.d.ts.map +1 -0
  45. package/build/launch/RecoveryProps.d.ts +1 -0
  46. package/build/launch/RecoveryProps.d.ts.map +1 -0
  47. package/build/launch/registerRootComponent.d.ts +1 -0
  48. package/build/launch/registerRootComponent.d.ts.map +1 -0
  49. package/build/launch/withExpoRoot.d.ts +1 -0
  50. package/build/launch/withExpoRoot.d.ts.map +1 -0
  51. package/build/launch/withExpoRoot.types.d.ts +1 -0
  52. package/build/launch/withExpoRoot.types.d.ts.map +1 -0
  53. package/build/launch/withExpoRoot.web.d.ts +1 -0
  54. package/build/launch/withExpoRoot.web.d.ts.map +1 -0
  55. package/build/logs/LogSerialization.d.ts +1 -0
  56. package/build/logs/LogSerialization.d.ts.map +1 -0
  57. package/build/logs/LogSerialization.js +1 -1
  58. package/build/logs/LogSerialization.js.map +1 -1
  59. package/build/logs/Logs.d.ts +1 -0
  60. package/build/logs/Logs.d.ts.map +1 -0
  61. package/build/logs/Logs.web.d.ts +1 -0
  62. package/build/logs/Logs.web.d.ts.map +1 -0
  63. package/build/logs/RemoteConsole.d.ts +1 -0
  64. package/build/logs/RemoteConsole.d.ts.map +1 -0
  65. package/build/logs/RemoteLogging.d.ts +1 -0
  66. package/build/logs/RemoteLogging.d.ts.map +1 -0
  67. package/build/logs/format/ReactNodeFormatter.d.ts +1 -0
  68. package/build/logs/format/ReactNodeFormatter.d.ts.map +1 -0
  69. package/build/timer/polyfillNextTick.d.ts +1 -0
  70. package/build/timer/polyfillNextTick.d.ts.map +1 -0
  71. package/bundledNativeModules.json +96 -94
  72. package/ios/EXAppDefinesLoader.m +6 -0
  73. package/package.json +22 -22
  74. package/requiresExtraSetup.json +2 -2
  75. package/scripts/resolveAppEntry.js +38 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,27 @@
1
+ # Changelog
2
+
3
+ ## Unpublished
4
+
5
+ ### 🛠 Breaking changes
6
+
7
+ ### 🎉 New features
8
+
9
+ ### 🐛 Bug fixes
10
+
11
+ ### 💡 Others
12
+
13
+ ## 45.0.0-beta.1 — 2022-04-18
14
+
15
+ _This version does not introduce any user-facing changes._
16
+
17
+ ## 45.0.0-beta.1 — 2022-04-18
18
+
19
+ _This version does not introduce any user-facing changes._
20
+
21
+ ## 45.0.0-beta.1 — 2022-04-18
22
+
23
+ ### 🎉 New features
24
+
25
+ - Add `EXPO_USE_BETA_CLI` to utilize the new `@expo/cli` versioned package. ([#17007](https://github.com/expo/expo/pull/17007) by [@EvanBacon](https://github.com/EvanBacon))
26
+ - Added Android `ReactNativeHostHandler.getJavaScriptExecutorFactory()` for a module to override the `JavaScriptExecutorFactory`. ([#17005](https://github.com/expo/expo/pull/17005) by [@kudo](https://github.com/kudo))
27
+ - Add `react`, `react-native`, `react-dom`, and `react-native-web` to `bundledNativeModules.json`. ([#17048](https://github.com/expo/expo/pull/17048) by [@EvanBacon](https://github.com/EvanBacon))
@@ -0,0 +1,261 @@
1
+
2
+ # Created by https://www.gitignore.io/api/java,maven,gradle,android,intellij,androidstudio
3
+
4
+ ### Android ###
5
+ # Built application files
6
+ *.apk
7
+ *.ap_
8
+
9
+ # Files for the ART/Dalvik VM
10
+ *.dex
11
+
12
+ # Java class files
13
+ *.class
14
+
15
+ # Generated files
16
+ bin/
17
+ gen/
18
+ out/
19
+
20
+ # Gradle files
21
+ .gradle/
22
+ build/
23
+
24
+ # Local configuration file (sdk path, etc)
25
+ local.properties
26
+
27
+ # Proguard folder generated by Eclipse
28
+ proguard/
29
+
30
+ # Log Files
31
+ *.log
32
+
33
+ # Android Studio Navigation editor temp files
34
+ .navigation/
35
+
36
+ # Android Studio captures folder
37
+ captures/
38
+
39
+ # Intellij
40
+ *.iml
41
+ .idea/workspace.xml
42
+ .idea/tasks.xml
43
+ .idea/gradle.xml
44
+ .idea/dictionaries
45
+ .idea/libraries
46
+
47
+ # External native build folder generated in Android Studio 2.2 and later
48
+ .externalNativeBuild
49
+
50
+ # Freeline
51
+ freeline.py
52
+ freeline/
53
+ freeline_project_description.json
54
+
55
+ ### Android Patch ###
56
+ gen-external-apklibs
57
+
58
+ ### AndroidStudio ###
59
+ # Covers files to be ignored for android development using Android Studio.
60
+
61
+ # Built application files
62
+
63
+ # Files for the ART/Dalvik VM
64
+
65
+ # Java class files
66
+
67
+ # Generated files
68
+
69
+ # Gradle files
70
+ .gradle
71
+
72
+ # Signing files
73
+ .signing/
74
+
75
+ # Local configuration file (sdk path, etc)
76
+
77
+ # Proguard folder generated by Eclipse
78
+
79
+ # Log Files
80
+
81
+ # Android Studio
82
+ /*/build/
83
+ /*/local.properties
84
+ /*/out
85
+ /*/*/build
86
+ /*/*/production
87
+ *.ipr
88
+ *~
89
+ *.swp
90
+
91
+ # Android Patch
92
+
93
+ # External native build folder generated in Android Studio 2.2 and later
94
+
95
+ # NDK
96
+ obj/
97
+
98
+ # IntelliJ IDEA
99
+ *.iws
100
+ /out/
101
+
102
+ # User-specific configurations
103
+ .idea/libraries/
104
+ .idea/.name
105
+ .idea/compiler.xml
106
+ .idea/copyright/profiles_settings.xml
107
+ .idea/encodings.xml
108
+ .idea/misc.xml
109
+ .idea/modules.xml
110
+ .idea/scopes/scope_settings.xml
111
+ .idea/vcs.xml
112
+ .idea/jsLibraryMappings.xml
113
+ .idea/datasources.xml
114
+ .idea/dataSources.ids
115
+ .idea/sqlDataSources.xml
116
+ .idea/dynamic.xml
117
+ .idea/uiDesigner.xml
118
+
119
+ # OS-specific files
120
+ .DS_Store
121
+ .DS_Store?
122
+ ._*
123
+ .Spotlight-V100
124
+ .Trashes
125
+ ehthumbs.db
126
+ Thumbs.db
127
+
128
+ # Legacy Eclipse project files
129
+ .classpath
130
+ .project
131
+ .cproject
132
+ .settings/
133
+
134
+ # Mobile Tools for Java (J2ME)
135
+ .mtj.tmp/
136
+
137
+ # Package Files #
138
+ *.war
139
+ *.ear
140
+
141
+ # virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml)
142
+ hs_err_pid*
143
+
144
+ ## Plugin-specific files:
145
+
146
+ # mpeltonen/sbt-idea plugin
147
+ .idea_modules/
148
+
149
+ # JIRA plugin
150
+ atlassian-ide-plugin.xml
151
+
152
+ # Mongo Explorer plugin
153
+ .idea/mongoSettings.xml
154
+
155
+ ### AndroidStudio Patch ###
156
+
157
+ !/gradle/wrapper/gradle-wrapper.jar
158
+
159
+ ### Intellij ###
160
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
161
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
162
+
163
+ # User-specific stuff:
164
+ .idea/**/workspace.xml
165
+ .idea/**/tasks.xml
166
+
167
+ # Sensitive or high-churn files:
168
+ .idea/**/dataSources/
169
+ .idea/**/dataSources.ids
170
+ .idea/**/dataSources.xml
171
+ .idea/**/dataSources.local.xml
172
+ .idea/**/sqlDataSources.xml
173
+ .idea/**/dynamic.xml
174
+ .idea/**/uiDesigner.xml
175
+
176
+ # Gradle:
177
+ .idea/**/gradle.xml
178
+ .idea/**/libraries
179
+
180
+ # CMake
181
+ cmake-build-debug/
182
+
183
+ # Mongo Explorer plugin:
184
+ .idea/**/mongoSettings.xml
185
+
186
+ ## File-based project format:
187
+
188
+ ## Plugin-specific files:
189
+
190
+ # IntelliJ
191
+
192
+ # mpeltonen/sbt-idea plugin
193
+
194
+ # JIRA plugin
195
+
196
+ # Cursive Clojure plugin
197
+ .idea/replstate.xml
198
+
199
+ # Ruby plugin and RubyMine
200
+ /.rakeTasks
201
+
202
+ ### Intellij Patch ###
203
+ # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
204
+
205
+ # *.iml
206
+ # modules.xml
207
+ # .idea/misc.xml
208
+ # *.ipr
209
+
210
+ # Sonarlint plugin
211
+ .idea/sonarlint
212
+
213
+ ### Java ###
214
+ # Compiled class file
215
+
216
+ # Log file
217
+
218
+ # BlueJ files
219
+ *.ctxt
220
+
221
+ # Mobile Tools for Java (J2ME)
222
+
223
+ # Package Files #
224
+ *.jar
225
+ *.zip
226
+ *.tar.gz
227
+ *.rar
228
+
229
+ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
230
+
231
+ ### Maven ###
232
+ target/
233
+ pom.xml.tag
234
+ pom.xml.releaseBackup
235
+ pom.xml.versionsBackup
236
+ pom.xml.next
237
+ release.properties
238
+ dependency-reduced-pom.xml
239
+ buildNumber.properties
240
+ .mvn/timing.properties
241
+
242
+ # Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
243
+ !/.mvn/wrapper/maven-wrapper.jar
244
+
245
+ ### Gradle ###
246
+ **/build/
247
+
248
+ # Ignore Gradle GUI config
249
+ gradle-app.setting
250
+
251
+ # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
252
+ !gradle-wrapper.jar
253
+
254
+ # Cache of project
255
+ .gradletasknamecache
256
+
257
+ # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
258
+ # gradle/wrapper/gradle-wrapper.properties
259
+
260
+
261
+ # End of https://www.gitignore.io/api/java,maven,gradle,android,intellij,androidstudio
@@ -1,76 +1,115 @@
1
1
  apply plugin: 'com.android.library'
2
2
  apply plugin: 'kotlin-android'
3
- apply plugin: 'maven'
3
+ apply plugin: 'maven-publish'
4
4
 
5
5
  // Import autolinking script
6
6
  apply from: "../scripts/autolinking.gradle"
7
7
 
8
+ static def versionToNumber(major, minor, patch) {
9
+ return patch * 100 + minor * 10000 + major * 1000000
10
+ }
11
+
12
+ def getRNVersion() {
13
+ def nodeModulesVersion = [
14
+ "node",
15
+ "-e",
16
+ "console.log(require('react-native/package.json').version);"
17
+ ]
18
+ .execute([], projectDir)
19
+ .text
20
+ .trim()
21
+
22
+ def version = safeExtGet("reactNativeVersion", nodeModulesVersion)
23
+ def coreVersion = version.split("-")[0]
24
+ def (major, minor, patch) = coreVersion.tokenize('.').collect { it.toInteger() }
25
+
26
+ return versionToNumber(
27
+ major,
28
+ minor,
29
+ patch
30
+ )
31
+ }
32
+
8
33
  ensureDependeciesWereEvaluated(project)
9
34
 
10
35
  group = 'host.exp.exponent'
11
- version = '44.0.4'
36
+ version = '45.0.0-beta.1'
12
37
 
13
38
  buildscript {
39
+ def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
40
+ if (expoModulesCorePlugin.exists()) {
41
+ apply from: expoModulesCorePlugin
42
+ applyKotlinExpoModulesCorePlugin()
43
+ }
44
+
14
45
  // Simple helper that allows the root project to override versions declared by this library.
15
46
  ext.safeExtGet = { prop, fallback ->
16
47
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
17
48
  }
18
49
 
50
+ // Ensures backward compatibility
51
+ ext.getKotlinVersion = {
52
+ if (ext.has("kotlinVersion")) {
53
+ ext.kotlinVersion()
54
+ } else {
55
+ ext.safeExtGet("kotlinVersion", "1.6.10")
56
+ }
57
+ }
58
+
19
59
  repositories {
20
60
  mavenCentral()
21
61
  }
22
62
 
23
63
  dependencies {
24
- classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', '1.4.21')}")
64
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
25
65
  }
26
66
  }
27
67
 
28
- //Upload android library to maven with javadoc and android sources
29
- configurations {
30
- deployerJars
31
- }
32
-
33
- //Creating sources with comments
68
+ // Creating sources with comments
34
69
  task androidSourcesJar(type: Jar) {
35
70
  classifier = 'sources'
36
71
  from android.sourceSets.main.java.srcDirs
37
72
  }
38
73
 
39
- //Put the androidSources and javadoc to the artifacts
40
- artifacts {
41
- archives androidSourcesJar
42
- }
43
-
44
- uploadArchives {
45
- repositories {
46
- mavenDeployer {
47
- configuration = configurations.deployerJars
48
- repository(url: mavenLocal().url)
74
+ afterEvaluate {
75
+ publishing {
76
+ publications {
77
+ release(MavenPublication) {
78
+ from components.release
79
+ // Add additional sourcesJar to artifacts
80
+ artifact(androidSourcesJar)
81
+ }
82
+ }
83
+ repositories {
84
+ maven {
85
+ url = mavenLocal().url
86
+ }
49
87
  }
50
88
  }
51
89
  }
52
90
 
53
91
  android {
54
- compileSdkVersion safeExtGet("compileSdkVersion", 30)
92
+ compileSdkVersion safeExtGet("compileSdkVersion", 31)
55
93
 
56
94
  compileOptions {
57
- sourceCompatibility JavaVersion.VERSION_1_8
58
- targetCompatibility JavaVersion.VERSION_1_8
95
+ sourceCompatibility JavaVersion.VERSION_11
96
+ targetCompatibility JavaVersion.VERSION_11
97
+ }
98
+
99
+ kotlinOptions {
100
+ jvmTarget = JavaVersion.VERSION_11.majorVersion
59
101
  }
60
102
 
61
103
  defaultConfig {
62
104
  minSdkVersion safeExtGet("minSdkVersion", 21)
63
- targetSdkVersion safeExtGet("targetSdkVersion", 30)
105
+ targetSdkVersion safeExtGet("targetSdkVersion", 31)
64
106
  versionCode 1
65
- versionName "44.0.4"
107
+ versionName "45.0.0-beta.1"
66
108
  consumerProguardFiles("proguard-rules.pro")
67
109
  }
68
110
  lintOptions {
69
111
  abortOnError false
70
112
  }
71
- kotlinOptions {
72
- jvmTarget = '1.8'
73
- }
74
113
  testOptions {
75
114
  unitTests.includeAndroidResources = true
76
115
  }
@@ -79,16 +118,16 @@ android {
79
118
  main {
80
119
  java {
81
120
  srcDirs += new File(project.buildDir, generatedFilesSrcDir)
121
+
122
+ def rnVersion = getRNVersion()
123
+ if (rnVersion >= versionToNumber(0, 67, 0)) {
124
+ srcDirs += "src/reactNativeHostWrapper"
125
+ } else {
126
+ srcDirs += "src/legacyReactNativeHostWrapper"
127
+ }
82
128
  }
83
129
  }
84
130
  }
85
-
86
- unitTestVariants.all {
87
- it.mergedFlavor.manifestPlaceholders = [
88
- // Fix expo-app-auth manifest merger issue for unit test
89
- appAuthRedirectScheme: "test"
90
- ]
91
- }
92
131
  }
93
132
 
94
133
  dependencies { dependencyHandler ->
@@ -1,8 +1,11 @@
1
- # For ReactNativeDelegateWrapper
1
+ # For ReactActivityDelegateWrapper
2
2
  -keepclassmembers public class com.facebook.react.ReactActivityDelegate {
3
3
  protected *;
4
4
  private ReactDelegate mReactDelegate;
5
5
  }
6
+ -keepclassmembers public class com.facebook.react.ReactActivity {
7
+ private final ReactActivityDelegate mDelegate;
8
+ }
6
9
 
7
10
  # For ReactNativeHostWrapper
8
11
  -keepclassmembers public class com.facebook.react.ReactNativeHost {
@@ -0,0 +1,9 @@
1
+ package expo.modules
2
+
3
+ import android.app.Application
4
+ import com.facebook.react.ReactNativeHost
5
+
6
+ class ReactNativeHostWrapper(
7
+ application: Application,
8
+ host: ReactNativeHost
9
+ ) : ReactNativeHostWrapperBase(application, host)
@@ -5,6 +5,7 @@ import android.content.Context
5
5
  import android.content.Intent
6
6
  import android.os.Bundle
7
7
  import android.view.KeyEvent
8
+ import android.view.ViewGroup
8
9
  import androidx.collection.ArrayMap
9
10
  import com.facebook.react.ReactActivity
10
11
  import com.facebook.react.ReactActivityDelegate
@@ -14,12 +15,18 @@ import com.facebook.react.ReactNativeHost
14
15
  import com.facebook.react.ReactRootView
15
16
  import com.facebook.react.modules.core.PermissionListener
16
17
  import expo.modules.core.interfaces.ReactActivityLifecycleListener
18
+ import java.lang.reflect.Field
17
19
  import java.lang.reflect.Method
20
+ import java.lang.reflect.Modifier
18
21
 
19
22
  class ReactActivityDelegateWrapper(
20
23
  private val activity: ReactActivity,
21
- private val delegate: ReactActivityDelegate
24
+ private val isNewArchitectureEnabled: Boolean,
25
+ private var delegate: ReactActivityDelegate
22
26
  ) : ReactActivityDelegate(activity, null) {
27
+ constructor(activity: ReactActivity, delegate: ReactActivityDelegate) :
28
+ this(activity, false, delegate)
29
+
23
30
  private val reactActivityLifecycleListeners = ExpoModulesPackage.packageList
24
31
  .flatMap { it.createReactActivityLifecycleListeners(activity) }
25
32
  private val reactActivityHandlers = ExpoModulesPackage.packageList
@@ -33,9 +40,11 @@ class ReactActivityDelegateWrapper(
33
40
  }
34
41
 
35
42
  override fun createRootView(): ReactRootView {
36
- return reactActivityHandlers.asSequence()
43
+ val rootView = reactActivityHandlers.asSequence()
37
44
  .mapNotNull { it.createReactRootView(activity) }
38
45
  .firstOrNull() ?: invokeDelegateMethod("createRootView")
46
+ rootView.setIsFabric(isNewArchitectureEnabled)
47
+ return rootView
39
48
  }
40
49
 
41
50
  override fun getReactNativeHost(): ReactNativeHost {
@@ -51,26 +60,59 @@ class ReactActivityDelegateWrapper(
51
60
  }
52
61
 
53
62
  override fun loadApp(appKey: String?) {
54
- return invokeDelegateMethod("loadApp", arrayOf(String::class.java), arrayOf(appKey))
63
+ // Give modules a chance to wrap the ReactRootView in a container ViewGroup. If some module
64
+ // wants to do this, we override the functionality of `loadApp` and call `setContentView` with
65
+ // the new container view instead.
66
+ val rootViewContainer = reactActivityHandlers.asSequence()
67
+ .mapNotNull { it.createReactRootViewContainer(activity) }
68
+ .firstOrNull()
69
+ if (rootViewContainer != null) {
70
+ val mReactDelegate = ReactActivityDelegate::class.java.getDeclaredField("mReactDelegate")
71
+ mReactDelegate.isAccessible = true
72
+ val reactDelegate = mReactDelegate[delegate] as ReactDelegate
73
+
74
+ reactDelegate.loadApp(appKey)
75
+ rootViewContainer.addView(reactDelegate.reactRootView, ViewGroup.LayoutParams.MATCH_PARENT)
76
+ activity.setContentView(rootViewContainer)
77
+ } else {
78
+ return invokeDelegateMethod("loadApp", arrayOf(String::class.java), arrayOf(appKey))
79
+ }
55
80
  }
56
81
 
57
82
  override fun onCreate(savedInstanceState: Bundle?) {
58
- // Since we just wrap `ReactActivityDelegate` but not inherit it, in its `onCreate`,
59
- // the calls to `createRootView()` or `getMainComponentName()` have no chances to be our wrapped methods.
60
- // Instead we intercept `ReactActivityDelegate.onCreate` and replace the `mReactDelegate` with our version.
61
- // That's not ideal but works.
62
- val reactDelegate = object : ReactDelegate(
63
- plainActivity, reactNativeHost, mainComponentName, launchOptions
64
- ) {
65
- override fun createRootView(): ReactRootView {
66
- return this@ReactActivityDelegateWrapper.createRootView()
83
+ // Give handlers a chance as early as possible to replace the wrapped delegate object.
84
+ // If they do, we call the new wrapped delegate's `onCreate` instead of overriding it here.
85
+ val newDelegate = reactActivityHandlers.asSequence()
86
+ .mapNotNull { it.onDidCreateReactActivityDelegate(activity, this) }
87
+ .firstOrNull()
88
+ if (newDelegate != null && newDelegate != this) {
89
+ val mDelegateField = ReactActivity::class.java.getDeclaredField("mDelegate")
90
+ mDelegateField.isAccessible = true
91
+ val modifiers = Field::class.java.getDeclaredField("accessFlags")
92
+ modifiers.isAccessible = true
93
+ modifiers.setInt(mDelegateField, mDelegateField.modifiers and Modifier.FINAL.inv())
94
+ mDelegateField.set(activity, newDelegate)
95
+ delegate = newDelegate
96
+
97
+ invokeDelegateMethod<Unit, Bundle?>("onCreate", arrayOf(Bundle::class.java), arrayOf(savedInstanceState))
98
+ } else {
99
+ // Since we just wrap `ReactActivityDelegate` but not inherit it, in its `onCreate`,
100
+ // the calls to `createRootView()` or `getMainComponentName()` have no chances to be our wrapped methods.
101
+ // Instead we intercept `ReactActivityDelegate.onCreate` and replace the `mReactDelegate` with our version.
102
+ // That's not ideal but works.
103
+ val reactDelegate = object : ReactDelegate(
104
+ plainActivity, reactNativeHost, mainComponentName, launchOptions
105
+ ) {
106
+ override fun createRootView(): ReactRootView {
107
+ return this@ReactActivityDelegateWrapper.createRootView()
108
+ }
109
+ }
110
+ val mReactDelegate = ReactActivityDelegate::class.java.getDeclaredField("mReactDelegate")
111
+ mReactDelegate.isAccessible = true
112
+ mReactDelegate.set(delegate, reactDelegate)
113
+ if (mainComponentName != null) {
114
+ loadApp(mainComponentName)
67
115
  }
68
- }
69
- val mReactDelegate = ReactActivityDelegate::class.java.getDeclaredField("mReactDelegate")
70
- mReactDelegate.isAccessible = true
71
- mReactDelegate.set(delegate, reactDelegate)
72
- if (mainComponentName != null) {
73
- loadApp(mainComponentName)
74
116
  }
75
117
 
76
118
  reactActivityLifecycleListeners.forEach { listener ->
@@ -108,7 +150,11 @@ class ReactActivityDelegateWrapper(
108
150
  }
109
151
 
110
152
  override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
111
- return delegate.onKeyUp(keyCode, event)
153
+ // if any of the handlers return true, intentionally consume the event instead of passing it
154
+ // through to the delegate
155
+ return reactActivityHandlers
156
+ .map { it.onKeyUp(keyCode, event) }
157
+ .fold(false) { accu, current -> accu || current } || delegate.onKeyUp(keyCode, event)
112
158
  }
113
159
 
114
160
  override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean {
@@ -14,11 +14,11 @@ import com.facebook.react.bridge.ReactApplicationContext
14
14
  import com.facebook.react.devsupport.RedBoxHandler
15
15
  import java.lang.reflect.Method
16
16
 
17
- class ReactNativeHostWrapper(
17
+ open class ReactNativeHostWrapperBase(
18
18
  application: Application,
19
- private val host: ReactNativeHost
19
+ protected val host: ReactNativeHost
20
20
  ) : ReactNativeHost(application) {
21
- private val reactNativeHostHandlers = ExpoModulesPackage.packageList
21
+ internal val reactNativeHostHandlers = ExpoModulesPackage.packageList
22
22
  .flatMap { it.createReactNativeHostHandlers(application) }
23
23
  private val methodMap: ArrayMap<String, Method> = ArrayMap()
24
24
 
@@ -44,7 +44,9 @@ class ReactNativeHostWrapper(
44
44
  }
45
45
 
46
46
  override fun getJavaScriptExecutorFactory(): JavaScriptExecutorFactory? {
47
- return invokeDelegateMethod("getJavaScriptExecutorFactory")
47
+ return reactNativeHostHandlers.asSequence()
48
+ .mapNotNull { it.javaScriptExecutorFactory }
49
+ .firstOrNull() ?: invokeDelegateMethod("getJavaScriptExecutorFactory")
48
50
  }
49
51
 
50
52
  @Suppress("DEPRECATION")
@@ -100,7 +102,7 @@ class ReactNativeHostWrapper(
100
102
  }
101
103
 
102
104
  @Suppress("UNCHECKED_CAST")
103
- private fun <T> invokeDelegateMethod(name: String): T {
105
+ internal fun <T> invokeDelegateMethod(name: String): T {
104
106
  var method = methodMap[name]
105
107
  if (method == null) {
106
108
  method = ReactNativeHost::class.java.getDeclaredMethod(name)
@@ -0,0 +1,32 @@
1
+ package expo.modules
2
+
3
+ import android.app.Application
4
+ import com.facebook.react.ReactNativeHost
5
+ import com.facebook.react.ReactPackageTurboModuleManagerDelegate
6
+ import com.facebook.react.common.SurfaceDelegateFactory
7
+ import com.facebook.react.devsupport.DevSupportManagerFactory
8
+
9
+ class ReactNativeHostWrapper(
10
+ application: Application,
11
+ host: ReactNativeHost
12
+ ) : ReactNativeHostWrapperBase(application, host) {
13
+ override fun getDevSupportManagerFactory(): DevSupportManagerFactory? {
14
+ return reactNativeHostHandlers
15
+ .asSequence()
16
+ .mapNotNull { it.devSupportManagerFactory }
17
+ .firstOrNull() as DevSupportManagerFactory?
18
+ ?: invokeDelegateMethod("getDevSupportManagerFactory")
19
+ }
20
+
21
+ override fun getReactPackageTurboModuleManagerDelegateBuilder(): ReactPackageTurboModuleManagerDelegate.Builder? {
22
+ return invokeDelegateMethod("getReactPackageTurboModuleManagerDelegateBuilder")
23
+ }
24
+
25
+ override fun getShouldRequireActivity(): Boolean {
26
+ return host.shouldRequireActivity
27
+ }
28
+
29
+ override fun getSurfaceDelegateFactory(): SurfaceDelegateFactory {
30
+ return host.surfaceDelegateFactory
31
+ }
32
+ }
@@ -0,0 +1,18 @@
1
+ <manifest package="expo.modules.appauth"
2
+ xmlns:android="http://schemas.android.com/apk/res/android"
3
+ xmlns:tools="http://schemas.android.com/tools">
4
+ <application>
5
+
6
+ <!-- Fix unit test manifestMerger build error from expo -> autolinked expo-app-auth -> net.openid.appauth -->
7
+ <activity
8
+ android:name="net.openid.appauth.RedirectUriReceiverActivity"
9
+ android:exported="true" tools:node="replace">
10
+ <intent-filter>
11
+ <action android:name="android.intent.action.VIEW" />
12
+ <category android:name="android.intent.category.DEFAULT" />
13
+ <category android:name="android.intent.category.BROWSABLE" />
14
+ <data android:scheme="test" />
15
+ </intent-filter>
16
+ </activity>
17
+ </application>
18
+ </manifest>