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] Refactor native gradient logic #27307

Merged
merged 7 commits into from
Nov 27, 2020
Merged

Conversation

lukewalczak
Copy link
Member

@lukewalczak lukewalczak commented Nov 26, 2020

Description

Refactor the parsing gradient which is passed to rn linear gradient component.

How has this been tested?

  1. Set theme Twenty Twenty

  2. Open a post

  3. Add cover block

  4. Choose the background color

  5. Press cog to open settings

  6. Go to color and press Gradient
    Expect there is no crash

  7. Choose one of the gradients

  8. Save the post

  9. Exit the editor and switch theme to Spearhead

  10. Kill the app and reopen it (known issue with themes)

  11. Go to the previous post
    Expect cover background is not set

  12. Choose the background color

  13. Press cog to open settings

  14. Go to color and press Gradient

Expect there is no crash and expect to see the following gradients:
image

  1. Choose one of them
  2. Save the post
  3. Open the post on web and compare if gradients looks alike

TO INVESTIGATE

Once trying to convert marked gradients to radial gradient (press customize gradient then radial) app crashes. I've checked that on the web and there user cannot convert these two gradients to linear.

Screenshot 2020-11-26 at 17 53 16

I push the commit with the fix and left the comment

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • 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.

@lukewalczak lukewalczak added the Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) label Nov 26, 2020
@lukewalczak lukewalczak self-assigned this Nov 26, 2020
@github-actions
Copy link

github-actions bot commented Nov 26, 2020

Size Change: +18 B (0%)

Total Size: 1.19 MB

Filename Size Change
build/components/index.js 172 kB +18 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.8 kB 0 B
build/api-fetch/index.js 3.42 kB 0 B
build/autop/index.js 2.84 kB 0 B
build/blob/index.js 665 B 0 B
build/block-directory/index.js 8.72 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-editor/index.js 128 kB 0 B
build/block-editor/style-rtl.css 11.2 kB 0 B
build/block-editor/style.css 11.2 kB 0 B
build/block-library/editor-rtl.css 8.95 kB 0 B
build/block-library/editor.css 8.95 kB 0 B
build/block-library/index.js 148 kB 0 B
build/block-library/style-rtl.css 8.27 kB 0 B
build/block-library/style.css 8.27 kB 0 B
build/block-library/theme-rtl.css 789 B 0 B
build/block-library/theme.css 790 B 0 B
build/block-serialization-default-parser/index.js 1.87 kB 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/blocks/index.js 48.1 kB 0 B
build/components/style-rtl.css 15.3 kB 0 B
build/components/style.css 15.3 kB 0 B
build/compose/index.js 9.95 kB 0 B
build/core-data/index.js 14.8 kB 0 B
build/data-controls/index.js 828 B 0 B
build/data/index.js 8.98 kB 0 B
build/date/index.js 11.2 kB 0 B
build/deprecated/index.js 769 B 0 B
build/dom-ready/index.js 571 B 0 B
build/dom/index.js 4.95 kB 0 B
build/edit-navigation/index.js 11.1 kB 0 B
build/edit-navigation/style-rtl.css 881 B 0 B
build/edit-navigation/style.css 885 B 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.42 kB 0 B
build/edit-post/style.css 6.4 kB 0 B
build/edit-site/index.js 24 kB 0 B
build/edit-site/style-rtl.css 3.92 kB 0 B
build/edit-site/style.css 3.92 kB 0 B
build/edit-widgets/index.js 26.3 kB 0 B
build/edit-widgets/style-rtl.css 3.13 kB 0 B
build/edit-widgets/style.css 3.13 kB 0 B
build/editor/editor-styles-rtl.css 476 B 0 B
build/editor/editor-styles.css 478 B 0 B
build/editor/index.js 43.3 kB 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.85 kB 0 B
build/element/index.js 4.62 kB 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/index.js 6.86 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.27 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 698 B 0 B
build/keyboard-shortcuts/index.js 2.54 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.1 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.32 kB 0 B
build/notices/index.js 1.82 kB 0 B
build/nux/index.js 3.42 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.43 kB 0 B
build/priority-queue/index.js 790 B 0 B
build/redux-routine/index.js 2.84 kB 0 B
build/reusable-blocks/index.js 2.92 kB 0 B
build/rich-text/index.js 13.4 kB 0 B
build/server-side-render/index.js 2.77 kB 0 B
build/shortcode/index.js 1.69 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.86 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.22 kB 0 B

compressed-size-action

