Skip to content

Commit b5d2fb5

Browse files
authored
Calc modifiers in render methods so we can access context (#1035)
1 parent 2d46a3a commit b5d2fb5

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

src/commons/asBaseComponent.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,21 @@ type ThemeComponent = {
2121

2222
function asBaseComponent<PROPS, STATICS = {}>(WrappedComponent: React.ComponentType<any>): React.ComponentClass<PROPS & ThemeComponent> & STATICS {
2323
class BaseComponent extends UIComponent {
24-
state = Modifiers.generateModifiersStyle(undefined, BaseComponent.getThemeProps(this.props, this.context));
2524
static displayName: string | undefined;
2625
static propTypes: any;
2726
static defaultProps: any;
2827

29-
static getDerivedStateFromProps(nextProps: any, prevState: any) {
30-
const themeProps = BaseComponent.getThemeProps(nextProps, undefined);
31-
const newModifiers = Modifiers.generateModifiersStyle(undefined, themeProps);
32-
if (!_.isEqual(newModifiers, prevState)) {
33-
return newModifiers;
34-
}
35-
36-
return null;
37-
}
38-
3928
static getThemeProps = (props: any, context: any) => {
4029
return Modifiers.getThemeProps.call(WrappedComponent, props, context);
4130
}
4231

4332
render() {
4433
const themeProps = BaseComponent.getThemeProps(this.props, this.context);
34+
const modifiers = Modifiers.generateModifiersStyle(undefined, themeProps);
4535
// TODO: omit original modifiers props (left, right, flex, etc..)
4636
// Because they throws an error when being passed to RNView on Android
4737
const {forwardedRef, ...others} = themeProps;
48-
return <WrappedComponent /* {...this.props} */ {...others} modifiers={this.state} ref={forwardedRef}/>;
38+
return <WrappedComponent {...others} modifiers={modifiers} ref={forwardedRef}/>;
4939
}
5040
}
5141

0 commit comments

Comments
 (0)