Skip to content

Commit 2273707

Browse files
Fix ESLint plugin and respond to height
1 parent cbaa9c5 commit 2273707

File tree

4 files changed

+181
-77
lines changed

4 files changed

+181
-77
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@
6666
"@types/jest": "^27.0.2",
6767
"@types/react": "^17.0.32",
6868
"@types/react-native": "0.66.0",
69+
"@typescript-eslint/eslint-plugin": "^5.2.0",
6970
"commitlint": "^13.2.1",
70-
"eslint": "^8.1.0",
71-
"eslint-config-prettier": "^8.3.0",
71+
"eslint": "^7.0.0",
72+
"eslint-config-prettier": "^7.0.0",
7273
"eslint-plugin-prettier": "^4.0.0",
7374
"husky": "^7.0.4",
7475
"jest": "^27.3.1",

src/__tests__/BottomSheet.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ describe('BottomSheet', () => {
174174
await waitFor(() => expect(onCloseFinish).toHaveBeenCalledTimes(1));
175175
});
176176

177-
it('should respond to height changes', () => {
177+
it('should respond to height changes', async () => {
178178
const ref = createRef<BottomSheetRef>();
179179
const { getByTestId, rerender } = render(
180180
<BottomSheet ref={ref} height={400}>
@@ -185,7 +185,7 @@ describe('BottomSheet', () => {
185185
ref.current?.show();
186186
});
187187

188-
expect(getByTestId('animated-view')).toHaveStyle({ height: 400 });
188+
await waitFor(() => expect(getByTestId('animated-view')).toHaveStyle({ height: 400 }));
189189

190190
rerender(
191191
<BottomSheet ref={ref} height={600}>

src/features/BottomSheet/BottomSheet.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,17 @@ export const BottomSheet = memo(
125125
})
126126
).current;
127127

128-
// If `height` prop changes, respond and change to new height immediately
128+
// If `height` prop changes while open, respond and change to new height immediately
129129
useEffect(() => {
130-
Animated.timing(animatedHeight, {
131-
toValue: height,
132-
duration: 0,
133-
useNativeDriver: false
134-
}).start();
135-
}, [height]);
130+
if (visible) {
131+
Animated.timing(animatedHeight, {
132+
toValue: height,
133+
duration: 0,
134+
useNativeDriver: false
135+
}).start();
136+
}
137+
// eslint-disable-next-line react-hooks/exhaustive-deps
138+
}, [height]); // we only want the useEffect to run when height prop changes
136139

137140
// Expose specific methods on hook
138141
useImperativeHandle(ref, () => ({

0 commit comments

Comments
 (0)