forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
react-native-config+1.5.3.patch
475 lines (455 loc) · 17.1 KB
/
react-native-config+1.5.3.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
diff --git a/node_modules/react-native-config/android/build.gradle b/node_modules/react-native-config/android/build.gradle
index d3bdb07..1629423 100644
--- a/node_modules/react-native-config/android/build.gradle
+++ b/node_modules/react-native-config/android/build.gradle
@@ -15,6 +15,18 @@ def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
+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"
+}
+
def supportsNamespace() {
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.');
def major = parsed[0].toInteger();
@@ -44,10 +56,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 {
@@ -55,5 +80,5 @@ repositories {
}
dependencies {
- implementation "com.facebook.react:react-native:${safeExtGet("reactNative", "+")}" // from node_modules
+ 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 55b853b..2784795 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
@@ -11,41 +11,58 @@ 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);
- }
+ public RNCConfigModule(ReactApplicationContext reactContext) {
+ super(reactContext);
+ }
- @Override
- public String getName() {
- return "RNCConfigModule";
- }
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ 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<>();
- @Override
- public Map<String, Object> getConstants() {
- final Map<String, Object> constants = new HashMap<>();
+ try {
+ Context context = getReactApplicationContext();
+ int resId = context.getResources().getIdentifier("build_config_package", "string", context.getPackageName());
+ String className;
+ try {
+ className = context.getString(resId);
+ } catch (Resources.NotFoundException e) {
+ className = getReactApplicationContext().getApplicationContext().getPackageName();
+ }
+ Class clazz = Class.forName(className + ".BuildConfig");
+ Field[] fields = clazz.getDeclaredFields();
+ for(Field f: fields) {
try {
- Context context = getReactApplicationContext();
- int resId = context.getResources().getIdentifier("build_config_package", "string", context.getPackageName());
- String className;
- try {
- className = context.getString(resId);
- } catch (Resources.NotFoundException e) {
- className = getReactApplicationContext().getApplicationContext().getPackageName();
- }
- Class clazz = Class.forName(className + ".BuildConfig");
- Field[] fields = clazz.getDeclaredFields();
- for (Field f : fields) {
- try {
- constants.put(f.getName(), f.get(null));
- } catch (IllegalAccessException e) {
- Log.d("ReactNative", "ReactConfig: Could not access BuildConfig field " + f.getName());
- }
- }
- } catch (ClassNotFoundException e) {
- Log.d("ReactNative", "ReactConfig: Could not find BuildConfig class");
+ realConstants.put(f.getName(), f.get(null));
}
- return constants;
+ catch (IllegalAccessException e) {
+ Log.d("ReactNative", "ReactConfig: Could not access BuildConfig field " + f.getName());
+ }
+ }
+ }
+ catch (ClassNotFoundException e) {
+ 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 599a81a..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,27 +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 java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
+import com.facebook.react.module.model.ReactModuleInfo;
+import com.facebook.react.module.model.ReactModuleInfoProvider;
-public class RNCConfigPackage implements ReactPackage {
+import java.util.HashMap;
+import java.util.Map;
- @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/RNCConfigModule.h b/node_modules/react-native-config/ios/ReactNativeConfig/RNCConfigModule.h
index 755d103..4e4c564 100644
--- a/node_modules/react-native-config/ios/ReactNativeConfig/RNCConfigModule.h
+++ b/node_modules/react-native-config/ios/ReactNativeConfig/RNCConfigModule.h
@@ -1,12 +1,15 @@
-#if __has_include(<React/RCTBridgeModule.h>)
-#import <React/RCTBridgeModule.h>
-#elif __has_include("React/RCTBridgeModule.h")
-#import "React/RCTBridgeModule.h"
+#ifdef RCT_NEW_ARCH_ENABLED
+#import "RNCConfigSpec.h"
#else
-#import "RCTBridgeModule.h"
-#endif
+#import <React/RCTBridgeModule.h>
+#endif // RCT_NEW_ARCH_ENABLED
-@interface RNCConfigModule : NSObject <RCTBridgeModule>
+@interface RNCConfigModule : NSObject
+#ifdef RCT_NEW_ARCH_ENABLED
+<NativeConfigModuleSpec>
+#else
+<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 f758725..f338b41 100644
--- a/node_modules/react-native-config/package.json
+++ b/node_modules/react-native-config/package.json
@@ -27,6 +27,7 @@
"android/",
"ios/",
"windows/",
+ "codegen/",
"index.js",
"index.d.ts",
"react-native-config.podspec",
@@ -39,11 +40,21 @@
"semantic-release": "^19.0.5"
},
"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 449b970..88b14c5 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']
@@ -35,8 +37,13 @@ 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
+ install_modules_dependencies(app)
+ else
+ app.dependency 'React-Core'
+ end
end
# Use this subspec for iOS extensions that cannot use React dependency