@callstack/react-native-brownfield 3.6.1 → 3.8.0

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 (96) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/ReactBrownfield.podspec +1 -0
  3. package/android/src/main/java/com/callstack/reactnativebrownfield/ReactNativeBrownfield.kt +38 -23
  4. package/ios/ExpoHostRuntime.swift +23 -5
  5. package/ios/ReactNativeBrownfield.swift +17 -0
  6. package/ios/ReactNativeHostRuntime.swift +10 -0
  7. package/ios/ReactNativeViewController.swift +58 -6
  8. package/lib/commonjs/expo-config-plugin/android/utils/androidManifest.js +2 -0
  9. package/lib/commonjs/expo-config-plugin/android/utils/androidManifest.js.map +1 -0
  10. package/lib/commonjs/expo-config-plugin/android/utils/constants.js +1 -1
  11. package/lib/commonjs/expo-config-plugin/android/utils/expo-updates.js +2 -0
  12. package/lib/commonjs/expo-config-plugin/android/utils/expo-updates.js.map +1 -0
  13. package/lib/commonjs/expo-config-plugin/android/withAndroidModuleFiles.js +1 -1
  14. package/lib/commonjs/expo-config-plugin/android/withAndroidModuleFiles.js.map +1 -1
  15. package/lib/commonjs/expo-config-plugin/android/withBrownfieldAndroid.js +1 -1
  16. package/lib/commonjs/expo-config-plugin/android/withBrownfieldAndroid.js.map +1 -1
  17. package/lib/commonjs/expo-config-plugin/expoUtils.js +1 -1
  18. package/lib/commonjs/expo-config-plugin/expoUtils.js.map +1 -1
  19. package/lib/commonjs/expo-config-plugin/ios/utils/expo-updates.js +2 -0
  20. package/lib/commonjs/expo-config-plugin/ios/utils/expo-updates.js.map +1 -0
  21. package/lib/commonjs/expo-config-plugin/ios/withBrownfieldIos.js +1 -1
  22. package/lib/commonjs/expo-config-plugin/ios/withBrownfieldIos.js.map +1 -1
  23. package/lib/commonjs/expo-config-plugin/ios/xcodeHelpers.js +1 -1
  24. package/lib/commonjs/expo-config-plugin/ios/xcodeHelpers.js.map +1 -1
  25. package/lib/commonjs/expo-config-plugin/template/android/AndroidManifest.xml +1 -1
  26. package/lib/commonjs/expo-config-plugin/template/android/ReactNativeHostManager.post55.kt +1 -7
  27. package/lib/commonjs/expo-config-plugin/template/android/ReactNativeHostManager.pre55.kt +6 -8
  28. package/lib/commonjs/expo-config-plugin/template/android/strings.xml +4 -0
  29. package/lib/commonjs/expo-config-plugin/template/ios/patchExpoPre55.sh +2 -0
  30. package/lib/module/expo-config-plugin/android/utils/androidManifest.js +2 -0
  31. package/lib/module/expo-config-plugin/android/utils/androidManifest.js.map +1 -0
  32. package/lib/module/expo-config-plugin/android/utils/constants.js +1 -1
  33. package/lib/module/expo-config-plugin/android/utils/expo-updates.js +2 -0
  34. package/lib/module/expo-config-plugin/android/utils/expo-updates.js.map +1 -0
  35. package/lib/module/expo-config-plugin/android/withAndroidModuleFiles.js +1 -1
  36. package/lib/module/expo-config-plugin/android/withAndroidModuleFiles.js.map +1 -1
  37. package/lib/module/expo-config-plugin/android/withBrownfieldAndroid.js +1 -1
  38. package/lib/module/expo-config-plugin/android/withBrownfieldAndroid.js.map +1 -1
  39. package/lib/module/expo-config-plugin/expoUtils.js +1 -1
  40. package/lib/module/expo-config-plugin/expoUtils.js.map +1 -1
  41. package/lib/module/expo-config-plugin/ios/utils/expo-updates.js +2 -0
  42. package/lib/module/expo-config-plugin/ios/utils/expo-updates.js.map +1 -0
  43. package/lib/module/expo-config-plugin/ios/withBrownfieldIos.js +1 -1
  44. package/lib/module/expo-config-plugin/ios/withBrownfieldIos.js.map +1 -1
  45. package/lib/module/expo-config-plugin/ios/xcodeHelpers.js +1 -1
  46. package/lib/module/expo-config-plugin/ios/xcodeHelpers.js.map +1 -1
  47. package/lib/module/expo-config-plugin/template/android/AndroidManifest.xml +1 -1
  48. package/lib/module/expo-config-plugin/template/android/ReactNativeHostManager.post55.kt +1 -7
  49. package/lib/module/expo-config-plugin/template/android/ReactNativeHostManager.pre55.kt +6 -8
  50. package/lib/module/expo-config-plugin/template/android/strings.xml +4 -0
  51. package/lib/module/expo-config-plugin/template/ios/patchExpoPre55.sh +2 -0
  52. package/lib/typescript/commonjs/src/expo-config-plugin/android/utils/androidManifest.d.ts +13 -0
  53. package/lib/typescript/commonjs/src/expo-config-plugin/android/utils/androidManifest.d.ts.map +1 -0
  54. package/lib/typescript/commonjs/src/expo-config-plugin/android/utils/constants.d.ts +2 -2
  55. package/lib/typescript/commonjs/src/expo-config-plugin/android/utils/expo-updates.d.ts +12 -0
  56. package/lib/typescript/commonjs/src/expo-config-plugin/android/utils/expo-updates.d.ts.map +1 -0
  57. package/lib/typescript/commonjs/src/expo-config-plugin/android/withAndroidModuleFiles.d.ts +20 -1
  58. package/lib/typescript/commonjs/src/expo-config-plugin/android/withAndroidModuleFiles.d.ts.map +1 -1
  59. package/lib/typescript/commonjs/src/expo-config-plugin/android/withBrownfieldAndroid.d.ts.map +1 -1
  60. package/lib/typescript/commonjs/src/expo-config-plugin/expoUtils.d.ts +1 -0
  61. package/lib/typescript/commonjs/src/expo-config-plugin/expoUtils.d.ts.map +1 -1
  62. package/lib/typescript/commonjs/src/expo-config-plugin/ios/utils/expo-updates.d.ts +30 -0
  63. package/lib/typescript/commonjs/src/expo-config-plugin/ios/utils/expo-updates.d.ts.map +1 -0
  64. package/lib/typescript/commonjs/src/expo-config-plugin/ios/withBrownfieldIos.d.ts.map +1 -1
  65. package/lib/typescript/commonjs/src/expo-config-plugin/ios/xcodeHelpers.d.ts +29 -0
  66. package/lib/typescript/commonjs/src/expo-config-plugin/ios/xcodeHelpers.d.ts.map +1 -1
  67. package/lib/typescript/module/src/expo-config-plugin/android/utils/androidManifest.d.ts +13 -0
  68. package/lib/typescript/module/src/expo-config-plugin/android/utils/androidManifest.d.ts.map +1 -0
  69. package/lib/typescript/module/src/expo-config-plugin/android/utils/constants.d.ts +2 -2
  70. package/lib/typescript/module/src/expo-config-plugin/android/utils/expo-updates.d.ts +12 -0
  71. package/lib/typescript/module/src/expo-config-plugin/android/utils/expo-updates.d.ts.map +1 -0
  72. package/lib/typescript/module/src/expo-config-plugin/android/withAndroidModuleFiles.d.ts +20 -1
  73. package/lib/typescript/module/src/expo-config-plugin/android/withAndroidModuleFiles.d.ts.map +1 -1
  74. package/lib/typescript/module/src/expo-config-plugin/android/withBrownfieldAndroid.d.ts.map +1 -1
  75. package/lib/typescript/module/src/expo-config-plugin/expoUtils.d.ts +1 -0
  76. package/lib/typescript/module/src/expo-config-plugin/expoUtils.d.ts.map +1 -1
  77. package/lib/typescript/module/src/expo-config-plugin/ios/utils/expo-updates.d.ts +30 -0
  78. package/lib/typescript/module/src/expo-config-plugin/ios/utils/expo-updates.d.ts.map +1 -0
  79. package/lib/typescript/module/src/expo-config-plugin/ios/withBrownfieldIos.d.ts.map +1 -1
  80. package/lib/typescript/module/src/expo-config-plugin/ios/xcodeHelpers.d.ts +29 -0
  81. package/lib/typescript/module/src/expo-config-plugin/ios/xcodeHelpers.d.ts.map +1 -1
  82. package/package.json +4 -4
  83. package/src/expo-config-plugin/android/utils/androidManifest.ts +131 -0
  84. package/src/expo-config-plugin/android/utils/constants.ts +1 -1
  85. package/src/expo-config-plugin/android/utils/expo-updates.ts +106 -0
  86. package/src/expo-config-plugin/android/withAndroidModuleFiles.ts +122 -8
  87. package/src/expo-config-plugin/android/withBrownfieldAndroid.ts +18 -1
  88. package/src/expo-config-plugin/expoUtils.ts +14 -0
  89. package/src/expo-config-plugin/ios/utils/expo-updates.ts +168 -0
  90. package/src/expo-config-plugin/ios/withBrownfieldIos.ts +13 -1
  91. package/src/expo-config-plugin/ios/xcodeHelpers.ts +217 -4
  92. package/src/expo-config-plugin/template/android/AndroidManifest.xml +1 -1
  93. package/src/expo-config-plugin/template/android/ReactNativeHostManager.post55.kt +1 -7
  94. package/src/expo-config-plugin/template/android/ReactNativeHostManager.pre55.kt +6 -8
  95. package/src/expo-config-plugin/template/android/strings.xml +4 -0
  96. package/src/expo-config-plugin/template/ios/patchExpoPre55.sh +2 -0
