Skip to content

Commit 8da3dbd

Browse files
authored
Fix/event listener warning (#1605)
* Upgrade to rn65 * return jcenter * Fix usage of Dimensions.removeEventListener for RN65 * Update button snapshot tests * Remove orientation listener from Dialog
1 parent ae996ae commit 8da3dbd

File tree

14 files changed

+29
-37
lines changed

14 files changed

+29
-37
lines changed

demo/src/screens/componentScreens/CarouselScreen.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interface State {
3636

3737
class CarouselScreen extends Component<Props, State> {
3838
carousel = React.createRef<typeof Carousel>();
39+
private dimensionsChangeListener: any;
3940

4041
constructor(props: Props) {
4142
super(props);
@@ -51,11 +52,11 @@ class CarouselScreen extends Component<Props, State> {
5152
}
5253

5354
componentDidMount() {
54-
Constants.addDimensionsEventListener(this.onOrientationChange);
55+
this.dimensionsChangeListener = Constants.addDimensionsEventListener(this.onOrientationChange);
5556
}
5657

5758
componentWillUnmount() {
58-
Constants.removeDimensionsEventListener(this.onOrientationChange);
59+
Constants.removeDimensionsEventListener(this.dimensionsChangeListener || this.onOrientationChange);
5960
}
6061

6162
onOrientationChange = () => {

generatedTypes/src/components/button/index.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,6 @@ declare class Button extends PureComponent<Props, ButtonState> {
154154
};
155155
};
156156
componentDidUpdate(prevProps: Props): void;
157-
componentDidMount(): void;
158-
componentWillUnmount(): void;
159-
onOrientationChanged: () => void;
160157
onLayout: (event: LayoutChangeEvent) => void;
161158
get isOutline(): boolean;
162159
get isFilled(): boolean;

generatedTypes/src/components/carousel/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ declare class Carousel extends Component<CarouselProps, CarouselState> {
2020
orientationChange?: boolean;
2121
skippedInitialScroll?: boolean;
2222
isAutoScrolled: boolean;
23+
private dimensionsChangeListener;
2324
constructor(props: CarouselProps);
2425
static getDerivedStateFromProps(nextProps: CarouselProps, prevState: CarouselState): {
2526
pageWidth: number;

generatedTypes/src/components/gridView/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ declare class GridView extends UIComponent<GridViewProps, State> {
4848
itemSpacing: number;
4949
};
5050
private itemSize?;
51+
private dimensionsChangeListener;
5152
constructor(props: ExistProps);
5253
static getDerivedStateFromProps(nextProps: ExistProps, prevState: State): {
5354
viewWidth: number;

generatedTypes/src/components/slider/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export default class Slider extends PureComponent<SliderProps, SliderState> {
124124
private containerSize;
125125
private trackSize;
126126
private thumbSize;
127+
private dimensionsChangeListener;
127128
constructor(props: SliderProps);
128129
checkProps(props: SliderProps): void;
129130
getAccessibilityProps(): {

generatedTypes/src/components/wizard/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ declare class Wizard extends Component<WizardProps, State> {
1818
static displayName: string;
1919
static Step: typeof WizardStep;
2020
static States: typeof WizardStepStates;
21+
private dimensionsChangeListener;
2122
constructor(props: WizardProps);
2223
componentDidMount(): void;
2324
componentWillUnmount(): void;

src/components/button/index.tsx

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,6 @@ class Button extends PureComponent<Props, ButtonState> {
4343
}
4444
}
4545

46-
componentDidMount() {
47-
Constants.addDimensionsEventListener(this.onOrientationChanged);
48-
}
49-
50-
componentWillUnmount() {
51-
Constants.removeDimensionsEventListener(this.onOrientationChanged);
52-
}
53-
54-
onOrientationChanged = () => {
55-
if (Constants.isTablet && this.props.fullWidth) {
56-
// only to trigger re-render
57-
this.setState({isLandscape: Constants.isLandscape});
58-
}
59-
};
60-
6146
// This method will be called more than once in case of layout change!
6247
onLayout = (event: LayoutChangeEvent) => {
6348
const height = event.nativeEvent.layout.height;

src/components/carousel/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Carousel extends Component<CarouselProps, CarouselState> {
4545
orientationChange?: boolean;
4646
skippedInitialScroll?: boolean;
4747
isAutoScrolled: boolean;
48+
private dimensionsChangeListener: any;
4849

4950
constructor(props: CarouselProps) {
5051
super(props);
@@ -106,15 +107,15 @@ class Carousel extends Component<CarouselProps, CarouselState> {
106107
}
107108

108109
componentDidMount() {
109-
Constants.addDimensionsEventListener(this.onOrientationChanged);
110+
this.dimensionsChangeListener = Constants.addDimensionsEventListener(this.onOrientationChanged);
110111

111112
if (this.props.autoplay) {
112113
this.startAutoPlay();
113114
}
114115
}
115116

116117
componentWillUnmount() {
117-
Constants.removeDimensionsEventListener(this.onOrientationChanged);
118+
Constants.removeDimensionsEventListener(this.dimensionsChangeListener || this.onOrientationChanged);
118119

119120
if (this.autoplayTimer) {
120121
clearInterval(this.autoplayTimer);

src/components/colorPicker/ColorPalette.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ class ColorPalette extends PureComponent<Props, State> {
110110
usePagination?: boolean = undefined;
111111
innerMargin?: number = undefined;
112112
swatchStyles?: StyleProp<ViewStyle>[] = undefined;
113+
private dimensionsChangeListener: any;
113114

114115
componentDidMount() {
115-
Constants.addDimensionsEventListener(this.onOrientationChanged);
116+
this.dimensionsChangeListener = Constants.addDimensionsEventListener(this.onOrientationChanged);
116117
}
117118

118119
componentWillUnmount() {
119-
Constants.removeDimensionsEventListener(this.onOrientationChanged);
120+
Constants.removeDimensionsEventListener(this.dimensionsChangeListener || this.onOrientationChanged);
120121
}
121122

122123
onOrientationChanged = () => {

src/components/gridView/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class GridView extends UIComponent<GridViewProps, State> {
6262
};
6363

6464
private itemSize?: number;
65+
private dimensionsChangeListener: any;
6566

6667
constructor(props: ExistProps) {
6768
super(props);
@@ -92,11 +93,11 @@ class GridView extends UIComponent<GridViewProps, State> {
9293
}
9394

9495
componentDidMount() {
95-
Constants.addDimensionsEventListener(this.onOrientationChanged);
96+
this.dimensionsChangeListener = Constants.addDimensionsEventListener(this.onOrientationChanged);
9697
}
9798

9899
componentWillUnmount() {
99-
Constants.removeDimensionsEventListener(this.onOrientationChanged);
100+
Constants.removeDimensionsEventListener(this.dimensionsChangeListener || this.onOrientationChanged);
100101
}
101102

102103
onOrientationChanged = () => {

0 commit comments

Comments
 (0)