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

Leaner code for the native mobile Toolbar #9064

Merged
merged 6 commits into from
Aug 17, 2018

Conversation

hypest
Copy link
Contributor

@hypest hypest commented Aug 17, 2018

Description

This PR should be considered as additional work on top of #9012.

Changes:

  • More code reuse by extracting into dedicated components what needs to be "nativized" and then "nativizing" those components/containers only
  • Nativized:
    • Button
    • Tooltip
    • (SVG) Path
  • De-nativized:
    • icon-button
    • toolbar
  • Fix lint errors

Note:

Turns out there's we want to propagate a key prop down to the ToolbarButtonContainer component but key being a Special Prop for React it cannot be propagated. We need to mirror/replicate its value to another , differently named prop to pick it up inside the child component. See here.

How has this been tested?

Using this PR on the gutenberg mobile repo.

Types of changes

  • New components
  • Lint error fixes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@hypest
Copy link
Contributor Author

hypest commented Aug 17, 2018

Some tests are failing. Example:

 FAIL  packages/components/src/dashicon/test/index.js
  Dashicon
    basic rendering
      ✓ should render an empty null element when icon is not provided (8ms)
      ✓ should render an empty null element when a non dashicon is provided (1ms)
      ✕ should render a SVG icon element when a matching icon is provided (9ms)
      ✓ should render an additional class to the SVG element (1ms)

  ● Dashicon › basic rendering › should render a SVG icon element when a matching icon is provided

    expect(received).toBe(expected) // Object.is equality

    Expected: "svg"
    Received: [Function _default]

    Difference:

      Comparing two different types of values. Expected string but received function.

      27 | 			expect( dashicon.hasClass( 'dashicon' ) ).toBe( true );
      28 | 			expect( dashicon.hasClass( 'dashicons-wordpress' ) ).toBe( true );
    > 29 | 			expect( dashicon.type() ).toBe( 'svg' );
         | 			                          ^
      30 | 			expect( dashicon.prop( 'xmlns' ) ).toBe( 'http://www.w3.org/2000/svg' );
      31 | 			expect( dashicon.prop( 'width' ) ).toBe( 20 );
      32 | 			expect( dashicon.prop( 'height' ) ).toBe( 20 );

      at Object.<anonymous> (packages/components/src/dashicon/test/index.js:29:30)

@gziolo or @youknowriad perhaps you have some hint about this one ^ ? Apparently it has something to do with the way the web version of the svg.js is defined here but, not sure how to fix it.

@gziolo gziolo requested a review from a team August 17, 2018 06:54
@gziolo gziolo added Framework Issues related to broader framework topics, especially as it relates to javascript Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) labels Aug 17, 2018
height={ size }
viewBox="0 0 20 20"
>
<Path d={ path } />
Copy link
Contributor

@SergioEstevao SergioEstevao Aug 17, 2018

Choose a reason for hiding this comment

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

I'm not sure this will work on the web. If you see my original code on my PR for the web the Path element is defined using lowercase. i.e: path

Copy link
Contributor

Choose a reason for hiding this comment

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

I see what you did know you redefined Path 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.

Hmm, I extracted the Path component to its own component and Path is imported here https://github.com/WordPress/gutenberg/pull/9064/files#diff-297ebddffcddddf088a365bab7f0909cR13. That should do it, although I think there's probably a problem with the way I've defined the web side variants (related to the comment).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this component is meant to be modified in the Dashicons repository first.

Copy link
Contributor

Choose a reason for hiding this comment

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

From the comments I saw on the file I thought this was the case, if we could a pointer to where to make the changes it will be great.

Copy link
Contributor

Choose a reason for hiding this comment

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

