@jobber/components-native 0.113.2 → 0.113.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components-native",
3
- "version": "0.113.2",
3
+ "version": "0.113.3",
4
4
  "license": "MIT",
5
5
  "description": "React Native implementation of Atlantis",
6
6
  "repository": {
@@ -124,5 +124,5 @@
124
124
  "react-native-screens": ">=4.18.0",
125
125
  "react-native-svg": ">=12.0.0"
126
126
  },
127
- "gitHead": "106e281adc9a3b0e87e125e1a9f1c945ce2de3cd"
127
+ "gitHead": "895ad886700e1a7e11927702a0e5f49cb554c4e3"
128
128
  }
@@ -96,20 +96,9 @@ function InternalForm({ children, onBeforeSubmit, onSubmit, onSubmitError, onSub
96
96
  setKeyboardScreenY(windowHeight - event.height);
97
97
  }, [windowHeight]);
98
98
  const handleKeyboardHide = useCallback(() => {
99
- var _a;
100
- (_a = bottomViewRef === null || bottomViewRef === void 0 ? void 0 : bottomViewRef.current) === null || _a === void 0 ? void 0 : _a.measureInWindow(
101
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
102
- (_x, y, _width, _height) => {
103
- var _a;
104
- // This fixes extra whitespace below the form if it was scrolled down while the keyboard was open
105
- // i.e. a View below the form is higher than the bottom of the window
106
- if (y < windowHeight) {
107
- (_a = scrollViewRef === null || scrollViewRef === void 0 ? void 0 : scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollToEnd();
108
- }
109
- });
110
99
  setKeyboardHeight(0);
111
100
  setKeyboardScreenY(0);
112
- }, [bottomViewRef, scrollViewRef, windowHeight]);
101
+ }, []);
113
102
  useEffect(() => {
114
103
  const showEvent = Platform.OS === "ios" ? "keyboardWillShow" : "keyboardDidShow";
115
104
  const hideEvent = Platform.OS === "ios" ? "keyboardWillHide" : "keyboardDidHide";
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import React from "react";
11
11
  import { act, fireEvent, render, waitFor } from "@testing-library/react-native";
12
12
  import { Alert, Keyboard } from "react-native";
13
+ import { KeyboardEvents } from "react-native-keyboard-controller";
13
14
  import { Form, FormBannerMessageType } from ".";
14
15
  import { FormSubmitErrorType } from "./types";
15
16
  import { atlantisContextDefaultValues } from "../AtlantisContext";
@@ -35,14 +36,34 @@ const onChangeMock = jest.fn();
35
36
  const onChangeSelectMock = jest.fn();
36
37
  const onChangeSwitchMock = jest.fn();
37
38
  const mockScrollTo = jest.fn();
39
+ const mockScrollToEnd = jest.fn();
38
40
  const mockScrollToTop = jest.fn();
41
+ const mockMeasureInWindow = jest.fn((callback) => {
42
+ callback(0, 0, 0, 0);
43
+ });
44
+ const mockScrollViewRef = {
45
+ get current() {
46
+ return { scrollTo: mockScrollTo, scrollToEnd: mockScrollToEnd };
47
+ },
48
+ // React assigns the ref while rendering KeyboardAwareScrollView. Keep the
49
+ // test double available to the keyboard-hide callback instead.
50
+ set current(value) {
51
+ void value;
52
+ },
53
+ };
54
+ const mockBottomViewRef = {
55
+ get current() {
56
+ return { measureInWindow: mockMeasureInWindow };
57
+ },
58
+ set current(value) {
59
+ void value;
60
+ },
61
+ };
39
62
  jest.mock("./hooks/useFormViewRefs", () => ({
40
63
  useFormViewRefs: () => {
41
64
  return {
42
- scrollViewRef: {
43
- current: { scrollTo: mockScrollTo },
44
- },
45
- bottomViewRef: { current: {} },
65
+ scrollViewRef: mockScrollViewRef,
66
+ bottomViewRef: mockBottomViewRef,
46
67
  scrollToTop: mockScrollToTop,
47
68
  };
48
69
  },
@@ -321,6 +342,30 @@ describe("Form", () => {
321
342
  expect(queryByTestId("ATL-FormSafeArea")).toBeNull();
322
343
  });
323
344
  });
345
+ describe("Keyboard dismissal", () => {
346
+ it("does not imperatively scroll the form to its end", () => __awaiter(void 0, void 0, void 0, function* () {
347
+ var _a;
348
+ const listeners = new Map();
349
+ const addListener = KeyboardEvents.addListener;
350
+ const registerListener = (eventName, listener) => {
351
+ listeners.set(eventName, listener);
352
+ return { remove: jest.fn() };
353
+ };
354
+ addListener
355
+ .mockImplementationOnce(registerListener)
356
+ .mockImplementationOnce(registerListener);
357
+ render(React.createElement(FormTest, { onSubmit: onSubmitMock }));
358
+ const hideListener = (_a = [...listeners.entries()].find(([eventName]) => eventName.endsWith("Hide"))) === null || _a === void 0 ? void 0 : _a[1];
359
+ expect(hideListener).toBeDefined();
360
+ if (!hideListener) {
361
+ throw new Error("Expected a keyboard hide listener");
362
+ }
363
+ yield act(() => __awaiter(void 0, void 0, void 0, function* () {
364
+ hideListener();
365
+ }));
366
+ expect(mockScrollToEnd).not.toHaveBeenCalled();
367
+ }));
368
+ });
324
369
  describe("Leaving the form", () => {
325
370
  let mockUseConfirmBeforeBack;
326
371
  let mockRemoveLocalCache;