@@ -21,7 +21,7 @@ export function serializeGradientColorStop( { type, value, length } ) {
return `${ serializeGradientColor( {
type,
value,
} ) } ${ serializeGradientPosition( length ) }`;
} ) } ${ length ? serializeGradientPosition( length ) : '' }`;
Copy link
Member Author

Choose a reason for hiding this comment

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

Gradient color length (gradient color location - e.g. 50%) can be undefined e.g. in linear-gradient(to top , #3C8067, #FAFBF6) from the theme called Spearhead. On web nothing happens when trying to switch from linear to radial but on mobile there is a crash since we reuse logic within serializer.js.

Properties of undefined length are then used in function:

export function serializeGradientPosition( { type, value } ) {
	return `${ value }${ type }`;
}

which makes a crash.

Copy link
Member

Choose a reason for hiding this comment

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

To me this seems ok to do, but this code is new to me as well. Maybe @jorgefilipecosta can have a quick look?

Copy link
Member

Choose a reason for hiding this comment

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

This change looks good to me 👍

I guess as an enhancement we can add this logic inside the serializeGradientPosition function directly:

export function serializeGradientPosition( position ) {
	if ( ! position ) {
		return '';
	}
	const { value, type } = position;
	return `${ value }${ type }`;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, make sense 👍🏼

@cameronvoell cameronvoell self-requested a review November 26, 2020 20:34
@cameronvoell
Copy link
Member

cameronvoell commented Nov 26, 2020

Hi @ajitbohra @chrisvanpatten 👋 , a review on this update to packages/components/src/custom-gradient-picker/serializer.js (see comment) from the web perspective would be appreciated. I believe what @lukewalczak is describing in the "TO INVESTIGATE" section of the PR description, is that setting the last two gradients to radial from mobile with this specific theme (Spearhead), seems to break the gradient background in the web editor, so the change suggested here fixes that potential problem.

The change is useful for fixing a crash in native mobile apps. I can review the rest of the PR from the mobile perspective. 🙇

@cameronvoell
Copy link
Member

Tested successfully from a mobile perspective 👍 . I see the change fixed the crash when setting the custom gradient on the cover block for the Spearhead Theme. This change is ready to go as long as the web side change checks out with necessary code owners.

@hypest
Copy link
Contributor

hypest commented Nov 27, 2020

End-to-End Tests / Admin - 3 (pull_request) Failing after 16m — Admin - 3 failed so, I went ahead and restarted the job that includes it.
Update: still failing after restarting.

@hypest
Copy link
Contributor

hypest commented Nov 27, 2020

The failing job also fails on master so, doesn't seem like this PR is introducing the fail.

@@ -21,7 +21,7 @@ export function serializeGradientColorStop( { type, value, length } ) {
return `${ serializeGradientColor( {
type,
value,
} ) } ${ serializeGradientPosition( length ) }`;
} ) } ${ length ? serializeGradientPosition( length ) : '' }`;
Copy link
Member

Choose a reason for hiding this comment

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

This change looks good to me 👍

I guess as an enhancement we can add this logic inside the serializeGradientPosition function directly:

export function serializeGradientPosition( position ) {
	if ( ! position ) {
		return '';
	}
	const { value, type } = position;
	return `${ value }${ type }`;
}

Copy link
Contributor

@Tug Tug left a comment

Choose a reason for hiding this comment

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

Code looks good but I still have an error when opening the page it was crashing on before.

Also it would be great to have some unit tests for those functions in mobile/gradient/.

@lukewalczak
Copy link
Member Author

@Tug Is there an option to paste a HTML of that post?

@lukewalczak
Copy link
Member Author

Also it would be great to have some unit tests for those functions in mobile/gradient/.

I will tackle it as a next task I think, that logic definitely need some unit tests.

@hypest
Copy link
Contributor

hypest commented Nov 27, 2020

I will tackle it as a next task I think

+1 for tackling that or similar tasks after we merge and include this fix to the ongoing mobile editor release that's due today.

@Tug
Copy link
Contributor

Tug commented Nov 27, 2020

My bad it's working fine, I had trouble with my environment.

@Tug
Copy link
Contributor

Tug commented Nov 27, 2020

Looks like #25854 broke CI tests on master. Let's go ahead and merge this one

@Tug Tug merged commit 33d0366 into master Nov 27, 2020
@Tug Tug deleted the rnmobile/adjust-native-gradient branch November 27, 2020 16:13
@github-actions github-actions bot added this to the Gutenberg 9.5 milestone Nov 27, 2020
cameronvoell pushed a commit that referenced this pull request Nov 27, 2020
* Refactor native gradient logic

* Make using 'length' conditional in serializing

* Move fixing logic directly to serializeGradientPosition

* Remove global from regex
cameronvoell added a commit that referenced this pull request Nov 30, 2020
* Release script: Update react-native-editor version to 1.42.0

* Release script: Update with changes from 'npm run core preios'

* [RNMobile] Make initial value passed to slider always a number (#27273)

* [RNMobile] Refactor native gradient logic (#27307)

* Refactor native gradient logic

* Make using 'length' conditional in serializing

* Move fixing logic directly to serializeGradientPosition

* Remove global from regex

Co-authored-by: Luke Walczak <lukasz.walczak.pwr@gmail.com>
cameronvoell added a commit that referenced this pull request Dec 7, 2020
* Release script: Update react-native-editor version to 1.42.0

* Release script: Update with changes from 'npm run core preios'

* [RNMobile] Make initial value passed to slider always a number (#27273)

* [RNMobile] Refactor native gradient logic (#27307)

* Refactor native gradient logic

* Make using 'length' conditional in serializing

* Move fixing logic directly to serializeGradientPosition

* Remove global from regex

* Release script: Update react-native-editor version to 1.42.1

* Release script: Update with changes from 'npm run core preios'

Co-authored-by: Cameron Voell <cameronvoell@gmail.com>
Co-authored-by: Luke Walczak <lukasz.walczak.pwr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants