Repository navigation
Convert iOS native module event arguments to JS without UTF-8 #59449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,6 @@ | |
| #import <react/featureflags/ReactNativeFeatureFlags.h> | ||
| #import <react/runtime/ReactInstance.h> | ||
| #import <react/utils/ContextContainer.h> | ||
| #import <react/utils/FollyConvert.h> | ||
| #import <react/utils/ManagedObjectWrapper.h> | ||
|
|
||
| #import "ObjCTimerRegistry.h" | ||
|
|
@@ -173,14 +172,26 @@ - (void)dealloc | |
|
|
||
| - (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args | ||
| { | ||
| if (moduleName.length == 0 || method.length == 0) { | ||
| return; | ||
| } | ||
| // The arguments are converted on the JS thread, like the values of codegen's AsyncEventEmitter. | ||
| NSArray *callArgs = [args copy]; | ||
| // This is called from arbitrary threads, while -invalidate destroys _reactInstance on | ||
| // the JS thread, so checking _valid and dereferencing have to happen as one step. | ||
| std::lock_guard<std::mutex> lock(_invalidationMutex); | ||
| if (!_valid || !_reactInstance) { | ||
| return; | ||
| } | ||
| _reactInstance->callFunctionOnModule( | ||
| [moduleName UTF8String] ?: "", [method UTF8String] ?: "", convertIdToFollyDynamic(args ? args : @[])); | ||
| [moduleName UTF8String] ?: "", | ||
| [method UTF8String] ?: "", | ||
|
Comment on lines
+187
to
+188
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Early return if either moduleName or method is the empty string.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done - 843adb2
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I wanted to avoid the That can be an early return inside |
||
| [callArgs](jsi::Runtime &runtime, std::vector<jsi::Value> &jsArgs) { | ||
| jsArgs.reserve(callArgs.count); | ||
| for (id arg in callArgs) { | ||
| jsArgs.push_back(TurboModuleConvertUtils::convertObjCObjectToJSIValue(runtime, arg)); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| - (void)invalidate | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jsArgs.reserve?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javache done, thanks! 843adb2