Skip to content

Commit efb0dc3

Browse files
committed
refactor: fix dimensions event removal deprecation handler
1 parent a24e373 commit efb0dc3

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/app/Components/HeaderArtworksFilter/HeaderArtworksFilter.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
import { FilterIcon, Flex, Box, Text, Separator } from "@artsy/palette-mobile"
1+
import {
2+
FilterIcon,
3+
Flex,
4+
Box,
5+
Text,
6+
Separator,
7+
TouchableHighlightColor,
8+
} from "@artsy/palette-mobile"
29
import { isPad } from "app/utils/hardware"
3-
import { TouchableHighlightColor } from "@artsy/palette-mobile"
10+
import { useScreenDimensions } from "app/utils/hooks"
411
import React, { useEffect, useState } from "react"
512
import { Animated, Dimensions, LayoutChangeEvent, PixelRatio } from "react-native"
6-
import { useScreenDimensions } from "app/utils/hooks"
713

814
export interface FilterProps {
915
total: number
@@ -61,10 +67,8 @@ export const HeaderArtworksFilter: React.FC<FilterProps> = ({ total, animationVa
6167

6268
useEffect(() => {
6369
// orientation changed, allow for recalculation of pageY
64-
Dimensions.addEventListener("change", orientationChanged)
65-
return () => {
66-
Dimensions.removeEventListener("change", orientationChanged)
67-
}
70+
const dimensionsEventSubscription = Dimensions.addEventListener("change", orientationChanged)
71+
return () => dimensionsEventSubscription.remove()
6872
}, [])
6973

7074
const orientationChanged = () => {

src/app/utils/hooks/useScreenDimensions.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ export const ProvideScreenDimensions: React.FC = ({ children }) => {
4343
const onChange = () => {
4444
setDimensions(getCurrentDimensions())
4545
}
46-
Dimensions.addEventListener("change", onChange)
47-
return () => {
48-
Dimensions.removeEventListener("change", onChange)
49-
}
46+
const dimensionsEventSubscription = Dimensions.addEventListener("change", onChange)
47+
return () => dimensionsEventSubscription.remove()
5048
}, [])
5149

5250
return (

0 commit comments

Comments
 (0)