forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable RuntimeScheduler in old architecture (facebook#37523)
Summary: [IOS] [FIXED] - unexpected useEffects flushing semantics Pull Request resolved: facebook#37523 Test Plan: Run RNTester with old architecture and make sure RuntimeScheduler is used. Reviewed By: cipolleschi Differential Revision: D46078324 Pulled By: sammy-SC fbshipit-source-id: 5f18cbe60e6c9c753c373f175ba413b79288a928
- Loading branch information
Showing
28 changed files
with
558 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
#ifdef __cplusplus | ||
#import <ReactCommon/RuntimeExecutor.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@class RCTBridge; | ||
|
||
facebook::react::RuntimeExecutor RCTRuntimeExecutorFromBridge(RCTBridge *bridge); | ||
|
||
NS_ASSUME_NONNULL_END | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import "RCTRuntimeExecutorFromBridge.h" | ||
#import <React/RCTAssert.h> | ||
#import <React/RCTBridge+Private.h> | ||
#import <cxxreact/MessageQueueThread.h> | ||
#import <react/utils/ManagedObjectWrapper.h> | ||
|
||
using namespace facebook::react; | ||
|
||
@interface RCTBridge () | ||
- (std::shared_ptr<MessageQueueThread>)jsMessageThread; | ||
- (void)invokeAsync:(std::function<void()> &&)func; | ||
@end | ||
|
||
RuntimeExecutor RCTRuntimeExecutorFromBridge(RCTBridge *bridge) | ||
{ | ||
RCTAssert(bridge, @"RCTRuntimeExecutorFromBridge: Bridge must not be nil."); | ||
|
||
auto bridgeWeakWrapper = wrapManagedObjectWeakly([bridge batchedBridge] ?: bridge); | ||
|
||
RuntimeExecutor runtimeExecutor = [bridgeWeakWrapper]( | ||
std::function<void(facebook::jsi::Runtime & runtime)> &&callback) { | ||
RCTBridge *bridge = unwrapManagedObjectWeakly(bridgeWeakWrapper); | ||
|
||
RCTAssert(bridge, @"RCTRuntimeExecutorFromBridge: Bridge must not be nil at the moment of scheduling a call."); | ||
|
||
[bridge invokeAsync:[bridgeWeakWrapper, callback = std::move(callback)]() { | ||
RCTCxxBridge *batchedBridge = (RCTCxxBridge *)unwrapManagedObjectWeakly(bridgeWeakWrapper); | ||
|
||
RCTAssert(batchedBridge, @"RCTRuntimeExecutorFromBridge: Bridge must not be nil at the moment of invocation."); | ||
|
||
if (!batchedBridge) { | ||
return; | ||
} | ||
|
||
auto runtime = (facebook::jsi::Runtime *)(batchedBridge.runtime); | ||
|
||
RCTAssert( | ||
runtime, @"RCTRuntimeExecutorFromBridge: Bridge must have a valid jsi::Runtime at the moment of invocation."); | ||
|
||
if (!runtime) { | ||
return; | ||
} | ||
|
||
callback(*runtime); | ||
}]; | ||
}; | ||
|
||
return runtimeExecutor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.