@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.
@@ -27,7 +27,6 @@ Pod::Spec.new do |s|
27
27
  "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
28
28
  }
29
29
  s.dependency "React-Codegen"
30
- s.dependency "RCT-Folly"
31
30
  s.dependency "RCTRequired"
32
31
  s.dependency "RCTTypeSafety"
33
32
  s.dependency "ReactCommon/turbomodule/core"
package/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
  }
@@ -1,6 +1,7 @@
1
1
  import React, { type ReactElement } from "react";
2
2
  import { act, fireEvent, render, waitFor } from "@testing-library/react-native";
3
3
  import { Alert, Keyboard } from "react-native";
4
+ import { KeyboardEvents } from "react-native-keyboard-controller";
4
5
  import type { FormBannerMessage } from ".";
5
6
  import { Form, FormBannerMessageType } from ".";
6
7
  import type { FormBannerErrors } from "./types";
@@ -32,15 +33,37 @@ const onChangeSelectMock = jest.fn();
32
33
  const onChangeSwitchMock = jest.fn();
33
34
 
34
35
  const mockScrollTo = jest.fn();
36
+ const mockScrollToEnd = jest.fn();
35
37
  const mockScrollToTop = jest.fn();
38
+ const mockMeasureInWindow = jest.fn(
39
+ (callback: (x: number, y: number, width: number, height: number) => void) => {
40
+ callback(0, 0, 0, 0);
41
+ },
42
+ );
43
+ const mockScrollViewRef = {
44
+ get current() {
45
+ return { scrollTo: mockScrollTo, scrollToEnd: mockScrollToEnd };
46
+ },
47
+ // React assigns the ref while rendering KeyboardAwareScrollView. Keep the
48
+ // test double available to the keyboard-hide callback instead.
49
+ set current(value: unknown) {
50
+ void value;
51
+ },
52
+ };
53
+ const mockBottomViewRef = {
54
+ get current() {
55
+ return { measureInWindow: mockMeasureInWindow };
56
+ },
57
+ set current(value: unknown) {
58
+ void value;
59
+ },
60
+ };
36
61
 
37
62
  jest.mock("./hooks/useFormViewRefs", () => ({
38
63
  useFormViewRefs: () => {
39
64
  return {
40
- scrollViewRef: {
41
- current: { scrollTo: mockScrollTo },
42
- },
43
- bottomViewRef: { current: {} },
65
+ scrollViewRef: mockScrollViewRef,
66
+ bottomViewRef: mockBottomViewRef,
44
67
  scrollToTop: mockScrollToTop,
45
68
  };
46
69
  },
@@ -566,6 +589,40 @@ describe("Form", () => {
566
589
  });
567
590
  });
568
591
 
592
+ describe("Keyboard dismissal", () => {
593
+ it("does not imperatively scroll the form to its end", async () => {
594
+ const listeners = new Map<string, () => void>();
595
+ const addListener = KeyboardEvents.addListener as jest.Mock;
596
+
597
+ const registerListener = (eventName: string, listener: () => void) => {
598
+ listeners.set(eventName, listener);
599
+
600
+ return { remove: jest.fn() };
601
+ };
602
+ addListener
603
+ .mockImplementationOnce(registerListener)
604
+ .mockImplementationOnce(registerListener);
605
+
606
+ render(<FormTest onSubmit={onSubmitMock} />);
607
+
608
+ const hideListener = [...listeners.entries()].find(([eventName]) =>
609
+ eventName.endsWith("Hide"),
610
+ )?.[1];
611
+
612
+ expect(hideListener).toBeDefined();
613
+
614
+ if (!hideListener) {
615
+ throw new Error("Expected a keyboard hide listener");
616
+ }
617
+
618
+ await act(async () => {
619
+ hideListener();
620
+ });
621
+
622
+ expect(mockScrollToEnd).not.toHaveBeenCalled();
623
+ });
624
+ });
625
+
569
626
  describe("Leaving the form", () => {
570
627
  let mockUseConfirmBeforeBack: jest.Mock;
571
628
  let mockRemoveLocalCache: jest.Mock;
package/src/Form/Form.tsx CHANGED
@@ -138,19 +138,9 @@ function InternalForm<T extends FieldValues, S>({
138
138
  );
139
139
 
140
140
  const handleKeyboardHide = useCallback(() => {
141
- bottomViewRef?.current?.measureInWindow(
142
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
143
- (_x: number, y: number, _width: number, _height: number) => {
144
- // This fixes extra whitespace below the form if it was scrolled down while the keyboard was open
145
- // i.e. a View below the form is higher than the bottom of the window
146
- if (y < windowHeight) {
147
- scrollViewRef?.current?.scrollToEnd();
148
- }
149
- },
150
- );
151
141
  setKeyboardHeight(0);
152
142
  setKeyboardScreenY(0);
153
- }, [bottomViewRef, scrollViewRef, windowHeight]);
143
+ }, []);
154
144
 
155
145
  useEffect(() => {
156
146
  const showEvent =