Dashicons are edited in https://github.com/WordPress/dashicons. Feel free to ping me for help, I can fasttrack any changes you'd like.

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 think this might be the file to modify on the Dashicons repo: https://github.com/WordPress/dashicons/blob/master/sources/react/index-footer.jsx. Not sure yet how to integrate that repo/project and have it hot-reloading in the React Native app but yeah, let's see.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you'd like to make a PR, I can approve it for you and ship it to Gutenberg.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@youknowriad , it would still be good to review the proposal in this PR and agree on whether we like/want it or not before migrating the change to the Dashicons repo, so we take advantage of the quick turnaround time we enjoy with the Gutenberg+ReactNative repo combo.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if the best approach here would be to have an alternative index.native.js for the whole dashicon component instead of extracting Path and Svg

key={ [ indexOfSet, indexOfControl ].join() }
keyProp={ [ indexOfSet, indexOfControl ].join() }
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we repeat key and keyProp?

Copy link
Contributor Author

@hypest hypest Aug 17, 2018

Choose a reason for hiding this comment

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

Ah, good catch, I should have mentioned this "gotcha" in the PR description. So, React has this set of "special" props that it doesn't propagate down to the child components. They call them Special Props. In this case, the key property cannot be picked up by the ToolbarButtonContainer component and we need to replicate it on purpose into a differently named prop, keyProp.

I'll update the PR description to include it for future ref.

@@ -0,0 +1,8 @@
export default ( props ) => (
<div
key={ props.keykeyProp }
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be prop.keyProp only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding of the docs is that key is used for the rendering reconciliation logic and since it was there in the original code (div) it needs to be here in the web variant of the component too. I can be wrong though as my React knowledge is limited still.

Copy link
Contributor

Choose a reason for hiding this comment

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

but keykeyPro?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see now, that's a typo, good catch! Fixed with aed7db6.

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.

Good work on this.

@SergioEstevao SergioEstevao merged commit fefcb3b into rnmobile/toolbar Aug 17, 2018
@SergioEstevao SergioEstevao deleted the rnmobile/toolbar-extra-lean-code branch August 17, 2018 09:12
@youknowriad
Copy link
Contributor

I feel this change has some impacts on the web, and since we've freezed developpement fo 3.6 for releasing, do you think it's possible to revert this change until the release?

@youknowriad
Copy link
Contributor

Oh! I missed that this was merged against another branch, it's fine. Sorry for the confusion (The dashicons feedback is still valid though cc @jasmussen )

@hypest
Copy link
Contributor Author

hypest commented Aug 17, 2018

I know this PR is not merged to the parent #9012 but I'd like to add here that we should prolly name the functions/components in the modules so it's more clear which compos they are in the React inspector (notice the couple of "Unknown"s in the screenshot below):

screen shot 2018-08-17 at 12 47 34

@hypest
Copy link
Contributor Author

hypest commented Aug 17, 2018

And oh, btw, I manually tested the Gutenberg changes and the toolbar works fine, as in, nothing seems broken on the UI.

SergioEstevao added a commit that referenced this pull request Aug 22, 2018
* Activate toolbar for RN.

* Move toolbar to the top.

* Implement RN icon buttons using SVG.

* Add extra properties for toolbar selection.

* Update url package entry point for RN.

* Leaner code for the native mobile Toolbar (#9064)

* Dedicated components for SVG, Path

* Fix lint errors

* Dedicated native components for button, icon-button, tooltip

* Dedicated native mobile comps for Toolbar containers

* Small code styling fix

* Fix double "key" typo in prop name

* Name the web side componets for better React debugging

* Update the tests to cater for SVG, Path

* Deconstruct arguments in single line.

* Remove comment.

* Remove unnecessary use of keyProp

* Fix use of platform for iOS detection.

* Update toolbar RN code to share more code with Web.

* Update index.native.js

* Address review comments.

* Address eslint errors.

* Remove extra white space.

* Components: Add new primitives to work cross-platform

* Keycodes: Include support for both iPad and iPhone when using external keyboard

* Components: Use explicit name for Tooltip component in RN

* Add token-list as a dependency to package.json to avoid random updates to the lock file

* Return null to avoid failure on render.

* Fix warning on SVG

* Fix potential error on style.

* Fix lint errors.

* Fix lint error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues related to broader framework topics, especially as it relates to javascript 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.

5 participants