Open mereka-ta opened 6 months ago
@votrai123
I've looked at the realm source code in Pods/Development Pods/RealmReact/RealmReact.mm
, looks like there is additional logic for bridging :
- (void)setBridge:(RCTBridge *)bridge {
_bridge = bridge;
if (objc_lookUpClass("RCTWebSocketExecutor") &&
[bridge executorClass] == objc_lookUpClass("RCTWebSocketExecutor")) {
// Skip native initialization when in legacy Chrome debugging mode
#if !DEBUG
@throw [NSException
exceptionWithName:@"Invalid Executor"
reason:@"Chrome debug mode not supported in Release builds"
userInfo:nil];
#endif
} else if ([bridge isKindOfClass:objc_lookUpClass("RCTCxxBridge")] ||
[NSStringFromClass([bridge class]) isEqual:@"RCTCxxBridge"]) {
__weak __typeof__(self) weakSelf = self;
__weak __typeof__(bridge) weakBridge = bridge;
[bridge
dispatchBlock:^{
__typeof__(self) self = weakSelf;
__typeof__(bridge) bridge = weakBridge;
if (!self || !bridge) {
return;
}
// Make sure the previous JS thread is completely finished before
// continuing.
static __weak NSThread *s_currentJSThread;
while (s_currentJSThread && !s_currentJSThread.finished) {
[NSThread sleepForTimeInterval:0.1];
}
s_currentJSThread = [NSThread currentThread];
auto &rt = *static_cast<facebook::jsi::Runtime *>(bridge.runtime);
auto exports = jsi::Object(rt);
realm_jsi_init(rt, exports, ^{
// Calling jsCallInvokver->invokeAsync tells React Native to execute the lambda passed
// in on the JS thread, and then flush the internal "microtask queue", which has the
// effect of flushing any pending UI updates.
//
// We call this after we have called into JS from C++, in order to ensure that the RN
// UI updates in response to any changes from Realm. We need to do this as we bypass
// the usual RN bridge mechanism for communicating between C++ and JS, so without doing
// this RN has no way to know that a change has occurred which might require an update
// (see #4389, facebook/react-native#33006).
//
// Calls are debounced using the waitingForUiFlush flag, so if an async flush is already
// pending when another JS to C++ call happens, we don't call invokeAsync again. This works
// because the work is performed before the microtask queue is flushed - see sequence
// diagram at https://bit.ly/3kexhHm. It might be possible to further optimize this,
// e.g. only flush the queue a maximum of once per frame, but this seems reasonable.
if (!waitingForUiFlush) {
waitingForUiFlush = true;
[bridge jsCallInvoker]->invokeAsync(
[&]() { waitingForUiFlush = false; });
}
});
}
queue:RCTJSThread];
}
}
I think your code works fine without realm package, I've opened an issue on the realm-js repo regarding this, let's stay tuned for their response.
Let you try install this library in React Native init other. It’s working, right? @mereka-ta RN 0.71.3 | Realm 11.5.1 OR RN 0.72.3 | Realm 12.6.0
I think you should follow https://www.mongodb.com/docs/realm/sdk/react-native/install/#std-label-react-native-install
It's working fine if I setup & use realm in the main bundle.
The issue only happen once I trigger the openApp
if realm is included (even without actually use it, just include in package.json
).
For react native v0.70
& below, everything works perfect with its compatible realm
Sample for Android, You make sure linked the lib in project super app @mereka-ta related: #1
https://github.com/votrai123/integrate-multiple-react-native/commit/5b2b69319b0043f37ded1736962358b6fde86867 this commit is a sample for install other lib, You can see it Branch: https://github.com/votrai123/integrate-multiple-react-native/tree/example-install-lib
https://github.com/votrai123/integrate-multiple-react-native/commit/5b2b69319b0043f37ded1736962358b6fde86867 this commit is a sample for install other lib, You can see it Branch: https://github.com/votrai123/integrate-multiple-react-native/tree/example-install-lib
@votrai123 Yes, thank you for your guidance on android.
I've no issue on android (every RN version is working, even with realm) as I read your explanation in other thread.
This issue occurs specifically on iOS for newer version of RN.
As I mentioned previously, I've created an issue on realm's repo & just want to let you know if they have rolled up a patch, I'll update it here too.
Issue If I installed realm package, (only install, no intialization in js yet), when triggering
openApp
in iOS, it shows blank screen with metro messageConnect to metro to develop javascript
. In XCode, the bundleinitialProperties
is successfully passed but with no other error log.I've tested for these version combination of react-native & realm: