Skip to content

Commit

Permalink
fix(Dimensions.removeEventListener): implements more simple condition…
Browse files Browse the repository at this point in the history
… for choosing a way of removing a listener
  • Loading branch information
zheoreh committed Nov 29, 2023
1 parent 9761dcf commit 5002417
Show file tree
Hide file tree
Showing 6 changed files with 23,917 additions and 32,415 deletions.
2 changes: 1 addition & 1 deletion packages/app/client/helpers/useMediaUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function useMediaUpdate () {
const listener = Dimensions.addEventListener('change', debouncedChangeDimensions)
return () => {
// removeEventListener has been removed from rn 0.70.4
if (listener && !Dimensions.removeEventListener) {
if (listener) {
listener.remove()
} else {
Dimensions.removeEventListener('change', debouncedChangeDimensions)
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/components/SmartSidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function SmartSidebar ({
let onChange
;({ open, onChange } = useBind({ $open, open, onChange }))

let [fixedLayout, $fixedLayout] = useValue(isFixedLayout(fixedLayoutBreakpoint))
const [fixedLayout, $fixedLayout] = useValue(isFixedLayout(fixedLayoutBreakpoint))

useLayoutEffect(() => {
if (!fixedLayout) return
Expand Down Expand Up @@ -73,7 +73,7 @@ function SmartSidebar ({
const listener = Dimensions.addEventListener('change', handleWidthChange)
return () => {
// removeEventListener has been removed from rn 0.70.4
if (listener && !Dimensions.removeEventListener) {
if (listener) {
listener.remove()
} else {
Dimensions.removeEventListener('change', handleWidthChange)
Expand Down Expand Up @@ -135,6 +135,6 @@ SmartSidebar.propTypes = {
export default observer(themed('SmartSidebar', SmartSidebar))

function isFixedLayout (fixedLayoutBreakpoint) {
let dim = Dimensions.get('window')
const dim = Dimensions.get('window')
return dim.width > fixedLayoutBreakpoint
}
2 changes: 1 addition & 1 deletion packages/ui/components/popups/Dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function Dropdown ({
return () => {
$isShow.del()
// removeEventListener has been removed from rn 0.70.4
if (listener && !Dimensions.removeEventListener) {
if (listener) {
listener.remove()
} else {
Dimensions.removeEventListener('change', handleWidthChange)
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/components/popups/Popover/Deprecated/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function Popover ({
return () => {
mounted = false
// removeEventListener has been removed from rn 0.70.4
if (listener && !Dimensions.removeEventListener) {
if (listener) {
listener.remove()
} else {
Dimensions.removeEventListener('change', handleDimensions)
Expand Down Expand Up @@ -197,7 +197,7 @@ function Popover ({

// parse children
let caption = null
let content = []
const content = []
const onLayoutCaption = e => {
captionInfo.current = e.nativeEvent.layout
}
Expand Down
1 change: 0 additions & 1 deletion packages/ui/hooks/useMedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,5 @@ function updateMediaFlags ({ window }) {

function listenForMediaUpdates () {
updateMediaFlags({ window: Dimensions.get('window') })
// todo: что на счет удаления слушателя?
Dimensions.addEventListener('change', debouncedUpdateMedia)
}
Loading

0 comments on commit 5002417

Please sign in to comment.