-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix(ios): update core logic to use sentinel value for preserving null
#8774
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
Merged
+578
−143
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e8c59a4
test: update httpscallable to latest test setup
russellwheatley a692098
podfile.lock
russellwheatley 3e74ed6
test: update storage test
russellwheatley de73856
fix(ios): fix `null` being stripped from TurboModules maps
russellwheatley bc44bd3
chore: script for rebuilding functions
russellwheatley 9c822b2
fix: double bang to get bool value
russellwheatley 9f5dd75
chore: ignore dist/ linting
russellwheatley 4ca139f
Apply suggestions from code review
russellwheatley d263840
chore: remove device from manual ios script
russellwheatley 8821d15
chore: update example https-callable
russellwheatley 694fb88
chore: move to functions directory
russellwheatley 3245b01
chore: fix path to functions manual test
russellwheatley d102dfe
fix: replace recursive method for encoding/decoding values
russellwheatley f03a331
chore: update note on how encoding works
russellwheatley e6a3d9b
chore: clarifying notes
russellwheatley 3af05fd
fix: update android lint to ignore generated code
russellwheatley 6da4e8f
chore: format
russellwheatley 7764cae
chore: ignore generated code in ios/ for linting
russellwheatley a8e276d
chore: format
russellwheatley 4adba7e
chore: remove duplicate comment
russellwheatley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,47 @@ | ||
| /** | ||
| * Copyright (c) 2016-present Invertase Limited & Contributors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this library except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| #ifndef RNFBNullSentinelInterceptor_h | ||
| #define RNFBNullSentinelInterceptor_h | ||
|
|
||
| #import <Foundation/Foundation.h> | ||
|
|
||
| /** | ||
| * Intercepts TurboModule conversions to automatically decode null sentinels. | ||
| * | ||
| * iOS TurboModules strip null values from object properties during serialization. | ||
| * See: https://github.com/facebook/react-native/issues/52802 | ||
| * The JavaScript side encodes nulls as sentinel objects, | ||
| * and this interceptor automatically converts them back to NSNull before they | ||
| * reach module implementation methods. | ||
| * | ||
| * This class uses method swizzling on RCTCxxConvert to intercept all TurboModule | ||
| * data conversion methods (JS_*Module_Spec*Data:), decoding sentinels before the | ||
| * data reaches the C++ bridging layer and ultimately your module methods. | ||
| */ | ||
| @interface RNFBNullSentinelInterceptor : NSObject | ||
|
|
||
| /** | ||
| * Initializes the null sentinel interceptor. | ||
| * This swizzles RCTCxxConvert (TurboModule converter) to automatically decode null sentinels. | ||
| * Called automatically when the class is loaded via +load. | ||
| */ | ||
| + (void)initialize; | ||
|
|
||
| @end | ||
|
|
||
| #endif | ||
This file contains hidden or 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,74 @@ | ||
| /** | ||
| * Copyright (c) 2016-present Invertase Limited & Contributors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this library except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| #import "RNFBNullSentinelInterceptor.h" | ||
| #import <objc/runtime.h> | ||
| #import "RNFBSharedUtils.h" | ||
|
|
||
| @implementation RNFBNullSentinelInterceptor | ||
|
|
||
| + (void)load { | ||
| static dispatch_once_t onceToken; | ||
| dispatch_once(&onceToken, ^{ | ||
| [self swizzleRCTConvertMethods]; | ||
| }); | ||
| } | ||
|
|
||
| + (void)swizzleRCTConvertMethods { | ||
| // For TurboModules: Swizzle RCTCxxConvert to intercept all conversion methods | ||
| Class cxxConvertClass = NSClassFromString(@"RCTCxxConvert"); | ||
| if (cxxConvertClass) { | ||
| [self swizzleTurboModuleConversions:cxxConvertClass]; | ||
| } | ||
| } | ||
|
|
||
| + (void)swizzleTurboModuleConversions:(Class)cxxConvertClass { | ||
| // Get all methods from RCTCxxConvert | ||
| unsigned int methodCount = 0; | ||
| Method *methods = class_copyMethodList(object_getClass(cxxConvertClass), &methodCount); | ||
|
|
||
| for (unsigned int i = 0; i < methodCount; i++) { | ||
| Method method = methods[i]; | ||
| SEL selector = method_getName(method); | ||
| NSString *selectorName = NSStringFromSelector(selector); | ||
|
|
||
| // Intercept TurboModule data conversion methods (they follow pattern: JS_*Module_Spec*Data:) | ||
| if ([selectorName hasPrefix:@"JS_"] && [selectorName containsString:@"Module_Spec"] && | ||
| ([selectorName hasSuffix:@"Data:"] || [selectorName containsString:@"Data:"])) { | ||
| // Create a swizzled version using IMP | ||
| IMP originalIMP = method_getImplementation(method); | ||
| const char *typeEncoding = method_getTypeEncoding(method); | ||
|
|
||
| // Replace with our wrapper that decodes nulls | ||
| IMP newIMP = imp_implementationWithBlock(^id(id self, id json) { | ||
| // Decode null sentinels before passing to original conversion | ||
| id decoded = [RNFBSharedUtils decodeNullSentinels:json]; | ||
|
|
||
| // Call original implementation with decoded data | ||
| typedef id (*OriginalFunc)(id, SEL, id); | ||
| OriginalFunc originalFunc = (OriginalFunc)originalIMP; | ||
| return originalFunc(self, selector, decoded); | ||
| }); | ||
|
|
||
| method_setImplementation(method, newIMP); | ||
| } | ||
| } | ||
|
|
||
| free(methods); | ||
| } | ||
|
|
||
| @end |
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.