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] Support Theme Colors and Gradients #14085

Merged
merged 20 commits into from
Jun 3, 2020

Conversation

chipsnyder
Copy link
Contributor

@chipsnyder chipsnyder commented May 8, 2020

Fixes: wordpress-mobile/gutenberg-mobile#1744

Related PRs
gutenberg WordPress/gutenberg#22197
gutenberg-mobile wordpress-mobile/gutenberg-mobile#2241


Description

Adds support for theme defined colors and gradients to be injected into the editor from the mobile apps.

Colors can then be displayed by the same mechanisms that utilize the settings lookup for colors and gradients. This is currently supported on Cover and Button blocks

How has this been tested?

Note Atomic sites don't seem to support the wp/v2/themes API changes yet so this can be tested with a free site or a self-hosted site
To help with testing this theme can be added to a self-hosted site: twentytwenty-copy.zip

Colors

1.) Select a theme with custom colors (such as TwentyTwenty)
2.) Create a post with blocks that have a custom color set (such as Cover or Button)
3.) Load editor on mobile

Expect to see the custom color on the block

Gradients

1.) Select a theme with custom gradients or add gradients to a theme
2.) Create a post with blocks that have a custom gradient set (such as Cover or Button)
3.) Load editor on mobile

Expect to see the custom gradient on the block

No Wifi

1.) Set up blocks for custom color and gradient
2.) View the post on mobile to cache the theme
3.) Turn off wifi to the device
4.) Reload the editor

Expect to see the custom colors on the blocks

No Wifi - Force kill the app

1.) Set up blocks for custom color and gradient
2.) View the post on mobile to cache the theme
3.) Turn off wifi to the device
4.) Stop the app from running in the background
5.) Reload the editor

Expect to see the custom colors on the blocks

Screenshots

Types of changes

New feature: Theme support

PR submission checklist:

  • I have considered adding unit tests where possible.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented May 8, 2020

You can trigger an installable build for these changes by visiting CircleCI here.

@github-actions
Copy link

github-actions bot commented May 8, 2020

Warnings
⚠️ PR is missing at least one label.

Generated by 🚫 dangerJS against 2436309

@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented May 8, 2020

You can trigger optional UI/connected tests for these changes by visiting CircleCI here.

Comment on lines 276 to 284
let themeSupportStore = StoreContainer.shared.editorTheme
themeSupportQuery = themeSupportStore.query(EditorThemeQuery(blog: post.blog))
themeSupportReceipt = themeSupportStore.onStateChange { [weak self] (_, state) in
DispatchQueue.main.async {
if let strongSelf = self, let themeSupport = state.editorTheme(forBlog: strongSelf.post.blog)?.themeSupport {
strongSelf.gutenberg.updateTheme(themeSupport)
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've considered moving these calls outside of the GutenbergViewController. Ultimately I liked it here better because:

  • It's closer to the location where it is being used.
  • It's a fast enough call to where the average case will have this loaded before the user sees the editor.
  • If on a significantly slow network and a user navigates quickly to the editor, then there would still need to be some hook to the Gutenberg editor to call update theme.
  • This only matters for the initial load of the editor for a blog, or if the theme changes; because the theme will load from a cache if no changes were detected.

Con:

  • There is a hiccup where the event can fire while the editor is still loading. I put a workaround for that issue here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this code to an extension file: GutenbergViewController+ThemeSupport?
And have all the methods associated with theme support moved there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that sounds like a good plan.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up moving these to an extension in the same file with a comment. Moving it to a new file would have resulted in changing the access level to a few objects like gutenberg and the themeSupportQuery and themeSupportReceipt which I feel are better left as private

Let me know if this works for you.

@chipsnyder
Copy link
Contributor Author

Hey @SergioEstevao

@pinarol and I thought you might be a good person to ask for in this review when you have time. Not sure how your review plate is right now though so let me know if you want me to ping someone else.

@chipsnyder chipsnyder marked this pull request as ready for review May 8, 2020 19:14
@SergioEstevao SergioEstevao self-assigned this May 21, 2020
@SergioEstevao
Copy link
Contributor

SergioEstevao commented May 21, 2020

Testing the following:

Button

  • Expect to see the custom solid color on the block
  • Expect to see the custom gradient color on the block

Cover

  • Expect to see the custom solid color on the block
  • Expect to see the custom gradient color on the block

No Wifi

  • Expect to see the custom solid color on the block
  • Expect to see the custom gradient color on the block

No Wifi - Force kill the app

  • Expect to see the custom solid color on the block
  • Expect to see the custom gradient color on the block

guard let responseData = try? JSONSerialization.data(withJSONObject: response, options: []) else { return }
let themeSupports = try? JSONDecoder().decode([EditorTheme].self, from: responseData)

if let themeKey = EditorThemeStoreState.key(forBlog: blog),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it easier to read this code can we use guard statements instead of having these nested conditions?


init(from decoder: Decoder) throws {
let map = try decoder.container(keyedBy: CodingKeys.self)
self.colors = try? map.decode([[String: String]].self, forKey: .colors)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using try? here because this key can be optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah if the colors or gradients are missing then the JSON will have editor-color-palette: false or editor-gradient-presets: false so try? here is to protect against the type change.

It's then left as an optional to make sure we don't send an empty array to Gutenberg and override the default colors that we might want.

Copy link
Contributor

@SergioEstevao SergioEstevao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality wise it's working as described, I just left some code comments to be addressed.

@chipsnyder
Copy link
Contributor Author

@SergioEstevao This should be good to go again. I'll handle the Podfile.lock conflict once I have the real commit from the GB side.

@@ -747,6 +753,10 @@ extension GutenbergViewController: GutenbergBridgeDataSource {
"mentions": post.blog.isAccessibleThroughWPCom()
]
}

func gutenbergEditorTheme() -> GutenbergEditorTheme? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this method move to the extension also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup I can move that. My thought here was that since it's a required method of GutenbergBridgeDataSource that it belonged with that extension, but I can just leave a comment on the method to help signify that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been moved now.

Copy link
Contributor

@SergioEstevao SergioEstevao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, feel free to merge after the merge conflict is solved.

@chipsnyder
Copy link
Contributor Author

Looking good, feel free to merge after the merge conflict is solved.

🙇 Thank you @SergioEstevao

@chipsnyder
Copy link
Contributor Author

I'll plan to merge this as soon as the Gutenber Pr's are approved and merged

@SergioEstevao
Copy link
Contributor

SergioEstevao commented May 28, 2020 via email

@SergioEstevao SergioEstevao self-requested a review May 28, 2020 16:21
Copy link
Contributor

@SergioEstevao SergioEstevao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please target the gutenberg/after_1.29.0 branch or wait for next week after the release 1.40 is cut from develop?

@chipsnyder
Copy link
Contributor Author

Yup that shouldn't be a problem to wait. I'm still working on getting reviews for the other layers any way.

@chipsnyder chipsnyder added this to the 15.1 milestone Jun 3, 2020
@SergioEstevao SergioEstevao self-requested a review June 3, 2020 19:20
Copy link
Contributor

@SergioEstevao SergioEstevao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good!

@chipsnyder chipsnyder merged commit 8056b01 into develop Jun 3, 2020
@chipsnyder chipsnyder deleted the rnmobile/issue/1744-themeColor branch June 3, 2020 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants