@codeleap/mobile 5.0.7 → 5.0.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.
Files changed (106) hide show
  1. package/dist/components/Checkbox/index.js +10 -12
  2. package/dist/components/Checkbox/index.js.map +1 -1
  3. package/dist/components/DatePickerModal/index.js +9 -12
  4. package/dist/components/DatePickerModal/index.js.map +1 -1
  5. package/dist/components/DatePickerModal/types.d.ts +1 -0
  6. package/dist/components/InputBase/useInputBase.d.ts +40 -2
  7. package/dist/components/InputBase/useInputBase.js +9 -13
  8. package/dist/components/InputBase/useInputBase.js.map +1 -1
  9. package/dist/components/NumberIncrement/index.js +8 -6
  10. package/dist/components/NumberIncrement/index.js.map +1 -1
  11. package/dist/components/NumberIncrement/useNumberIncrement.d.ts +36 -1
  12. package/dist/components/NumberIncrement/useNumberIncrement.js +29 -27
  13. package/dist/components/NumberIncrement/useNumberIncrement.js.map +1 -1
  14. package/dist/components/PlacesAutocomplete/index.js +5 -5
  15. package/dist/components/PlacesAutocomplete/index.js.map +1 -1
  16. package/dist/components/RadioInput/index.js +3 -3
  17. package/dist/components/RadioInput/index.js.map +1 -1
  18. package/dist/components/SearchInput/index.js +1 -1
  19. package/dist/components/SearchInput/index.js.map +1 -1
  20. package/dist/components/Select/index.js +16 -17
  21. package/dist/components/Select/index.js.map +1 -1
  22. package/dist/components/Slider/index.js +10 -10
  23. package/dist/components/Slider/index.js.map +1 -1
  24. package/dist/components/Switch/index.js +10 -12
  25. package/dist/components/Switch/index.js.map +1 -1
  26. package/dist/components/TextInput/index.js +5 -5
  27. package/dist/components/TextInput/index.js.map +1 -1
  28. package/dist/components/TextInput/useTextInput.d.ts +36 -1
  29. package/dist/components/TextInput/useTextInput.js +9 -7
  30. package/dist/components/TextInput/useTextInput.js.map +1 -1
  31. package/dist/deprecated/index.d.ts +1 -0
  32. package/dist/deprecated/index.js +3 -0
  33. package/dist/deprecated/index.js.map +1 -0
  34. package/dist/{utils/PermissionManager/context.d.ts → deprecated/permissions/Context.d.ts} +2 -2
  35. package/dist/{utils/PermissionManager/context.js → deprecated/permissions/Context.js} +2 -2
  36. package/dist/deprecated/permissions/Context.js.map +1 -0
  37. package/dist/{utils/PermissionManager → deprecated/permissions}/index.d.ts +2 -1
  38. package/dist/{utils/PermissionManager → deprecated/permissions}/index.js +2 -1
  39. package/dist/deprecated/permissions/index.js.map +1 -0
  40. package/dist/{utils/MobilePermissionManager/PermissionManager.js → deprecated/permissions/package/Manager.js} +1 -1
  41. package/dist/deprecated/permissions/package/Manager.js.map +1 -0
  42. package/dist/deprecated/permissions/package/Permission.js.map +1 -0
  43. package/dist/{utils/MobilePermissionManager → deprecated/permissions/package}/index.d.ts +1 -1
  44. package/dist/{utils/MobilePermissionManager → deprecated/permissions/package}/index.js +1 -1
  45. package/dist/deprecated/permissions/package/index.js.map +1 -0
  46. package/dist/deprecated/permissions/package/types.js.map +1 -0
  47. package/dist/{utils/PermissionManager → deprecated/permissions}/types.d.ts +1 -1
  48. package/dist/deprecated/permissions/types.js.map +1 -0
  49. package/dist/hooks/index.d.ts +1 -0
  50. package/dist/hooks/index.js +1 -0
  51. package/dist/hooks/index.js.map +1 -1
  52. package/dist/hooks/useAppState.d.ts +4 -0
  53. package/dist/hooks/useAppState.js +16 -0
  54. package/dist/hooks/useAppState.js.map +1 -0
  55. package/dist/index.d.ts +1 -0
  56. package/dist/index.js +1 -0
  57. package/dist/index.js.map +1 -1
  58. package/dist/utils/hooks.d.ts +1 -4
  59. package/dist/utils/hooks.js +2 -15
  60. package/dist/utils/hooks.js.map +1 -1
  61. package/dist/utils/index.d.ts +0 -3
  62. package/dist/utils/index.js +0 -3
  63. package/dist/utils/index.js.map +1 -1
  64. package/package.json +15 -17
  65. package/package.json.bak +1 -3
  66. package/src/components/Checkbox/index.tsx +12 -13
  67. package/src/components/DatePickerModal/index.tsx +14 -16
  68. package/src/components/DatePickerModal/types.ts +1 -0
  69. package/src/components/InputBase/useInputBase.ts +11 -15
  70. package/src/components/NumberIncrement/index.tsx +11 -8
  71. package/src/components/NumberIncrement/useNumberIncrement.ts +33 -29
  72. package/src/components/PlacesAutocomplete/index.tsx +4 -4
  73. package/src/components/RadioInput/index.tsx +6 -5
  74. package/src/components/SearchInput/index.tsx +1 -1
  75. package/src/components/Select/index.tsx +24 -20
  76. package/src/components/Slider/index.tsx +12 -11
  77. package/src/components/Switch/index.tsx +12 -13
  78. package/src/components/TextInput/index.tsx +6 -5
  79. package/src/components/TextInput/useTextInput.ts +11 -7
  80. package/src/deprecated/index.ts +1 -0
  81. package/src/{utils/PermissionManager/context.tsx → deprecated/permissions/Context.tsx} +19 -19
  82. package/src/{utils/PermissionManager → deprecated/permissions}/index.ts +4 -8
  83. package/src/{utils/MobilePermissionManager/PermissionManager.ts → deprecated/permissions/package/Manager.ts} +11 -11
  84. package/src/{utils/MobilePermissionManager → deprecated/permissions/package}/Permission.ts +4 -4
  85. package/src/{utils/MobilePermissionManager → deprecated/permissions/package}/index.ts +1 -1
  86. package/src/{utils/MobilePermissionManager → deprecated/permissions/package}/types.ts +12 -12
  87. package/src/deprecated/permissions/types.ts +27 -0
  88. package/src/hooks/index.ts +2 -1
  89. package/src/hooks/useAppState.ts +23 -0
  90. package/src/index.ts +1 -0
  91. package/src/utils/hooks.ts +2 -18
  92. package/src/utils/index.ts +1 -6
  93. package/dist/utils/MobilePermissionManager/Permission.js.map +0 -1
  94. package/dist/utils/MobilePermissionManager/PermissionManager.js.map +0 -1
  95. package/dist/utils/MobilePermissionManager/index.js.map +0 -1
  96. package/dist/utils/MobilePermissionManager/types.js.map +0 -1
  97. package/dist/utils/PermissionManager/context.js.map +0 -1
  98. package/dist/utils/PermissionManager/index.js.map +0 -1
  99. package/dist/utils/PermissionManager/types.js.map +0 -1
  100. package/src/utils/PermissionManager/types.ts +0 -27
  101. /package/dist/{utils/MobilePermissionManager/PermissionManager.d.ts → deprecated/permissions/package/Manager.d.ts} +0 -0
  102. /package/dist/{utils/MobilePermissionManager → deprecated/permissions/package}/Permission.d.ts +0 -0
  103. /package/dist/{utils/MobilePermissionManager → deprecated/permissions/package}/Permission.js +0 -0
  104. /package/dist/{utils/MobilePermissionManager → deprecated/permissions/package}/types.d.ts +0 -0
  105. /package/dist/{utils/MobilePermissionManager → deprecated/permissions/package}/types.js +0 -0
  106. /package/dist/{utils/PermissionManager → deprecated/permissions}/types.js +0 -0
@@ -12,7 +12,7 @@ import { MobileStyleRegistry } from '../../Registry'
12
12
  import { useStylesFor } from '../../hooks'
13
13
  import CurrencyInput from 'react-native-currency-input'
14
14
  import { useInputBasePartialStyles } from '../InputBase/useInputBasePartialStyles'
15
- import { useNumberIncrement } from './useNumberIncrement'
15
+ import { MAX_VALID_DIGITS, useNumberIncrement } from './useNumberIncrement'
16
16
 
17
17
  export * from './styles'
18
18
  export * from './types'
@@ -63,7 +63,6 @@ export const NumberIncrement = forwardRef<NativeTextInput, NumberIncrementProps>
63
63
  const styles = useStylesFor(NumberIncrement.styleRegistryName, style)
64
64
 
65
65
  const {
66
- fieldHandle,
67
66
  validation,
68
67
  min,
69
68
  max,
@@ -79,6 +78,8 @@ export const NumberIncrement = forwardRef<NativeTextInput, NumberIncrementProps>
79
78
  handleMaskChange,
80
79
  handleBlur,
81
80
  handleFocus,
81
+ inputValue,
82
+ onInputValueChange,
82
83
  } = useNumberIncrement(allProps)
83
84
 
84
85
  const isFormatted = TypeGuards.isFunction(formatter)
@@ -123,9 +124,9 @@ export const NumberIncrement = forwardRef<NativeTextInput, NumberIncrementProps>
123
124
  } : {}
124
125
 
125
126
  const currencyExtraProps = isCurrency ? {
126
- value: fieldHandle?.value,
127
+ value: inputValue,
127
128
  onChangeText: null,
128
- onChangeValue: fieldHandle.setValue,
129
+ onChangeValue: onInputValueChange,
129
130
  prefix: prefix,
130
131
  separator: separator ?? '.',
131
132
  suffix: suffix,
@@ -145,7 +146,7 @@ export const NumberIncrement = forwardRef<NativeTextInput, NumberIncrementProps>
145
146
  <InputBase
146
147
  {...inputBaseProps}
147
148
  ref={wrapperRef}
148
- error={hasError ? validation.message || forceError : null}
149
+ error={hasError ? validation?.message || forceError : null}
149
150
  style={styles}
150
151
  rightIcon={TypeGuards.isComponentOrElement(inputBaseProps.rightIcon) ? inputBaseProps.rightIcon : {
151
152
  name: 'plus' as AppIcon,
@@ -179,10 +180,10 @@ export const NumberIncrement = forwardRef<NativeTextInput, NumberIncrementProps>
179
180
  allowFontScaling={false}
180
181
  editable={!disabled}
181
182
  placeholderTextColor={partialStyles?.placeholder?.color}
182
- value={isFormatted ? formatter(fieldHandle?.value ?? min) : String(fieldHandle?.value ?? min)}
183
183
  selectionColor={partialStyles?.selection?.color}
184
- onChangeText={handleChangeInput}
185
184
  {...textInputProps}
185
+ onChangeText={handleChangeInput}
186
+ value={isFormatted ? formatter(inputValue ?? min) : String(inputValue ?? min)}
186
187
  onBlur={handleBlur}
187
188
  onFocus={handleFocus}
188
189
  style={[styles.input, partialStyles.input]}
@@ -192,7 +193,7 @@ export const NumberIncrement = forwardRef<NativeTextInput, NumberIncrementProps>
192
193
  />
193
194
  ) : (
194
195
  <Text
195
- text={isFormatted ? formatter(fieldHandle?.value) : String(fieldHandle?.value)}
196
+ text={isFormatted ? formatter(inputValue) : String(inputValue)}
196
197
  style={[styles.input, partialStyles.input]}
197
198
  />
198
199
  )}
@@ -220,6 +221,8 @@ NumberIncrement.defaultProps = {
220
221
  timeoutActionFocus: 300,
221
222
  actionPressAutoFocus: true,
222
223
  actionDebounce: null,
224
+ min: 0,
225
+ max: MAX_VALID_DIGITS
223
226
  } as Partial<NumberIncrementProps>
224
227
 
225
228
  MobileStyleRegistry.registerComponent(NumberIncrement)
@@ -32,12 +32,24 @@ export function useNumberIncrement(props: Partial<NumberIncrementProps>) {
32
32
  validation,
33
33
  innerInputRef,
34
34
  wrapperRef,
35
+ inputValue,
36
+ onInputValueChange,
35
37
  } = useInputBase(
36
38
  field as Field<number, any, any>,
37
39
  fields.number as () => Field<number, any, any>,
38
- [value, onValueChange]
40
+ { value, onValueChange }
39
41
  )
40
42
 
43
+ const incrementDisabled = useMemo(() => {
44
+ const maxLimit = TypeGuards.isNumber(max) && (Number(inputValue) >= max)
45
+ return maxLimit
46
+ }, [inputValue])
47
+
48
+ const decrementDisabled = useMemo(() => {
49
+ const minLimit = TypeGuards.isNumber(min) && (Number(inputValue) <= min)
50
+ return minLimit
51
+ }, [inputValue])
52
+
41
53
  const actionTimeoutRef = useRef(null)
42
54
 
43
55
  const clearActionTimeoutRef = useCallback(() => {
@@ -52,11 +64,11 @@ export function useNumberIncrement(props: Partial<NumberIncrementProps>) {
52
64
  clearActionTimeoutRef()
53
65
 
54
66
  if (action === 'increment' && !incrementDisabled) {
55
- const newValue = Number(fieldHandle?.value) + step
56
- fieldHandle.setValue(newValue)
67
+ const newValue = Number(inputValue) + step
68
+ onInputValueChange(newValue)
57
69
  } else if (action === 'decrement' && !decrementDisabled) {
58
- const newValue = Number(fieldHandle?.value) - step
59
- fieldHandle.setValue(newValue)
70
+ const newValue = Number(inputValue) - step
71
+ onInputValueChange(newValue)
60
72
  }
61
73
 
62
74
  if (actionPressAutoFocus) {
@@ -64,10 +76,10 @@ export function useNumberIncrement(props: Partial<NumberIncrementProps>) {
64
76
  setIsFocused(false)
65
77
  }, timeoutActionFocus)
66
78
  }
67
- }, [fieldHandle?.value])
79
+ }, [inputValue, incrementDisabled, decrementDisabled])
68
80
 
