react-native-terra-ui 0.13.6 → 0.13.8
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/CHANGELOG.md +18 -0
- package/lib/module/components/input/hooks/use-focus-state.js +25 -0
- package/lib/module/components/input/hooks/use-focus-state.js.map +1 -0
- package/lib/module/components/input/parts/InputField.js +53 -31
- package/lib/module/components/input/parts/InputField.js.map +1 -1
- package/lib/module/components/input/variants/SearchInput/SearchCancelButton.js +93 -0
- package/lib/module/components/input/variants/SearchInput/SearchCancelButton.js.map +1 -0
- package/lib/module/components/input/variants/SearchInput/SearchClearButton.js +52 -0
- package/lib/module/components/input/variants/SearchInput/SearchClearButton.js.map +1 -0
- package/lib/module/components/input/variants/SearchInput/index.js +85 -30
- package/lib/module/components/input/variants/SearchInput/index.js.map +1 -1
- package/lib/module/components/input/variants/SearchInput/utils.js +9 -0
- package/lib/module/components/input/variants/SearchInput/utils.js.map +1 -0
- package/lib/module/components/screen/ScreenList.js +5 -1
- package/lib/module/components/screen/ScreenList.js.map +1 -1
- package/lib/module/components/screen/ScreenScrollView.js +5 -1
- package/lib/module/components/screen/ScreenScrollView.js.map +1 -1
- package/lib/module/theme/tokens/dark.js +16 -16
- package/lib/module/theme/tokens/dark.js.map +1 -1
- package/lib/module/theme/tokens/light.js +4 -4
- package/lib/module/theme/tokens/light.js.map +1 -1
- package/lib/module/theme/tokens/primitives.js +12 -0
- package/lib/module/theme/tokens/primitives.js.map +1 -1
- package/lib/typescript/src/components/input/hooks/use-focus-state.d.ts +15 -0
- package/lib/typescript/src/components/input/hooks/use-focus-state.d.ts.map +1 -0
- package/lib/typescript/src/components/input/parts/InputField.d.ts +3 -1
- package/lib/typescript/src/components/input/parts/InputField.d.ts.map +1 -1
- package/lib/typescript/src/components/input/types.d.ts +11 -1
- package/lib/typescript/src/components/input/types.d.ts.map +1 -1
- package/lib/typescript/src/components/input/variants/SearchInput/SearchCancelButton.d.ts +19 -0
- package/lib/typescript/src/components/input/variants/SearchInput/SearchCancelButton.d.ts.map +1 -0
- package/lib/typescript/src/components/input/variants/SearchInput/SearchClearButton.d.ts +13 -0
- package/lib/typescript/src/components/input/variants/SearchInput/SearchClearButton.d.ts.map +1 -0
- package/lib/typescript/src/components/input/variants/SearchInput/index.d.ts +15 -1
- package/lib/typescript/src/components/input/variants/SearchInput/index.d.ts.map +1 -1
- package/lib/typescript/src/components/input/variants/SearchInput/utils.d.ts +4 -0
- package/lib/typescript/src/components/input/variants/SearchInput/utils.d.ts.map +1 -0
- package/lib/typescript/src/components/screen/ScreenList.d.ts.map +1 -1
- package/lib/typescript/src/components/screen/ScreenScrollView.d.ts.map +1 -1
- package/lib/typescript/src/theme/tokens/primitives.d.ts +11 -0
- package/lib/typescript/src/theme/tokens/primitives.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/input/hooks/use-focus-state.ts +32 -0
- package/src/components/input/parts/InputField.tsx +45 -31
- package/src/components/input/types.ts +11 -1
- package/src/components/input/variants/SearchInput/SearchCancelButton.tsx +109 -0
- package/src/components/input/variants/SearchInput/SearchClearButton.tsx +58 -0
- package/src/components/input/variants/SearchInput/index.tsx +92 -24
- package/src/components/input/variants/SearchInput/utils.ts +4 -0
- package/src/components/screen/ScreenList.tsx +3 -0
- package/src/components/screen/ScreenScrollView.tsx +3 -0
- package/src/theme/tokens/dark.ts +16 -16
- package/src/theme/tokens/light.ts +4 -4
- package/src/theme/tokens/primitives.ts +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.13.8](https://github.com/earthlin9/react-native-terra-ui/compare/v0.13.7...v0.13.8) (2026-10-05)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* **ui:** [input] add focus border and glow props, and a search cancel button ([c502519](https://github.com/earthlin9/react-native-terra-ui/commit/c50251916dc80669fc2a55933babfb59a1842e0c))
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **ui:** [input] call onCancelPress after blur so a cleared query sticks ([2e42186](https://github.com/earthlin9/react-native-terra-ui/commit/2e42186bfcade644710adb89e5efe7a4525679a1))
|
|
12
|
+
* **ui:** [screen] scroll focused inputs above the keyboard on iOS ([8b85d47](https://github.com/earthlin9/react-native-terra-ui/commit/8b85d4795d11fd49410a4c1087c3a3ddc4494f0a))
|
|
13
|
+
* **ui:** [theme] widen light text hierarchy within 4.5:1 contrast ([10f7143](https://github.com/earthlin9/react-native-terra-ui/commit/10f714331fb2ba0d4784dffbd4d6e8bcf13eb47b))
|
|
14
|
+
|
|
15
|
+
## [0.13.7](https://github.com/earthlin9/react-native-terra-ui/compare/v0.13.6...v0.13.7) (2026-10-04)
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* **ui:** [theme] add ink palette and move dark theme neutrals onto it ([de39054](https://github.com/earthlin9/react-native-terra-ui/commit/de39054c1b3b9f0c71d2ac205d22299a30f7e7c6))
|
|
20
|
+
|
|
3
21
|
## [0.13.6](https://github.com/earthlin9/react-native-terra-ui/compare/v0.13.5...v0.13.6) (2026-10-04)
|
|
4
22
|
|
|
5
23
|
### Features
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useState } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* Track whether a `TextInput` is focused while still forwarding the caller's
|
|
6
|
+
* own `onFocus` / `onBlur`. Shared by the field (for its focus ring) and by
|
|
7
|
+
* variants that show extra controls while focused.
|
|
8
|
+
*/
|
|
9
|
+
export function useFocusState(onFocus, onBlur) {
|
|
10
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
11
|
+
const handleFocus = useCallback(event => {
|
|
12
|
+
setIsFocused(true);
|
|
13
|
+
onFocus?.(event);
|
|
14
|
+
}, [onFocus]);
|
|
15
|
+
const handleBlur = useCallback(event => {
|
|
16
|
+
setIsFocused(false);
|
|
17
|
+
onBlur?.(event);
|
|
18
|
+
}, [onBlur]);
|
|
19
|
+
return {
|
|
20
|
+
isFocused,
|
|
21
|
+
handleFocus,
|
|
22
|
+
handleBlur
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=use-focus-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useCallback","useState","useFocusState","onFocus","onBlur","isFocused","setIsFocused","handleFocus","event","handleBlur"],"sourceRoot":"../../../../../src","sources":["components/input/hooks/use-focus-state.ts"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,QAAQ,QAAQ,OAAO;AAM7C;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAACC,OAAsB,EAAEC,MAAoB,EAAE;EAC1E,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGL,QAAQ,CAAC,KAAK,CAAC;EAEjD,MAAMM,WAAW,GAAGP,WAAW,CAC5BQ,KAAK,IAAK;IACTF,YAAY,CAAC,IAAI,CAAC;IAClBH,OAAO,GAAGK,KAAK,CAAC;EAClB,CAAC,EACD,CAACL,OAAO,CACV,CAAC;EAED,MAAMM,UAAU,GAAGT,WAAW,CAC3BQ,KAAK,IAAK;IACTF,YAAY,CAAC,KAAK,CAAC;IACnBF,MAAM,GAAGI,KAAK,CAAC;EACjB,CAAC,EACD,CAACJ,MAAM,CACT,CAAC;EAED,OAAO;IAAEC,SAAS;IAAEE,WAAW;IAAEE;EAAW,CAAC;AAC/C","ignoreList":[]}
|
|
@@ -2,11 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
import { View } from "react-native-unistyles/components/native/View";
|
|
4
4
|
import { TextInput } from "react-native-unistyles/components/native/TextInput";
|
|
5
|
-
import { forwardRef
|
|
5
|
+
import { forwardRef } from "react";
|
|
6
6
|
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
|
7
7
|
import { resolveThemeColor } from "../../../utils/resolve-theme-color.js";
|
|
8
8
|
import { FONT_WEIGHT_VALUE, SYSTEM_FONT } from "../../../utils/typography.js";
|
|
9
|
+
import { useFocusState } from "../hooks/use-focus-state.js";
|
|
9
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
/** Container height per size, in dp. Sibling controls sized to match read from here. */
|
|
12
|
+
export const FIELD_HEIGHT = {
|
|
13
|
+
sm: 36,
|
|
14
|
+
md: 44,
|
|
15
|
+
lg: 52
|
|
16
|
+
};
|
|
17
|
+
|
|
10
18
|
/** Typographic role of the text, per size. */
|
|
11
19
|
const TEXT_VARIANT = {
|
|
12
20
|
sm: "subheadline",
|
|
@@ -23,6 +31,9 @@ export const InputField = /*#__PURE__*/forwardRef(function InputField({
|
|
|
23
31
|
size = "md",
|
|
24
32
|
isDisabled = false,
|
|
25
33
|
isInvalid = false,
|
|
34
|
+
focusBorderColor,
|
|
35
|
+
focusBorderWidth,
|
|
36
|
+
hasFocusGlow = false,
|
|
26
37
|
leading,
|
|
27
38
|
trailing,
|
|
28
39
|
background = "surface.sunken",
|
|
@@ -32,31 +43,27 @@ export const InputField = /*#__PURE__*/forwardRef(function InputField({
|
|
|
32
43
|
onBlur,
|
|
33
44
|
...rest
|
|
34
45
|
}, ref) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
const {
|
|
47
|
+
isFocused,
|
|
48
|
+
handleFocus,
|
|
49
|
+
handleBlur
|
|
50
|
+
} = useFocusState(onFocus, onBlur);
|
|
51
|
+
const showsFocus = isFocused && !isDisabled;
|
|
52
|
+
|
|
53
|
+
// The placeholder colour has to leave the stylesheet because `TextInput` takes
|
|
54
|
+
// it as a prop rather than as a style.
|
|
39
55
|
const {
|
|
40
56
|
theme
|
|
41
57
|
} = useUnistyles();
|
|
42
|
-
const handleFocus = useCallback(event => {
|
|
43
|
-
setIsFocused(true);
|
|
44
|
-
onFocus?.(event);
|
|
45
|
-
}, [onFocus]);
|
|
46
|
-
const handleBlur = useCallback(event => {
|
|
47
|
-
setIsFocused(false);
|
|
48
|
-
onBlur?.(event);
|
|
49
|
-
}, [onBlur]);
|
|
50
58
|
const _styles = styles;
|
|
51
59
|
{
|
|
52
60
|
const styles = _styles.useVariants({
|
|
53
61
|
size,
|
|
54
62
|
disabled: isDisabled,
|
|
55
|
-
invalid: isInvalid
|
|
56
|
-
focused: isFocused && !isDisabled
|
|
63
|
+
invalid: isInvalid
|
|
57
64
|
});
|
|
58
65
|
return /*#__PURE__*/_jsxs(View, {
|
|
59
|
-
style: [styles.container, styles.fill(background, radius), style],
|
|
66
|
+
style: [styles.container, styles.fill(background, radius), showsFocus && styles.focus(focusBorderColor, focusBorderWidth, hasFocusGlow, isInvalid), style],
|
|
60
67
|
children: [leading, /*#__PURE__*/_jsx(TextInput, {
|
|
61
68
|
ref: ref,
|
|
62
69
|
editable: !isDisabled,
|
|
@@ -90,27 +97,21 @@ const styles = StyleSheet.create(theme => {
|
|
|
90
97
|
variants: {
|
|
91
98
|
size: {
|
|
92
99
|
sm: {
|
|
93
|
-
height:
|
|
94
|
-
paddingHorizontal: theme.spacing["
|
|
100
|
+
height: FIELD_HEIGHT.sm,
|
|
101
|
+
paddingHorizontal: theme.spacing["3"],
|
|
95
102
|
gap: 6
|
|
96
103
|
},
|
|
97
104
|
md: {
|
|
98
|
-
height:
|
|
99
|
-
paddingHorizontal: theme.spacing["
|
|
105
|
+
height: FIELD_HEIGHT.md,
|
|
106
|
+
paddingHorizontal: theme.spacing["3"],
|
|
100
107
|
gap: 6
|
|
101
108
|
},
|
|
102
109
|
lg: {
|
|
103
|
-
height:
|
|
110
|
+
height: FIELD_HEIGHT.lg,
|
|
104
111
|
paddingHorizontal: theme.spacing["4"],
|
|
105
112
|
gap: 6
|
|
106
113
|
}
|
|
107
114
|
},
|
|
108
|
-
focused: {
|
|
109
|
-
true: {
|
|
110
|
-
borderColor: theme.color["accent.border"]
|
|
111
|
-
},
|
|
112
|
-
false: {}
|
|
113
|
-
},
|
|
114
115
|
invalid: {
|
|
115
116
|
true: {
|
|
116
117
|
borderColor: theme.color["danger.text"]
|
|
@@ -126,6 +127,31 @@ const styles = StyleSheet.create(theme => {
|
|
|
126
127
|
},
|
|
127
128
|
uni__dependencies: [0, 4]
|
|
128
129
|
},
|
|
130
|
+
// Only the keys that apply are set, so an unset option leaves the resting
|
|
131
|
+
// border alone rather than overriding it with `undefined`. An invalid field
|
|
132
|
+
// keeps its danger border and skips the glow, so the error stays the loudest
|
|
133
|
+
// signal; only the width still follows focus.
|
|
134
|
+
focus: (color, width, hasGlow, isInvalid) => {
|
|
135
|
+
const focusColor = resolveThemeColor(color ?? "border.default", theme);
|
|
136
|
+
return {
|
|
137
|
+
...(width !== undefined && {
|
|
138
|
+
borderWidth: width
|
|
139
|
+
}),
|
|
140
|
+
...(color && !isInvalid && {
|
|
141
|
+
borderColor: focusColor
|
|
142
|
+
}),
|
|
143
|
+
...(hasGlow && !isInvalid && {
|
|
144
|
+
boxShadow: [{
|
|
145
|
+
offsetX: 0,
|
|
146
|
+
offsetY: 0,
|
|
147
|
+
blurRadius: 4,
|
|
148
|
+
spreadDistance: 1,
|
|
149
|
+
color: focusColor
|
|
150
|
+
}]
|
|
151
|
+
}),
|
|
152
|
+
uni__dependencies: [0]
|
|
153
|
+
};
|
|
154
|
+
},
|
|
129
155
|
// `background` is an open `ColorToken` and `radius` an eight-step scale, so
|
|
130
156
|
// both resolve in a dynamic function rather than enumerating as variants.
|
|
131
157
|
fill: (background, radius) => ({
|
|
@@ -155,10 +181,6 @@ const styles = StyleSheet.create(theme => {
|
|
|
155
181
|
fontSize: theme.typography.variants[TEXT_VARIANT.lg].fontSize
|
|
156
182
|
}
|
|
157
183
|
},
|
|
158
|
-
focused: {
|
|
159
|
-
true: {},
|
|
160
|
-
false: {}
|
|
161
|
-
},
|
|
162
184
|
invalid: {
|
|
163
185
|
true: {},
|
|
164
186
|
false: {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["forwardRef","
|
|
1
|
+
{"version":3,"names":["forwardRef","StyleSheet","useUnistyles","resolveThemeColor","FONT_WEIGHT_VALUE","SYSTEM_FONT","useFocusState","jsx","_jsx","jsxs","_jsxs","FIELD_HEIGHT","sm","md","lg","TEXT_VARIANT","InputField","size","isDisabled","isInvalid","focusBorderColor","focusBorderWidth","hasFocusGlow","leading","trailing","background","radius","style","onFocus","onBlur","rest","ref","isFocused","handleFocus","handleBlur","showsFocus","theme","_styles","styles","useVariants","disabled","invalid","View","container","fill","focus","children","TextInput","editable","placeholderTextColor","color","input","maxFontSizeMultiplier","typography","variants","create","bodyWeight","fontWeight","bodyFont","fonts","isSystemBodyFont","flexDirection","alignItems","borderWidth","hairlineWidth","borderColor","height","paddingHorizontal","spacing","gap","true","false","opacity","uni__dependencies","width","hasGlow","focusColor","undefined","boxShadow","offsetX","offsetY","blurRadius","spreadDistance","backgroundColor","borderRadius","flex","paddingVertical","fontFamily","fontSize"],"sourceRoot":"../../../../../src","sources":["components/input/parts/InputField.tsx"],"mappings":";;;;AAAA,SAA4BA,UAAU,QAAQ,OAAO;AAGrD,SAASC,UAAU,EAAEC,YAAY,QAAQ,wBAAwB;AAGjE,SAASC,iBAAiB;AAC1B,SAASC,iBAAiB,EAAEC,WAAW;AACvC,SAASC,aAAa;AAAmC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAGzD;AACA,OAAO,MAAMC,YAAuC,GAAG;EAAEC,EAAE,EAAE,EAAE;EAAEC,EAAE,EAAE,EAAE;EAAEC,EAAE,EAAE;AAAG,CAAC;;AAEjF;AACA,MAAMC,YAAmE,GAAG;EAC1EH,EAAE,EAAE,aAAa;EACjBC,EAAE,EAAE,SAAS;EACbC,EAAE,EAAE;AACN,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,MAAME,UAAU,gBAAGhB,UAAU,CAAiD,SAASgB,UAAUA,CACtG;EACEC,IAAI,GAAG,IAAI;EACXC,UAAU,G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C,UAAU,EAAE3B,gBAAgB,GAAGiB,SAAS,GAAGnB,QAAQ;MACnDD,UAAU,EAAEG,gBAAgB,GAAGxD,iBAAiB,CAACoD,UAAU,CAAC,GAAGqB,SAAS;MACxEvB,QAAQ,EAAE;QACRrC,IAAI,EAAE;UACJL,EAAE,EAAE;YAAE4E,QAAQ,EAAEpD,KAAK,CAACiB,UAAU,CAACC,QAAQ,CAACvC,YAAY,CAACH,EAAE,CAAC,CAAC4E;UAAS,CAAC;UACrE3E,EAAE,EAAE;YAAE2E,QAAQ,EAAEpD,KAAK,CAACiB,UAAU,CAACC,QAAQ,CAACvC,YAAY,CAACF,EAAE,CAAC,CAAC2E;UAAS,CAAC;UACrE1E,EAAE,EAAE;YAAE0E,QAAQ,EAAEpD,KAAK,CAACiB,UAAU,CAACC,QAAQ,CAACvC,YAAY,CAACD,EAAE,CAAC,CAAC0E;UAAS;QACtE,CAAC;QACD/C,OAAO,EAAE;UAAE6B,IAAI,EAAE,CAAC,CAAC;UAAEC,KAAK,EAAE,CAAC;QAAE,CAAC;QAChC/B,QAAQ,EAAE;UAAE8B,IAAI,EAAE,CAAC,CAAC;UAAEC,KAAK,EAAE,CAAC;QAAE;MAClC,CAAC;MAAAE,iBAAA;IACH;EACF,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import Animated, { Easing, interpolate, useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
|
|
5
|
+
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
|
6
|
+
import { resolveThemeColor } from "../../../../utils/resolve-theme-color.js";
|
|
7
|
+
import { Icon } from "../../../icon/index.js";
|
|
8
|
+
import { PressableOpacity } from "../../../pressable/index.js";
|
|
9
|
+
import { FIELD_HEIGHT } from "../../parts/InputField.js";
|
|
10
|
+
import { ICON_SIZE } from "./utils.js";
|
|
11
|
+
|
|
12
|
+
/** How long the button takes to slide in and the field to make room, in ms. */
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
const TRANSITION_MS = 250;
|
|
15
|
+
|
|
16
|
+
/** Scale the button grows from, so it pops in rather than only fading. */
|
|
17
|
+
const START_SCALE = 0.6;
|
|
18
|
+
|
|
19
|
+
/** The x runs a touch larger than the field's glyphs; it has a circle to itself. */
|
|
20
|
+
const GLYPH_EXTRA = 2;
|
|
21
|
+
/**
|
|
22
|
+
* A round button the height of the field, in a slot that opens and closes
|
|
23
|
+
* beside it. The slot stays mounted so it can animate out; while collapsed it
|
|
24
|
+
* is hidden from touch and from screen readers.
|
|
25
|
+
*/
|
|
26
|
+
export function SearchCancelButton({
|
|
27
|
+
isVisible,
|
|
28
|
+
size,
|
|
29
|
+
background,
|
|
30
|
+
accessibilityLabel,
|
|
31
|
+
onPress
|
|
32
|
+
}) {
|
|
33
|
+
// One progress value drives the slot's width, so the field (flex: 1) gives
|
|
34
|
+
// up its room frame by frame instead of jumping when the button appears.
|
|
35
|
+
const {
|
|
36
|
+
theme
|
|
37
|
+
} = useUnistyles();
|
|
38
|
+
const progress = useSharedValue(0);
|
|
39
|
+
const diameter = FIELD_HEIGHT[size];
|
|
40
|
+
// The gap lives inside the slot, so it opens with the button and the field
|
|
41
|
+
// sits flush to the edge when the button is gone.
|
|
42
|
+
const slotWidth = diameter + theme.spacing["2"];
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
progress.value = withTiming(isVisible ? 1 : 0, {
|
|
45
|
+
duration: TRANSITION_MS,
|
|
46
|
+
easing: Easing.bezier(0.25, 0.1, 0.25, 1)
|
|
47
|
+
});
|
|
48
|
+
}, [isVisible, progress]);
|
|
49
|
+
const slotStyle = useAnimatedStyle(() => ({
|
|
50
|
+
width: progress.value * slotWidth,
|
|
51
|
+
opacity: progress.value,
|
|
52
|
+
transform: [{
|
|
53
|
+
scale: interpolate(progress.value, [0, 1], [START_SCALE, 1])
|
|
54
|
+
}]
|
|
55
|
+
}));
|
|
56
|
+
return /*#__PURE__*/_jsx(Animated.View, {
|
|
57
|
+
style: [styles.slot(isVisible), slotStyle],
|
|
58
|
+
accessibilityElementsHidden: !isVisible,
|
|
59
|
+
importantForAccessibility: isVisible ? "auto" : "no-hide-descendants",
|
|
60
|
+
children: /*#__PURE__*/_jsx(PressableOpacity, {
|
|
61
|
+
accessibilityLabel: accessibilityLabel,
|
|
62
|
+
accessibilityRole: "button",
|
|
63
|
+
onPress: onPress,
|
|
64
|
+
style: styles.button(diameter, background),
|
|
65
|
+
children: /*#__PURE__*/_jsx(Icon, {
|
|
66
|
+
name: "terra.x",
|
|
67
|
+
size: ICON_SIZE[size] + GLYPH_EXTRA,
|
|
68
|
+
color: "text.primary"
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const styles = StyleSheet.create(theme => ({
|
|
74
|
+
slot: isVisible => ({
|
|
75
|
+
flexDirection: "row",
|
|
76
|
+
justifyContent: "flex-end",
|
|
77
|
+
overflow: "hidden",
|
|
78
|
+
pointerEvents: isVisible ? "auto" : "none"
|
|
79
|
+
}),
|
|
80
|
+
// A circle the height of the field, filled and edged to match it.
|
|
81
|
+
button: (diameter, background) => ({
|
|
82
|
+
width: diameter,
|
|
83
|
+
height: diameter,
|
|
84
|
+
borderRadius: diameter / 2,
|
|
85
|
+
alignItems: "center",
|
|
86
|
+
justifyContent: "center",
|
|
87
|
+
backgroundColor: resolveThemeColor(background, theme),
|
|
88
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
89
|
+
borderColor: theme.color["border.subtle"],
|
|
90
|
+
uni__dependencies: [0]
|
|
91
|
+
})
|
|
92
|
+
}));
|
|
93
|
+
//# sourceMappingURL=SearchCancelButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","Animated","Easing","interpolate","useAnimatedStyle","useSharedValue","withTiming","StyleSheet","useUnistyles","resolveThemeColor","Icon","PressableOpacity","FIELD_HEIGHT","ICON_SIZE","jsx","_jsx","TRANSITION_MS","START_SCALE","GLYPH_EXTRA","SearchCancelButton","isVisible","size","background","accessibilityLabel","onPress","theme","progress","diameter","slotWidth","spacing","value","duration","easing","bezier","slotStyle","width","opacity","transform","scale","View","style","styles","slot","accessibilityElementsHidden","importantForAccessibility","children","accessibilityRole","button","name","color","create","flexDirection","justifyContent","overflow","pointerEvents","height","borderRadius","alignItems","backgroundColor","borderWidth","hairlineWidth","borderColor","uni__dependencies"],"sourceRoot":"../../../../../../src","sources":["components/input/variants/SearchInput/SearchCancelButton.tsx"],"mappings":";;AAAA,SAASA,SAAS,QAAQ,OAAO;AAEjC,OAAOC,QAAQ,IACbC,MAAM,EACNC,WAAW,EACXC,gBAAgB,EAChBC,cAAc,EACdC,UAAU,QACL,yBAAyB;AAChC,SAASC,UAAU,EAAEC,YAAY,QAAQ,wBAAwB;AAGjE,SAASC,iBAAiB;AAC1B,SAASC,IAAI;AACb,SAASC,gBAAgB;AACzB,SAASC,YAAY;AAErB,SAASC,SAAS;;AAElB;AAAA,SAAAC,GAAA,IAAAC,IAAA;AACA,MAAMC,aAAa,GAAG,GAAG;;AAEzB;AACA,MAAMC,WAAW,GAAG,GAAG;;AAEvB;AACA,MAAMC,WAAW,GAAG,CAAC;AAYrB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAAC;EACjCC,SAAS;EACTC,IAAI;EACJC,UAAU;EACVC,kBAAkB;EAClBC;AACuB,CAAC,EAAE;EAC1B;EACA;EACA,MAAM;IAAEC;EAAM,CAAC,GAAGjB,YAAY,CAAC,CAAC;EAChC,MAAMkB,QAAQ,GAAGrB,cAAc,CAAC,CAAC,CAAC;EAClC,MAAMsB,QAAQ,GAAGf,YAAY,CAACS,IAAI,CAAC;EACnC;EACA;EACA,MAAMO,SAAS,GAAGD,QAAQ,GAAGF,KAAK,CAACI,OAAO,CAAC,GAAG,CAAC;EAE/C7B,SAAS,CA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CAAC;AAEpB;AAEA,MAAMR,MAAM,GAAGlC,UAAU,CAAC2C,MAAM,CAAEzB,KAAK,KAAM;EAC3CiB,IAAI,EAAGtB,SAAkB,KAAM;IAC7B+B,aAAa,EAAE,KAAK;IACpBC,cAAc,EAAE,UAAU;IAC1BC,QAAQ,EAAE,QAAQ;IAClBC,aAAa,EAAElC,SAAS,GAAG,MAAM,GAAG;EACtC,CAAC,CAAC;EACF;EACA2B,MAAM,EAAEA,CAACpB,QAAgB,EAAEL,UAAsB,MAAM;IACrDa,KAAK,EAAER,QAAQ;IACf4B,MAAM,EAAE5B,QAAQ;IAChB6B,YAAY,EAAE7B,QAAQ,GAAG,CAAC;IAC1B8B,UAAU,EAAE,QAAQ;IACpBL,cAAc,EAAE,QAAQ;IACxBM,eAAe,EAAEjD,iBAAiB,CAACa,UAAU,EAAEG,KAAK,CAAC;IACrDkC,WAAW,EAAEpD,UAAU,CAACqD,aAAa;IACrCC,WAAW,EAAEpC,KAAK,CAACwB,KAAK,CAAC,eAAe,CAAC;IAAAa,iBAAA;EAC3C,CAAC;AACH,CAAC,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Pressable } from "react-native-unistyles/components/native/Pressable";
|
|
4
|
+
import { StyleSheet } from "react-native-unistyles";
|
|
5
|
+
import { Icon } from "../../../icon/index.js";
|
|
6
|
+
import { ICON_SIZE } from "./utils.js";
|
|
7
|
+
|
|
8
|
+
/** Touch expansion around the button, in dp — it is smaller than a cell. */
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
const HIT_SLOP = 8;
|
|
11
|
+
|
|
12
|
+
/** The x as a share of its disc, so it reads inside the circle. */
|
|
13
|
+
const GLYPH_RATIO = 0.6;
|
|
14
|
+
|
|
15
|
+
/** Heavier than the icon default so the small glyph stays legible on the disc. */
|
|
16
|
+
const GLYPH_STROKE_WIDTH = 3.3;
|
|
17
|
+
/**
|
|
18
|
+
* A solid disc with an x, like iOS's `xmark.circle.fill`. Sized to the field's
|
|
19
|
+
* glyphs so it sits in the trailing slot without changing the row height.
|
|
20
|
+
*/
|
|
21
|
+
export function SearchClearButton({
|
|
22
|
+
size,
|
|
23
|
+
accessibilityLabel,
|
|
24
|
+
onPress
|
|
25
|
+
}) {
|
|
26
|
+
const diameter = ICON_SIZE[size];
|
|
27
|
+
return /*#__PURE__*/_jsx(Pressable, {
|
|
28
|
+
accessibilityLabel: accessibilityLabel,
|
|
29
|
+
accessibilityRole: "button",
|
|
30
|
+
hitSlop: HIT_SLOP,
|
|
31
|
+
onPress: onPress,
|
|
32
|
+
style: styles.disc(diameter),
|
|
33
|
+
children: /*#__PURE__*/_jsx(Icon, {
|
|
34
|
+
name: "terra.x",
|
|
35
|
+
size: Math.round(diameter * GLYPH_RATIO),
|
|
36
|
+
color: "text.inverse",
|
|
37
|
+
strokeWidth: GLYPH_STROKE_WIDTH
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const styles = StyleSheet.create(theme => ({
|
|
42
|
+
disc: diameter => ({
|
|
43
|
+
width: diameter,
|
|
44
|
+
height: diameter,
|
|
45
|
+
borderRadius: diameter / 2,
|
|
46
|
+
alignItems: "center",
|
|
47
|
+
justifyContent: "center",
|
|
48
|
+
backgroundColor: theme.color["text.tertiary"],
|
|
49
|
+
uni__dependencies: [0]
|
|
50
|
+
})
|
|
51
|
+
}));
|
|
52
|
+
//# sourceMappingURL=SearchClearButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["StyleSheet","Icon","ICON_SIZE","jsx","_jsx","HIT_SLOP","GLYPH_RATIO","GLYPH_STROKE_WIDTH","SearchClearButton","size","accessibilityLabel","onPress","diameter","Pressable","accessibilityRole","hitSlop","style","styles","disc","children","name","Math","round","color","strokeWidth","create","theme","width","height","borderRadius","alignItems","justifyContent","backgroundColor","uni__dependencies"],"sourceRoot":"../../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":[]}
|
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { forwardRef, useCallback, useState } from "react";
|
|
3
|
+
import { View } from "react-native-unistyles/components/native/View";
|
|
4
|
+
import { forwardRef, useCallback, useImperativeHandle, useRef, useState } from "react";
|
|
5
5
|
import { StyleSheet } from "react-native-unistyles";
|
|
6
6
|
import { Icon } from "../../../icon/index.js";
|
|
7
|
+
import { useFocusState } from "../../hooks/use-focus-state.js";
|
|
7
8
|
import { InputField } from "../../parts/InputField.js";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
md: 18,
|
|
13
|
-
lg: 20
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/** Touch expansion around the clear button, in dp — it is smaller than a cell. */
|
|
17
|
-
const CLEAR_HIT_SLOP = 8;
|
|
9
|
+
import { SearchCancelButton } from "./SearchCancelButton.js";
|
|
10
|
+
import { SearchClearButton } from "./SearchClearButton.js";
|
|
11
|
+
import { ICON_SIZE } from "./utils.js";
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
13
|
/**
|
|
19
14
|
* A search field: a leading magnifier, and a clear button that appears as soon
|
|
20
15
|
* as there is text. Controlled through `value` or left to manage its own, and
|
|
21
|
-
* it defaults to the search return key so the keyboard reads correctly.
|
|
16
|
+
* it defaults to the search return key so the keyboard reads correctly. With
|
|
17
|
+
* `hasCancelButton`, a round cancel button slides in beside it while focused.
|
|
22
18
|
*
|
|
23
19
|
* @example
|
|
24
20
|
* ```tsx
|
|
25
21
|
* <Input.Search value={query} onChangeText={setQuery} onSubmitEditing={run} />
|
|
22
|
+
* <Input.Search hasCancelButton onCancelPress={() => setQuery("")} />
|
|
26
23
|
* ```
|
|
27
24
|
*/
|
|
28
25
|
export const SearchInput = /*#__PURE__*/forwardRef(function SearchInput({
|
|
@@ -32,14 +29,27 @@ export const SearchInput = /*#__PURE__*/forwardRef(function SearchInput({
|
|
|
32
29
|
onClear,
|
|
33
30
|
isClearable = true,
|
|
34
31
|
clearAccessibilityLabel = "Clear search",
|
|
32
|
+
hasCancelButton = false,
|
|
33
|
+
onCancelPress,
|
|
34
|
+
cancelAccessibilityLabel = "Cancel search",
|
|
35
35
|
placeholder = "Search",
|
|
36
36
|
isDisabled = false,
|
|
37
37
|
size = "md",
|
|
38
38
|
radius = "full",
|
|
39
|
+
background = "surface.sunken",
|
|
40
|
+
hasFocusGlow = true,
|
|
39
41
|
returnKeyType = "search",
|
|
40
42
|
clearButtonMode = "never",
|
|
43
|
+
style,
|
|
44
|
+
onFocus,
|
|
45
|
+
onBlur,
|
|
41
46
|
...rest
|
|
42
47
|
}, ref) {
|
|
48
|
+
// The cancel button needs the native input to blur it, and the caller still
|
|
49
|
+
// gets the same instance through the forwarded ref.
|
|
50
|
+
const inputRef = useRef(null);
|
|
51
|
+
useImperativeHandle(ref, () => inputRef.current);
|
|
52
|
+
|
|
43
53
|
// The clear button only exists while there is text, so an uncontrolled field
|
|
44
54
|
// still has to be tracked. That state also has to drive the native input:
|
|
45
55
|
// resetting it alone would hide the button while the text stayed on screen,
|
|
@@ -48,6 +58,21 @@ export const SearchInput = /*#__PURE__*/forwardRef(function SearchInput({
|
|
|
48
58
|
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue ?? "");
|
|
49
59
|
const isControlled = value !== undefined;
|
|
50
60
|
const text = isControlled ? value : uncontrolledValue;
|
|
61
|
+
// Ending the edit makes iOS commit any pending autocorrect suggestion as one
|
|
62
|
+
// last `onChangeText`. `onCancelPress` waits for the blur event, which comes
|
|
63
|
+
// after it, so a query cleared there is not overwritten by the late commit.
|
|
64
|
+
const isCancellingRef = useRef(false);
|
|
65
|
+
const handleBlurAfterCancel = useCallback(event => {
|
|
66
|
+
onBlur?.(event);
|
|
67
|
+
if (!isCancellingRef.current) return;
|
|
68
|
+
isCancellingRef.current = false;
|
|
69
|
+
onCancelPress?.();
|
|
70
|
+
}, [onBlur, onCancelPress]);
|
|
71
|
+
const {
|
|
72
|
+
isFocused,
|
|
73
|
+
handleFocus,
|
|
74
|
+
handleBlur
|
|
75
|
+
} = useFocusState(onFocus, handleBlurAfterCancel);
|
|
51
76
|
const handleChangeText = useCallback(next => {
|
|
52
77
|
if (!isControlled) setUncontrolledValue(next);
|
|
53
78
|
onChangeText?.(next);
|
|
@@ -57,12 +82,25 @@ export const SearchInput = /*#__PURE__*/forwardRef(function SearchInput({
|
|
|
57
82
|
onChangeText?.("");
|
|
58
83
|
onClear?.();
|
|
59
84
|
}, [isControlled, onChangeText, onClear]);
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
85
|
+
const handleCancel = useCallback(() => {
|
|
86
|
+
const input = inputRef.current;
|
|
87
|
+
// No blur event will come for a field that is not focused, so call through.
|
|
88
|
+
if (!input?.isFocused()) {
|
|
89
|
+
onCancelPress?.();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
isCancellingRef.current = true;
|
|
93
|
+
input.blur();
|
|
94
|
+
}, [onCancelPress]);
|
|
95
|
+
const showsClear = isClearable && text.length > 0 && !isDisabled;
|
|
96
|
+
const showsCancel = isFocused && !isDisabled;
|
|
97
|
+
const field = /*#__PURE__*/_jsx(InputField, {
|
|
98
|
+
ref: inputRef,
|
|
63
99
|
size: size,
|
|
64
100
|
radius: radius,
|
|
101
|
+
background: background,
|
|
65
102
|
isDisabled: isDisabled,
|
|
103
|
+
hasFocusGlow: hasFocusGlow,
|
|
66
104
|
placeholder: placeholder,
|
|
67
105
|
returnKeyType: returnKeyType
|
|
68
106
|
// iOS's native clear button would sit beside ours; ours is the
|
|
@@ -71,30 +109,47 @@ export const SearchInput = /*#__PURE__*/forwardRef(function SearchInput({
|
|
|
71
109
|
clearButtonMode: clearButtonMode,
|
|
72
110
|
value: text,
|
|
73
111
|
onChangeText: handleChangeText,
|
|
112
|
+
onFocus: handleFocus,
|
|
113
|
+
onBlur: handleBlur,
|
|
74
114
|
leading: /*#__PURE__*/_jsx(Icon, {
|
|
75
115
|
name: "terra.search",
|
|
76
116
|
size: ICON_SIZE[size],
|
|
77
117
|
color: "text.tertiary"
|
|
78
118
|
}),
|
|
79
|
-
trailing:
|
|
119
|
+
trailing: showsClear ? /*#__PURE__*/_jsx(SearchClearButton, {
|
|
120
|
+
size: size,
|
|
80
121
|
accessibilityLabel: clearAccessibilityLabel,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
name: "terra.x",
|
|
87
|
-
size: ICON_SIZE[size],
|
|
88
|
-
color: "text.tertiary"
|
|
89
|
-
})
|
|
90
|
-
}) : undefined,
|
|
122
|
+
onPress: handleClear
|
|
123
|
+
}) : undefined
|
|
124
|
+
// With a cancel button the row is the outer element, so `style` moves there.
|
|
125
|
+
,
|
|
126
|
+
style: hasCancelButton ? undefined : style,
|
|
91
127
|
...rest
|
|
92
128
|
});
|
|
129
|
+
|
|
130
|
+
// Without a cancel button the field renders bare, so its layout is unchanged.
|
|
131
|
+
if (!hasCancelButton) return field;
|
|
132
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
133
|
+
style: [styles.row, style],
|
|
134
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
135
|
+
style: styles.fieldSlot,
|
|
136
|
+
children: field
|
|
137
|
+
}), /*#__PURE__*/_jsx(SearchCancelButton, {
|
|
138
|
+
isVisible: showsCancel,
|
|
139
|
+
size: size,
|
|
140
|
+
background: background,
|
|
141
|
+
accessibilityLabel: cancelAccessibilityLabel,
|
|
142
|
+
onPress: handleCancel
|
|
143
|
+
})]
|
|
144
|
+
});
|
|
93
145
|
});
|
|
94
146
|
const styles = StyleSheet.create(() => ({
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
147
|
+
row: {
|
|
148
|
+
flexDirection: "row",
|
|
149
|
+
alignItems: "center"
|
|
150
|
+
},
|
|
151
|
+
fieldSlot: {
|
|
152
|
+
flex: 1
|
|
98
153
|
}
|
|
99
154
|
}));
|
|
100
155
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["forwardRef","useCallback","useState","StyleSheet","Icon","InputField","
|
|
1
|
+
{"version":3,"names":["forwardRef","useCallback","useImperativeHandle","useRef","useState","StyleSheet","Icon","useFocusState","InputField","SearchCancelButton","SearchClearButton","ICON_SIZE","jsx","_jsx","jsxs","_jsxs","SearchInput","value","defaultValue","onChangeText","onClear","isClearable","clearAccessibilityLabel","hasCancelButton","onCancelPress","cancelAccessibilityLabel","placeholder","isDisabled","size","radius","background","hasFocusGlow","returnKeyType","clearButtonMode","style","onFocus","onBlur","rest","ref","inputRef","current","uncontrolledValue","setUncontrolledValue","isControlled","undefined","text","isCancellingRef","handleBlurAfterCancel","event","isFocused","handleFocus","handleBlur","handleChangeText","next","handleClear","handleCancel","input","blur","showsClear","length","showsCancel","field","leading","name","color","trailing","accessibilityLabel","onPress","View","styles","row","children","fieldSlot","isVisible","create","flexDirection","alignItems","flex"],"sourceRoot":"../../../../../../src","sources":["components/input/variants/SearchInput/index.tsx"],"mappings":";;;AAAA,SAA4BA,UAAU,EAAEC,WAAW,EAAEC,mBAAmB,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAGzG,SAASC,UAAU,QAAQ,wBAAwB;AAEnD,SAASC,IAAI;AACb,SAASC,aAAa;AACtB,SAASC,UAAU;AAEnB,SAASC,kBAAkB;AAC3B,SAASC,iBAAiB;AAC1B,SAASC,SAAS;AAAkB,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AA0BpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,WAAW,gBAAGhB,UAAU,CAAmD,SAASgB,WAAWA,CAC1G;EACEC,KAAK;EACLC,YAAY;EACZC,YAAY;EACZC,OAAO;EACPC,WAAW,GAAG,IAAI;EAClBC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UAAW;IACnBW,OAAO,eAAEjD,IAAA,CAACP,IAAI;MAACyD,IAAI,EAAC,cAAc;MAACnC,IAAI,EAAEjB,SAAS,CAACiB,IAAI,CAAE;MAACoC,KAAK,EAAC;IAAe,CAAE,CAAE;IACnFC,QAAQ,EACNP,UAAU,gBACR7C,IAAA,CAACH,iBAAiB;MAACkB,IAAI,EAAEA,IAAK;MAACsC,kBAAkB,EAAE5C,uBAAwB;MAAC6C,OAAO,EAAEb;IAAY,CAAE,CAAC,GAClGV;IAEN;IAAA;IACAV,KAAK,EAAEX,eAAe,GAAGqB,SAAS,GAAGV,KAAM;IAAA,GACvCG;EAAI,CACT,CACF;;EAED;EACA,IAAI,CAACd,eAAe,EAAE,OAAOsC,KAAK;EAElC,oBACE9C,KAAA,CAACqD,IAAI;IAAClC,KAAK,EAAE,CAACmC,MAAM,CAACC,GAAG,EAAEpC,KAAK,CAAE;IAAAqC,QAAA,gBAC/B1D,IAAA,CAACuD,IAAI;MAAClC,KAAK,EAAEmC,MAAM,CAACG,SAAU;MAAAD,QAAA,EAAEV;IAAK,CAAO,CAAC,eAC7ChD,IAAA,CAACJ,kBAAkB;MACjBgE,SAAS,EAAEb,WAAY;MACvBhC,IAAI,EAAEA,IAAK;MACXE,UAAU,EAAEA,UAAW;MACvBoC,kBAAkB,EAAEzC,wBAAyB;MAC7C0C,OAAO,EAAEZ;IAAa,CACvB,CAAC;EAAA,CACE,CAAC;AAEX,CAAC,CAAC;AAEF,MAAMc,MAAM,GAAGhE,UAAU,CAACqE,MAAM,CAAC,OAAO;EACtCJ,GAAG,EAAE;IACHK,aAAa,EAAE,KAAK;IACpBC,UAAU,EAAE;EACd,CAAC;EACDJ,SAAS,EAAE;IACTK,IAAI,EAAE;EACR;AACF,CAAC,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ICON_SIZE","sm","md","lg"],"sourceRoot":"../../../../../../src","sources":["components/input/variants/SearchInput/utils.ts"],"mappings":";;AAEA;AACA,OAAO,MAAMA,SAAoC,GAAG;EAAEC,EAAE,EAAE,EAAE;EAAEC,EAAE,EAAE,EAAE;EAAEC,EAAE,EAAE;AAAG,CAAC","ignoreList":[]}
|
|
@@ -124,7 +124,11 @@ const ScreenListBase = /*#__PURE__*/forwardRef(function ScreenList({
|
|
|
124
124
|
*/,
|
|
125
125
|
contentInsetAdjustmentBehavior: platformAdjustsInsets ? "automatic" : "never",
|
|
126
126
|
automaticallyAdjustContentInsets: false,
|
|
127
|
-
automaticallyAdjustsScrollIndicatorInsets: false
|
|
127
|
+
automaticallyAdjustsScrollIndicatorInsets: false
|
|
128
|
+
// iOS: inset by the keyboard so a focused field can scroll above it.
|
|
129
|
+
,
|
|
130
|
+
automaticallyAdjustKeyboardInsets: true,
|
|
131
|
+
keyboardShouldPersistTaps: "handled",
|
|
128
132
|
contentContainerStyle: [styles.content(resolvedPadding, hasHeader, hasLargeTitle, bottomInset, extraBottomPadding, headerAccessoryHeight), contentContainerStyle],
|
|
129
133
|
ListHeaderComponent: header,
|
|
130
134
|
ListFooterComponent: footer,
|