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] iOS DarkMode toolbar buttons #17356

Merged
merged 6 commits into from
Oct 3, 2019

Conversation

etoledom
Copy link
Contributor

@etoledom etoledom commented Sep 6, 2019

gutenberg-mobile PR: wordpress-mobile/gutenberg-mobile#1357

Description

This PR allow us to add different styles to DashIcons inside IconButton component depending on the the style theme (Dark/Light mode).

It also enhance the DarkMode theme for Toolbar buttons (and the toolbar separator)

With this change, is not needed to send ariaPressed prop from IconButton. This is a change that was requested long ago, (even though we still are sending it button states).

A second idea is to send styles directly to DashIcon from the Button, to avoid having to declare styles for every new class. I'm not sure if this is something we want to change though.

As always any moment is welcome!

toolbar

To test:

  • Run the example app with Xcode 11 beta
  • Check that the toolbar colors are correct on the toolbar (following the screenshots)
  • Check that the rest of the icons in the app shows properly
    • In particular the BottomSheet icons (Add link / Image settings)
  • Check that the icon Subscript is colored properly (Numbers on H1, H2, etc...)

@etoledom etoledom 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 Sep 6, 2019
@etoledom etoledom self-assigned this Sep 6, 2019
@etoledom etoledom changed the title Rnmobile/darkmode toolbar buttons [RNMobile] iOS DarkMode toolbar buttons Sep 6, 2019
@etoledom etoledom requested a review from Tug September 6, 2019 07:08
@etoledom
Copy link
Contributor Author

Updated this PR implementing the DarkMode refactor from: #17552

@Tug or @mchowning - Could any of you please take a look? Thank you!

@@ -56,7 +55,7 @@ function IconButton( props, ref ) {
className={ classes }
ref={ ref }
>
<Icon icon={ icon } ariaPressed={ ariaPressed } />
<Icon icon={ icon } />
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure that it's safe to stop passing down this prop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's basically being replaced by this line here:
https://github.com/WordPress/gutenberg/blob/82a96dd640354ba5068dee5a10e6195e96ea65bb/packages/components/src/button/index.native.js#L97
Were we send the colorScheme and the active state to all children of Button.

But considering @Tug's comment here: https://github.com/WordPress/gutenberg/pull/17356/files#r328582023 I might need to change this anyway.

What do you think?

Copy link
Member

@gziolo gziolo Oct 3, 2019

Choose a reason for hiding this comment

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

I checked the history and it looks like ariaPressed was introduced in #11827. It was never really used in the web code. Should it be also removed in other places?

In particular, I think about Dashicon implementation which used to pass this prop down but it seems to longer be necessary. See:

const iconClass = getIconClassName( icon, className, ariaPressed );

Copy link
Member

Choose a reason for hiding this comment

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

Filed here: #17741.

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.

I left a comment about the way we pass the colorScheme props down tho children.

An alternative would be to consider having the colorScheme available in a more global context. Basically have DarkModeProvider in the EditorProvider (we could rename mode to colorScheme), we could get rid of all the HOCs but we would need to use <DarkModeContext.Consumer> ( { colorScheme, active } ) ) => whenever we want to access that value

@@ -80,6 +91,12 @@ export default function Button( props ) {
states.push( 'disabled' );
}

const subscriptInactive = getStylesFromColorScheme( styles.subscriptInactive, styles.subscriptInactiveDark );

const newChildren = Children.map( compact( children ), ( child ) => {
Copy link
Contributor

@Tug Tug Sep 26, 2019

Choose a reason for hiding this comment

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

I'd rather we use a context for this:

// in Button:
export const ButtonContext = React.createContext( {
  active: false,
  colorScheme: 'light',
} );

export function Button( props ) {

	...

	const buttonContext = {
	  active: props.active,
	  colorScheme: props.colorScheme,
	};

	{ Children.count( children ) &&
		<ButtonContext.Provider value={ buttonContext }>
			{ children }
		</ButtonContext.Provider>
	}

	...

// in IconButton
<ButtonContext.Consumer>
    { ( { colorScheme, active } )  =>
    	<Icon icon={ icon } ariaPressed={ active } colorScheme={ colorScheme } />
</ButtonContext.Consumer>

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 copied the idea from here: https://github.com/WordPress/gutenberg/blob/82a96dd640354ba5068dee5a10e6195e96ea65bb/packages/components/src/primitives/block-quotation/index.native.js#L15

And the main idea was to clear up IconButton from sending the ariaPressed or active related states.

I like that we can get enough information to style any child of button, but you are right that this might not be the best option.

I'll give this a try!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about it, I guess using cloneElement should not have any impact on performance, it's just a bit more limited in terms of features. Basically, you'll only be able to access those props from the direct children of the button, whereas a consumer could be added anywhere. If direct children is fine then I guess we can keep it that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the main (and only, so far) usage of this is the IconButton where the Icon component is a direct child.
So, if you think it's fine to keep this, let's move on 👍

I restarted a CI job to get the ✅ from travis.
Thanks for your review!

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't know about React Context before. Thanks for leaving this comment @Tug !

@etoledom etoledom requested a review from Tug September 27, 2019 10:21
@etoledom
Copy link
Contributor Author

@Tug I'm thinking to wait until #17228 is merged before merging this one. What do you think?

@etoledom etoledom changed the base branch from rnmobile/master to master September 27, 2019 16:05
@etoledom etoledom changed the base branch from master to rnmobile/master September 27, 2019 16:08
@etoledom etoledom force-pushed the rnmobile/darkmode-toolbar-buttons branch from 82a96dd to 640b17f Compare September 27, 2019 16:32
@etoledom
Copy link
Contributor Author

@Tug if you agree with this implementation, could you please ✅ to move forward? :)
Thank you!

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 LGTM 👍

@etoledom
Copy link
Contributor Author

etoledom commented Oct 2, 2019

Thank you @Tug !
@mchowning could you please give this PR a run to be sure it's working as expected?

Thank you!

Copy link
Contributor

@mchowning mchowning left a comment

Choose a reason for hiding this comment

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

Tested and everything looks good. Nice job @etoledom !

@etoledom etoledom merged commit 5c5dc12 into master Oct 3, 2019
@etoledom etoledom deleted the rnmobile/darkmode-toolbar-buttons branch October 3, 2019 06:15
@etoledom
Copy link
Contributor Author

etoledom commented Oct 3, 2019

Thank you all!

@gziolo
Copy link
Member

gziolo commented Oct 3, 2019

It should fix #17695, thank you for working on it 👍

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.

5 participants