69
81
  const checkValue = useCallback((newValue: number = null, withLimits = true) => {
70
- const value = newValue ?? fieldHandle?.value
82
+ const value = newValue ?? inputValue
71
83
 
72
84
  if (withLimits) {
73
85
  if (TypeGuards.isNumber(max) && (Number(value) >= max)) {
@@ -82,19 +94,19 @@ export function useNumberIncrement(props: Partial<NumberIncrementProps>) {
82
94
  }
83
95
 
84
96
  if (value >= MAX_VALID_DIGITS) {
85
- fieldHandle.setValue(MAX_VALID_DIGITS)
97
+ onInputValueChange(MAX_VALID_DIGITS)
86
98
  return MAX_VALID_DIGITS
87
99
  }
88
100
 
89
101
  return value
90
- }, [])
102
+ }, [inputValue])
91
103
 
92
104
  const handleBlur = useCallback((e: NativeSyntheticEvent<TextInputFocusEventData>) => {
93
- fieldHandle.setValue(checkValue())
94
- validation.onInputBlurred()
105
+ onInputValueChange(checkValue())
106
+ validation?.onInputBlurred?.()
95
107
  setIsFocused(false)
96
108
  onBlur?.(e)
97
- }, [validation.onInputBlurred, onBlur])
109
+ }, [validation?.onInputBlurred, onBlur, checkValue])
98
110
 
99
111
  const handleFocus = useCallback((e: NativeSyntheticEvent<TextInputFocusEventData>) => {
100
112
  clearActionTimeoutRef()
@@ -105,31 +117,21 @@ export function useNumberIncrement(props: Partial<NumberIncrementProps>) {
105
117
  const handleChangeInput = useCallback((text: string) => {
106
118
  const value = checkValue(parseValue(text), false)
107
119
 
108
- fieldHandle.setValue(value)
120
+ onInputValueChange(value)
109
121
 
110
122
  return value
111
- }, [])
123
+ }, [checkValue])
112
124
 
113
125
  const handleMaskChange = useCallback((masked, unmasked) => {
114
126
  handleChangeInput?.(masked)
115
127
  if (onChangeMask) onChangeMask(masked, unmasked)
116
- }, [onChangeMask])
117
-
118
- const incrementDisabled = useMemo(() => {
119
- const maxLimit = TypeGuards.isNumber(max) && (Number(fieldHandle?.value) >= max)
120
- return maxLimit
121
- }, [fieldHandle?.value])
122
-
123
- const decrementDisabled = useMemo(() => {
124
- const minLimit = TypeGuards.isNumber(min) && (Number(fieldHandle?.value) <= min)
125
- return minLimit
126
- }, [fieldHandle?.value])
128
+ }, [onChangeMask, handleChangeInput])
127
129
 
128
- const hasValue = TypeGuards.isString(fieldHandle?.value)
129
- ? (fieldHandle?.value as string).length > 0
130
- : !TypeGuards.isNil(fieldHandle?.value)
130
+ const hasValue = TypeGuards.isString(inputValue)
131
+ ? (inputValue as string).length > 0
132
+ : !TypeGuards.isNil(inputValue)
131
133
 
132
- const hasError = validation.showError || forceError
134
+ const hasError = validation?.showError || forceError
133
135
 
134
136
  return {
135
137
  isFocused,
@@ -148,5 +150,7 @@ export function useNumberIncrement(props: Partial<NumberIncrementProps>) {
148
150
  decrementDisabled,
149
151
  min,
150
152
  max,
153
+ inputValue,
154
+ onInputValueChange,
151
155
  }
152
156
  }
@@ -99,10 +99,6 @@ export const PlacesAutocomplete = (props: PlacesAutocompleteProps) => {
99
99
  <View style={styles.wrapper} {...rest}>
100
100
  <TextInput
101
101
  style={compositionStyles.input}
102
- onChangeText={(value) => {
103
- setIsTyping(true)
104
- handleChangeAddress(value)
105
- }}
106
102
  onBlur={() => {
107
103
  setIsFocused(false)
108
104
  }}
@@ -111,6 +107,10 @@ export const PlacesAutocomplete = (props: PlacesAutocompleteProps) => {
111
107
  }}
112
108
  {...textInputProps}
