forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact-native-config+1.5.0.patch
518 lines (494 loc) · 19 KB
/
react-native-config+1.5.0.patch
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
diff --git a/node_modules/react-native-config/README.md b/node_modules/react-native-config/README.md
index 8424402..ca29e39 100644
--- a/node_modules/react-native-config/README.md
+++ b/node_modules/react-native-config/README.md
@@ -78,13 +78,13 @@ if cocoapods are used in the project then pod has to be installed as well:
**MainApplication.java**
```diff
- + import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;
+ + import com.lugg.RNCConfig.RNCConfigPackage;
@Override
protected List<ReactPackage> getPackages() {
return Arrays.asList(
new MainReactPackage()
- + new ReactNativeConfigPackage()
+ + new RNCConfigPackage()
);
}
```
diff --git a/node_modules/react-native-config/android/build.gradle b/node_modules/react-native-config/android/build.gradle
index c8f7fd4..86b3e1a 100644
--- a/node_modules/react-native-config/android/build.gradle
+++ b/node_modules/react-native-config/android/build.gradle
@@ -15,6 +15,55 @@ def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
+def resolveReactNativeDirectory() {
+ def reactNativeLocation = safeExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
+ if (reactNativeLocation != null) {
+ return file(reactNativeLocation)
+ }
+
+ // monorepo workaround
+ // react-native can be hoisted or in project's own node_modules
+ def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
+ if (reactNativeFromProjectNodeModules.exists()) {
+ return reactNativeFromProjectNodeModules
+ }
+
+ def reactNativeFromNodeModulesWithRNCConfig = file("${projectDir}/../../react-native")
+ if (reactNativeFromNodeModulesWithRNCConfig.exists()) {
+ return reactNativeFromNodeModulesWithRNCConfig
+ }
+
+ throw new Exception(
+ "[react-native-config] Unable to resolve react-native location in " +
+ "node_modules. You should add project extension property (in app/build.gradle) " +
+ "`REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
+ )
+}
+
+def getReactNativeMinorVersion() {
+ def REACT_NATIVE_DIR = resolveReactNativeDirectory()
+
+ def reactProperties = new Properties()
+ file("$REACT_NATIVE_DIR/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
+
+ def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
+ def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
+
+ return REACT_NATIVE_MINOR_VERSION
+}
+
+def isNewArchitectureEnabled() {
+ // To opt-in for the New Architecture, you can either:
+ // - Set `newArchEnabled` to true inside the `gradle.properties` file
+ // - Invoke gradle with `-newArchEnabled=true`
+ // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
+ return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
+}
+
+if (isNewArchitectureEnabled()) {
+ apply plugin: "com.facebook.react"
+}
+
android {
compileSdkVersion rootProject.ext.compileSdkVersion
@@ -23,10 +72,23 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
+
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}
lintOptions {
abortOnError false
}
+
+ sourceSets.main {
+ java {
+ if (!isNewArchitectureEnabled()) {
+ srcDirs += 'src/paper/java'
+ } else {
+ // This should be done by the RN gradle plugin, for some reason it sometimes doesn't work
+ srcDirs += 'build/generated/source/codegen/java'
+ }
+ }
+ }
}
repositories {
@@ -34,5 +96,9 @@ repositories {
}
dependencies {
- implementation "com.facebook.react:react-native:${safeExtGet("reactNative", "+")}" // from node_modules
+ if (isNewArchitectureEnabled() && getReactNativeMinorVersion() < 71) {
+ implementation project(":ReactAndroid")
+ } else {
+ implementation 'com.facebook.react:react-native:+'
+ }
}
diff --git a/node_modules/react-native-config/android/src/main/java/com/lugg/RNCConfig/RNCConfigModule.java b/node_modules/react-native-config/android/src/main/java/com/lugg/RNCConfig/RNCConfigModule.java
index 0b52515..bef2834 100644
--- a/node_modules/react-native-config/android/src/main/java/com/lugg/RNCConfig/RNCConfigModule.java
+++ b/node_modules/react-native-config/android/src/main/java/com/lugg/RNCConfig/RNCConfigModule.java
@@ -13,20 +13,32 @@ import java.lang.reflect.Field;
import java.util.Map;
import java.util.HashMap;
-public class RNCConfigModule extends ReactContextBaseJavaModule {
+public class RNCConfigModule extends NativeConfigModuleSpec {
+ public static final String NAME = "RNCConfigModule";
+
public RNCConfigModule(ReactApplicationContext reactContext) {
super(reactContext);
}
@Override
public String getName() {
- return "RNCConfigModule";
+ return NAME;
}
@Override
- public Map<String, Object> getConstants() {
+ public Map<String, Object> getTypedExportedConstants() {
final Map<String, Object> constants = new HashMap<>();
+ // Codegen ensures that the constants defined in the module spec and in the native module implementation
+ // are consistent, which is tad problematic in this case, as the constants are dependant on the `.env`
+ // file. The simple workaround is to define a `constants` object that will contain actual constants.
+ // This way the types between JS and Native side remain consistent, while functionality stays the same.
+ // TL;DR:
+ // instead of exporting { constant1: "value1", constant2: "value2" }
+ // we export { constants: { constant1: "value1", constant2: "value2" } }
+ // because of type safety on the new arch
+ final Map<String, Object> realConstants = new HashMap<>();
+
try {
Context context = getReactApplicationContext();
int resId = context.getResources().getIdentifier("build_config_package", "string", context.getPackageName());
@@ -40,7 +52,7 @@ public class RNCConfigModule extends ReactContextBaseJavaModule {
Field[] fields = clazz.getDeclaredFields();
for(Field f: fields) {
try {
- constants.put(f.getName(), f.get(null));
+ realConstants.put(f.getName(), f.get(null));
}
catch (IllegalAccessException e) {
Log.d("ReactNative", "ReactConfig: Could not access BuildConfig field " + f.getName());
@@ -51,6 +63,8 @@ public class RNCConfigModule extends ReactContextBaseJavaModule {
Log.d("ReactNative", "ReactConfig: Could not find BuildConfig class");
}
+ constants.put("constants", realConstants);
+
return constants;
}
}
diff --git a/node_modules/react-native-config/android/src/main/java/com/lugg/RNCConfig/RNCConfigPackage.java b/node_modules/react-native-config/android/src/main/java/com/lugg/RNCConfig/RNCConfigPackage.java
index 9251c09..2edd797 100644
--- a/node_modules/react-native-config/android/src/main/java/com/lugg/RNCConfig/RNCConfigPackage.java
+++ b/node_modules/react-native-config/android/src/main/java/com/lugg/RNCConfig/RNCConfigPackage.java
@@ -1,29 +1,42 @@
package com.lugg.RNCConfig;
-import com.facebook.react.ReactPackage;
-import com.facebook.react.bridge.JavaScriptModule;
+import com.facebook.react.TurboReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
-import com.facebook.react.uimanager.ViewManager;
+import com.facebook.react.module.model.ReactModuleInfo;
+import com.facebook.react.module.model.ReactModuleInfoProvider;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
-public class RNCConfigPackage implements ReactPackage {
- @Override
- public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
- return Arrays.<NativeModule>asList(
- new RNCConfigModule(reactContext)
- );
- }
+public class RNCConfigPackage extends TurboReactPackage {
- public List<Class<? extends JavaScriptModule>> createJSModules() {
- return Collections.emptyList();
+ @Override
+ public NativeModule getModule(String name, ReactApplicationContext reactContext) {
+ if (name.equals(RNCConfigModule.NAME)) {
+ return new RNCConfigModule(reactContext);
+ } else {
+ return null;
+ }
}
@Override
- public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
- return Collections.emptyList();
+ public ReactModuleInfoProvider getReactModuleInfoProvider() {
+ return () -> {
+ final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
+ boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
+ moduleInfos.put(
+ RNCConfigModule.NAME,
+ new ReactModuleInfo(
+ RNCConfigModule.NAME,
+ RNCConfigModule.NAME,
+ false, // canOverrideExistingModule
+ false, // needsEagerInit
+ true, // hasConstants
+ false, // isCxxModule
+ isTurboModule // isTurboModule
+ ));
+ return moduleInfos;
+ };
}
}
diff --git a/node_modules/react-native-config/android/src/paper/java/com/lugg/RNCConfig/NativeConfigModuleSpec.java b/node_modules/react-native-config/android/src/paper/java/com/lugg/RNCConfig/NativeConfigModuleSpec.java
new file mode 100644
index 0000000..7a65504
--- /dev/null
+++ b/node_modules/react-native-config/android/src/paper/java/com/lugg/RNCConfig/NativeConfigModuleSpec.java
@@ -0,0 +1,58 @@
+
+/**
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
+ *
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
+ * once the code is regenerated.
+ *
+ * @generated by codegen project: GenerateModuleJavaSpec.js
+ *
+ * @nolint
+ */
+
+package com.lugg.RNCConfig;
+
+import com.facebook.proguard.annotations.DoNotStrip;
+import com.facebook.react.bridge.ReactApplicationContext;
+import com.facebook.react.bridge.ReactContextBaseJavaModule;
+import com.facebook.react.bridge.ReactMethod;
+import com.facebook.react.bridge.ReactModuleWithSpec;
+import com.facebook.react.common.build.ReactBuildConfig;
+import com.facebook.react.turbomodule.core.interfaces.TurboModule;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+
+public abstract class NativeConfigModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
+ public NativeConfigModuleSpec(ReactApplicationContext reactContext) {
+ super(reactContext);
+ }
+
+ protected abstract Map<String, Object> getTypedExportedConstants();
+
+ @Override
+ @DoNotStrip
+ public final @Nullable Map<String, Object> getConstants() {
+ Map<String, Object> constants = getTypedExportedConstants();
+ if (ReactBuildConfig.DEBUG || ReactBuildConfig.IS_INTERNAL_BUILD) {
+ Set<String> obligatoryFlowConstants = new HashSet<>(Arrays.asList(
+ "constants"
+ ));
+ Set<String> optionalFlowConstants = new HashSet<>();
+ Set<String> undeclaredConstants = new HashSet<>(constants.keySet());
+ undeclaredConstants.removeAll(obligatoryFlowConstants);
+ undeclaredConstants.removeAll(optionalFlowConstants);
+ if (!undeclaredConstants.isEmpty()) {
+ throw new IllegalStateException(String.format("Native Module Flow doesn't declare constants: %s", undeclaredConstants));
+ }
+ undeclaredConstants = obligatoryFlowConstants;
+ undeclaredConstants.removeAll(constants.keySet());
+ if (!undeclaredConstants.isEmpty()) {
+ throw new IllegalStateException(String.format("Native Module doesn't fill in constants: %s", undeclaredConstants));
+ }
+ }
+ return constants;
+ }
+}
diff --git a/node_modules/react-native-config/codegen/NativeConfigModule.js b/node_modules/react-native-config/codegen/NativeConfigModule.js
new file mode 100644
index 0000000..8cc9ac8
--- /dev/null
+++ b/node_modules/react-native-config/codegen/NativeConfigModule.js
@@ -0,0 +1,11 @@
+// @flow
+import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
+import { TurboModuleRegistry } from 'react-native';
+
+export interface Spec extends TurboModule {
+ +getConstants: () => {|
+ constants: Object,
+ |};
+}
+
+export default (TurboModuleRegistry.get<Spec>('RNCConfigModule'): ?Spec);
diff --git a/node_modules/react-native-config/index.js b/node_modules/react-native-config/index.js
index 70866c4..a8f3624 100644
--- a/node_modules/react-native-config/index.js
+++ b/node_modules/react-native-config/index.js
@@ -1,9 +1,10 @@
'use strict';
-// Bridge to:
-// Android: buildConfigField vars set in build.gradle, and exported via ReactConfig
-// iOS: config vars set in xcconfig and exposed via RNCConfig.m
-import { NativeModules } from 'react-native';
+import { NativeModules, Platform } from 'react-native';
+
+// new arch is not supported on Windows yet
+export const Config = Platform.OS === 'windows'
+ ? NativeModules.RNCConfigModule
+ : require('./codegen/NativeConfigModule').default.getConstants().constants;
-export const Config = NativeModules.RNCConfigModule || {}
export default Config;
diff --git a/node_modules/react-native-config/ios/ReactNativeConfig/GeneratedDotEnv.m b/node_modules/react-native-config/ios/ReactNativeConfig/GeneratedDotEnv.m
index 04a2f3d..59df625 100644
--- a/node_modules/react-native-config/ios/ReactNativeConfig/GeneratedDotEnv.m
+++ b/node_modules/react-native-config/ios/ReactNativeConfig/GeneratedDotEnv.m
@@ -1 +1 @@
- #define DOT_ENV @{ };
+ #define DOT_ENV @{ @"ENV":@"dev",@"API_URL":@"http://localhost" };
diff --git a/node_modules/react-native-config/ios/ReactNativeConfig/RNCConfigModule.h b/node_modules/react-native-config/ios/ReactNativeConfig/RNCConfigModule.h
index 755d103..5341aca 100644
--- a/node_modules/react-native-config/ios/ReactNativeConfig/RNCConfigModule.h
+++ b/node_modules/react-native-config/ios/ReactNativeConfig/RNCConfigModule.h
@@ -1,3 +1,9 @@
+#ifdef RCT_NEW_ARCH_ENABLED
+#import "RNCConfigSpec.h"
+
+@interface RNCConfigModule : NSObject <NativeConfigModuleSpec>
+#else
+
#if __has_include(<React/RCTBridgeModule.h>)
#import <React/RCTBridgeModule.h>
#elif __has_include("React/RCTBridgeModule.h")
@@ -7,6 +13,7 @@
#endif
@interface RNCConfigModule : NSObject <RCTBridgeModule>
+#endif // RCT_NEW_ARCH_ENABLED
+ (NSDictionary *)env;
+ (NSString *)envFor: (NSString *)key;
diff --git a/node_modules/react-native-config/ios/ReactNativeConfig/RNCConfigModule.m b/node_modules/react-native-config/ios/ReactNativeConfig/RNCConfigModule.m
deleted file mode 100644
index 5365d4c..0000000
--- a/node_modules/react-native-config/ios/ReactNativeConfig/RNCConfigModule.m
+++ /dev/null
@@ -1,25 +0,0 @@
-#import "RNCConfig.h"
-#import "RNCConfigModule.h"
-
-@implementation RNCConfigModule
-
-RCT_EXPORT_MODULE()
-
-+ (BOOL)requiresMainQueueSetup
-{
- return YES;
-}
-
-+ (NSDictionary *)env {
- return RNCConfig.env;
-}
-
-+ (NSString *)envFor: (NSString *)key {
- return [RNCConfig envFor:key];
-}
-
-- (NSDictionary *)constantsToExport {
- return RNCConfig.env;
-}
-
-@end
diff --git a/node_modules/react-native-config/ios/ReactNativeConfig/RNCConfigModule.mm b/node_modules/react-native-config/ios/ReactNativeConfig/RNCConfigModule.mm
new file mode 100644
index 0000000..1cacb65
--- /dev/null
+++ b/node_modules/react-native-config/ios/ReactNativeConfig/RNCConfigModule.mm
@@ -0,0 +1,37 @@
+#import "RNCConfig.h"
+#import "RNCConfigModule.h"
+
+@implementation RNCConfigModule
+
+RCT_EXPORT_MODULE()
+
++ (BOOL)requiresMainQueueSetup
+{
+ return YES;
+}
+
++ (NSDictionary *)env {
+ return RNCConfig.env;
+}
+
++ (NSString *)envFor: (NSString *)key {
+ return [RNCConfig envFor:key];
+}
+
+- (NSDictionary *)constantsToExport {
+ return @{ @"constants": RNCConfig.env };
+}
+
+- (NSDictionary *)getConstants {
+ return self.constantsToExport;
+}
+
+#ifdef RCT_NEW_ARCH_ENABLED
+- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
+ (const facebook::react::ObjCTurboModule::InitParams &)params
+{
+ return std::make_shared<facebook::react::NativeConfigModuleSpecJSI>(params);
+}
+#endif
+
+@end
diff --git a/node_modules/react-native-config/package.json b/node_modules/react-native-config/package.json
index b4d1fba..0a018a7 100644
--- a/node_modules/react-native-config/package.json
+++ b/node_modules/react-native-config/package.json
@@ -26,6 +26,7 @@
"android/",
"ios/",
"windows/",
+ "codegen/",
"index.js",
"index.d.ts",
"react-native-config.podspec",
@@ -38,11 +39,21 @@
"semantic-release": "^17.0.4"
},
"peerDependencies": {
+ "react": "*",
+ "react-native": "*",
"react-native-windows": ">=0.61"
},
"peerDependenciesMeta": {
"react-native-windows": {
"optional": true
}
+ },
+ "codegenConfig": {
+ "name": "RNCConfigSpec",
+ "type": "modules",
+ "jsSrcsDir": "./codegen",
+ "android": {
+ "javaPackageName": "com.lugg.RNCConfig"
+ }
}
}
diff --git a/node_modules/react-native-config/react-native-config.podspec b/node_modules/react-native-config/react-native-config.podspec
index 35313d4..56bce4a 100644
--- a/node_modules/react-native-config/react-native-config.podspec
+++ b/node_modules/react-native-config/react-native-config.podspec
@@ -4,6 +4,8 @@ require 'json'
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
+fabric_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
+
Pod::Spec.new do |s|
s.name = 'react-native-config'
s.version = package['version']
@@ -33,8 +35,27 @@ HOST_PATH="$SRCROOT/../.."
s.default_subspec = 'App'
s.subspec 'App' do |app|
- app.source_files = 'ios/**/*.{h,m}'
- app.dependency 'React-Core'
+ app.source_files = 'ios/**/*.{h,m,mm}'
+
+ if fabric_enabled
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
+
+ app.pod_target_xcconfig = {
+ 'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/boost" "$(PODS_ROOT)/boost-for-react-native" "$(PODS_ROOT)/RCT-Folly"',
+ 'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
+ }
+ app.compiler_flags = folly_compiler_flags + ' -DRCT_NEW_ARCH_ENABLED'
+
+ app.dependency "React"
+ app.dependency "React-RCTFabric" # This is for fabric component
+ app.dependency "React-Codegen"
+ app.dependency "RCT-Folly"
+ app.dependency "RCTRequired"
+ app.dependency "RCTTypeSafety"
+ app.dependency "ReactCommon/turbomodule/core"
+ else
+ app.dependency 'React-Core'
+ end
end
# Use this subspec for iOS extensions that cannot use React dependency