Summary:
Regression, fix image load from `~/Library` not respect scale factor.
Fixes#22383 , the bug comes from [Clean up some URL path handling](998197f444).
[iOS] [Fixed] - Fix image wrong scale factor when load image from file system
Pull Request resolved: https://github.com/facebook/react-native/pull/23446
Differential Revision: D14099614
Pulled By: cpojer
fbshipit-source-id: eb2267b195a05eb70cdc4671536a4c1d47fb03e2
Summary:
There's a very old issue with reload logic: invalidation and resetting up of the bridge could be racing. In this case, we hit a redbox when:
* Chrome debugger is enabled in previous app run, then we launch the app again
* The bridge starts, then immediately reloads itself to connect to Chrome
* On the 2nd setup, the logic to update the green loading bar, with the % indicator for loading off metro, failed to find the DevLoadingView module instance because the bridge is in the middle of invalidating
See https://github.com/facebook/react-native/issues/23235
To test:
Using react-native init from github, do the steps in https://github.com/facebook/react-native/issues/23235, no more redbox. Note that the loading indicator % won't be proper still, but at least it doesn't crash/redbox.
Reviewed By: JoshuaGross
Differential Revision: D14110814
fbshipit-source-id: 835061e50acc6968bffbcc2ddfbe8da79a100df9
Summary:
A common util from RN to gate on testing code is `Platform.isTesting()`
Unfortunately, this util does not account for ServerSnapshotTests, since they don't use apple's XCTest infra.
Reviewed By: sahrens
Differential Revision: D13981728
fbshipit-source-id: bf902a04f5d7fcb98a06816f5c2c9b082e7d14b8
Summary:
TurboModules depend on a getConstants method. Existing ObjectiveC modules do not have this method. Therefore, I moved the contents of `constantsToExport` to `getConstants` and then had `constantsToExports` call `getConstants`.
facebook
Since all NativeModules will eventually need to be migrated to the TurboModule system, I didn't restrict this to just the NativeModules in Marketplace.
```
const fs = require('fs');
if (process.argv.length < 3) {
throw new Error('Expected a file containing a list of native modules as the third param');
}
function read(filename) {
return fs.readFileSync(filename, 'utf8');
}
const nativeModuleFilenames = read(process.argv[2]).split('\n').filter(Boolean);
nativeModuleFilenames.forEach((fileName) => {
if (fileName.endsWith('.h')) {
return;
}
const absPath = `${process.env.HOME}/${fileName}`;
const fileSource = read(absPath);
if (/(\n|^)-\s*\((.+)\)getConstants/.test(fileSource)) {
return;
}
const constantsToExportRegex = /(\n|^)-\s*\((.+)\)constantsToExport/;
const result = constantsToExportRegex.exec(fileSource);
if (result == null) {
throw new Error(`Didn't find a constantsToExport function inside NativeModule ${fileName}`);
}
const returnType = result[2];
const newFileSource = fileSource.replace(
constantsToExportRegex,
'$1- ($2)constantsToExport\n' +
'{\n' +
` return ${returnType.includes('ModuleConstants') ? '($2)' : ''}[self getConstants];\n` +
'}\n' +
'\n' +
'- ($2)getConstants'
);
fs.writeFileSync(absPath, newFileSource);
});
```
```
> xbgs -l ')constantsToExport'
```
Reviewed By: fkgozali
Differential Revision: D13951197
fbshipit-source-id: 394a319d42aff466c56a3d748e17c335307a8f47
Summary:
NativeModules are instantiated by the bridge. If they choose, they can capture the bridge instance that instantiated them. From within the NativeModule, the bridge can then be used to lookup other NativeModules. TurboModules have no way to do such a lookup.
Both NativeModules and TurboModules need to be able to query for one another. Therefore, we have four cases:
1. NativeModule accesses NativeModule.
2. NativeModule accesses TurboModule.
3. TurboModule accesses NativeModule.
4. TurboModule accesses TurboModule.
In summary, this solution extends the bridge to support querying TurboModules. It also introduces a `RCTTurboModuleLookupDelegate` protocol, which, implemented by `RCTTurboModuleManager`, supports querying TurboModules:
```
protocol RCTTurboModuleLookupDelegate <NSObject>
- (id)moduleForName:(NSString *)moduleName;
- (id)moduleForName:(NSString *)moduleName warnOnLookupFailure:(BOOL)warnOnLookupFailure;
- (BOOL)moduleIsInitialized:(NSString *)moduleName
end
```
If TurboModules want to query other TurboModules, then they need to implement this protocol and synthesize `turboModuleLookupDelegate`:
```
protocol RCTTurboModuleWithLookupCapabilities
property (nonatomic, weak) id<RCTTurboModuleLookupDelegate> turboModuleLookupDelegate;
end
```
NativeModules will continue to use `RCTBridge` to access other NativeModules. Nothing needs to change.
When we attach the bridge to `RCTTurboModuleManager`, we also attach `RCTTurboModuleManager` to the bridge as a `RCTTurboModuleLookupDelegate`. This allows the bridge to query TurboModules, which enables our NativeModules to transparently (i.e: without any NativeModule code modification) query TurboModules.
In an ideal world, all modules would be TurboModules. Until then, we're going to require that TurboModules use the bridge to query for NativeModules or TurboModules.
`RCTTurboModuleManager` keeps a map of all TurboModules that we instantiated. We simply search in this map and return the TurboModule.
This setup allows us to switch NativeModules to TurboModules without compromising their ability to use the bridge to search for other NativeModules (and TurboModules). When we write new TurboModules, we can have them use `RCTTurboModuleLookupDelegate` to do access other TurboModules. Eventually, after we migrate all NativeModules to TurboModules, we can migrate all old callsites to use `RCTTurboModuleLookupDelegate`.
Reviewed By: fkgozali
Differential Revision: D13553186
fbshipit-source-id: 4d0488eef081332c8b70782e1337eccf10717dae
Summary:
For better modularity, each module conforming to RCTTurboModule should provide a getter for the specific TurboModule instance for itself. This is a bit more extra work for devs, but simplify tooling and allow better modularity vs having a central function that provides the correct instance based on name.
Note: Android may or may not follow this new pattern -- TBD.
Reviewed By: RSNara
Differential Revision: D13882073
fbshipit-source-id: 6d5f82af67278c39c43c4f7970995690d4a82a98
Summary:
Xcode 9 has compiler settings that are more strict. This can occur if someone updates there project to use the default settings.
This patch declares the default type instead of allowing the compiler to determine it. Instead of () we now say (void) in a block call.
Motivation
It was just trying to get my project totally empty of warnings, and it has no side effects. If there are side effects, then we should fix the type and not go with empty to represent void.
Test Plan
Update project settings in Xcode. This code doesn't have any known side effects since the compiler assumes the type is void when not declared.
Release Notes
[DOCS] - Fixed potential compiler build issue on Xcode 9 after updating settings in project.
Pull Request resolved: https://github.com/facebook/react-native/pull/17872
Differential Revision: D6981435
Pulled By: hramos
fbshipit-source-id: 508ecea0f8874dc16a25f1dee6255481b309f8c2
Summary:
Motivation:
----------
As developers want to handle multiple actions on Siri Remote input when using TVEventHandler, it is crucial to differentiate 'swap' and 'tap' events.
Changelog:
----------
[tvOS] [Changed] - 'up', 'down', 'left' and 'right' events are now connected with tapping on edges of remote. New events 'swipeUp', 'swipeDown', 'swipeLeft' and 'swipeRight' added to detect swipes.
Pull Request resolved: https://github.com/facebook/react-native/pull/22916
Differential Revision: D13682705
Pulled By: hramos
fbshipit-source-id: 233ad1cecc04ca4ced75cd00e7fcb65d224ed3ca
Summary:
On iOS platform, RN retains launchOptions dictionary after bridge reload which can lead to unexpected consequences to a developer. The app will receive the same value for `Linking.getInitialURL` during initial launch and during bridge reload. Here's an example from our application. We use deeplinks via custom URL scheme so a user can open the app via link. Also, we reload the bridge when a user signs out. So if a user opens the app via URL, logs out, and a second user logs into the app, the app will behave as though the second user launched the app via the same deeplink. Because reload destroys the JS engine, there's nowhere for our app to remember that it already handled the deeplink activation.
On iOS Linking.getInitialURL() gets URL from the _launchOptions dictionary, so by setting it to nil we prevent retention of initialURL after reload.
This change makes iOS's behavior consistent with Android's. On Android, the launch URL is stored on the `Intent` and reloading the app involves creating a new `Intent`. Consequently, the launch URL is dropped as desired during the reload process.
Pull Request resolved: https://github.com/facebook/react-native/pull/22659
Differential Revision: D13564251
Pulled By: cpojer
fbshipit-source-id: 4c6d81f1775eb3c41b100582436f1c0f1ee6dc36
Summary:
`RCTSurfaceHostingProxyRootView` surfaces are still automatically started right after the initialization to match `RCTRootView` interface, but `RCTSurfaceHostingView` must be started explicitly now. Also fixed some internal stuff so start and register are clear and distinct.
Background / initial motivation:
One tricky bit - we render the template as part of init`ing the rootView, so we don't know what the surfaceId will be before hand to register the UITemplate. Two possible solutions:
1) Require start be called explicitly after initializing the rootView, and setup the context in between.
2) Do something like "setUITemplateConfigForNextSurface" before creating the rootView, and have some hook when the surfaceId is assigned that associates the surfaceId with that "next" UITemplate stuff before.
(1) seems a lot cleaner, but it requires ever user of rootView to explicitly call start on it - how do you feel about that? Seems like we could also use that start call to decide if the initial render should be synchronous or not? start vs. startSync?
Reviewed By: mdvacca
Differential Revision: D13372914
fbshipit-source-id: 6db297870610e6c231f8a78c0dd74d584cb64910
Summary:
So, it does not start itself automatically right after instantiation.
(Classic RCTSurface still kinda start itself automatically but only because start/stop concept is not implemented for this yet.)
Reviewed By: sahrens
Differential Revision: D13461294
fbshipit-source-id: 05430688f69a0d9bf75d03e6d25f02ccd5d3176a
Summary: Some logic to check for surface stage should've done bitwise `&` operation instead of equality check, because we do bitwise `|` whenever we "set stage".
Reviewed By: shergin
Differential Revision: D13459156
fbshipit-source-id: 94e2f5279fb1a31060beb7d6195953b25ce603c9
Summary:
Adds two additional UIBarStyles to RCTConvert
- [x] UIBarStyleBlackOpaque
- [x] UIBarStyleBlackTranslucent
Does not affect any tests or current usage of this conversion.
Pull Request resolved: https://github.com/facebook/react-native/pull/20102
Differential Revision: D13421942
Pulled By: hramos
fbshipit-source-id: 1e609eca0fdea2b56b9f6ac87e759c661bdee12b
Summary:
Fixes#22530
As described in the issue, the previous behavior for the `RCTFatal` macro was to truncate the `reason` on the resulting `NSException` to 75 characters. This would ensure the reason would fit on a single line, but resulted in issues debugging errors that occurred in the wild, as many crash logging tools (like Sentry) discard the `name` value of the exception and use the `reason` as their primary identifier. At 75 characters, useful information like the location of the error would usually be truncated.
- [x] This extends the truncation threshold to 175 characters, which should be short enough to prevent full-screen-takeover length errors, but long enough to provide useful context to the error.
- [x] This adds a `userInfo` value to the resulting `NSException`. It copies over the `userInfo` from the `NSError` passed to the macro, and adds an "untruncated message" value that contains the untruncated version of the `NSException`'s reason.
[iOS] [Changed] - RCTFatalExceptions now include more information in their reason and a userInfo.
<!--
CATEGORY may be:
- [General]
- [iOS]
- [Android]
TYPE may be:
- [Added] for new features.
- [Changed] for changes in existing functionality.
- [Deprecated] for soon-to-be removed features.
- [Removed] for now removed features.
- [Fixed] for any bug fixes.
- [Security] in case of vulnerabilities.
For more detail, see https://keepachangelog.com/en/1.0.0/#how
MESSAGE may answer "what and why" on a feature level. Use this to briefly tell React Native users about notable changes.
EXAMPLES:
[General] [Added] - Add snapToOffsets prop to ScrollView component
[General] [Fixed] - Fix various issues in snapToInterval on ScrollView component
[iOS] [Fixed] - Fix crash in RCTImagePicker
-->
Pull Request resolved: https://github.com/facebook/react-native/pull/22532
Differential Revision: D13373469
Pulled By: cpojer
fbshipit-source-id: ac140d14ce76e1664869437c2c178bdd65ab6e0e
Summary:
This may be controversial.
Right now, RelayPrefetcher is initialized [here](https://fburl.com/p01iunr1), after bridge is initialized. I want to create a FBRelayPrefetcherModule instance eagerly (diff 3 in stack), and then pass that into the bridge module registry. This way, native side gets to use RelayPrefetcher before bridge is init, and JS still accesses the same instance of FBRelayPrefetcherModule.
The only other option is drastically change bridge init, to allow passing in some eagerly initialized instances.
Reviewed By: shergin
Differential Revision: D13164277
fbshipit-source-id: b45111cd68d78820e61e4fca7e54a7e8df32a3f0
Summary:
Update reference to property in code comment in `RCTBridgeModule`. There is no such thing as `requiresMainThreadSetup` in the codebase. Its called `requiresMainQueueSetup` now.
Pull Request resolved: https://github.com/facebook/react-native/pull/22328
Differential Revision: D13115352
Pulled By: shergin
fbshipit-source-id: 511d627388b51029821c4b1ddf4caac30e573040
Summary:
Some module classes may not be loaded yet, so looking up via classes may not always give the correct instance. This diff added a new lookup method that delegate to the bridge delegate to force load the modules as needed.
The existing moduleForName: method was left untouched because it's solely used by RCTUIManager at the moment.
Reviewed By: dshahidehpour
Differential Revision: D13033876
fbshipit-source-id: 4082fcd68498004f678b4b95adc82b5b134fefdf
Summary:
Previously, asking for an instance of NativeModule from the native side gave `nil` if the lazy modules have not been loaded, which is not consistent with the access from JS. This at least attempts to force load the lazy modules when asked from native.
p.s. one asks for a module by doing `[bridge moduleForClass:[FooBar class]]`.
Reviewed By: spredolac
Differential Revision: D12931640
fbshipit-source-id: 15d2dc574067d3386ef921512ce4bc837749dabd
Summary:
@public
This allows apps to specify custom lazy modules that they need to load during chrome debugging. This is because lazy modules won't be available on start up, hence these modules will be missing in JS land, causing problems.
Reviewed By: shergin
Differential Revision: D12899408
fbshipit-source-id: dca313648e994b22e3ee5afec856ef76470065f9
Summary: Simply changing RCTLogWarn() to RCTLogInfo(), since some modules can be loaded without explicit export (experimental).
Reviewed By: mdvacca
Differential Revision: D12899442
fbshipit-source-id: 524d345265eda4a601101d878d51c244a8441fb5
Summary:
This diff introduces a new integration concept (called RuntimeExecutor) which consolidates `Runtime` and the dispatching mechanism.
As simple as that:
`using RuntimeExecutor = std::function<void(std::function<void(facebook::jsi::Runtime &runtime)> &&callback)>;`
Reviewed By: fkgozali
Differential Revision: D12816746
fbshipit-source-id: 9e27ef16b98af861d494fe50c7e50bd0536e6aaf
Summary:
While debugging internally, we have found that modules are almost always registered
with their "RK" or "RCT" prefixes dropped.
However, if a view is named `RCTFooView` and needs `RCTFooViewManager` to render natively, it will almost never find it because `RCT` was dropped from the key to the ViewManager instance.
In the event you look for a `ViewManager` and don't find it, this strips any "React" prefixes from your key and tries ones more time.
Reviewed By: spredolac
Differential Revision: D10734005
fbshipit-source-id: 2bfa6f19830f14f09af2fe7dc7e44b7e26e0ac3f
Summary:
This class contains metrics about RN bridge startup that was being sent via FBAnalytics.
This diff refactors out any timespans being collected into a separate method. This refactor is NOT ENOUGH to format the data into a format QPL accepts. I still need to refactor these timespans into _start and _end points for QPL points to work correctly. This diff is a starting point.
Reviewed By: ejanzer
Differential Revision: D10466982
fbshipit-source-id: 4bc1159c4e53328f2252a8c606c8d6ff8d657489
Summary:
JSI+JSCRuntime replaces direct use of JSC. This is like the previous
diff, except for iOS.
Reviewed By: RSNara
Differential Revision: D9369108
fbshipit-source-id: 4ed2c0d660ba2a30edf699d95278c72cabcc9203
Summary:
change RCTCxxBridge to use JSIExecutorFactory+JSCRuntime
instead of JSCExecutorFactory. Also remove JSC usage from RN in other
files. This allows deleting files, too, which is done further down
the stack.
Reviewed By: RSNara
Differential Revision: D9369111
fbshipit-source-id: 67ef3146e3abe5244b6cf3249a0268598f91b277
Summary:
The original design of RCTSurface implied that the Surface starts on initialization and stops on deallocation. Recently I realized that this not sufficient API in some cases when the application uses ARC with autorelease pools (that can postpone object deallocations, which is highly undesirable).
And that's simply handy to have those methods sometimes.
Reviewed By: mdvacca
Differential Revision: D9982356
fbshipit-source-id: baa3bd24804d3708606ebd00b8795f2d5c9d4de9
Summary: We call this method in a constructor before the actual object is beeing constructed, so it's incorrect; it should be class method.
Reviewed By: mdvacca
Differential Revision: D9931315
fbshipit-source-id: 304ba8e2354f3f408cfa2bf1729266525a08f951
Summary: All integration with Bridge was removed from RCTFabricSurface, now it's Surface's responsibility to start and stop JS app and register the ShadowTree in the Scheduler.
Reviewed By: mdvacca
Differential Revision: D9931317
fbshipit-source-id: 55a682f0afb1c542a904e1a8570029e4690967cc