@lookiero/checkout 0.2.27-beta.7 → 0.2.27-beta.9

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.
@@ -3,6 +3,7 @@ import { StyleProp, TextInputProps, TextStyle } from "react-native";
3
3
  declare type InputStyle = StyleProp<TextStyle>;
4
4
  interface InputProps extends TextInputProps {
5
5
  readonly minHeight?: number;
6
+ readonly maxHeight?: number;
6
7
  readonly style?: InputStyle;
7
8
  }
8
9
  declare const Input: FC<InputProps>;
@@ -1,29 +1,36 @@
1
- import React, { useCallback, useState } from "react";
1
+ import React, { useCallback, useLayoutEffect, useRef, useState } from "react";
2
2
  import { Platform, TextInput, } from "react-native";
3
3
  import { theme } from "../../../../theme/theme";
4
- import { style } from "./Input.style";
5
- const DEFAULT_HEIGHT = 56;
4
+ import { style, borderSize, paddingVertical } from "./Input.style";
5
+ const MIN_HEIGHT = 56;
6
+ const MAX_HEIGHT = 242; // 10 lines
6
7
  const { colorGrayscaleL } = theme();
7
- const Input = ({ minHeight = DEFAULT_HEIGHT, style: customStyle, placeholderTextColor = colorGrayscaleL, onChange, onContentSizeChange, ...restOfProps }) => {
8
+ const clamp = (min, max, value) => Math.min(Math.max(min, value), max);
9
+ const Input = ({ minHeight = MIN_HEIGHT, maxHeight = MAX_HEIGHT, style: customStyle, placeholderTextColor = colorGrayscaleL, onChange, onContentSizeChange, value, ...restOfProps }) => {
8
10
  const [height, setHeight] = useState(minHeight);
9
11
  // When content height has became smaller the onContentSizeChange does in fact triggered but the internal height is incorrect.
10
12
  const handleOnContentSizeChange = useCallback((event) => {
11
13
  onContentSizeChange?.(event);
12
- if (Platform.OS === "web")
14
+ if (Platform.OS === "web") {
13
15
  return;
14
- setHeight(Math.max(minHeight, event.nativeEvent.contentSize.height));
15
- }, [minHeight, onContentSizeChange]);
16
- // It's just update textarea height based on el.scrollHeight
17
- const handleOnChange = useCallback((event) => {
18
- onChange?.(event);
19
- if (Platform.OS !== "web")
16
+ }
17
+ setHeight(clamp(minHeight, maxHeight, event.nativeEvent.contentSize.height + borderSize * 2 + paddingVertical * 2));
18
+ }, [maxHeight, minHeight, onContentSizeChange]);
19
+ const handleOnContentSizeChangeWeb = useCallback(() => {
20
+ if (Platform.OS !== "web") {
20
21
  return;
22
+ }
21
23
  window.requestAnimationFrame(() => {
22
- const element = event.nativeEvent.target;
24
+ const element = textInputRef.current;
25
+ if (!element) {
26
+ return;
27
+ }
23
28
  element.style.height = "0px";
24
- element.style.height = `${Math.max(minHeight, element.scrollHeight)}px`;
29
+ element.style.height = `${clamp(minHeight, maxHeight, element.scrollHeight + borderSize * 2)}px`;
25
30
  });
26
- }, [minHeight, onChange]);
27
- return (React.createElement(TextInput, { ...restOfProps, placeholderTextColor: placeholderTextColor, style: [style.input, customStyle, { height }], testID: "input", textAlignVertical: "top", onChange: handleOnChange, onContentSizeChange: handleOnContentSizeChange }));
31
+ }, [maxHeight, minHeight]);
32
+ useLayoutEffect(handleOnContentSizeChangeWeb, [handleOnContentSizeChangeWeb, value]);
33
+ const textInputRef = useRef(null);
34
+ return (React.createElement(TextInput, { ...restOfProps, ref: textInputRef, placeholderTextColor: placeholderTextColor, style: [style.input, customStyle, { height }], testID: "input", textAlignVertical: "top", value: value, onChange: onChange, onContentSizeChange: handleOnContentSizeChange }));
28
35
  };
29
36
  export { Input };
