[RNMobile] Pass Android Fetch Responses Across the Bridge as Objects #34391
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.
Description
Fetch request in Android being passed as a String, instead of an Object: https://github.com/wordpress-mobile/WordPress-Android/blob/ddb3be8823733e4d6305e63978e8f8353b7c4528/WordPress/src/main/java/org/wordpress/android/ui/posts/reactnative/ReactNativeRequestHandler.kt#L82
fetchRequest
method on the JS side.iOS
and for iOS, we seem to have an object response from here: https://github.com/wordpress-mobile/WordPressKit-iOS/blob/19a2f186ef6e08e95c4678fd2af487727f3da9a3/WordPressKit/WordPressComRestApi.swift#L203
which is passed along without unwrapping here: https://github.com/wordpress-mobile/WordPress-iOS/blob/837fbd067d0af8162fa0e21af499a4e469c50b25/WordPress/Classes/ViewRelated/Gutenberg/GutenbergNetworking.swift#L26
Things I've tried
Replicating Error Bundle
What I tried: I attempted to replicate the way data is being passed over the bridge via a bundle for the error: https://github.com/wordpress-mobile/WordPress-Android/blob/develop/WordPress/src/main/java/org/wordpress/android/ui/posts/reactnative/ReactNativeRequestHandler.kt#L56
Challenges: There doesn't appear to be an easy way to add an object to a bundle.
Possible: Look into the
putParcelable
method?Using WritableMap or WritableArray to convert the string to a JsonObject
What I tried: I attempted to see whether the WritableMap helper method could be used to convert the string to a JsonObject here, including reading through multiple SO posts and tutorials: https://github.com/WordPress/gutenberg/blob/trunk/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java#L303
Challenges: I wasn't able to get this working.
Possible: It's possible that my lack of experience is a blocker here and I could continue experimenting.
Passing the response as a JsonObject
What I tried: Similar to the above, but rather than using a bundle, I cast the response to a JsonObject and attempted to pass it over the bridge.
Challenges: The
import com.google.gson.JsonObject;
library is required, which will require gradle changes for the files that live on the Gutenberg side. I had an experiment but wasn't able to find a straightforward way to achieve this.Possible: Ask for help from Platform around gradle changes.
How has this been tested?
Latest Posts is an example of a block that uses fetch responses in order to fetch categories. We can therefore follow these testing steps to check whether responses still work as expected on Android:
Screenshots
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).