113
109
  value={hasCustomValue ? textInputProps?.value : address}
110
+ onValueChange={(value) => {
111
+ setIsTyping(true)
112
+ handleChangeAddress(value)
113
+ }}
114
114
  rightIcon={rightIcon}
115
115
  />
116
116
  {isTyping ? (
@@ -96,18 +96,19 @@ export const RadioGroup = <T extends string | number>(props: RadioGroupProps<T>)
96
96
  const styles = useStylesFor(RadioGroup.styleRegistryName, style)
97
97
 
98
98
  const {
99
- fieldHandle,
100
99
  wrapperRef,
100
+ inputValue,
101
+ onInputValueChange,
101
102
  } = useInputBase(
102
103
  field as SelectableField<T, any>,
103
104
  fields.selectable as () => SelectableField<T, any>,
104
- [value, onValueChange]
105
+ { value, onValueChange }
105
106
  )
106
107
 
107
108
  // @ts-expect-error icss type
108
109
  const _radioOnRight = radioOnRight ?? styles?.__props?.radioOnRight
109
110
 
110
- const hasValue = !TypeGuards.isNil(fieldHandle?.value)
111
+ const hasValue = !TypeGuards.isNil(inputValue)
111
112
 
112
113
  return <InputBase
113
114
  {...inputBaseProps}
@@ -124,8 +125,8 @@ export const RadioGroup = <T extends string | number>(props: RadioGroupProps<T>)
124
125
  key={idx}
125
126
  disabled={disabled}
126
127
  styles={styles}
127
- selected={fieldHandle?.value === item.value}
128
- onSelect={() => fieldHandle.setValue(item.value)}
128
+ selected={inputValue === item.value}
129
+ onSelect={() => onInputValueChange(item.value)}
129
130
  separator={idx < options?.length - 1}
130
131
  reverseOrder={_radioOnRight}
131
132
  />
@@ -68,7 +68,7 @@ export const SearchInput: ForwardRefComponentWithDefaultProps<SearchInputProps,
68
68
  return (
69
69
  <TextInput
70
70
  value={search}
71
- onChangeText={(value) => {
71
+ onValueChange={(value) => {
72
72
  onTypingChange?.(true)
73
73
  handleChangeSearch(value)
74
74
  }}
@@ -117,17 +117,22 @@ export const Select = <T extends string | number = string, Multi extends boolean
117
117
  outerInputComponent,
118
118
  disabled,
119
119
  field,
120
- value: _value,
121
- onValueChange: _onValueChange,
120
+ value,
121
+ onValueChange,
122
122
  onSelect,
123
123
  ...modalProps
124
124
  } = allProps
125
125
 
126
- const { fieldHandle } = useInputBase(field, fields.selectable as () => SelectableField<T, any>, [_value, _onValueChange])
127
-
128
- const value = fieldHandle.value
126
+ const {
127
+ inputValue,
128
+ onInputValueChange,
129
+ } = useInputBase(
130
+ field,
131
+ fields.selectable as () => SelectableField<T, any>,
132
+ { value, onValueChange }
133
+ )
129
134
 
130
- const isValueArray = TypeGuards.isArray(value) && multiple
135
+ const isValueArray = TypeGuards.isArray(inputValue) && multiple
131
136
 
132
137
  const {
133
138
  loading,
@@ -138,7 +143,7 @@ export const Select = <T extends string | number = string, Multi extends boolean
138
143
  load,
139
144
  onChangeSearch,
140
145
  } = useSearch({
141
- value,
146
+ value: inputValue,
142
147
  multiple,
143
148
  options,
144
149
  filterItems,
@@ -186,25 +191,25 @@ export const Select = <T extends string | number = string, Multi extends boolean
186
191
  let removedIndex = null
187
192
 
188
193
  if (multiple && isValueArray) {
189
- if (value.includes(selectedValue)) {
190
- removedIndex = value.findIndex(v => v === selectedValue)
194
+ if (inputValue.includes(selectedValue)) {
195
+ removedIndex = inputValue.findIndex(v => v === selectedValue)
191
196
 
192
- newValue = value.filter((v, i) => i !== removedIndex)
197
+ newValue = inputValue.filter((v, i) => i !== removedIndex)
193
198
  } else {
194
- if (TypeGuards.isNumber(limit) && value.length >= limit) {
199
+ if (TypeGuards.isNumber(limit) && inputValue.length >= limit) {
195
200
  return
196
201
  }
197
202
 
198
203
  newOption = currentOptions.find(o => o.value === selectedValue)
199
204
 
200
- newValue = [...value, selectedValue]
205
+ newValue = [...inputValue, selectedValue]
201
206
  }
202
207
  } else {
203
208
  newValue = selectedValue
204
209
  newOption = currentOptions.find(o => o.value === selectedValue)
205
210
  }
206
211
 
207
- fieldHandle.setValue(newValue)
212
+ onInputValueChange(newValue)
208
213
 
209
214
  onSelect?.(newValue)
210
215
 
@@ -224,15 +229,15 @@ export const Select = <T extends string | number = string, Multi extends boolean
224
229
  if (closeOnSelect) {
225
230
  close?.()
226
231
  }
227
- }, [isValueArray, (isValueArray ? value : [value]), limit, multiple, labelOptions, currentOptions])
232
+ }, [isValueArray, (isValueArray ? inputValue : [inputValue]), limit, multiple, labelOptions, currentOptions])
228
233
 
229
234
  const renderListItem = useCallback(({ item, index }) => {
230
235
  let selected = false
231
236
 
232
237
  if (multiple && isValueArray) {
233
- selected = value?.includes(item.value)
238
+ selected = inputValue?.includes(item.value)
234
239
  } else {
235
- selected = value === item.value
240
+ selected = inputValue === item.value
236
241
  }
237
242
 
238
243
  return (
@@ -251,20 +256,19 @@ export const Select = <T extends string | number = string, Multi extends boolean
251
256
  {...itemProps}
252
257
  />
253
258
  )
254
- }, [value, select, multiple])
259
+ }, [inputValue, select, multiple])
255
260
 
256
- const isEmpty = TypeGuards.isNil(value)
261
+ const isEmpty = TypeGuards.isNil(inputValue)
257
262
  const showClearIcon = !isEmpty && clearable
258
263
 
259
264
  const inputIcon = showClearIcon ? clearIconName : arrowIconName
260
265
 
261
266
  const onPressInputIcon = () => {
262
267
  if (showClearIcon) {
263
- fieldHandle.setValue(null)
268
+ onInputValueChange(null)
264
269
  } else {
265
270
  close?.()
266
271
  }
267
-
268
272
  }
269
273
 
270
274
  const searchHeader = searchable ? <SearchInput
@@ -64,18 +64,19 @@ export const Slider = (props: SliderProps) => {
64
64
  } = others
65
65
 
66
66
  const {
67
- fieldHandle,
68
67
  wrapperRef,
69
- } = useInputBase(field, fields.number, [value, onValueChange])
68
+ inputValue,
69
+ onInputValueChange,
70
+ } = useInputBase(field, fields.number, { value, onValueChange })
70
71
 
71
- const [_value, _setValue] = updateImmediately ? [fieldHandle?.value, fieldHandle.setValue] : React.useState<number | Array<number>>(0)
72
+ const [_value, _setValue] = updateImmediately ? [inputValue, onInputValueChange] : React.useState<number | Array<number>>(0)
72
73
 
73
74
  onUpdate(() => {
74
75
  if (updateImmediately) return
75
- if (fieldHandle?.value !== _value) {
76
- _setValue(fieldHandle?.value)
76
+ if (inputValue !== _value) {
77
+ _setValue(inputValue)
77
78
  }
78
- }, [fieldHandle?.value])
79
+ }, [inputValue])
79
80
 