@@ -182,6 +182,220 @@ export function addSourceFilesBuildPhase(
182
182
  );
183
183
  }
184
184
 
185
+ export type PbxReferenceLike = { value?: string; comment?: string } | string;
186
+
187
+ export type PbxNativeTarget = {
188
+ buildPhases?: PbxReferenceLike[];
189
+ name?: string;
190
+ };
191
+
192
+ export type PbxResourcesBuildPhase = {
193
+ isa: 'PBXResourcesBuildPhase';
194
+ buildActionMask: number;
195
+ files?: PbxReferenceLike[];
196
+ runOnlyForDeploymentPostprocessing: number;
197
+ };
198
+
199
+ export type PbxBuildFile = {
200
+ isa: 'PBXBuildFile';
201
+ fileRef: string;
202
+ };
203
+
204
+ export type PbxCommentedReference = { value: string; comment: string };
205
+
206
+ const PBX_BUILD_ACTION_MASK_ALL = 2147483647;
207
+ const PBX_RUN_ONLY_FOR_DEPLOYMENT_POSTPROCESSING_DISABLED = 0;
208
+ const PBX_RESOURCES_BUILD_PHASE_ISA = 'PBXResourcesBuildPhase';
209
+ const PBX_BUILD_FILE_ISA = 'PBXBuildFile';
210
+
211
+ export function createPbxCommentedReference(
212
+ value: string,
213
+ comment: string
214
+ ): PbxCommentedReference {
215
+ return { value, comment };
216
+ }
217
+
218
+ function createResourcesBuildPhase(): PbxResourcesBuildPhase {
219
+ return {
220
+ isa: PBX_RESOURCES_BUILD_PHASE_ISA,
221
+ buildActionMask: PBX_BUILD_ACTION_MASK_ALL,
222
+ files: [],
223
+ runOnlyForDeploymentPostprocessing:
224
+ PBX_RUN_ONLY_FOR_DEPLOYMENT_POSTPROCESSING_DISABLED,
225
+ };
226
+ }
227
+
228
+ function createBuildFile(fileRef: string): PbxBuildFile {
229
+ return {
230
+ isa: PBX_BUILD_FILE_ISA,
231
+ fileRef,
232
+ };
233
+ }
234
+
235
+ function getRawProjectObjects(project: XcodeProject): Record<string, any> {
236
+ return (project as any).hash?.project?.objects ?? {};
237
+ }
238
+
239
+ function getReferencedUuid(
240
+ reference: PbxReferenceLike | undefined
241
+ ): string | null {
242
+ if (!reference) {
243
+ return null;
244
+ }
245
+
246
+ return typeof reference === 'string' ? reference : (reference.value ?? null);
247
+ }
248
+
249
+ function getFrameworkTargetOrThrow(
250
+ project: XcodeProject,
251
+ frameworkTargetUUID: string
252
+ ): PbxNativeTarget {
253
+ const nativeTargets = getRawProjectObjects(project).PBXNativeTarget as
254
+ | Record<string, PbxNativeTarget>
255
+ | undefined;
256
+ const frameworkTarget = nativeTargets?.[frameworkTargetUUID];
257
+
258
+ if (!frameworkTarget) {
259
+ throw new SourceModificationError(
260
+ `Framework target UUID "${frameworkTargetUUID}" not found while wiring a resources build phase`
261
+ );
262
+ }
263
+
264
+ return frameworkTarget;
265
+ }
266
+
267
+ function getOrCreateResourcesBuildPhaseForTarget(
268
+ project: XcodeProject,
269
+ frameworkTargetUUID: string,
270
+ frameworkTarget: PbxNativeTarget,
271
+ resourcesBuildPhaseComment: string
272
+ ): PbxResourcesBuildPhase {
273
+ const rawProjectObjects = getRawProjectObjects(project);
274
+ const resourceBuildPhases = (rawProjectObjects.PBXResourcesBuildPhase ??
275
+ (rawProjectObjects.PBXResourcesBuildPhase = {})) as Record<
276
+ string,
277
+ PbxResourcesBuildPhase | string
278
+ >;
279
+
280
+ const resourcesBuildPhaseUuid = (frameworkTarget.buildPhases ?? [])
281
+ .map((phase) => getReferencedUuid(phase))
282
+ .find((phaseUuid): phaseUuid is string => {
283
+ return !!phaseUuid && !!resourceBuildPhases[phaseUuid];
284
+ });
285
+
286
+ if (resourcesBuildPhaseUuid) {
287
+ return resourceBuildPhases[
288
+ resourcesBuildPhaseUuid
289
+ ] as PbxResourcesBuildPhase;
290
+ }
291
+
292
+ const createdResourcesBuildPhaseUuid = (project as any).generateUuid();
293
+ resourceBuildPhases[createdResourcesBuildPhaseUuid] =
294
+ createResourcesBuildPhase();
295
+ resourceBuildPhases[`${createdResourcesBuildPhaseUuid}_comment`] =
296
+ resourcesBuildPhaseComment;
297
+
298
+ const targetBuildPhases = Array.isArray(frameworkTarget.buildPhases)
299
+ ? frameworkTarget.buildPhases
300
+ : [];
301
+ targetBuildPhases.push(
302
+ createPbxCommentedReference(
303
+ createdResourcesBuildPhaseUuid,
304
+ resourcesBuildPhaseComment
305
+ )
306
+ );
307
+ frameworkTarget.buildPhases = targetBuildPhases;
308
+
309
+ Logger.logDebug(
310
+ `Created missing PBXResourcesBuildPhase for framework target "${frameworkTargetUUID}"`
311
+ );
312
+
313
+ return resourceBuildPhases[
314
+ createdResourcesBuildPhaseUuid
315
+ ] as PbxResourcesBuildPhase;
316
+ }
317
+
318
+ function hasBuildFileForFileRef(
319
+ project: XcodeProject,
320
+ resourcesBuildPhase: PbxResourcesBuildPhase,
321
+ fileRefUuid: string
322
+ ): boolean {
323
+ const buildFileSection = project.pbxBuildFileSection() as Record<
324
+ string,
325
+ PbxBuildFile
326
+ >;
327
+ const files = Array.isArray(resourcesBuildPhase.files)
328
+ ? resourcesBuildPhase.files
329
+ : [];
330
+
331
+ return files.some((phaseFile) => {
332
+ const buildFileUuid = getReferencedUuid(phaseFile);
333
+ if (!buildFileUuid) {
334
+ return false;
335
+ }
336
+
337
+ return buildFileSection[buildFileUuid]?.fileRef === fileRefUuid;
338
+ });
339
+ }
340
+
341
+ function addBuildFileToResourcesPhase(
342
+ project: XcodeProject,
343
+ resourcesBuildPhase: PbxResourcesBuildPhase,
344
+ fileRefUuid: string,
345
+ buildFileComment: string
346
+ ): void {
347
+ const buildFileSection = project.pbxBuildFileSection() as Record<
348
+ string,
349
+ PbxBuildFile | string
350
+ >;
351
+ const buildFileUuid = (project as any).generateUuid();
352
+
353
+ buildFileSection[buildFileUuid] = createBuildFile(fileRefUuid);
354
+ buildFileSection[`${buildFileUuid}_comment`] = buildFileComment;
355
+
356
+ const files = Array.isArray(resourcesBuildPhase.files)
357
+ ? resourcesBuildPhase.files
358
+ : [];
359
+ files.push(createPbxCommentedReference(buildFileUuid, buildFileComment));
360
+ resourcesBuildPhase.files = files;
361
+ }
362
+
363
+ type ResourcesBuildPhaseOptions = {
364
+ resourcesBuildPhaseComment: string;
365
+ buildFileComment: string;
366
+ };
367
+
368
+ export function ensureTargetHasFileReferenceInResourcesBuildPhase(
369
+ project: XcodeProject,
370
+ frameworkTargetUUID: string,
371
+ fileRefUuid: string,
372
+ { resourcesBuildPhaseComment, buildFileComment }: ResourcesBuildPhaseOptions
373
+ ): boolean {
374
+ const frameworkTarget = getFrameworkTargetOrThrow(
375
+ project,
376
+ frameworkTargetUUID
377
+ );
378
+ const resourcesBuildPhase = getOrCreateResourcesBuildPhaseForTarget(
379
+ project,
380
+ frameworkTargetUUID,
381
+ frameworkTarget,
382
+ resourcesBuildPhaseComment
383
+ );
384
+
385
+ if (hasBuildFileForFileRef(project, resourcesBuildPhase, fileRefUuid)) {
386
+ return false;
387
+ }
388
+
389
+ addBuildFileToResourcesPhase(
390
+ project,
391
+ resourcesBuildPhase,
392
+ fileRefUuid,
393
+ buildFileComment
394
+ );
395
+
396
+ return true;
397
+ }
398
+
185
399
  /**
186
400
  * Returns build settings for the framework target
187
401
  * @param options The user configuration
@@ -277,10 +491,9 @@ export function copyBundleReactNativePhase(
277
491
  (phase: { value: string }) => phase.value === existingPhaseUuid
278
492
  )
279
493
  ) {
280
- target.buildPhases.push({
281
- value: existingPhaseUuid,
282
- comment: buildPhaseName,
283
- });
494
+ target.buildPhases.push(
495
+ createPbxCommentedReference(existingPhaseUuid, buildPhaseName)
496
+ );
284
497
 
285
498
  Logger.logDebug(
286
499
  `Added "${buildPhaseName}" build phase to framework target ${target.name}`
@@ -1,4 +1,4 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
2
  <manifest xmlns:android="http://schemas.android.com/apk/res/android">
3
-
3
+ {{APPLICATION_BLOCK}}
4
4
  </manifest>
@@ -5,25 +5,19 @@ import android.content.res.Configuration
5
5
  import com.callstack.reactnativebrownfield.OnJSBundleLoaded
6
6
  import com.callstack.reactnativebrownfield.ReactNativeBrownfield
7
7
  import com.facebook.react.PackageList
8
- import com.facebook.react.ReactHost
9
- import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
10
8
  import expo.modules.ApplicationLifecycleDispatcher
11
9
  import expo.modules.ExpoReactHostFactory
12
10
 
13
11
  object ReactNativeHostManager {
14
12
  fun initialize(application: Application, onJSBundleLoaded: OnJSBundleLoaded? = null) {
15
- loadReactNative(application)
16
-
17
13
  ApplicationLifecycleDispatcher.onApplicationCreate(application)
18
14
 
19
- val reactHost: ReactHost by lazy {
15
+ ReactNativeBrownfield.initialize(application, onJSBundleLoaded) {
20
16
  ExpoReactHostFactory.getDefaultReactHost(
21
17
  context = application.applicationContext,
22
18
  packageList = PackageList(application).packages,
23
19
  )
24
20
  }
25
-
26
- ReactNativeBrownfield.initialize(application, reactHost, onJSBundleLoaded)
27
21
  }
28
22
 
29
23
  fun onConfigurationChanged(application: Application, newConfig: Configuration) {
@@ -5,18 +5,15 @@ import android.content.res.Configuration
5
5
  import com.callstack.reactnativebrownfield.OnJSBundleLoaded
6
6
  import com.callstack.reactnativebrownfield.ReactNativeBrownfield
7
7
  import com.facebook.react.PackageList
8
- import com.facebook.react.ReactHost
9
- import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
10
8
  import com.facebook.react.ReactPackage
11
9
  import com.facebook.react.defaults.DefaultReactNativeHost
12
10
  import expo.modules.ApplicationLifecycleDispatcher
13
11
  import expo.modules.ExpoReactHostFactory
14
12
  import expo.modules.ReactNativeHostWrapper
13
+ {{EXPO_UPDATES_IMPORTS}}
15
14
 
16
15
  object ReactNativeHostManager {
17
16
  fun initialize(application: Application, onJSBundleLoaded: OnJSBundleLoaded? = null) {
18
- loadReactNative(application)
19
-
20
17
  ApplicationLifecycleDispatcher.onApplicationCreate(application)
21
18
 
22
19
  val reactNativeHost = ReactNativeHostWrapper(
@@ -38,14 +35,15 @@ object ReactNativeHostManager {
38
35
  })
39
36
 
40
37
 
41
- val reactHost: ReactHost by lazy {
42
- ExpoReactHostFactory.createFromReactNativeHost(
38
+ ReactNativeBrownfield.initialize(application, onJSBundleLoaded) {
39
+ val reactHost = ExpoReactHostFactory.createFromReactNativeHost(
43
40
  context = application.applicationContext,
44
41
  reactNativeHost = reactNativeHost
45
42
  )
43
+
44
+ {{EXPO_UPDATES_REACT_HOST_BLOCK}}
45
+ reactHost
46
46
  }
47
-
48
- ReactNativeBrownfield.initialize(application, reactHost, onJSBundleLoaded)
49
47
  }
50
48
 
51
49
  fun onConfigurationChanged(application: Application, newConfig: Configuration) {
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ {{STRING_RESOURCES}}
4
+ </resources>
@@ -11,6 +11,8 @@ if [ -f "$FILE" ]; then
11
11
 
12
12
  sed -i '' 's/^import Ex/internal import Ex/' "$FILE"
13
13
 
14
+ sed -i '' 's/^import EA/internal import EA/' "$FILE"
15
+
14
16
  # 2. Replace class visibility
15
17
  sed -i '' 's/public class ExpoModulesProvider/internal class ExpoModulesProvider/' "$FILE"
16
18