-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## 📜 Description Starting from REA 3.15 a new API with `get`/`set` methods was added. In this PR I'm adding corresponding methods to mock. ## 💡 Motivation and Context If devs are using `get`/`set` methods in their code (which is recommended way right now), then tests will crash because `get`/`set` methods are `undefined`. To fix this problem I reflect corresponding changes from Reanimated and adding these methods. ## 📢 Changelog <!-- High level overview of important changes --> <!-- For example: fixed status bar manipulation; added new types declarations; --> <!-- If your changes don't affect one of platform/language below - then remove this platform/language --> ### JS - added `get`/`set` methods to mock; - added new unit tests with new API methods usage; ## 🤔 How Has This Been Tested? Tested via unit-tests. ## 📸 Screenshots (if appropriate): <img width="409" alt="image" src="https://github.com/user-attachments/assets/e9c6390d-be7d-464d-8130-2d5bfd1a80cc"> ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
- Loading branch information
1 parent
fb5c52e
commit 737e452
Showing
3 changed files
with
133 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import "@testing-library/jest-native/extend-expect"; | ||
import { render } from "@testing-library/react-native"; | ||
import React from "react"; | ||
import { | ||
useReanimatedFocusedInput, | ||
useReanimatedKeyboardAnimation, | ||
} from "react-native-keyboard-controller"; | ||
import Reanimated, { useAnimatedStyle } from "react-native-reanimated"; | ||
|
||
function TestKeyboardMovementComponent() { | ||
const { height } = useReanimatedKeyboardAnimation(); | ||
const style = useAnimatedStyle( | ||
() => ({ | ||
width: 20, | ||
height: 20, | ||
backgroundColor: "red", | ||
transform: [{ translateY: height.get() }], | ||
}), | ||
[], | ||
); | ||
|
||
return <Reanimated.View style={style} testID="view" />; | ||
} | ||
|
||
function TestFocusedInputLayoutComponent() { | ||
const { input } = useReanimatedFocusedInput(); | ||
const style = useAnimatedStyle(() => { | ||
const layout = input.get()?.layout; | ||
|
||
return { | ||
top: layout?.y, | ||
left: layout?.x, | ||
height: layout?.height, | ||
width: layout?.width, | ||
}; | ||
}, []); | ||
|
||
return <Reanimated.View style={style} testID="view" />; | ||
} | ||
|
||
describe("basic keyboard interaction", () => { | ||
it("should have default style with new reanimated API", () => { | ||
const { getByTestId } = render(<TestKeyboardMovementComponent />); | ||
|
||
expect(getByTestId("view")).toHaveStyle({ transform: [{ translateY: 0 }] }); | ||
}); | ||
|
||
it("should have default style with `useReanimatedFocusedInput` using new reanimated API", () => { | ||
const { getByTestId } = render(<TestFocusedInputLayoutComponent />); | ||
|
||
expect(getByTestId("view")).toHaveStyle({ | ||
top: 0, | ||
left: 0, | ||
width: 200, | ||
height: 40, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import "@testing-library/jest-native/extend-expect"; | ||
import { render } from "@testing-library/react-native"; | ||
import React from "react"; | ||
import { | ||
useReanimatedFocusedInput, | ||
useReanimatedKeyboardAnimation, | ||
} from "react-native-keyboard-controller"; | ||
import Reanimated, { useAnimatedStyle } from "react-native-reanimated"; | ||
|
||
function TestKeyboardMovementComponent() { | ||
const { height } = useReanimatedKeyboardAnimation(); | ||
const style = useAnimatedStyle( | ||
() => ({ | ||
width: 20, | ||
height: 20, | ||
backgroundColor: "red", | ||
transform: [{ translateY: height.get() }], | ||
}), | ||
[], | ||
); | ||
|
||
return <Reanimated.View style={style} testID="view" />; | ||
} | ||
|
||
function TestFocusedInputLayoutComponent() { | ||
const { input } = useReanimatedFocusedInput(); | ||
const style = useAnimatedStyle(() => { | ||
const layout = input.get()?.layout; | ||
|
||
return { | ||
top: layout?.y, | ||
left: layout?.x, | ||
height: layout?.height, | ||
width: layout?.width, | ||
}; | ||
}, []); | ||
|
||
return <Reanimated.View style={style} testID="view" />; | ||
} | ||
|
||
describe("basic keyboard interaction", () => { | ||
it("should have default style with new reanimated API", () => { | ||
const { getByTestId } = render(<TestKeyboardMovementComponent />); | ||
|
||
expect(getByTestId("view")).toHaveStyle({ transform: [{ translateY: 0 }] }); | ||
}); | ||
|
||
it("should have default style with `useReanimatedFocusedInput` using new reanimated API", () => { | ||
const { getByTestId } = render(<TestFocusedInputLayoutComponent />); | ||
|
||
expect(getByTestId("view")).toHaveStyle({ | ||
top: 0, | ||
left: 0, | ||
width: 200, | ||
height: 40, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters