Skip to content

Commit 1afbcfe

Browse files
authored
fix(theme): style provider - reduce setState calls
1 parent 74fac39 commit 1afbcfe

File tree

3 files changed

+31
-38
lines changed

3 files changed

+31
-38
lines changed

src/framework/theme/component/application/applicationProvider.component.tsx

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,19 @@ interface State {
2323

2424
export class ApplicationProvider extends React.Component<Props, State> {
2525

26-
state: State;
26+
public state: State = {
27+
mapping: this.props.mapping,
28+
styles: this.props.styles,
29+
theme: this.props.theme,
30+
};
2731

28-
constructor(props: Props) {
29-
super(props);
30-
this.state = {
31-
mapping: props.mapping,
32-
styles: props.styles,
33-
theme: props.theme,
34-
};
35-
}
36-
37-
render() {
38-
return (
39-
<ModalPanel>
40-
<StyleProvider
41-
mapping={this.state.mapping}
42-
styles={this.state.styles}
43-
theme={this.state.theme}
44-
children={this.props.children}
45-
/>
46-
</ModalPanel>
47-
);
32+
public render(): React.ReactNode {
33+
return (
34+
<StyleProvider {...this.state}>
35+
<ModalPanel>
36+
{this.props.children}
37+
</ModalPanel>
38+
</StyleProvider>
39+
);
4840
}
4941
}

src/framework/ui/popover/popover.component.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ export class Popover extends React.Component<Props, State> {
6060
};
6161

6262
private containerRef: React.RefObject<MeasuredNode> = React.createRef();
63-
private componentId: string = '';
63+
private modalIdentifier: string = '';
6464

65-
public shouldComponentUpdate(nextProps: Props, nextState: State): boolean {
65+
public shouldComponentUpdate(nextProps: Props, nextState: State, nextContext: any): boolean {
6666
const isLayoutChanged: boolean = nextState.layout !== undefined;
6767
const isVisibilityChanged: boolean = this.props.visible !== nextProps.visible;
6868

@@ -82,23 +82,23 @@ export class Popover extends React.Component<Props, State> {
8282

8383
const { current: container } = this.containerRef;
8484

85-
// Retrieve `content` from popover children
86-
// and clone it with measured position
85+
// Retrieve `content` from popover children and clone it with measured position
8786
const { [TAG_CONTENT]: popoverView } = container.props.children;
88-
const popover: React.ReactElement<ModalComponentCloseProps> =
89-
React.cloneElement(popoverView, {
90-
style: style,
91-
onRequestClose: onRequestClose,
92-
});
93-
this.componentId = ModalService.show(popover, true);
87+
88+
const popover: React.ReactElement<ModalComponentCloseProps> = React.cloneElement(popoverView, {
89+
style: style,
90+
onRequestClose: onRequestClose,
91+
});
92+
93+
this.modalIdentifier = ModalService.show(popover, true);
9494
} else {
95-
ModalService.hide(this.componentId);
95+
ModalService.hide(this.modalIdentifier);
9696
}
9797
}
9898
}
9999

100100
public componentWillUnmount(): void {
101-
this.componentId = '';
101+
this.modalIdentifier = '';
102102
}
103103

104104
private getComponentStyle = (source: StyleType): StyleType => {

src/framework/ui/tooltip/tooltip.component.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import React from 'react';
2-
import {
3-
Text,
4-
StyleSheet,
5-
TextProps,
6-
} from 'react-native';
2+
import { StyleSheet } from 'react-native';
73
import {
84
styled,
95
StyledComponentProps,
106
StyleType,
117
} from '@kitten/theme';
8+
import {
9+
Text as TextComponent,
10+
Props as TextProps,
11+
} from '../text/text.component';
1212
import {
1313
Popover as PopoverComponent,
1414
Props as PopoverProps,
@@ -21,6 +21,7 @@ interface TooltipProps {
2121
}
2222

2323
const Popover = styled<PopoverComponent, PopoverProps>(PopoverComponent);
24+
const Text = styled<TextComponent, TextProps>(TextComponent);
2425

2526
export type Props = TooltipProps & StyledComponentProps & Omit<PopoverProps, 'content'>;
2627

0 commit comments

Comments
 (0)