80
81
  const styles = useStylesFor(Slider.styleRegistryName, style)
81
82
 
@@ -106,7 +107,7 @@ export const Slider = (props: SliderProps) => {
106
107
  <View style={styles.labelRow}>
107
108
  {label ? (
108
109
  <Touchable
109
- onPress={() => labelClickable ? fieldHandle.setValue(sliderProps?.minimumValue || minimumValue) : null}
110
+ onPress={() => labelClickable ? onInputValueChange(sliderProps?.minimumValue || minimumValue) : null}
110
111
  style={styles.labelBtn}
111
112
  debugName='slider title'
112
113
  >
@@ -115,7 +116,7 @@ export const Slider = (props: SliderProps) => {
115
116
  ) : null}
116
117
  {description ? (
117
118
  <Touchable
118
- onPress={() => labelClickable ? fieldHandle.setValue(sliderProps?.maximumValue || maximumValue) : null}
119
+ onPress={() => labelClickable ? onInputValueChange(sliderProps?.maximumValue || maximumValue) : null}
119
120
  style={styles?.descriptionBtn}
120
121
  debugName='slider description'
121
122
  >
@@ -137,7 +138,7 @@ export const Slider = (props: SliderProps) => {
137
138
  maximumValue={maximumValue}
138
139
  onSlidingComplete={() => {
139
140
  if (updateImmediately) return
140
- fieldHandle.setValue(_value)
141
+ onInputValueChange(_value)
141
142
  }}
142
143
  disabled={disabled}
143
144
  {...sliderProps}
@@ -163,7 +164,7 @@ export const Slider = (props: SliderProps) => {
163
164
  index={idx}
164
165
  style={style}
165
166
  key={idx}
166
- onPress={() => trackMarksClickable ? fieldHandle.setValue(trackMarksProp[idx]) : null}
167
+ onPress={() => trackMarksClickable ? onInputValueChange(trackMarksProp[idx]) : null}
167
168
  />
168
169
  }
169
170
 
@@ -175,7 +176,7 @@ export const Slider = (props: SliderProps) => {
175
176
  content={content}
176
177
  style={style}
177
178
  key={idx}
178
- onPress={() => trackMarksClickable ? fieldHandle.setValue(trackMarksProp[idx]) : null}
179
+ onPress={() => trackMarksClickable ? onInputValueChange(trackMarksProp[idx]) : null}
179
180
  />
180
181
  })
181
182
  }
@@ -38,10 +38,11 @@ export const Switch = (props: SwitchProps) => {
38
38
  const styles = useStylesFor(Switch.styleRegistryName, style)
39
39
 
40
40
  const {
41
- fieldHandle,
42
41
  validation,
43
42
  wrapperRef,
44
- } = useInputBase<boolean>(field, fields.boolean, [value, onValueChange])
43
+ inputValue,
44
+ onInputValueChange,
45
+ } = useInputBase<boolean>(field, fields.boolean, { value, onValueChange })
45
46
 
46
47
  const trackAnimation = useAnimatedVariantStyles({
47
48
  variantStyles: styles,
@@ -51,16 +52,16 @@ export const Switch = (props: SwitchProps) => {
51
52
  'worklet'
52
53
  let disabledStyle = {}
53
54
  if (disabled) {
54
- disabledStyle = fieldHandle?.value ? styles['track:disabled-on'] : styles['track:disabled-off']
55
+ disabledStyle = inputValue ? styles['track:disabled-on'] : styles['track:disabled-off']
55
56
  }
56
- const style = fieldHandle?.value ? styles['track:on'] : styles['track:off']
57
+ const style = inputValue ? styles['track:on'] : styles['track:off']
57
58
 
58
59
  return {
59
60
  ...style,
60
61
  ...disabledStyle,
61
62
  }
62
63
  },
63
- dependencies: [fieldHandle?.value, disabled],
64
+ dependencies: [inputValue, disabled],
64
65
  })
65
66
 
66
67
  const thumbAnimation = useAnimatedVariantStyles({
@@ -71,34 +72,32 @@ export const Switch = (props: SwitchProps) => {
71
72
  'worklet'
72
73
  let disabledStyle = {}
73
74
  if (disabled) {
74
- disabledStyle = fieldHandle?.value ? styles['thumb:disabled-on'] : styles['thumb:disabled-off']
75
+ disabledStyle = inputValue ? styles['thumb:disabled-on'] : styles['thumb:disabled-off']
75
76
  }
76
- const style = fieldHandle?.value ? styles['thumb:on'] : styles['thumb:off']
77
+ const style = inputValue ? styles['thumb:on'] : styles['thumb:off']
77
78
  return {
78
79
  ...style,
79
80
  ...disabledStyle,
80
81
  }
81
82
 
82
83
  },
83
- dependencies: [fieldHandle?.value, disabled],
84
+ dependencies: [inputValue, disabled],
84
85
  })
85
86
 
86
87
  // @ts-expect-error
87
88
  const _switchOnLeft = switchOnLeft ?? styles?.__props?.switchOnLeft
88
89
 
89
- const hasError = validation.showError || forceError
90
+ const hasError = validation?.showError || forceError
90
91
 
91
92
  return <InputBase
92
93
  {...inputBaseProps}
93
94
  ref={wrapperRef}
94
95
  debugName={debugName}
95
96
  wrapper={Touchable}
96
- error={hasError ? validation.message || forceError : null}
97
+ error={hasError ? validation?.message || forceError : null}
97
98
  style={styles}
98
99
  wrapperProps={{
99
- onPress: () => {
100
- fieldHandle.setValue(!fieldHandle?.value)
101
- },
100
+ onPress: () => onInputValueChange(!inputValue),
102
101
  disabled,
103
102
  rippleDisabled: true,
104
103
  }}
@@ -40,7 +40,6 @@ export const TextInput = forwardRef<NativeTextInput, TextInputProps>((props, inp
40
40
  autoAdjustSelection,
41
41
  selectionStart,
42
42
  forceError,
43
- onChangeText,
44
43
  multiline,
45
44
  ...textInputProps
46
45
  } = others
@@ -48,8 +47,9 @@ export const TextInput = forwardRef<NativeTextInput, TextInputProps>((props, inp
48
47
  const styles = useStylesFor(TextInput.styleRegistryName, style)
49
48
 
50
49
  const {
51
- fieldHandle,
52
50
  validation,
51
+ inputValue,
52
+ onInputValueChange,
53
53
  innerInputRef,
54
54
  wrapperRef,
55
55
  isFocused,
@@ -92,7 +92,7 @@ export const TextInput = forwardRef<NativeTextInput, TextInputProps>((props, inp
92
92
  },
93
93
  ...masking,
94
94
  } : {
95
- onChangeText: fieldHandle.setValue
95
+ onChangeText: onInputValueChange,
96
96
  }
97
97
 
98
98
  const buttonModeProps = isPressable ? {
@@ -105,7 +105,7 @@ export const TextInput = forwardRef<NativeTextInput, TextInputProps>((props, inp
105
105
  ref={wrapperRef}
106
106
  innerWrapper={isPressable ? Touchable : undefined}
107
107
  debugName={debugName}
108
- error={hasError ? validation.message || forceError : null}
108
+ error={hasError ? validation?.message || forceError : null}
109
109
  style={{
110
110
  ...styles,
111
111
  innerWrapper: [
@@ -130,12 +130,13 @@ export const TextInput = forwardRef<NativeTextInput, TextInputProps>((props, inp
130
130
  {...buttonModeProps}
131
131
  selection={autoAdjustSelection ? currentSelection : undefined}
132
132
  placeholderTextColor={partialStyles?.placeholder?.color}
133
- value={fieldHandle?.value}
134
133
  selectionColor={partialStyles?.selection?.color}
135
134
  secureTextEntry={secure && secureTextEntry}
136
135
  textAlignVertical={multiline ? 'top' : undefined}
137
136
  multiline={multiline}
138
137
  {...textInputProps}
138
+ value={inputValue}
139
+ onChangeText={onInputValueChange}
139
140
  onBlur={handleBlur}
140
141
  onFocus={handleFocus}
141
142
  style={[
@@ -33,7 +33,9 @@ export function useTextInput(props: Partial<TextInputProps>) {
33
33
  validation,
34
34
  innerInputRef,
35
35
  wrapperRef,
36
- } = useInputBase<string>(field, fields.text, [value, onValueChange], {
36
+ onInputValueChange,
37
+ inputValue,
38
+ } = useInputBase<string>(field, fields.text, { value, onValueChange }, {
37
39
  revealValue() {
38
40
  setSecureTextEntry(false)
39
41
  },
@@ -46,11 +48,11 @@ export function useTextInput(props: Partial<TextInputProps>) {
46
48
  }, [setSecureTextEntry])
47
49
 
48
50
  const handleBlur = useCallback((e: NativeSyntheticEvent<TextInputFocusEventData>) => {
49
- validation.onInputBlurred()
51
+ validation?.onInputBlurred?.()
50
52
  setIsFocused(false)
51
53
  if (autoAdjustSelection) setCurrentSelection({ start: selectionStart })
52
54
  onBlur?.(e)
53
- }, [validation.onInputBlurred, onBlur])
55
+ }, [validation?.onInputBlurred, onBlur])
54
56
 
55
57
  const handleFocus = useCallback((e: NativeSyntheticEvent<TextInputFocusEventData>) => {
56
58
  setIsFocused(true)
@@ -59,15 +61,15 @@ export function useTextInput(props: Partial<TextInputProps>) {
59
61
  }, [onFocus])
60
62
 
61
63
  const handleMaskChange = useCallback((masked, unmasked) => {
62
- fieldHandle.setValue(masking?.saveFormatted ? masked : masked)
64
+ onInputValueChange(masking?.saveFormatted ? masked : masked)
63
65
  if (onChangeMask) onChangeMask(masked, unmasked)
64
66
  }, [masking?.saveFormatted, onChangeMask])
65
67
 
66
- const hasMultipleLines = multiline && fieldHandle?.value?.includes('\n')
68
+ const hasMultipleLines = multiline && inputValue?.includes('\n')
67
69
 
68
- const hasValue = fieldHandle?.value?.length > 0
70
+ const hasValue = inputValue?.length > 0
69
71
 
70
- const hasError = validation.showError || forceError
72
+ const hasError = validation?.showError || forceError
71
73
 
72
74
  return {
73
75
  isFocused,
@@ -84,5 +86,7 @@ export function useTextInput(props: Partial<TextInputProps>) {
84
86
  hasMultipleLines,
85
87
  hasValue,
86
88
  hasError,
89
+ inputValue,
90
+ onInputValueChange,
87
91
  }
88
92
  }
@@ -0,0 +1 @@
1
+ export * as Permissions from './permissions'