@wanderlogapp/react-native 0.86.3-wanderlog.2 → 0.86.3-wanderlog.3

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.
@@ -14,7 +14,6 @@ import type {RootTag} from '../Types/RootTagTypes';
14
14
  import type {UIManagerJSInterface} from '../Types/UIManagerJSInterface';
15
15
 
16
16
  import {unstable_hasComponent} from '../NativeComponent/NativeComponentRegistryUnstable';
17
- import defineLazyObjectProperty from '../Utilities/defineLazyObjectProperty';
18
17
  import Platform from '../Utilities/Platform';
19
18
  import {getFabricUIManager} from './FabricUIManager';
20
19
  import nullthrows from 'nullthrows';
@@ -44,6 +43,20 @@ const getUIManagerConstantsCached = (function () {
44
43
  const getConstantsForViewManager: ?(viewManagerName: string) => ?Object =
45
44
  global.RN$LegacyInterop_UIManager_getConstantsForViewManager;
46
45
 
46
+ // Unknown names are cached as null too, because a miss is slow on Android:
47
+ // every on-demand package tries to create the view manager.
48
+ const viewManagerConfigCache: Map<string, ?Object> = new Map();
49
+
50
+ function getConstantsForViewManagerCached(viewManagerName: string): ?Object {
51
+ if (!viewManagerConfigCache.has(viewManagerName)) {
52
+ viewManagerConfigCache.set(
53
+ viewManagerName,
54
+ nullthrows(getConstantsForViewManager)(viewManagerName),
55
+ );
56
+ }
57
+ return viewManagerConfigCache.get(viewManagerName);
58
+ }
59
+
47
60
  const getDefaultEventTypes: ?() => Object =
48
61
  global.RN$LegacyInterop_UIManager_getDefaultEventTypes;
49
62
 
@@ -167,20 +180,12 @@ const UIManagerJSPlatformAPIs = Platform.select({
167
180
  android: {
168
181
  getConstantsForViewManager: (viewManagerName: string): ?Object => {
169
182
  if (getConstantsForViewManager) {
170
- return getConstantsForViewManager(viewManagerName);
183
+ return getConstantsForViewManagerCached(viewManagerName);
171
184
  }
172
185
 
173
186
  raiseSoftError('getConstantsForViewManager');
174
187
  return {};
175
188
  },
176
- getDefaultEventTypes: (): Array<string> => {
177
- if (getDefaultEventTypes) {
178
- return getDefaultEventTypesCached();
179
- }
180
-
181
- raiseSoftError('getDefaultEventTypes');
182
- return [];
183
- },
184
189
  setLayoutAnimationEnabledExperimental: (enabled: boolean): void => {
185
190
  if (__DEV__) {
186
191
  console.warn(
@@ -266,16 +271,8 @@ const UIManagerJS: UIManagerJSInterface & {[string]: any} = {
266
271
  ...UIManagerJSPlatformAPIs,
267
272
  ...UIManagerJSUnusedInNewArchAPIs,
268
273
  getViewManagerConfig: (viewManagerName: string): unknown => {
269
- if (getUIManagerConstants) {
270
- const constants = getUIManagerConstantsCached();
271
- if (
272
- !constants[viewManagerName] &&
273
- UIManagerJS.getConstantsForViewManager
274
- ) {
275
- constants[viewManagerName] =
276
- UIManagerJS.getConstantsForViewManager(viewManagerName);
277
- }
278
- return constants[viewManagerName];
274
+ if (getConstantsForViewManager) {
275
+ return getConstantsForViewManagerCached(viewManagerName);
279
276
  } else {
280
277
  raiseSoftError(
281
278
  `getViewManagerConfig('${viewManagerName}')`,
@@ -295,6 +292,14 @@ const UIManagerJS: UIManagerJSInterface & {[string]: any} = {
295
292
  return null;
296
293
  }
297
294
  },
295
+ getDefaultEventTypes: (): Object => {
296
+ if (getDefaultEventTypes) {
297
+ return getDefaultEventTypesCached();
298
+ }
299
+
300
+ raiseSoftError('getDefaultEventTypes');
301
+ return {};
302
+ },
298
303
  findSubviewIn: (
299
304
  reactTag: number,
300
305
  point: Array<number>,
@@ -396,19 +401,4 @@ const UIManagerJS: UIManagerJSInterface & {[string]: any} = {
396
401
  },
397
402
  };
398
403
 
399
- if (getUIManagerConstants) {
400
- Object.keys(getUIManagerConstantsCached()).forEach(viewConfigName => {
401
- UIManagerJS[viewConfigName] = getUIManagerConstantsCached()[viewConfigName];
402
- });
403
-
404
- if (UIManagerJS.getConstants().ViewManagerNames) {
405
- UIManagerJS.getConstants().ViewManagerNames.forEach(viewManagerName => {
406
- defineLazyObjectProperty(UIManagerJS, viewManagerName, {
407
- get: () =>
408
- nullthrows(UIManagerJS.getConstantsForViewManager)(viewManagerName),
409
- });
410
- });
411
- }
412
- }
413
-
414
404
  export default UIManagerJS;
@@ -23,9 +23,7 @@ const UIManagerImpl: UIManagerJSInterface =
23
23
  ? require('./BridgelessUIManager').default
24
24
  : require('./PaperUIManager').default;
25
25
 
26
- // $FlowFixMe[cannot-spread-interface]
27
- const UIManager: UIManagerJSInterface = {
28
- ...UIManagerImpl,
26
+ const UIManagerOverrides = {
29
27
  measure(
30
28
  reactTag: number,
31
29
  callback: (
@@ -190,4 +188,19 @@ const UIManager: UIManagerJSInterface = {
190
188
  },
191
189
  };
192
190
 
191
+ // Copy property descriptors instead of spreading UIManagerImpl. In Bridgeless
192
+ // mode, UIManagerImpl may define enumerable lazy ViewManager getters. Spreading
193
+ // the object would invoke every getter during module initialization.
194
+ // $FlowFixMe[incompatible-type] Flow cannot infer properties from descriptors.
195
+ const UIManager: UIManagerJSInterface = Object.create(
196
+ Object.getPrototypeOf(UIManagerImpl),
197
+ {
198
+ ...Object.getOwnPropertyDescriptors(
199
+ // $FlowFixMe[class-object-subtyping] UIManagerImpl is a runtime object.
200
+ UIManagerImpl,
201
+ ),
202
+ ...Object.getOwnPropertyDescriptors(UIManagerOverrides),
203
+ },
204
+ );
205
+
193
206
  export default UIManager;
@@ -110,6 +110,12 @@ function getNativeComponentAttributes(uiViewClassName: string): any {
110
110
  }
111
111
 
112
112
  function attachDefaultEventTypes(viewConfig: any) {
113
+ // Prefer getDefaultEventTypes, because getConstants() builds every view
114
+ // manager's config. Only bridge mode gets past this.
115
+ if (global.RN$LegacyInterop_UIManager_getDefaultEventTypes != null) {
116
+ merge(viewConfig, nullthrows(UIManager.getDefaultEventTypes)());
117
+ return;
118
+ }
113
119
  // This is supported on UIManager platforms (ex: Android),
114
120
  // as lazy view managers are not implemented for all platforms.
115
121
  // See [UIManager] for details on constants and implementations.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Wanderlog-specific header
2
2
 
3
- This is Wanderlog's fork of React Native. See [**Patching React Native**](https://app.notion.com/p/wanderlog/Patching-React-Native-17b4797ed24d481eb2155c9daec1ba98) in Notion for how to patch, backport, publish and upgrade it.
3
+ This is Wanderlog's fork of React Native, published to npm as [`@wanderlogapp/react-native`](https://www.npmjs.com/package/@wanderlogapp/react-native). See [**Patching React Native**](https://app.notion.com/p/wanderlog/Patching-React-Native-17b4797ed24d481eb2155c9daec1ba98) in Notion for how to patch, backport, release and upgrade it.
4
4
 
5
5
  --------
6
6
 
@@ -1,4 +1,4 @@
1
- VERSION_NAME=0.86.3-wanderlog.2
1
+ VERSION_NAME=0.86.3
2
2
  react.internal.publishingGroup=com.facebook.react
3
3
  react.internal.hermesPublishingGroup=com.facebook.hermes
4
4
 
@@ -13,7 +13,9 @@ namespace facebook::react {
13
13
  /*
14
14
  * Installs UIManger constants provider into JavaScript runtime. This is needed
15
15
  * to implement UIManager.getConstants in bridgeless mode. The constants object
16
- * contains view configs for every legacy native component.
16
+ * contains view configs for every legacy native component. Also installs
17
+ * getConstantsForViewManager, which builds one view config, and
18
+ * getDefaultEventTypes.
17
19
  */
18
20
  void installLegacyUIManagerConstantsProviderBinding(jsi::Runtime &runtime);
19
21
  } // namespace facebook::react
@@ -17,27 +17,69 @@
17
17
  namespace facebook::react {
18
18
  namespace {
19
19
 
20
+ // Cached, since modules register in +load, before JS runs
21
+ NSDictionary<NSString *, Class> *getViewManagerClassesByName()
22
+ {
23
+ static NSDictionary<NSString *, Class> *viewManagerClassesByName;
24
+ static dispatch_once_t onceToken;
25
+ dispatch_once(&onceToken, ^{
26
+ NSMutableDictionary<NSString *, Class> *classesByName = [NSMutableDictionary new];
27
+ for (Class moduleClass in RCTGetModuleClasses()) {
28
+ if ([moduleClass isSubclassOfClass:RCTViewManager.class]) {
29
+ classesByName[RCTViewManagerModuleNameForClass(moduleClass)] = moduleClass;
30
+ }
31
+ }
32
+ viewManagerClassesByName = classesByName;
33
+ });
34
+ return viewManagerClassesByName;
35
+ }
36
+
37
+ NSMutableDictionary<NSString *, id> *viewConfigForViewManagerClass(
38
+ Class moduleClass,
39
+ NSString *name,
40
+ NSMutableDictionary<NSString *, NSDictionary *> *directEvents,
41
+ NSMutableDictionary<NSString *, NSDictionary *> *bubblingEvents)
42
+ {
43
+ auto viewConfig = [RCTComponentData viewConfigForViewMangerClass:moduleClass];
44
+ return RCTModuleConstantsForDestructuredComponent(directEvents, bubblingEvents, moduleClass, name, viewConfig);
45
+ }
46
+
20
47
  jsi::Value getConstants(facebook::jsi::Runtime &runtime)
21
48
  {
22
49
  NSMutableDictionary<NSString *, NSObject *> *result = [NSMutableDictionary new];
23
50
  auto directEvents = [NSMutableDictionary new];
24
51
  auto bubblingEvents = [NSMutableDictionary new];
25
- for (Class moduleClass in RCTGetModuleClasses()) {
26
- if ([moduleClass isSubclassOfClass:RCTViewManager.class]) {
27
- auto name = RCTViewManagerModuleNameForClass(moduleClass);
28
- auto viewConfig = [RCTComponentData viewConfigForViewMangerClass:moduleClass];
29
- auto moduleConstants =
30
- RCTModuleConstantsForDestructuredComponent(directEvents, bubblingEvents, moduleClass, name, viewConfig);
31
- result[name] = moduleConstants;
32
- }
33
- }
52
+ [getViewManagerClassesByName()
53
+ enumerateKeysAndObjectsUsingBlock:^(NSString *name, Class moduleClass, __unused BOOL *stop) {
54
+ result[name] = viewConfigForViewManagerClass(moduleClass, name, directEvents, bubblingEvents);
55
+ }];
34
56
  return TurboModuleConvertUtils::convertObjCObjectToJSIValue(runtime, result);
35
57
  };
36
58
 
59
+ jsi::Value getConstantsForViewManager(facebook::jsi::Runtime &runtime, const std::string &viewManagerName)
60
+ {
61
+ NSString *name = [NSString stringWithUTF8String:viewManagerName.c_str()];
62
+ Class moduleClass = getViewManagerClassesByName()[name];
63
+ if (moduleClass == nil) {
64
+ return jsi::Value::null();
65
+ }
66
+ return TurboModuleConvertUtils::convertObjCObjectToJSIValue(
67
+ runtime, viewConfigForViewManagerClass(moduleClass, name, [NSMutableDictionary new], [NSMutableDictionary new]));
68
+ }
69
+
70
+ // Empty, since iOS has no generic event types, unlike Android. Events every
71
+ // view supports, like touches, are in BaseViewConfig.ios.js.
72
+ jsi::Value getDefaultEventTypes(facebook::jsi::Runtime &runtime)
73
+ {
74
+ return jsi::Object(runtime);
75
+ }
76
+
37
77
  } // namespace
38
78
 
39
79
  void installLegacyUIManagerConstantsProviderBinding(jsi::Runtime &runtime)
40
80
  {
41
81
  LegacyUIManagerConstantsProviderBinding::install(runtime, "getConstants", getConstants);
82
+ LegacyUIManagerConstantsProviderBinding::install(runtime, "getConstantsForViewManager", getConstantsForViewManager);
83
+ LegacyUIManagerConstantsProviderBinding::install(runtime, "getDefaultEventTypes", getDefaultEventTypes);
42
84
  }
43
85
  } // namespace facebook::react
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wanderlogapp/react-native",
3
- "version": "0.86.3-wanderlog.2",
3
+ "version": "0.86.3-wanderlog.3",
4
4
  "description": "A framework for building native apps using React",
5
5
  "license": "MIT",
6
6
  "repository": {