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

WRR-5248: Convert ThemeDecorator to functional component #1712

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 28 additions & 31 deletions ThemeDecorator/ThemeDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import {addAll} from '@enact/core/keymap';
import hoc from '@enact/core/hoc';
import I18nDecorator from '@enact/i18n/I18nDecorator';
import {Component} from 'react';
import {useEffect} from 'react';
import classNames from 'classnames';
import {ResolutionDecorator} from '@enact/ui/resolution';
import {FloatingLayerDecorator} from '@enact/ui/FloatingLayer';
Expand Down Expand Up @@ -242,20 +242,15 @@
// set the DOM node ID of the React DOM tree root
setDefaultTargetById(rootId);

const Decorator = class extends Component {
static displayName = 'ThemeDecorator';
const Decorator = (props) => {
const {skin: skinProp, ...rest} = props;
const skinName = skinProp || 'neutral';
const className = classNames(css.root, props.className, 'sandstone-theme', 'enact-unselectable', {
[bgClassName]: !float,
'enact-fit': !disableFullscreen
});

static propTypes = /** @lends sandstone/ThemeDecorator.prototype */ {
/**
* Assign a skin.
*
* @type {String}
* @private
*/
skin: PropTypes.string
};

componentDidMount () {
useEffect(() => {
if (spotlight) {
activateInputType(true);
requestInputType = requestLastInputType({
Expand All @@ -271,26 +266,28 @@
}
});
}
}

componentWillUnmount () {
if (requestInputType) {
requestInputType.cancel();
}
}
return () => {
if (requestInputType) {
requestInputType.cancel();

Check warning on line 272 in ThemeDecorator/ThemeDecorator.js

View check run for this annotation

Codecov / codecov/patch

ThemeDecorator/ThemeDecorator.js#L272

Added line #L272 was not covered by tests
}
};
}, []);

render () {
const {skin: skinProp, ...rest} = this.props;
const skinName = skinProp || 'neutral';
const className = classNames(css.root, this.props.className, 'sandstone-theme', 'enact-unselectable', {
[bgClassName]: !float,
'enact-fit': !disableFullscreen
});
return (
<App {...rest} skin={skinName} className={className} />
);
};

return (
<App {...rest} skin={skinName} className={className} />
);
}
Decorator.displayName = "ThemeDecorator";
Decorator.propTypes = /** @lends sandstone/ThemeDecorator.prototype */ {
/**
* Assign a skin.
*
* @type {String}
* @private
*/
skin: PropTypes.string
};

return Decorator;
Expand Down