@@ -1,3 +1,4 @@
1
+ declare const borderSize: number;
1
2
  declare const style: {
2
3
  input: {
3
4
  lineHeight?: number | undefined;
@@ -7,7 +8,6 @@ declare const style: {
7
8
  fontSize: number;
8
9
  letterSpacing: number;
9
10
  outlineStyle: string;
10
- overflow: "hidden";
11
11
  paddingBottom: number;
12
12
  paddingHorizontal: number;
13
13
  paddingTop: number;
@@ -15,4 +15,5 @@ declare const style: {
15
15
  whiteSpace: string;
16
16
  };
17
17
  };
18
- export { style };
18
+ declare const paddingVertical: number;
19
+ export { style, borderSize, paddingVertical };
@@ -10,7 +10,6 @@ const style = StyleSheet.create({
10
10
  fontSize: fontBodySize3,
11
11
  letterSpacing: fontBodyLetterSpacing3,
12
12
  outlineStyle: "none",
13
- overflow: "hidden",
14
13
  paddingBottom: spaceM,
15
14
  paddingHorizontal: spaceM,
16
15
  paddingTop: spaceM,
@@ -23,4 +22,5 @@ const style = StyleSheet.create({
23
22
  }),
24
23
  },
25
24
  });
26
- export { style };
25
+ const paddingVertical = spaceM;
26
+ export { style, borderSize, paddingVertical };
@@ -13,7 +13,7 @@ const { spaceXXL } = theme();
13
13
  const TRANSITION_MODAL_SCALE = 0.9;
14
14
  const DEFAULT_SAFEAREA_INSET_TOP = spaceXXL;
15
15
  const Modal = ({ children, visible, header, portalHostName, onClose, showCloseButton = false, size = { M: "2/3", L: "1/3" }, style: customStyle, scroll = false, }) => {
16
- const { height: screenHeight } = Dimensions.get("screen");
16
+ const { height: screenHeight } = Dimensions.get(Platform.OS === "web" ? "window" : "screen");
17
17
  const { top: safeAreaInsetTop, bottom: safeAreaInsetBottom } = useSafeAreaInsets();
18
18
  // On Android safeAreaInsetTop won't return the actual value.
19
19
  const screenSizeWithoutInsets = screenHeight - (Platform.OS === "android" ? DEFAULT_SAFEAREA_INSET_TOP : safeAreaInsetTop);
@@ -19,7 +19,7 @@ const InputField = ({ label, placeholder, value, multiline = false, minHeight, e
19
19
  field: [style.field, customStyle?.field],
20
20
  fieldText: [{ color }, customStyle?.fieldText],
21
21
  } }),
22
- React.createElement(Input, { minHeight: minHeight, multiline: multiline, placeholder: placeholder, placeholderTextColor: isFocused ? colorGrayscaleL : colorBase, style: [!!icon ? { paddingRight: inputPaddingRightWithIcon } : {}, { borderColor: color }, customStyle?.input], value: value, onBlur: handleOnBlur, onChangeText: handleOnChange, onFocus: handleOnFocus, ...inputRestProps }),
22
+ React.createElement(Input, { minHeight: minHeight, multiline: multiline, placeholder: placeholder, placeholderTextColor: isFocused ? colorGrayscaleL : colorBase, style: [!!icon && { paddingRight: inputPaddingRightWithIcon }, { borderColor: color }, customStyle?.input], value: value, onBlur: handleOnBlur, onChangeText: handleOnChange, onFocus: handleOnFocus, ...inputRestProps }),
23
23
  !!icon && React.createElement(Icon, { name: icon, style: [style.icon, { color }, customStyle?.icon] }),
24
24
  !!error && React.createElement(Error, { error: error, style: [style.error, customStyle?.error] })));
25
25
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "0.2.27-beta.7",
3
+ "version": "0.2.27-beta.9",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -25,8 +25,8 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@gorhom/portal": "^1.0.14",
28
- "@lookiero/i18n": "^0.8.0",
29
- "@lookiero/i18n-react": "^0.8.0-beta.0",
28
+ "@lookiero/i18n": "^0.8.1",
29
+ "@lookiero/i18n-react": "^0.8.1",
30
30
  "@lookiero/messaging": "^8.0.0",
31
31
  "@lookiero/messaging-react": "^8.0.0",
32
32
  "@react-spring/native": "^9.5.5",