Skip to content
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

[RNMobile] Pass Android Fetch Responses Across the Bridge as Objects #34391

Closed
wants to merge 2 commits into from

Conversation

SiobhyB
Copy link
Contributor

@SiobhyB SiobhyB commented Aug 30, 2021

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:

  • In the Android app, navigate to the post editor. If the site doesn't already have categories, add some via the Post Settings tab.
  • Add the Latest Posts block.
  • Tap on the block's cog/gear icon and then tap the categories option.
  • Verify that you're able to view the list of the site's categories.

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).
@SiobhyB SiobhyB closed this Mar 1, 2024
@SiobhyB SiobhyB deleted the rnmobile/update/android-fetch-response branch March 1, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Code Quality Issues or PRs that relate to code quality
1 participant