@jobber/components-native 0.95.2-JOB-141866-cab4e3f.3 → 0.95.2-JOB-141866-acfcddc.7

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.95.2-JOB-141866-cab4e3f.3+cab4e3feb",
3
+ "version": "0.95.2-JOB-141866-acfcddc.7+acfcddc57",
4
4
  "license": "MIT",
5
5
  "description": "React Native implementation of Atlantis",
6
6
  "repository": {
@@ -96,5 +96,5 @@
96
96
  "react-native-safe-area-context": "^5.4.0",
97
97
  "react-native-svg": ">=12.0.0"
98
98
  },
99
- "gitHead": "cab4e3febe1c59269f69b54e3b442122ac0a3cde"
99
+ "gitHead": "acfcddc57c91d179ef43e2ed44fd25bd3cae6405"
100
100
  }
@@ -2,11 +2,10 @@ import React, { forwardRef, useCallback, useImperativeHandle, useMemo, useRef, u
2
2
  import { useSafeAreaInsets } from "react-native-safe-area-context";
3
3
  import { AccessibilityInfo, Platform, View, findNodeHandle, useWindowDimensions, } from "react-native";
4
4
  import { Portal } from "react-native-portalize";
5
- import { useKeyboardVisibility } from "./hooks/useKeyboardVisibility";
6
5
  import { useStyles } from "./ContentOverlay.style";
7
6
  import { useViewLayoutHeight } from "./hooks/useViewLayoutHeight";
8
7
  import { UNSAFE_WrappedModalize } from "./UNSAFE_WrappedModalize";
9
- import { useIsScreenReaderEnabled } from "../hooks";
8
+ import { useIsScreenReaderEnabled, useKeyboardVisibility } from "../hooks";
10
9
  import { IconButton } from "../IconButton";
11
10
  import { Heading } from "../Heading";
12
11
  import { useAtlantisI18n } from "../hooks/useAtlantisI18n";
@@ -39,7 +39,7 @@ import { FormSaveButton } from "./components/FormSaveButton";
39
39
  import { useSaveButtonPosition } from "./hooks/useSaveButtonPosition";
40
40
  import { FormCache } from "./components/FormCache/FormCache";
41
41
  import { useAtlantisFormContext } from "./context/AtlantisFormContext";
42
- import { InputAccessoriesProvider } from "../InputText";
42
+ import { InputAccessoriesProvider, useInputAccessoriesContext, } from "../InputText";
43
43
  import { tokens } from "../utils/design";
44
44
  import { ErrorMessageProvider } from "../ErrorMessageWrapper";
45
45
  export function Form(_a) {
@@ -54,6 +54,7 @@ function InternalForm({ children, onBeforeSubmit, onSubmit, onSubmitError, onSub
54
54
  const { scrollViewRef, bottomViewRef, scrollToTop } = useFormViewRefs();
55
55
  const [saveButtonHeight, setSaveButtonHeight] = useState(0);
56
56
  const [messageBannerHeight, setMessageBannerHeight] = useState(0);
57
+ const { setIsScrolling } = useInputAccessoriesContext();
57
58
  const { formMethods, handleSubmit, isSubmitting, removeListenerRef, setLocalCache, } = useInternalForm({
58
59
  mode,
59
60
  reValidateMode,
@@ -92,18 +93,14 @@ function InternalForm({ children, onBeforeSubmit, onSubmit, onSubmitError, onSub
92
93
  const handleOfflineSubmit = useOfflineHandler();
93
94
  const keyboardProps = Platform.select({
94
95
  ios: {
95
- onKeyboardDidHide: handleKeyboardHide,
96
- onKeyboardDidShow: handleKeyboardShow,
97
- onKeyboardDidChangeFrame: handleKeyboardDidChangeFrame,
96
+ onKeyboardWillHide: handleKeyboardHide,
97
+ onKeyboardWillShow: handleKeyboardShow,
98
98
  },
99
99
  android: {
100
100
  onKeyboardDidHide: handleKeyboardHide,
101
101
  onKeyboardDidShow: handleKeyboardShow,
102
102
  },
103
103
  });
104
- const onLayout = (event) => {
105
- setMessageBannerHeight(event.nativeEvent.layout.height);
106
- };
107
104
  const styles = useStyles();
108
105
  const { edgeToEdgeEnabled } = useAtlantisFormContext();
109
106
  return (React.createElement(FormProvider, Object.assign({}, formMethods),
@@ -111,11 +108,17 @@ function InternalForm({ children, onBeforeSubmit, onSubmit, onSubmitError, onSub
111
108
  (isSubmitting || isSecondaryActionLoading) && React.createElement(FormMask, null),
112
109
  React.createElement(FormCache, { localCacheKey: localCacheKey, localCacheExclude: localCacheExclude, setLocalCache: setLocalCache }),
113
110
  React.createElement(FormBody, { keyboardHeight: calculateSaveButtonOffset(), submit: handleSubmit(internalSubmit), isFormSubmitting: isSubmitting, saveButtonLabel: saveButtonLabel, shouldRenderActionBar: saveButtonPosition === "sticky", renderStickySection: renderStickySection, secondaryActions: secondaryActions, setSecondaryActionLoading: setIsSecondaryActionLoading, setSaveButtonHeight: setSaveButtonHeight, saveButtonOffset: saveButtonOffset },
114
- React.createElement(KeyboardAwareScrollView, Object.assign({ enableResetScrollToCoords: false, enableAutomaticScroll: true, enableOnAndroid: edgeToEdgeEnabled, keyboardOpeningTime: Platform.OS === "ios" ? tokens["timing-slowest"] : 0, keyboardShouldPersistTaps: "handled", ref: scrollViewRef }, keyboardProps, { extraHeight: headerHeight, extraScrollHeight: edgeToEdgeEnabled ? tokens["space-large"] : 0, contentContainerStyle: !keyboardHeight && styles.scrollContentContainer }),
111
+ React.createElement(KeyboardAwareScrollView, Object.assign({ enableResetScrollToCoords: false, enableAutomaticScroll: true, enableOnAndroid: edgeToEdgeEnabled, keyboardOpeningTime: Platform.OS === "ios" ? tokens["timing-slowest"] : 0, keyboardShouldPersistTaps: "handled", ref: scrollViewRef }, keyboardProps, { extraHeight: headerHeight, extraScrollHeight: edgeToEdgeEnabled ? tokens["space-large"] : 0, contentContainerStyle: !keyboardHeight && styles.scrollContentContainer, onScrollBeginDrag: () => {
112
+ setIsScrolling(true);
113
+ }, onScrollEndDrag: () => {
114
+ setIsScrolling(false);
115
+ } }),
115
116
  React.createElement(View, { onLayout: ({ nativeEvent }) => {
116
117
  setFormContentHeight(nativeEvent.layout.height);
117
118
  } },
118
- React.createElement(View, { onLayout: onLayout },
119
+ React.createElement(View, { onLayout: ({ nativeEvent }) => {
120
+ setMessageBannerHeight(nativeEvent.layout.height);
121
+ } },
119
122
  React.createElement(FormMessageBanner, { bannerMessages: bannerMessages }),
120
123
  React.createElement(FormErrorBanner, { networkError: bannerErrors === null || bannerErrors === void 0 ? void 0 : bannerErrors.networkError, bannerError: bannerErrors === null || bannerErrors === void 0 ? void 0 : bannerErrors.bannerError })),
121
124
  React.createElement(View, { style: styles.formChildContainer },
@@ -126,19 +129,6 @@ function InternalForm({ children, onBeforeSubmit, onSubmit, onSubmitError, onSub
126
129
  React.createElement(View, { style: styles.safeArea, ref: bottomViewRef })))),
127
130
  React.createElement(FormMessage, null)));
128
131
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
129
- function handleKeyboardDidChangeFrame(frames) {
130
- if (frames &&
131
- "endCoordinates" in frames &&
132
- "height" in frames.endCoordinates &&
133
- typeof frames.endCoordinates.height === "number" &&
134
- frames.endCoordinates.height > keyboardHeight) {
135
- handleKeyboardShow(frames);
136
- }
137
- else {
138
- handleKeyboardHide();
139
- }
140
- }
141
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
142
132
  function handleKeyboardShow(frames) {
143
133
  setKeyboardScreenY(frames.endCoordinates.screenY);
144
134
  setKeyboardHeight(frames.endCoordinates.height);
@@ -7,6 +7,14 @@ import { useInputAccessoriesContext } from "./context";
7
7
  import { useFormController } from "../hooks";
8
8
  import { InputFieldWrapper } from "../InputFieldWrapper";
9
9
  import { useCommonInputStyles } from "../InputFieldWrapper/CommonInputStyles.style";
10
+ import { useScreenInformation } from "../Form/hooks/useScreenInformation";
11
+ /**
12
+ * Buffer zone in pixels for offscreen detection.
13
+ * This makes the detection more sensitive by marking the component as offscreen
14
+ * even if it's technically still visible but within this buffer distance from the edge.
15
+ */
16
+ // 44 (accessory bar height) + 20 (buffer)
17
+ const KEYBOARD_AWARE_DETECTION_BUFFER = 64;
10
18
  export const InputText = forwardRef(InputTextInternal);
11
19
  // eslint-disable-next-line max-statements
12
20
  function InputTextInternal({ invalid, disabled, readonly = false, name, placeholder, assistiveText, showMiniLabel = true, keyboard, value: controlledValue, defaultValue, autoFocus, autoComplete = "off", spellCheck, textContentType = "none", validations, onChangeText, onSubmitEditing, onFocus, accessibilityLabel, accessibilityHint, autoCorrect, autoCapitalize, onBlur, multiline = false, prefix, suffix, transform = {}, clearable = multiline ? "never" : "while-editing", testID, secureTextEntry, styleOverride, toolbar, toolbarVisibility, loading, loadingType, }, ref) {
@@ -40,7 +48,7 @@ function InputTextInternal({ invalid, disabled, readonly = false, name, placehol
40
48
  placeholderTextColor: "transparent",
41
49
  }));
42
50
  const _name = name !== null && name !== void 0 ? name : field.name;
43
- const { inputAccessoryID, register, unregister, setFocusedInput, canFocusNext, onFocusNext, } = useInputAccessoriesContext();
51
+ const { inputAccessoryID, register, unregister, setFocusedInput, canFocusNext, onFocusNext, isScrolling, } = useInputAccessoriesContext();
44
52
  useEffect(() => {
45
53
  _name &&
46
54
  register(_name, () => {
@@ -75,8 +83,23 @@ function InputTextInternal({ invalid, disabled, readonly = false, name, placehol
75
83
  }
76
84
  const styles = useStyles();
77
85
  const commonInputStyles = useCommonInputStyles();
86
+ const { headerHeight, windowHeight } = useScreenInformation();
87
+ // State to track if the InputText component can fully fit on screen
88
+ // (i.e., it's completely visible). Use this state to handle visibility issues.
89
+ const [canFullyFitOnScreen, setCanFullyFitOnScreen] = useState(true);
78
90
  return (React.createElement(InputFieldWrapper, { prefix: prefix, suffix: suffix, hasValue: hasValue, placeholderMode: placeholderMode, assistiveText: assistiveText, focused: focused, error: error, invalid: invalid, placeholder: placeholder, disabled: disabled, onClear: handleClear, showClearAction: showClear, styleOverride: styleOverride, toolbar: toolbar, toolbarVisibility: toolbarVisibility, loading: loading, loadingType: loadingType },
79
- React.createElement(TextInput, Object.assign({ inputAccessoryViewID: inputAccessoryID || undefined, testID: testID, autoCapitalize: autoCapitalize, autoCorrect: autoCorrect, spellCheck: spellCheck, style: [
91
+ React.createElement(TextInput, Object.assign({ onLayout: (event) => {
92
+ var _a;
93
+ (_a = event.target) === null || _a === void 0 ? void 0 : _a.measureInWindow((_, y, __, height) => {
94
+ // Check if component can't fully fit on screen (height only)
95
+ // Account for headerHeight at the top of the screen and buffer zone
96
+ const visibleTop = headerHeight + KEYBOARD_AWARE_DETECTION_BUFFER; // Top of visible area (below header) with buffer
97
+ const visibleBottom = windowHeight - KEYBOARD_AWARE_DETECTION_BUFFER; // Bottom of visible area with buffer
98
+ const isOffScreen = y < visibleTop || // Top edge is behind or above the header (with buffer)
99
+ y + height > visibleBottom; // Bottom edge is below the window (with buffer)
100
+ setCanFullyFitOnScreen(!isOffScreen);
101
+ });
102
+ }, inputAccessoryViewID: inputAccessoryID || undefined, testID: testID, autoCapitalize: autoCapitalize, autoCorrect: autoCorrect, spellCheck: spellCheck, style: [
80
103
  commonInputStyles.input,
81
104
  styles.inputPaddingTop,
82
105
  !miniLabelActive && commonInputStyles.inputEmpty,
@@ -89,7 +112,17 @@ function InputTextInternal({ invalid, disabled, readonly = false, name, placehol
89
112
  styles.multilineWithoutMiniLabel,
90
113
  styleOverride === null || styleOverride === void 0 ? void 0 : styleOverride.inputText,
91
114
  loading && loadingType === "glimmer" && { color: "transparent" },
92
- ], readOnly: readonly, editable: !disabled, keyboardType: keyboard, value: inputTransform(internalValue), autoFocus: autoFocus, autoComplete: autoComplete, multiline: multiline, scrollEnabled: false, textContentType: textContentType, onChangeText: handleChangeText, onSubmitEditing: handleOnSubmitEditing, returnKeyType: returnKeyType, blurOnSubmit: shouldBlurOnSubmit, accessibilityLabel: accessibilityLabel || placeholder, accessibilityHint: accessibilityHint, accessibilityState: { busy: loading }, secureTextEntry: secureTextEntry }, androidA11yProps, { onFocus: event => {
115
+ ],
116
+ // Prevent focus during scroll for multiline inputs to avoid
117
+ // the input focusing when the user is trying to scroll the form
118
+ readOnly: readonly || (multiline && isScrolling && !focused),
119
+ // readOnly={readonly}
120
+ editable: !disabled, keyboardType: keyboard, value: inputTransform(internalValue), autoFocus: autoFocus, autoComplete: autoComplete, multiline: multiline,
121
+ // Makes sure it doesn't jump to the top of the screen when the keyboard is shown and a new line is added.
122
+ // State for tracking if the input should be scrollable.
123
+ // This is tech debt related to an issue where keyboard aware scrollview doesn't work if `scrollEnabled` is true. However,
124
+ // when `scrollEnabled` is false it causes an issue where super long text inputs will jump to the top when a new line is added to the bottom of the input.
125
+ scrollEnabled: Platform.OS === "ios" && !canFullyFitOnScreen, textContentType: textContentType, onChangeText: handleChangeText, onSubmitEditing: handleOnSubmitEditing, returnKeyType: returnKeyType, blurOnSubmit: shouldBlurOnSubmit, accessibilityLabel: accessibilityLabel || placeholder, accessibilityHint: accessibilityHint, accessibilityState: { busy: loading }, secureTextEntry: secureTextEntry }, androidA11yProps, { onFocus: event => {
93
126
  _name && setFocusedInput(_name);
94
127
  setFocused(true);
95
128
  onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
@@ -10,6 +10,8 @@ const inputAccessoriesContextDefaultValues = {
10
10
  onFocusNext: () => undefined,
11
11
  onFocusPrevious: () => undefined,
12
12
  setFocusedInput: () => undefined,
13
+ isScrolling: false,
14
+ setIsScrolling: () => undefined,
13
15
  };
14
16
  export const InputAccessoriesContext = createContext(inputAccessoriesContextDefaultValues);
15
17
  export function useInputAccessoriesContext() {
@@ -5,7 +5,7 @@ import { InputAccessoriesContext } from "./InputAccessoriesContext";
5
5
  import { useStyles } from "./InputAccessoriesProvider.style";
6
6
  export function InputAccessoriesProvider({ children, }) {
7
7
  const inputAccessoryID = useRef(v4()).current;
8
- const { focusedInput, setFocusedInput, canFocusNext, canFocusPrevious, elements, setElements, previousKey, nextKey, } = useInputAccessoriesProviderState();
8
+ const { focusedInput, setFocusedInput, canFocusNext, canFocusPrevious, elements, setElements, previousKey, nextKey, isScrolling, setIsScrolling, } = useInputAccessoriesProviderState();
9
9
  const colorScheme = useColorScheme();
10
10
  const styles = useStyles();
11
11
  return (React.createElement(InputAccessoriesContext.Provider, { value: {
@@ -19,6 +19,8 @@ export function InputAccessoriesProvider({ children, }) {
19
19
  onFocusNext,
20
20
  onFocusPrevious,
21
21
  setFocusedInput,
22
+ isScrolling,
23
+ setIsScrolling,
22
24
  } },
23
25
  children,
24
26
  Platform.OS === "ios" && (React.createElement(InputAccessoryView, { nativeID: inputAccessoryID },
@@ -49,6 +51,7 @@ function useInputAccessoriesProviderState() {
49
51
  const [canFocusNext, setCanFocusNext] = useState(false);
50
52
  const [canFocusPrevious, setCanFocusPrevious] = useState(false);
51
53
  const [elements, setElements] = useState({});
54
+ const [isScrolling, setIsScrolling] = useState(false);
52
55
  const keys = Object.keys(elements);
53
56
  const selectedIndex = keys.findIndex(key => key === focusedInput);
54
57
  const nextKey = keys[selectedIndex + 1];
@@ -68,5 +71,7 @@ function useInputAccessoriesProviderState() {
68
71
  setCanFocusPrevious,
69
72
  elements,
70
73
  setElements,
74
+ isScrolling,
75
+ setIsScrolling,
71
76
  };
72
77
  }
@@ -1,2 +1,3 @@
1
1
  export * from "./useFormController";
2
2
  export * from "./useIsScreenReaderEnabled";
3
+ export * from "./useKeyboardVisibility";