diff --git a/FabricExample/__tests__/reanimated-new-api.spec.tsx b/FabricExample/__tests__/reanimated-new-api.spec.tsx new file mode 100644 index 000000000..9b5aa7903 --- /dev/null +++ b/FabricExample/__tests__/reanimated-new-api.spec.tsx @@ -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 ; +} + +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 ; +} + +describe("basic keyboard interaction", () => { + it("should have default style with new reanimated API", () => { + const { getByTestId } = render(); + + expect(getByTestId("view")).toHaveStyle({ transform: [{ translateY: 0 }] }); + }); + + it("should have default style with `useReanimatedFocusedInput` using new reanimated API", () => { + const { getByTestId } = render(); + + expect(getByTestId("view")).toHaveStyle({ + top: 0, + left: 0, + width: 200, + height: 40, + }); + }); +}); diff --git a/example/__tests__/reanimated-new-api.spec.tsx b/example/__tests__/reanimated-new-api.spec.tsx new file mode 100644 index 000000000..9b5aa7903 --- /dev/null +++ b/example/__tests__/reanimated-new-api.spec.tsx @@ -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 ; +} + +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 ; +} + +describe("basic keyboard interaction", () => { + it("should have default style with new reanimated API", () => { + const { getByTestId } = render(); + + expect(getByTestId("view")).toHaveStyle({ transform: [{ translateY: 0 }] }); + }); + + it("should have default style with `useReanimatedFocusedInput` using new reanimated API", () => { + const { getByTestId } = render(); + + expect(getByTestId("view")).toHaveStyle({ + top: 0, + left: 0, + width: 200, + height: 40, + }); + }); +}); diff --git a/jest/index.js b/jest/index.js index 55da80c89..724fa0fc9 100644 --- a/jest/index.js +++ b/jest/index.js @@ -6,24 +6,27 @@ const values = { height: new Animated.Value(0), }, reanimated: { - progress: { value: 0 }, - height: { value: 0 }, + progress: { value: 0, get: jest.fn().mockReturnValue(0), set: jest.fn() }, + height: { value: 0, get: jest.fn().mockReturnValue(0), set: jest.fn() }, + }, +}; +const inputData = { + target: 1, + parentScrollViewTarget: -1, + layout: { + x: 0, + y: 0, + width: 200, + height: 40, + absoluteX: 0, + absoluteY: 100, }, }; const focusedInput = { input: { - value: { - target: 1, - parentScrollViewTarget: -1, - layout: { - x: 0, - y: 0, - width: 200, - height: 40, - absoluteX: 0, - absoluteY: 100, - }, - }, + value: inputData, + get: jest.fn().mockReturnValue(inputData), + set: jest.fn(), }, };