@janiscommerce/ui-native 1.13.0 → 1.13.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.
@@ -1,7 +1,6 @@
1
1
  import React from 'react';
2
2
  import { StyleSheet, Text as TextComponent, } from 'react-native';
3
3
  import { moderateScale, scaledForDevice } from '../../../scale';
4
- import { isDevEnv } from '../../../utils/index';
5
4
  const Text = ({ children, style, ...props }) => {
6
5
  if (!children) {
7
6
  return null;
@@ -13,10 +12,6 @@ const Text = ({ children, style, ...props }) => {
13
12
  fontFamily: 'Roboto',
14
13
  },
15
14
  });
16
- // istanbul ignore next
17
- if (isDevEnv()) {
18
- console.warn('This component is going to be deprecated soon.');
19
- }
20
15
  return (<TextComponent style={[styles.TextStyles, style]} {...props}>
21
16
  {children}
22
17
  </TextComponent>);
@@ -17,18 +17,11 @@ var InputType;
17
17
  InputType["amountTotal"] = "numeric";
18
18
  InputType["numeric"] = "numeric";
19
19
  })(InputType || (InputType = {}));
20
- const setRef = (ref, value) => {
21
- if (typeof ref === 'function') {
22
- ref(value);
23
- }
24
- else if (ref && 'current' in ref) {
25
- ref.current = value;
26
- }
27
- };
28
20
  const Input = forwardRef(({ style, type, variant = 'default', totalValue, onChangeText, ...props }, ref) => {
29
21
  const [value, setValue] = useState('');
30
22
  const isAmountTotalVariant = variant === 'amountTotal';
31
- const inputRef = useRef(null);
23
+ const internalRef = useRef(null);
24
+ const inputRef = ref ?? internalRef;
32
25
  if (isAmountTotalVariant && typeof totalValue !== 'number') {
33
26
  return null;
34
27
  }
@@ -52,10 +45,16 @@ const Input = forwardRef(({ style, type, variant = 'default', totalValue, onChan
52
45
  color: palette.primary.main,
53
46
  },
54
47
  });
55
- const changeTextCb = (text) => handleChangeText(text, setValue, variant, onChangeText);
48
+ const changeTextCb = (text) => {
49
+ const transformedText = handleChangeText(text, variant);
50
+ setValue(transformedText);
51
+ if (onChangeText) {
52
+ onChangeText(transformedText);
53
+ }
54
+ };
56
55
  const handlePress = () => {
57
56
  // istanbul ignore next
58
- if (inputRef.current) {
57
+ if (inputRef && 'current' in inputRef && inputRef.current) {
59
58
  Keyboard.dismiss();
60
59
  inputRef.current.focus();
61
60
  }
@@ -71,10 +70,7 @@ const Input = forwardRef(({ style, type, variant = 'default', totalValue, onChan
71
70
  })();
72
71
  return (<TouchableWithoutFeedback onPress={handlePress}>
73
72
  <View style={styles.container}>
74
- <BaseInput style={[styles.input, style]} ref={(instance) => {
75
- setRef(inputRef, instance);
76
- setRef(ref, instance);
77
- }} value={value} keyboardType={resolvedKeyboardType} onChangeText={changeTextCb} {...props}/>
73
+ <BaseInput style={[styles.input, style]} ref={inputRef} value={value} keyboardType={resolvedKeyboardType} onChangeText={changeTextCb} {...props}/>
78
74
  {isAmountTotalVariant && (<Typography style={styles.totalValue} type="display" size="medium">
79
75
  {`/${totalValue?.toString()}`}
80
76
  </Typography>)}
@@ -1,4 +1,3 @@
1
1
  import { InputVariant } from '../../../Input';
2
- import { Dispatch, SetStateAction } from 'react';
3
- declare const handleChangeText: (text: string, setValue: Dispatch<SetStateAction<string>>, variant: InputVariant, onChangeText?: ((text: string) => void) | undefined) => void;
2
+ declare const handleChangeText: (text: string, variant: InputVariant) => string;
4
3
  export default handleChangeText;
@@ -9,11 +9,8 @@ const transformText = (text, variant) => {
9
9
  const transform = variantLogicMapper[variant] || variantLogicMapper.default;
10
10
  return transform(text);
11
11
  };
12
- const handleChangeText = (text, setValue, variant, onChangeText) => {
12
+ const handleChangeText = (text, variant) => {
13
13
  const transformedText = transformText(text, variant);
14
- setValue(transformedText);
15
- if (onChangeText) {
16
- onChangeText(transformedText);
17
- }
14
+ return transformedText;
18
15
  };
19
16
  export default handleChangeText;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@janiscommerce/ui-native",
3
- "version": "1.13.0",
3
+ "version": "1.13.3",
4
4
  "description": "components library for Janis app",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",