Skip to content

Performance improvements #470

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

Merged
merged 6 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
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
40 changes: 18 additions & 22 deletions src/commons/modifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ export function extractColorValue(props) {
return Colors[color];
}

// todo: refactor this and use BACKGROUND_KEY_PATTERN
export function extractBackgroundColorValue(props) {
let backgroundColor;
_.forEach(Colors, (value, key) => {
if (props[`background-${key}`] === true || props[`bg-${key}`] === true) {
backgroundColor = value;
}
});

const keys = Object.keys(props);
const bgProp = _.findLast(keys, (prop) => Colors.getBackgroundKeysPattern().test(prop));
if (bgProp) {
const key = bgProp.replace(Colors.getBackgroundKeysPattern(), '');
backgroundColor = Colors[key];
}

return backgroundColor;
}
Expand Down Expand Up @@ -152,13 +153,11 @@ export function extractFlexStyle(props) {
flexG: 'flexGrow',
flexS: 'flexShrink',
};
const flexPropKey = _.chain(props)
.keys(props)
.filter(key => FLEX_KEY_PATTERN.test(key))
.last()
.value();
if (flexPropKey && props[flexPropKey] === true) {
let [flexKey, flexValue] = flexPropKey.split('-');

const keys = Object.keys(props);
const flexProp = keys.find((item) => FLEX_KEY_PATTERN.test(item));
if (flexProp && props[flexProp] === true) {
let [flexKey, flexValue] = flexProp.split('-');
flexKey = STYLE_KEY_CONVERTERS[flexKey];
flexValue = _.isEmpty(flexValue) ? 1 : Number(flexValue);

Expand All @@ -167,16 +166,13 @@ export function extractFlexStyle(props) {
}

export function extractBorderRadiusValue(props) {
const borderRadiusPropsKeys = _.chain(props)
.keys()
.filter(key => BorderRadiuses.getKeysPattern().test(key))
.value();
let borderRadius;
_.forEach(borderRadiusPropsKeys, key => {
if (props[key] === true) {
borderRadius = BorderRadiuses[key];
}
});

const keys = Object.keys(props);
const radiusProp = keys.find((prop) => BorderRadiuses.getKeysPattern().test(prop));
if (radiusProp) {
borderRadius = BorderRadiuses[radiusProp];
}

return borderRadius;
}
Expand Down
7 changes: 5 additions & 2 deletions src/components/card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class Card extends BaseComponent {
};

static defaultProps = {
selected: false,
enableShadow: true,
};

Expand Down Expand Up @@ -170,9 +169,13 @@ class Card extends BaseComponent {
}

renderSelection() {
const {selectionOptions, borderRadius} = this.getThemeProps();
const {selectionOptions, borderRadius, selected} = this.getThemeProps();
const {animatedSelected} = this.state;

if (_.isUndefined(selected)) {
return null;
}

return (
<Animated.View
style={[this.styles.selectedBorder, borderRadius && {borderRadius}, {opacity: animatedSelected}]}
Expand Down
9 changes: 1 addition & 8 deletions src/style/borderRadiuses.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@ class BorderRadiuses {
}

getKeysPattern() {
return new RegExp(
_.chain(this)
.keys()
.map(key => [`${key}`])
.flatten()
.join('|')
.value(),
);
return /^(br[0-9]+)/;
}
}

Expand Down
9 changes: 1 addition & 8 deletions src/style/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,7 @@ class Colors {
}

getBackgroundKeysPattern() {
return new RegExp(
_.chain(this)
.keys()
.map(key => [`bg-${key}`, `background-${key}`])
.flatten()
.join('|')
.value(),
);
return /^(bg-|background-)/;
}

isEmpty(color) {
Expand Down