@tamagui/focusable 1.0.1-beta.207 → 1.0.1-beta.208
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/cjs/focusableInputHOC.js +47 -44
- package/dist/cjs/focusableInputHOC.js.map +2 -2
- package/dist/esm/focusableInputHOC.js +47 -44
- package/dist/esm/focusableInputHOC.js.map +2 -2
- package/dist/jsx/focusableInputHOC.js +43 -40
- package/dist/jsx/focusableInputHOC.js.map +2 -2
- package/package.json +4 -4
- package/src/focusableInputHOC.tsx +57 -52
- package/types/focusableInputHOC.d.ts +2 -1
|
@@ -28,53 +28,56 @@ var import_react = require("react");
|
|
|
28
28
|
var import_react2 = require("react");
|
|
29
29
|
var import_registerFocusable = require("./registerFocusable");
|
|
30
30
|
function focusableInputHOC(Component) {
|
|
31
|
-
|
|
32
|
-
(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
input.setSelection
|
|
31
|
+
const component = Component.extractable(
|
|
32
|
+
(0, import_react2.forwardRef)(
|
|
33
|
+
(props, ref) => {
|
|
34
|
+
const isInput = (0, import_core.isTamaguiComponent)(Component) && Component.staticConfig.isInput;
|
|
35
|
+
const inputValue = (0, import_react.useRef)(props.value || props.defaultValue || "");
|
|
36
|
+
const inputRef = (0, import_react2.useCallback)(
|
|
37
|
+
(input) => {
|
|
38
|
+
if (!props.id)
|
|
39
|
+
return;
|
|
40
|
+
if (!input)
|
|
41
|
+
return;
|
|
42
|
+
(0, import_registerFocusable.registerFocusable)(props.id, {
|
|
43
|
+
focus: input.focus,
|
|
44
|
+
...isInput && {
|
|
45
|
+
focusAndSelect() {
|
|
46
|
+
input.focus();
|
|
47
|
+
if (input.setSelection && typeof inputValue.current === "string") {
|
|
48
|
+
input.setSelection(0, inputValue.current.length);
|
|
49
|
+
}
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
[isInput, props.id]
|
|
55
|
+
);
|
|
56
|
+
const combinedRefs = (0, import_compose_refs.composeRefs)(ref, inputRef);
|
|
57
|
+
(0, import_react2.useEffect)(() => {
|
|
58
|
+
if (!props.id)
|
|
59
|
+
return;
|
|
60
|
+
return () => {
|
|
61
|
+
(0, import_registerFocusable.unregisterFocusable)(props.id);
|
|
62
|
+
};
|
|
63
|
+
}, [props.id]);
|
|
64
|
+
const onChangeText = (0, import_core.useEvent)((value) => {
|
|
65
|
+
var _a;
|
|
66
|
+
inputValue.current = value;
|
|
67
|
+
(_a = props.onChangeText) == null ? void 0 : _a.call(props, value);
|
|
68
|
+
});
|
|
69
|
+
const finalProps = isInput ? {
|
|
70
|
+
...props,
|
|
71
|
+
onChangeText
|
|
72
|
+
} : props;
|
|
73
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {
|
|
74
|
+
ref: combinedRefs,
|
|
75
|
+
...finalProps
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
)
|
|
77
79
|
);
|
|
80
|
+
return component;
|
|
78
81
|
}
|
|
79
82
|
// Annotate the CommonJS export names for ESM import in node:
|
|
80
83
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/focusableInputHOC.tsx"],
|
|
4
|
-
"sourcesContent": ["import { composeRefs } from '@tamagui/compose-refs'\nimport { isTamaguiComponent, useEvent } from '@tamagui/core'\nimport React, { useRef } from 'react'\nimport { forwardRef, useCallback, useEffect } from 'react'\n\nimport { registerFocusable, unregisterFocusable } from './registerFocusable'\n\nexport function focusableInputHOC<A extends
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { composeRefs } from '@tamagui/compose-refs'\nimport { TamaguiComponent, isTamaguiComponent, useEvent } from '@tamagui/core'\nimport React, { useRef } from 'react'\nimport { forwardRef, useCallback, useEffect } from 'react'\n\nimport { registerFocusable, unregisterFocusable } from './registerFocusable'\n\nexport function focusableInputHOC<A extends TamaguiComponent>(Component: A): A {\n const component = Component.extractable(\n forwardRef(\n (\n props: {\n id?: string\n onChangeText?: (val: string) => void\n value?: string\n defaultValue?: string\n },\n ref\n ) => {\n const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput\n const inputValue = useRef(props.value || props.defaultValue || '')\n\n const inputRef = useCallback(\n (input) => {\n if (!props.id) return\n if (!input) return\n registerFocusable(props.id, {\n focus: input.focus,\n\n ...(isInput && {\n // react-native doesn't support programmatic .select()\n focusAndSelect() {\n input.focus()\n if (input.setSelection && typeof inputValue.current === 'string') {\n input.setSelection(0, inputValue.current.length)\n }\n },\n }),\n })\n },\n [isInput, props.id]\n )\n\n const combinedRefs = composeRefs(ref, inputRef)\n\n useEffect(() => {\n if (!props.id) return\n return () => {\n unregisterFocusable(props.id!)\n }\n }, [props.id])\n\n const onChangeText = useEvent((value) => {\n inputValue.current = value\n props.onChangeText?.(value)\n })\n\n const finalProps = isInput\n ? {\n ...props,\n onChangeText,\n }\n : props\n\n // @ts-expect-error\n return <Component ref={combinedRefs} {...finalProps} />\n }\n )\n ) as any\n\n return component\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiEe;AAjEf,0BAA4B;AAC5B,kBAA+D;AAC/D,mBAA8B;AAC9B,IAAAA,gBAAmD;AAEnD,+BAAuD;AAEhD,SAAS,kBAA8C,WAAiB;AAC7E,QAAM,YAAY,UAAU;AAAA,QAC1B;AAAA,MACE,CACE,OAMA,QACG;AACH,cAAM,cAAU,gCAAmB,SAAS,KAAK,UAAU,aAAa;AACxE,cAAM,iBAAa,qBAAO,MAAM,SAAS,MAAM,gBAAgB,EAAE;AAEjE,cAAM,eAAW;AAAA,UACf,CAAC,UAAU;AACT,gBAAI,CAAC,MAAM;AAAI;AACf,gBAAI,CAAC;AAAO;AACZ,4DAAkB,MAAM,IAAI;AAAA,cAC1B,OAAO,MAAM;AAAA,cAEb,GAAI,WAAW;AAAA,gBAEb,iBAAiB;AACf,wBAAM,MAAM;AACZ,sBAAI,MAAM,gBAAgB,OAAO,WAAW,YAAY,UAAU;AAChE,0BAAM,aAAa,GAAG,WAAW,QAAQ,MAAM;AAAA,kBACjD;AAAA,gBACF;AAAA,cACF;AAAA,YACF,CAAC;AAAA,UACH;AAAA,UACA,CAAC,SAAS,MAAM,EAAE;AAAA,QACpB;AAEA,cAAM,mBAAe,iCAAY,KAAK,QAAQ;AAE9C,qCAAU,MAAM;AACd,cAAI,CAAC,MAAM;AAAI;AACf,iBAAO,MAAM;AACX,8DAAoB,MAAM,EAAG;AAAA,UAC/B;AAAA,QACF,GAAG,CAAC,MAAM,EAAE,CAAC;AAEb,cAAM,mBAAe,sBAAS,CAAC,UAAU;AApDjD;AAqDU,qBAAW,UAAU;AACrB,sBAAM,iBAAN,+BAAqB;AAAA,QACvB,CAAC;AAED,cAAM,aAAa,UACf;AAAA,UACE,GAAG;AAAA,UACH;AAAA,QACF,IACA;AAGJ,eAAO,4CAAC;AAAA,UAAU,KAAK;AAAA,UAAe,GAAG;AAAA,SAAY;AAAA,MACvD;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": ["import_react"]
|
|
7
7
|
}
|
|
@@ -5,53 +5,56 @@ import { useRef } from "react";
|
|
|
5
5
|
import { forwardRef, useCallback, useEffect } from "react";
|
|
6
6
|
import { registerFocusable, unregisterFocusable } from "./registerFocusable";
|
|
7
7
|
function focusableInputHOC(Component) {
|
|
8
|
-
|
|
9
|
-
(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
input.setSelection
|
|
8
|
+
const component = Component.extractable(
|
|
9
|
+
forwardRef(
|
|
10
|
+
(props, ref) => {
|
|
11
|
+
const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput;
|
|
12
|
+
const inputValue = useRef(props.value || props.defaultValue || "");
|
|
13
|
+
const inputRef = useCallback(
|
|
14
|
+
(input) => {
|
|
15
|
+
if (!props.id)
|
|
16
|
+
return;
|
|
17
|
+
if (!input)
|
|
18
|
+
return;
|
|
19
|
+
registerFocusable(props.id, {
|
|
20
|
+
focus: input.focus,
|
|
21
|
+
...isInput && {
|
|
22
|
+
focusAndSelect() {
|
|
23
|
+
input.focus();
|
|
24
|
+
if (input.setSelection && typeof inputValue.current === "string") {
|
|
25
|
+
input.setSelection(0, inputValue.current.length);
|
|
26
|
+
}
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
[isInput, props.id]
|
|
32
|
+
);
|
|
33
|
+
const combinedRefs = composeRefs(ref, inputRef);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!props.id)
|
|
36
|
+
return;
|
|
37
|
+
return () => {
|
|
38
|
+
unregisterFocusable(props.id);
|
|
39
|
+
};
|
|
40
|
+
}, [props.id]);
|
|
41
|
+
const onChangeText = useEvent((value) => {
|
|
42
|
+
var _a;
|
|
43
|
+
inputValue.current = value;
|
|
44
|
+
(_a = props.onChangeText) == null ? void 0 : _a.call(props, value);
|
|
45
|
+
});
|
|
46
|
+
const finalProps = isInput ? {
|
|
47
|
+
...props,
|
|
48
|
+
onChangeText
|
|
49
|
+
} : props;
|
|
50
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
51
|
+
ref: combinedRefs,
|
|
52
|
+
...finalProps
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
)
|
|
54
56
|
);
|
|
57
|
+
return component;
|
|
55
58
|
}
|
|
56
59
|
export {
|
|
57
60
|
focusableInputHOC
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/focusableInputHOC.tsx"],
|
|
4
|
-
"sourcesContent": ["import { composeRefs } from '@tamagui/compose-refs'\nimport { isTamaguiComponent, useEvent } from '@tamagui/core'\nimport React, { useRef } from 'react'\nimport { forwardRef, useCallback, useEffect } from 'react'\n\nimport { registerFocusable, unregisterFocusable } from './registerFocusable'\n\nexport function focusableInputHOC<A extends
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { composeRefs } from '@tamagui/compose-refs'\nimport { TamaguiComponent, isTamaguiComponent, useEvent } from '@tamagui/core'\nimport React, { useRef } from 'react'\nimport { forwardRef, useCallback, useEffect } from 'react'\n\nimport { registerFocusable, unregisterFocusable } from './registerFocusable'\n\nexport function focusableInputHOC<A extends TamaguiComponent>(Component: A): A {\n const component = Component.extractable(\n forwardRef(\n (\n props: {\n id?: string\n onChangeText?: (val: string) => void\n value?: string\n defaultValue?: string\n },\n ref\n ) => {\n const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput\n const inputValue = useRef(props.value || props.defaultValue || '')\n\n const inputRef = useCallback(\n (input) => {\n if (!props.id) return\n if (!input) return\n registerFocusable(props.id, {\n focus: input.focus,\n\n ...(isInput && {\n // react-native doesn't support programmatic .select()\n focusAndSelect() {\n input.focus()\n if (input.setSelection && typeof inputValue.current === 'string') {\n input.setSelection(0, inputValue.current.length)\n }\n },\n }),\n })\n },\n [isInput, props.id]\n )\n\n const combinedRefs = composeRefs(ref, inputRef)\n\n useEffect(() => {\n if (!props.id) return\n return () => {\n unregisterFocusable(props.id!)\n }\n }, [props.id])\n\n const onChangeText = useEvent((value) => {\n inputValue.current = value\n props.onChangeText?.(value)\n })\n\n const finalProps = isInput\n ? {\n ...props,\n onChangeText,\n }\n : props\n\n // @ts-expect-error\n return <Component ref={combinedRefs} {...finalProps} />\n }\n )\n ) as any\n\n return component\n}\n"],
|
|
5
|
+
"mappings": "AAiEe;AAjEf,SAAS,mBAAmB;AAC5B,SAA2B,oBAAoB,gBAAgB;AAC/D,SAAgB,cAAc;AAC9B,SAAS,YAAY,aAAa,iBAAiB;AAEnD,SAAS,mBAAmB,2BAA2B;AAEhD,SAAS,kBAA8C,WAAiB;AAC7E,QAAM,YAAY,UAAU;AAAA,IAC1B;AAAA,MACE,CACE,OAMA,QACG;AACH,cAAM,UAAU,mBAAmB,SAAS,KAAK,UAAU,aAAa;AACxE,cAAM,aAAa,OAAO,MAAM,SAAS,MAAM,gBAAgB,EAAE;AAEjE,cAAM,WAAW;AAAA,UACf,CAAC,UAAU;AACT,gBAAI,CAAC,MAAM;AAAI;AACf,gBAAI,CAAC;AAAO;AACZ,8BAAkB,MAAM,IAAI;AAAA,cAC1B,OAAO,MAAM;AAAA,cAEb,GAAI,WAAW;AAAA,gBAEb,iBAAiB;AACf,wBAAM,MAAM;AACZ,sBAAI,MAAM,gBAAgB,OAAO,WAAW,YAAY,UAAU;AAChE,0BAAM,aAAa,GAAG,WAAW,QAAQ,MAAM;AAAA,kBACjD;AAAA,gBACF;AAAA,cACF;AAAA,YACF,CAAC;AAAA,UACH;AAAA,UACA,CAAC,SAAS,MAAM,EAAE;AAAA,QACpB;AAEA,cAAM,eAAe,YAAY,KAAK,QAAQ;AAE9C,kBAAU,MAAM;AACd,cAAI,CAAC,MAAM;AAAI;AACf,iBAAO,MAAM;AACX,gCAAoB,MAAM,EAAG;AAAA,UAC/B;AAAA,QACF,GAAG,CAAC,MAAM,EAAE,CAAC;AAEb,cAAM,eAAe,SAAS,CAAC,UAAU;AApDjD;AAqDU,qBAAW,UAAU;AACrB,sBAAM,iBAAN,+BAAqB;AAAA,QACvB,CAAC;AAED,cAAM,aAAa,UACf;AAAA,UACE,GAAG;AAAA,UACH;AAAA,QACF,IACA;AAGJ,eAAO,oBAAC;AAAA,UAAU,KAAK;AAAA,UAAe,GAAG;AAAA,SAAY;AAAA,MACvD;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,49 +4,52 @@ import { useRef } from "react";
|
|
|
4
4
|
import { forwardRef, useCallback, useEffect } from "react";
|
|
5
5
|
import { registerFocusable, unregisterFocusable } from "./registerFocusable";
|
|
6
6
|
function focusableInputHOC(Component) {
|
|
7
|
-
|
|
8
|
-
(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
input.setSelection
|
|
7
|
+
const component = Component.extractable(
|
|
8
|
+
forwardRef(
|
|
9
|
+
(props, ref) => {
|
|
10
|
+
const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput;
|
|
11
|
+
const inputValue = useRef(props.value || props.defaultValue || "");
|
|
12
|
+
const inputRef = useCallback(
|
|
13
|
+
(input) => {
|
|
14
|
+
if (!props.id)
|
|
15
|
+
return;
|
|
16
|
+
if (!input)
|
|
17
|
+
return;
|
|
18
|
+
registerFocusable(props.id, {
|
|
19
|
+
focus: input.focus,
|
|
20
|
+
...isInput && {
|
|
21
|
+
focusAndSelect() {
|
|
22
|
+
input.focus();
|
|
23
|
+
if (input.setSelection && typeof inputValue.current === "string") {
|
|
24
|
+
input.setSelection(0, inputValue.current.length);
|
|
25
|
+
}
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
[isInput, props.id]
|
|
31
|
+
);
|
|
32
|
+
const combinedRefs = composeRefs(ref, inputRef);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!props.id)
|
|
35
|
+
return;
|
|
36
|
+
return () => {
|
|
37
|
+
unregisterFocusable(props.id);
|
|
38
|
+
};
|
|
39
|
+
}, [props.id]);
|
|
40
|
+
const onChangeText = useEvent((value) => {
|
|
41
|
+
inputValue.current = value;
|
|
42
|
+
props.onChangeText?.(value);
|
|
43
|
+
});
|
|
44
|
+
const finalProps = isInput ? {
|
|
45
|
+
...props,
|
|
46
|
+
onChangeText
|
|
47
|
+
} : props;
|
|
48
|
+
return <Component ref={combinedRefs} {...finalProps} />;
|
|
49
|
+
}
|
|
50
|
+
)
|
|
49
51
|
);
|
|
52
|
+
return component;
|
|
50
53
|
}
|
|
51
54
|
export {
|
|
52
55
|
focusableInputHOC
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/focusableInputHOC.tsx"],
|
|
4
|
-
"sourcesContent": ["import { composeRefs } from '@tamagui/compose-refs'\nimport { isTamaguiComponent, useEvent } from '@tamagui/core'\nimport React, { useRef } from 'react'\nimport { forwardRef, useCallback, useEffect } from 'react'\n\nimport { registerFocusable, unregisterFocusable } from './registerFocusable'\n\nexport function focusableInputHOC<A extends
|
|
5
|
-
"mappings": "AAAA,SAAS,mBAAmB;AAC5B,
|
|
4
|
+
"sourcesContent": ["import { composeRefs } from '@tamagui/compose-refs'\nimport { TamaguiComponent, isTamaguiComponent, useEvent } from '@tamagui/core'\nimport React, { useRef } from 'react'\nimport { forwardRef, useCallback, useEffect } from 'react'\n\nimport { registerFocusable, unregisterFocusable } from './registerFocusable'\n\nexport function focusableInputHOC<A extends TamaguiComponent>(Component: A): A {\n const component = Component.extractable(\n forwardRef(\n (\n props: {\n id?: string\n onChangeText?: (val: string) => void\n value?: string\n defaultValue?: string\n },\n ref\n ) => {\n const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput\n const inputValue = useRef(props.value || props.defaultValue || '')\n\n const inputRef = useCallback(\n (input) => {\n if (!props.id) return\n if (!input) return\n registerFocusable(props.id, {\n focus: input.focus,\n\n ...(isInput && {\n // react-native doesn't support programmatic .select()\n focusAndSelect() {\n input.focus()\n if (input.setSelection && typeof inputValue.current === 'string') {\n input.setSelection(0, inputValue.current.length)\n }\n },\n }),\n })\n },\n [isInput, props.id]\n )\n\n const combinedRefs = composeRefs(ref, inputRef)\n\n useEffect(() => {\n if (!props.id) return\n return () => {\n unregisterFocusable(props.id!)\n }\n }, [props.id])\n\n const onChangeText = useEvent((value) => {\n inputValue.current = value\n props.onChangeText?.(value)\n })\n\n const finalProps = isInput\n ? {\n ...props,\n onChangeText,\n }\n : props\n\n // @ts-expect-error\n return <Component ref={combinedRefs} {...finalProps} />\n }\n )\n ) as any\n\n return component\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAA2B,oBAAoB,gBAAgB;AAC/D,SAAgB,cAAc;AAC9B,SAAS,YAAY,aAAa,iBAAiB;AAEnD,SAAS,mBAAmB,2BAA2B;AAEhD,SAAS,kBAA8C,WAAiB;AAC7E,QAAM,YAAY,UAAU;AAAA,IAC1B;AAAA,MACE,CACE,OAMA,QACG;AACH,cAAM,UAAU,mBAAmB,SAAS,KAAK,UAAU,aAAa;AACxE,cAAM,aAAa,OAAO,MAAM,SAAS,MAAM,gBAAgB,EAAE;AAEjE,cAAM,WAAW;AAAA,UACf,CAAC,UAAU;AACT,gBAAI,CAAC,MAAM;AAAI;AACf,gBAAI,CAAC;AAAO;AACZ,8BAAkB,MAAM,IAAI;AAAA,cAC1B,OAAO,MAAM;AAAA,cAEb,GAAI,WAAW;AAAA,gBAEb,iBAAiB;AACf,wBAAM,MAAM;AACZ,sBAAI,MAAM,gBAAgB,OAAO,WAAW,YAAY,UAAU;AAChE,0BAAM,aAAa,GAAG,WAAW,QAAQ,MAAM;AAAA,kBACjD;AAAA,gBACF;AAAA,cACF;AAAA,YACF,CAAC;AAAA,UACH;AAAA,UACA,CAAC,SAAS,MAAM,EAAE;AAAA,QACpB;AAEA,cAAM,eAAe,YAAY,KAAK,QAAQ;AAE9C,kBAAU,MAAM;AACd,cAAI,CAAC,MAAM;AAAI;AACf,iBAAO,MAAM;AACX,gCAAoB,MAAM,EAAG;AAAA,UAC/B;AAAA,QACF,GAAG,CAAC,MAAM,EAAE,CAAC;AAEb,cAAM,eAAe,SAAS,CAAC,UAAU;AACvC,qBAAW,UAAU;AACrB,gBAAM,eAAe,KAAK;AAAA,QAC5B,CAAC;AAED,cAAM,aAAa,UACf;AAAA,UACE,GAAG;AAAA,UACH;AAAA,QACF,IACA;AAGJ,eAAO,CAAC,UAAU,KAAK,kBAAkB,YAAY;AAAA,MACvD;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/focusable",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.208",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"clean:build": "tamagui-build clean:build"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@tamagui/compose-refs": "^1.0.1-beta.
|
|
26
|
-
"@tamagui/core": "^1.0.1-beta.
|
|
25
|
+
"@tamagui/compose-refs": "^1.0.1-beta.208",
|
|
26
|
+
"@tamagui/core": "^1.0.1-beta.208"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": "*",
|
|
30
30
|
"react-dom": "*"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
33
|
+
"@tamagui/build": "^1.0.1-beta.208",
|
|
34
34
|
"react": "*",
|
|
35
35
|
"react-dom": "*"
|
|
36
36
|
},
|
|
@@ -1,67 +1,72 @@
|
|
|
1
1
|
import { composeRefs } from '@tamagui/compose-refs'
|
|
2
|
-
import { isTamaguiComponent, useEvent } from '@tamagui/core'
|
|
2
|
+
import { TamaguiComponent, isTamaguiComponent, useEvent } from '@tamagui/core'
|
|
3
3
|
import React, { useRef } from 'react'
|
|
4
4
|
import { forwardRef, useCallback, useEffect } from 'react'
|
|
5
5
|
|
|
6
6
|
import { registerFocusable, unregisterFocusable } from './registerFocusable'
|
|
7
7
|
|
|
8
|
-
export function focusableInputHOC<A extends
|
|
9
|
-
|
|
10
|
-
(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
ref
|
|
18
|
-
) => {
|
|
19
|
-
const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput
|
|
20
|
-
const inputValue = useRef(props.value || props.defaultValue || '')
|
|
21
|
-
|
|
22
|
-
const inputRef = useCallback(
|
|
23
|
-
(input) => {
|
|
24
|
-
if (!props.id) return
|
|
25
|
-
if (!input) return
|
|
26
|
-
registerFocusable(props.id, {
|
|
27
|
-
focus: input.focus,
|
|
28
|
-
|
|
29
|
-
...(isInput && {
|
|
30
|
-
// react-native doesn't support programmatic .select()
|
|
31
|
-
focusAndSelect() {
|
|
32
|
-
input.focus()
|
|
33
|
-
if (input.setSelection && typeof inputValue.current === 'string') {
|
|
34
|
-
input.setSelection(0, inputValue.current.length)
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
}),
|
|
38
|
-
})
|
|
8
|
+
export function focusableInputHOC<A extends TamaguiComponent>(Component: A): A {
|
|
9
|
+
const component = Component.extractable(
|
|
10
|
+
forwardRef(
|
|
11
|
+
(
|
|
12
|
+
props: {
|
|
13
|
+
id?: string
|
|
14
|
+
onChangeText?: (val: string) => void
|
|
15
|
+
value?: string
|
|
16
|
+
defaultValue?: string
|
|
39
17
|
},
|
|
40
|
-
|
|
41
|
-
)
|
|
18
|
+
ref
|
|
19
|
+
) => {
|
|
20
|
+
const isInput = isTamaguiComponent(Component) && Component.staticConfig.isInput
|
|
21
|
+
const inputValue = useRef(props.value || props.defaultValue || '')
|
|
42
22
|
|
|
43
|
-
|
|
23
|
+
const inputRef = useCallback(
|
|
24
|
+
(input) => {
|
|
25
|
+
if (!props.id) return
|
|
26
|
+
if (!input) return
|
|
27
|
+
registerFocusable(props.id, {
|
|
28
|
+
focus: input.focus,
|
|
44
29
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
30
|
+
...(isInput && {
|
|
31
|
+
// react-native doesn't support programmatic .select()
|
|
32
|
+
focusAndSelect() {
|
|
33
|
+
input.focus()
|
|
34
|
+
if (input.setSelection && typeof inputValue.current === 'string') {
|
|
35
|
+
input.setSelection(0, inputValue.current.length)
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
})
|
|
40
|
+
},
|
|
41
|
+
[isInput, props.id]
|
|
42
|
+
)
|
|
51
43
|
|
|
52
|
-
|
|
53
|
-
inputValue.current = value
|
|
54
|
-
props.onChangeText?.(value)
|
|
55
|
-
})
|
|
44
|
+
const combinedRefs = composeRefs(ref, inputRef)
|
|
56
45
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!props.id) return
|
|
48
|
+
return () => {
|
|
49
|
+
unregisterFocusable(props.id!)
|
|
61
50
|
}
|
|
62
|
-
|
|
51
|
+
}, [props.id])
|
|
63
52
|
|
|
64
|
-
|
|
65
|
-
|
|
53
|
+
const onChangeText = useEvent((value) => {
|
|
54
|
+
inputValue.current = value
|
|
55
|
+
props.onChangeText?.(value)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const finalProps = isInput
|
|
59
|
+
? {
|
|
60
|
+
...props,
|
|
61
|
+
onChangeText,
|
|
62
|
+
}
|
|
63
|
+
: props
|
|
64
|
+
|
|
65
|
+
// @ts-expect-error
|
|
66
|
+
return <Component ref={combinedRefs} {...finalProps} />
|
|
67
|
+
}
|
|
68
|
+
)
|
|
66
69
|
) as any
|
|
70
|
+
|
|
71
|
+
return component
|
|
67
72
|
}
|