Skip to content

Commit

Permalink
Remove stable references from onInsetsChange deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Noitidart committed Aug 29, 2023
1 parent 56b42f2 commit 3313cb9
Showing 1 changed file with 34 additions and 37 deletions.
71 changes: 34 additions & 37 deletions src/SafeAreaContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,43 +53,40 @@ export function SafeAreaProvider({
height: Dimensions.get('window').height,
},
);
const onInsetsChange = React.useCallback(
(event: InsetChangedEvent) => {
const {
nativeEvent: { frame: nextFrame, insets: nextInsets },
} = event;

setFrame((frame) => {
if (
// Backwards compat with old native code that won't send frame.
nextFrame &&
(nextFrame.height !== frame.height ||
nextFrame.width !== frame.width ||
nextFrame.x !== frame.x ||
nextFrame.y !== frame.y)
) {
return nextFrame;
} else {
return frame;
}
});

setInsets((insets) => {
if (
!insets ||
nextInsets.bottom !== insets.bottom ||
nextInsets.left !== insets.left ||
nextInsets.right !== insets.right ||
nextInsets.top !== insets.top
) {
return nextInsets;
} else {
return insets;
}
});
},
[setFrame, setInsets],
);
const onInsetsChange = React.useCallback((event: InsetChangedEvent) => {
const {
nativeEvent: { frame: nextFrame, insets: nextInsets },
} = event;

setFrame((frame) => {

Check warning on line 61 in src/SafeAreaContext.tsx

View workflow job for this annotation

GitHub Actions / js-tests

'frame' is already declared in the upper scope on line 46 column 10
if (
// Backwards compat with old native code that won't send frame.
nextFrame &&
(nextFrame.height !== frame.height ||
nextFrame.width !== frame.width ||
nextFrame.x !== frame.x ||
nextFrame.y !== frame.y)
) {
return nextFrame;
} else {
return frame;
}
});

setInsets((insets) => {

Check warning on line 76 in src/SafeAreaContext.tsx

View workflow job for this annotation

GitHub Actions / js-tests

'insets' is already declared in the upper scope on line 43 column 10
if (
!insets ||
nextInsets.bottom !== insets.bottom ||
nextInsets.left !== insets.left ||
nextInsets.right !== insets.right ||
nextInsets.top !== insets.top
) {
return nextInsets;
} else {
return insets;
}
});
}, []);

return (
<NativeSafeAreaProvider
Expand Down

0 comments on commit 3313cb9

Please sign in to comment.