@tamagui/focusable 1.125.19 → 1.125.21
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.cjs +15 -12
- package/dist/cjs/focusableInputHOC.js +16 -12
- package/dist/cjs/focusableInputHOC.js.map +1 -1
- package/dist/cjs/focusableInputHOC.native.js +22 -11
- package/dist/cjs/focusableInputHOC.native.js.map +2 -2
- package/dist/esm/focusableInputHOC.js +16 -12
- package/dist/esm/focusableInputHOC.js.map +1 -1
- package/dist/esm/focusableInputHOC.mjs +15 -12
- package/dist/esm/focusableInputHOC.mjs.map +1 -1
- package/dist/esm/focusableInputHOC.native.js +18 -11
- package/dist/esm/focusableInputHOC.native.js.map +1 -1
- package/dist/jsx/focusableInputHOC.js +16 -12
- package/dist/jsx/focusableInputHOC.js.map +1 -1
- package/dist/jsx/focusableInputHOC.mjs +15 -12
- package/dist/jsx/focusableInputHOC.mjs.map +1 -1
- package/dist/jsx/focusableInputHOC.native.js +22 -11
- package/dist/jsx/focusableInputHOC.native.js.map +2 -2
- package/package.json +4 -4
- package/src/focusableInputHOC.tsx +33 -20
- package/types/focusableInputHOC.d.ts +1 -1
- package/types/focusable.d.ts.map +0 -1
- package/types/focusableInputHOC.d.ts.map +0 -1
- package/types/index.d.ts.map +0 -1
- package/types/registerFocusable.d.ts.map +0 -1
- package/types/registerFocusable.native.d.ts.map +0 -1
|
@@ -51,24 +51,27 @@ function useFocusable({
|
|
|
51
51
|
} = props,
|
|
52
52
|
inputValue = import_react.default.useRef(value || defaultValue || ""),
|
|
53
53
|
unregisterFocusable = import_react.default.useRef(),
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
focusAndSelect = import_react.default.useCallback(input => {
|
|
55
|
+
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
56
|
+
}, []),
|
|
57
|
+
registerFocusableHandler = import_react.default.useCallback(input => {
|
|
58
|
+
!id || !input || (unregisterFocusable.current?.(), unregisterFocusable.current = (0, import_registerFocusable.registerFocusable)(id, {
|
|
56
59
|
focus: input.focus,
|
|
57
60
|
...(isInput && {
|
|
58
|
-
|
|
59
|
-
focusAndSelect() {
|
|
60
|
-
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
61
|
-
}
|
|
61
|
+
focusAndSelect: () => focusAndSelect(input)
|
|
62
62
|
})
|
|
63
63
|
}));
|
|
64
|
-
}, [isInput,
|
|
65
|
-
|
|
64
|
+
}, [id, isInput, focusAndSelect]),
|
|
65
|
+
inputRef = import_react.default.useCallback(input => {
|
|
66
|
+
input && registerFocusableHandler(input);
|
|
67
|
+
}, [registerFocusableHandler]),
|
|
68
|
+
handleChangeText = (0, import_web.useEvent)(value2 => {
|
|
69
|
+
inputValue.current = value2, onChangeText?.(value2);
|
|
70
|
+
});
|
|
66
71
|
return import_react.default.useEffect(() => () => {
|
|
67
72
|
unregisterFocusable.current?.();
|
|
68
73
|
}, []), {
|
|
69
|
-
ref:
|
|
70
|
-
onChangeText:
|
|
71
|
-
inputValue.current = value2, onChangeText?.(value2);
|
|
72
|
-
})
|
|
74
|
+
ref: import_react.default.useMemo(() => (0, import_compose_refs.composeRefs)(ref, inputRef), [ref, inputRef]),
|
|
75
|
+
onChangeText: handleChangeText
|
|
73
76
|
};
|
|
74
77
|
}
|
|
@@ -31,27 +31,31 @@ function useFocusable({
|
|
|
31
31
|
props,
|
|
32
32
|
ref
|
|
33
33
|
}) {
|
|
34
|
-
const { id, onChangeText, value, defaultValue } = props, inputValue = import_react.default.useRef(value || defaultValue || ""), unregisterFocusable = import_react.default.useRef(),
|
|
34
|
+
const { id, onChangeText, value, defaultValue } = props, inputValue = import_react.default.useRef(value || defaultValue || ""), unregisterFocusable = import_react.default.useRef(), focusAndSelect = import_react.default.useCallback((input) => {
|
|
35
|
+
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
36
|
+
}, []), registerFocusableHandler = import_react.default.useCallback(
|
|
35
37
|
(input) => {
|
|
36
|
-
id
|
|
38
|
+
!id || !input || (unregisterFocusable.current?.(), unregisterFocusable.current = (0, import_registerFocusable.registerFocusable)(id, {
|
|
37
39
|
focus: input.focus,
|
|
38
40
|
...isInput && {
|
|
39
|
-
|
|
40
|
-
focusAndSelect() {
|
|
41
|
-
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
42
|
-
}
|
|
41
|
+
focusAndSelect: () => focusAndSelect(input)
|
|
43
42
|
}
|
|
44
43
|
}));
|
|
45
44
|
},
|
|
46
|
-
[isInput,
|
|
47
|
-
),
|
|
45
|
+
[id, isInput, focusAndSelect]
|
|
46
|
+
), inputRef = import_react.default.useCallback(
|
|
47
|
+
(input) => {
|
|
48
|
+
input && registerFocusableHandler(input);
|
|
49
|
+
},
|
|
50
|
+
[registerFocusableHandler]
|
|
51
|
+
), handleChangeText = (0, import_web.useEvent)((value2) => {
|
|
52
|
+
inputValue.current = value2, onChangeText?.(value2);
|
|
53
|
+
});
|
|
48
54
|
return import_react.default.useEffect(() => () => {
|
|
49
55
|
unregisterFocusable.current?.();
|
|
50
56
|
}, []), {
|
|
51
|
-
ref:
|
|
52
|
-
onChangeText:
|
|
53
|
-
inputValue.current = value2, onChangeText?.(value2);
|
|
54
|
-
})
|
|
57
|
+
ref: import_react.default.useMemo(() => (0, import_compose_refs.composeRefs)(ref, inputRef), [ref, inputRef]),
|
|
58
|
+
onChangeText: handleChangeText
|
|
55
59
|
};
|
|
56
60
|
}
|
|
57
61
|
//# sourceMappingURL=focusableInputHOC.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/focusableInputHOC.tsx"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA4B,kCAC5B,aAA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AAAA,IACL,KAAK,aAAAA,QAAM,QAAQ,UAAM,iCAAY,KAAK,QAAQ,GAAG,CAAC,KAAK,QAAQ,CAAC;AAAA,IACpE,cAAc;AAAA,EAChB;AACF;",
|
|
5
5
|
"names": ["React", "value"]
|
|
6
6
|
}
|
|
@@ -28,31 +28,42 @@ __export(focusableInputHOC_exports, {
|
|
|
28
28
|
module.exports = __toCommonJS(focusableInputHOC_exports);
|
|
29
29
|
var import_compose_refs = require("@tamagui/compose-refs"), import_web = require("@tamagui/web"), import_react = __toESM(require("react")), import_registerFocusable = require("./registerFocusable");
|
|
30
30
|
function useFocusable(param) {
|
|
31
|
-
var { isInput, props, ref } = param, { id, onChangeText, value, defaultValue } = props, inputValue = import_react.default.useRef(value || defaultValue || ""), unregisterFocusable = import_react.default.useRef(),
|
|
31
|
+
var { isInput, props, ref } = param, { id, onChangeText, value, defaultValue } = props, inputValue = import_react.default.useRef(value || defaultValue || ""), unregisterFocusable = import_react.default.useRef(), focusAndSelect = import_react.default.useCallback(function(input) {
|
|
32
|
+
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
33
|
+
}, []), registerFocusableHandler = import_react.default.useCallback(function(input) {
|
|
32
34
|
var _unregisterFocusable_current;
|
|
33
|
-
id
|
|
35
|
+
!id || !input || ((_unregisterFocusable_current = unregisterFocusable.current) === null || _unregisterFocusable_current === void 0 || _unregisterFocusable_current.call(unregisterFocusable), unregisterFocusable.current = (0, import_registerFocusable.registerFocusable)(id, {
|
|
34
36
|
focus: input.focus,
|
|
35
37
|
...isInput && {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
38
|
+
focusAndSelect: function() {
|
|
39
|
+
return focusAndSelect(input);
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
}));
|
|
42
43
|
}, [
|
|
44
|
+
id,
|
|
43
45
|
isInput,
|
|
44
|
-
|
|
45
|
-
]),
|
|
46
|
+
focusAndSelect
|
|
47
|
+
]), inputRef = import_react.default.useCallback(function(input) {
|
|
48
|
+
input && registerFocusableHandler(input);
|
|
49
|
+
}, [
|
|
50
|
+
registerFocusableHandler
|
|
51
|
+
]), handleChangeText = (0, import_web.useEvent)(function(value2) {
|
|
52
|
+
inputValue.current = value2, onChangeText == null || onChangeText(value2);
|
|
53
|
+
});
|
|
46
54
|
return import_react.default.useEffect(function() {
|
|
47
55
|
return function() {
|
|
48
56
|
var _unregisterFocusable_current;
|
|
49
57
|
(_unregisterFocusable_current = unregisterFocusable.current) === null || _unregisterFocusable_current === void 0 || _unregisterFocusable_current.call(unregisterFocusable);
|
|
50
58
|
};
|
|
51
59
|
}, []), {
|
|
52
|
-
ref:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
ref: import_react.default.useMemo(function() {
|
|
61
|
+
return (0, import_compose_refs.composeRefs)(ref, inputRef);
|
|
62
|
+
}, [
|
|
63
|
+
ref,
|
|
64
|
+
inputRef
|
|
65
|
+
]),
|
|
66
|
+
onChangeText: handleChangeText
|
|
56
67
|
};
|
|
57
68
|
}
|
|
58
69
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Users/n8/tamagui/code/ui/focusable/src/focusableInputHOC.tsx"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;0BAA4B,kCAC5B,aAAyB,yBAEzB,eAAkB,2BAElB,2BAAkC;AAS3B,SAASA,aAAa,
|
|
5
|
-
"names": ["useFocusable", "isInput", "props", "ref", "id", "onChangeText", "value", "defaultValue", "inputValue", "React", "useRef", "unregisterFocusable", "
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;0BAA4B,kCAC5B,aAAyB,yBAEzB,eAAkB,2BAElB,2BAAkC;A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IACpEhB,cAAciB;EAChB;AACF;",
|
|
5
|
+
"names": ["useFocusable", "isInput", "props", "ref", "id", "onChangeText", "value", "defaultValue", "inputValue", "React", "useRef", "unregisterFocusable", "focusAndSelect", "useCallback", "input", "focus", "setSelection", "current", "length", "registerFocusableHandler", "registerFocusable", "inputRef", "handleChangeText", "useEvent", "useEffect", "useMemo", "composeRefs"]
|
|
6
6
|
}
|
|
@@ -7,27 +7,31 @@ function useFocusable({
|
|
|
7
7
|
props,
|
|
8
8
|
ref
|
|
9
9
|
}) {
|
|
10
|
-
const { id, onChangeText, value, defaultValue } = props, inputValue = React.useRef(value || defaultValue || ""), unregisterFocusable = React.useRef(),
|
|
10
|
+
const { id, onChangeText, value, defaultValue } = props, inputValue = React.useRef(value || defaultValue || ""), unregisterFocusable = React.useRef(), focusAndSelect = React.useCallback((input) => {
|
|
11
|
+
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
12
|
+
}, []), registerFocusableHandler = React.useCallback(
|
|
11
13
|
(input) => {
|
|
12
|
-
id
|
|
14
|
+
!id || !input || (unregisterFocusable.current?.(), unregisterFocusable.current = registerFocusable(id, {
|
|
13
15
|
focus: input.focus,
|
|
14
16
|
...isInput && {
|
|
15
|
-
|
|
16
|
-
focusAndSelect() {
|
|
17
|
-
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
18
|
-
}
|
|
17
|
+
focusAndSelect: () => focusAndSelect(input)
|
|
19
18
|
}
|
|
20
19
|
}));
|
|
21
20
|
},
|
|
22
|
-
[isInput,
|
|
23
|
-
),
|
|
21
|
+
[id, isInput, focusAndSelect]
|
|
22
|
+
), inputRef = React.useCallback(
|
|
23
|
+
(input) => {
|
|
24
|
+
input && registerFocusableHandler(input);
|
|
25
|
+
},
|
|
26
|
+
[registerFocusableHandler]
|
|
27
|
+
), handleChangeText = useEvent((value2) => {
|
|
28
|
+
inputValue.current = value2, onChangeText?.(value2);
|
|
29
|
+
});
|
|
24
30
|
return React.useEffect(() => () => {
|
|
25
31
|
unregisterFocusable.current?.();
|
|
26
32
|
}, []), {
|
|
27
|
-
ref:
|
|
28
|
-
onChangeText:
|
|
29
|
-
inputValue.current = value2, onChangeText?.(value2);
|
|
30
|
-
})
|
|
33
|
+
ref: React.useMemo(() => composeRefs(ref, inputRef), [ref, inputRef]),
|
|
34
|
+
onChangeText: handleChangeText
|
|
31
35
|
};
|
|
32
36
|
}
|
|
33
37
|
export {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/focusableInputHOC.tsx"],
|
|
4
|
-
"mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAEzB,OAAO,WAAW;AAElB,SAAS,yBAAyB;AAS3B,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AACF,
|
|
4
|
+
"mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAEzB,OAAO,WAAW;AAElB,SAAS,yBAAyB;AAS3B,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,QAAM,EAAE,IAAI,cAAc,OAAO,aAAa,IAAI,OAC5C,aAAa,MAAM,OAAO,SAAS,gBAAgB,EAAE,GACrD,sBAAsB,MAAM,OAA+B,GAE3D,iBAAiB,MAAM,YAAY,CAAC,UAAe;AACvD,UAAM,MAAM,GACR,MAAM,gBAAgB,OAAO,WAAW,WAAY,YACtD,MAAM,aAAa,GAAG,WAAW,QAAQ,MAAM;AAAA,EAEnD,GAAG,CAAC,CAAC,GAEC,2BAA2B,MAAM;AAAA,IACrC,CAAC,UAAe;AACd,MAAI,CAAC,MAAM,CAAC,UAEZ,oBAAoB,UAAU,GAC9B,oBAAoB,UAAU,kBAAkB,IAAI;AAAA,QAClD,OAAO,MAAM;AAAA,QACb,GAAI,WAAW;AAAA,UACb,gBAAgB,MAAM,eAAe,KAAK;AAAA,QAC5C;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IACA,CAAC,IAAI,SAAS,cAAc;AAAA,EAC9B,GAEM,WAAW,MAAM;AAAA,IACrB,CAAC,UAAe;AACd,MAAI,SACF,yBAAyB,KAAK;AAAA,IAElC;AAAA,IACA,CAAC,wBAAwB;AAAA,EAC3B,GAEM,mBAAmB,SAAS,CAACA,WAAkB;AACnD,eAAW,UAAUA,QACrB,eAAeA,MAAK;AAAA,EACtB,CAAC;AAED,eAAM,UAAU,MACP,MAAM;AACX,wBAAoB,UAAU;AAAA,EAChC,GACC,CAAC,CAAC,GAEE;AAAA,IACL,KAAK,MAAM,QAAQ,MAAM,YAAY,KAAK,QAAQ,GAAG,CAAC,KAAK,QAAQ,CAAC;AAAA,IACpE,cAAc;AAAA,EAChB;AACF;",
|
|
5
5
|
"names": ["value"]
|
|
6
6
|
}
|
|
@@ -15,25 +15,28 @@ function useFocusable({
|
|
|
15
15
|
} = props,
|
|
16
16
|
inputValue = React.useRef(value || defaultValue || ""),
|
|
17
17
|
unregisterFocusable = React.useRef(),
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
focusAndSelect = React.useCallback(input => {
|
|
19
|
+
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
20
|
+
}, []),
|
|
21
|
+
registerFocusableHandler = React.useCallback(input => {
|
|
22
|
+
!id || !input || (unregisterFocusable.current?.(), unregisterFocusable.current = registerFocusable(id, {
|
|
20
23
|
focus: input.focus,
|
|
21
24
|
...(isInput && {
|
|
22
|
-
|
|
23
|
-
focusAndSelect() {
|
|
24
|
-
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
25
|
-
}
|
|
25
|
+
focusAndSelect: () => focusAndSelect(input)
|
|
26
26
|
})
|
|
27
27
|
}));
|
|
28
|
-
}, [isInput,
|
|
29
|
-
|
|
28
|
+
}, [id, isInput, focusAndSelect]),
|
|
29
|
+
inputRef = React.useCallback(input => {
|
|
30
|
+
input && registerFocusableHandler(input);
|
|
31
|
+
}, [registerFocusableHandler]),
|
|
32
|
+
handleChangeText = useEvent(value2 => {
|
|
33
|
+
inputValue.current = value2, onChangeText?.(value2);
|
|
34
|
+
});
|
|
30
35
|
return React.useEffect(() => () => {
|
|
31
36
|
unregisterFocusable.current?.();
|
|
32
37
|
}, []), {
|
|
33
|
-
ref:
|
|
34
|
-
onChangeText:
|
|
35
|
-
inputValue.current = value2, onChangeText?.(value2);
|
|
36
|
-
})
|
|
38
|
+
ref: React.useMemo(() => composeRefs(ref, inputRef), [ref, inputRef]),
|
|
39
|
+
onChangeText: handleChangeText
|
|
37
40
|
};
|
|
38
41
|
}
|
|
39
42
|
export { useFocusable };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["composeRefs","useEvent","React","registerFocusable","useFocusable","isInput","props","ref","id","onChangeText","value","defaultValue","inputValue","useRef","unregisterFocusable","
|
|
1
|
+
{"version":3,"names":["composeRefs","useEvent","React","registerFocusable","useFocusable","isInput","props","ref","id","onChangeText","value","defaultValue","inputValue","useRef","unregisterFocusable","focusAndSelect","useCallback","input","focus","setSelection","current","length","registerFocusableHandler","inputRef","handleChangeText","value2","useEffect","useMemo"],"sources":["../../src/focusableInputHOC.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,WAAA,QAAmB;AAC5B,SAASC,QAAA,QAAgB;AAEzB,OAAOC,KAAA,MAAW;AAElB,SAASC,iBAAA,QAAyB;AAS3B,SAASC,aAAa;EAC3BC,OAAA;EACAC,KAAA;EACAC;AACF,GAIG;EACD,MAAM;MAAEC,EAAA;MAAIC,YAAA;MAAcC,KAAA;MAAOC;IAAa,IAAIL,KAAA;IAC5CM,UAAA,GAAaV,KAAA,CAAMW,MAAA,CAAOH,KAAA,IAASC,YAAA,IAAgB,EAAE;IACrDG,mBAAA,GAAsBZ,KAAA,CAAMW,MAAA,CAA+B;IAE3DE,cAAA,GAAiBb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putValue = React.useRef(value || defaultValue || ""),
|
|
18
18
|
unregisterFocusable = React.useRef(),
|
|
19
|
-
|
|
19
|
+
focusAndSelect = React.useCallback(function (input) {
|
|
20
|
+
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
21
|
+
}, []),
|
|
22
|
+
registerFocusableHandler = React.useCallback(function (input) {
|
|
20
23
|
var _unregisterFocusable_current;
|
|
21
|
-
id
|
|
24
|
+
!id || !input || ((_unregisterFocusable_current = unregisterFocusable.current) === null || _unregisterFocusable_current === void 0 || _unregisterFocusable_current.call(unregisterFocusable), unregisterFocusable.current = registerFocusable(id, {
|
|
22
25
|
focus: input.focus,
|
|
23
26
|
...(isInput && {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
27
|
+
focusAndSelect: function () {
|
|
28
|
+
return focusAndSelect(input);
|
|
27
29
|
}
|
|
28
30
|
})
|
|
29
31
|
}));
|
|
30
|
-
}, [isInput,
|
|
31
|
-
|
|
32
|
+
}, [id, isInput, focusAndSelect]),
|
|
33
|
+
inputRef = React.useCallback(function (input) {
|
|
34
|
+
input && registerFocusableHandler(input);
|
|
35
|
+
}, [registerFocusableHandler]),
|
|
36
|
+
handleChangeText = useEvent(function (value2) {
|
|
37
|
+
inputValue.current = value2, onChangeText?.(value2);
|
|
38
|
+
});
|
|
32
39
|
return React.useEffect(function () {
|
|
33
40
|
return function () {
|
|
34
41
|
var _unregisterFocusable_current;
|
|
35
42
|
(_unregisterFocusable_current = unregisterFocusable.current) === null || _unregisterFocusable_current === void 0 || _unregisterFocusable_current.call(unregisterFocusable);
|
|
36
43
|
};
|
|
37
44
|
}, []), {
|
|
38
|
-
ref:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
ref: React.useMemo(function () {
|
|
46
|
+
return composeRefs(ref, inputRef);
|
|
47
|
+
}, [ref, inputRef]),
|
|
48
|
+
onChangeText: handleChangeText
|
|
42
49
|
};
|
|
43
50
|
}
|
|
44
51
|
export { useFocusable };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["composeRefs","useEvent","React","registerFocusable","useFocusable","param","isInput","props","ref","id","onChangeText","value","defaultValue","inputValue","useRef","unregisterFocusable","
|
|
1
|
+
{"version":3,"names":["composeRefs","useEvent","React","registerFocusable","useFocusable","param","isInput","props","ref","id","onChangeText","value","defaultValue","inputValue","useRef","unregisterFocusable","focusAndSelect","useCallback","input","focus","setSelection","current","length","registerFocusableHandler","_unregisterFocusable_current","call","inputRef","handleChangeText","value2","useEffect","useMemo"],"sources":["../../src/focusableInputHOC.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,WAAA,QAAmB;AAC5B,SAASC,QAAA,QAAgB;AAEzB,OAAOC,KAAA,MAAW;AAElB,SAASC,iBAAA,QAAyB;AAS3B,SAASC,aAAaC,KAAA;EAC3B;MAAAC,OAAA;MAAAC,KAAA;MAAAC;IAAA,IAAAH,KAAA;IAAA;MAAAI,EAAA;MAAAC,YAAA;MAAAC,KAAA;MAAAC;IAAA,IAAAL,KAAA;IAAAM,UAAA,GAAAX,KAAA,CAAAY,MAAA,CAAAH,KAAA,IAAAC,YAAA;IAAAG,mBAAA,GAAAb,KAAA,CAAAY,MAAA;IAAAE,cAAA,GAAAd,KAAA,CAAAe,WAAA,WAAAC,KAAA;MACAA,KAAA,CAAAC,KAAA,IAAAD,KAAA,CAAAE,YAAA,WAAAP,UAAA,CAAAQ,OAAA,gBAAAH,KAAA,CAAAE,YAAA,IAAAP,UAAA,CAAAQ,OAAA,CAAAC,MAAA;IACA;IAAAC,wBAAA,GAAArB,KAAA,CAAAe,WAAA,WAAAC,KAAA;MAKC,IAAAM,4BAAA;MACD,CAAAf,EAAA,IAAQ,CAAAS,KAAI,MAAAM,4BAAkC,GAAIT,mBAC/B,CAAAM,OAAM,MAAO,QAASG,4BACnC,eAAsBA,4BAEtB,CAAAC,IAAiB,CAAAV,mBAAmB,GAAAA,mBAAe,CAAAM,OAAA,GAAAlB,iBAAA,CAAAM,EAAA;QACvDU,KAAM,EAAAD,KAAM,CACRC,KAAA;QAGF,IAACb,OAEC;UACHU,cAAe,WAAAA,CAAA;YACT,OAAOA,cAEZ,CAAAE,KAAA;UAEE;QAAa;MACE;IAC6B,IAC5CT,EACF,EACFH,OAAA,EACAU,cAAc,CAChB;IAEMU,QAAA,GAAWxB,KAAM,CAAAe,WAAA,WAAAC,KAAA;MACrBA,KAAC,IAAAK,wBAAe,CAAAL,KAAA;IACd,IAGFK,wBAAA,EACA;IAACI,gBAAA,GAAA1B,QAAwB,WAAA2B,MAAA;MAC3Bf,UAEM,CAAAQ,OAAA,GAAmBO,MAAA,EAASlB,YAAmB,GAAAkB,MAAA;IACnD;EAEF,OAAC1B,KAAA,CAAA2B,SAAA;IAED,mBAAM;MAEF,IAAAL,4BAA8B;MAE9B,CAACA,4BAEE,GAAAT,mBAAA,CAAAM,OAAA,cAAAG,4BAAA,eAAAA,4BAAA,CAAAC,IAAA,CAAAV,mBAAA;IACL;EAAoE,GACpE;IACFP,GAAA,EAAAN,KAAA,CAAA4B,OAAA;MACF,OAAA9B,WAAA,CAAAQ,GAAA,EAAAkB,QAAA","ignoreList":[]}
|
|
@@ -7,27 +7,31 @@ function useFocusable({
|
|
|
7
7
|
props,
|
|
8
8
|
ref
|
|
9
9
|
}) {
|
|
10
|
-
const { id, onChangeText, value, defaultValue } = props, inputValue = React.useRef(value || defaultValue || ""), unregisterFocusable = React.useRef(),
|
|
10
|
+
const { id, onChangeText, value, defaultValue } = props, inputValue = React.useRef(value || defaultValue || ""), unregisterFocusable = React.useRef(), focusAndSelect = React.useCallback((input) => {
|
|
11
|
+
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
12
|
+
}, []), registerFocusableHandler = React.useCallback(
|
|
11
13
|
(input) => {
|
|
12
|
-
id
|
|
14
|
+
!id || !input || (unregisterFocusable.current?.(), unregisterFocusable.current = registerFocusable(id, {
|
|
13
15
|
focus: input.focus,
|
|
14
16
|
...isInput && {
|
|
15
|
-
|
|
16
|
-
focusAndSelect() {
|
|
17
|
-
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
18
|
-
}
|
|
17
|
+
focusAndSelect: () => focusAndSelect(input)
|
|
19
18
|
}
|
|
20
19
|
}));
|
|
21
20
|
},
|
|
22
|
-
[isInput,
|
|
23
|
-
),
|
|
21
|
+
[id, isInput, focusAndSelect]
|
|
22
|
+
), inputRef = React.useCallback(
|
|
23
|
+
(input) => {
|
|
24
|
+
input && registerFocusableHandler(input);
|
|
25
|
+
},
|
|
26
|
+
[registerFocusableHandler]
|
|
27
|
+
), handleChangeText = useEvent((value2) => {
|
|
28
|
+
inputValue.current = value2, onChangeText?.(value2);
|
|
29
|
+
});
|
|
24
30
|
return React.useEffect(() => () => {
|
|
25
31
|
unregisterFocusable.current?.();
|
|
26
32
|
}, []), {
|
|
27
|
-
ref:
|
|
28
|
-
onChangeText:
|
|
29
|
-
inputValue.current = value2, onChangeText?.(value2);
|
|
30
|
-
})
|
|
33
|
+
ref: React.useMemo(() => composeRefs(ref, inputRef), [ref, inputRef]),
|
|
34
|
+
onChangeText: handleChangeText
|
|
31
35
|
};
|
|
32
36
|
}
|
|
33
37
|
export {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/focusableInputHOC.tsx"],
|
|
4
|
-
"mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAEzB,OAAO,WAAW;AAElB,SAAS,yBAAyB;AAS3B,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AACF,
|
|
4
|
+
"mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAEzB,OAAO,WAAW;AAElB,SAAS,yBAAyB;AAS3B,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,QAAM,EAAE,IAAI,cAAc,OAAO,aAAa,IAAI,OAC5C,aAAa,MAAM,OAAO,SAAS,gBAAgB,EAAE,GACrD,sBAAsB,MAAM,OAA+B,GAE3D,iBAAiB,MAAM,YAAY,CAAC,UAAe;AACvD,UAAM,MAAM,GACR,MAAM,gBAAgB,OAAO,WAAW,WAAY,YACtD,MAAM,aAAa,GAAG,WAAW,QAAQ,MAAM;AAAA,EAEnD,GAAG,CAAC,CAAC,GAEC,2BAA2B,MAAM;AAAA,IACrC,CAAC,UAAe;AACd,MAAI,CAAC,MAAM,CAAC,UAEZ,oBAAoB,UAAU,GAC9B,oBAAoB,UAAU,kBAAkB,IAAI;AAAA,QAClD,OAAO,MAAM;AAAA,QACb,GAAI,WAAW;AAAA,UACb,gBAAgB,MAAM,eAAe,KAAK;AAAA,QAC5C;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IACA,CAAC,IAAI,SAAS,cAAc;AAAA,EAC9B,GAEM,WAAW,MAAM;AAAA,IACrB,CAAC,UAAe;AACd,MAAI,SACF,yBAAyB,KAAK;AAAA,IAElC;AAAA,IACA,CAAC,wBAAwB;AAAA,EAC3B,GAEM,mBAAmB,SAAS,CAACA,WAAkB;AACnD,eAAW,UAAUA,QACrB,eAAeA,MAAK;AAAA,EACtB,CAAC;AAED,eAAM,UAAU,MACP,MAAM;AACX,wBAAoB,UAAU;AAAA,EAChC,GACC,CAAC,CAAC,GAEE;AAAA,IACL,KAAK,MAAM,QAAQ,MAAM,YAAY,KAAK,QAAQ,GAAG,CAAC,KAAK,QAAQ,CAAC;AAAA,IACpE,cAAc;AAAA,EAChB;AACF;",
|
|
5
5
|
"names": ["value"]
|
|
6
6
|
}
|
|
@@ -15,25 +15,28 @@ function useFocusable({
|
|
|
15
15
|
} = props,
|
|
16
16
|
inputValue = React.useRef(value || defaultValue || ""),
|
|
17
17
|
unregisterFocusable = React.useRef(),
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
focusAndSelect = React.useCallback(input => {
|
|
19
|
+
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
20
|
+
}, []),
|
|
21
|
+
registerFocusableHandler = React.useCallback(input => {
|
|
22
|
+
!id || !input || (unregisterFocusable.current?.(), unregisterFocusable.current = registerFocusable(id, {
|
|
20
23
|
focus: input.focus,
|
|
21
24
|
...(isInput && {
|
|
22
|
-
|
|
23
|
-
focusAndSelect() {
|
|
24
|
-
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
25
|
-
}
|
|
25
|
+
focusAndSelect: () => focusAndSelect(input)
|
|
26
26
|
})
|
|
27
27
|
}));
|
|
28
|
-
}, [isInput,
|
|
29
|
-
|
|
28
|
+
}, [id, isInput, focusAndSelect]),
|
|
29
|
+
inputRef = React.useCallback(input => {
|
|
30
|
+
input && registerFocusableHandler(input);
|
|
31
|
+
}, [registerFocusableHandler]),
|
|
32
|
+
handleChangeText = useEvent(value2 => {
|
|
33
|
+
inputValue.current = value2, onChangeText?.(value2);
|
|
34
|
+
});
|
|
30
35
|
return React.useEffect(() => () => {
|
|
31
36
|
unregisterFocusable.current?.();
|
|
32
37
|
}, []), {
|
|
33
|
-
ref:
|
|
34
|
-
onChangeText:
|
|
35
|
-
inputValue.current = value2, onChangeText?.(value2);
|
|
36
|
-
})
|
|
38
|
+
ref: React.useMemo(() => composeRefs(ref, inputRef), [ref, inputRef]),
|
|
39
|
+
onChangeText: handleChangeText
|
|
37
40
|
};
|
|
38
41
|
}
|
|
39
42
|
export { useFocusable };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["composeRefs","useEvent","React","registerFocusable","useFocusable","isInput","props","ref","id","onChangeText","value","defaultValue","inputValue","useRef","unregisterFocusable","
|
|
1
|
+
{"version":3,"names":["composeRefs","useEvent","React","registerFocusable","useFocusable","isInput","props","ref","id","onChangeText","value","defaultValue","inputValue","useRef","unregisterFocusable","focusAndSelect","useCallback","input","focus","setSelection","current","length","registerFocusableHandler","inputRef","handleChangeText","value2","useEffect","useMemo"],"sources":["../../src/focusableInputHOC.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,WAAA,QAAmB;AAC5B,SAASC,QAAA,QAAgB;AAEzB,OAAOC,KAAA,MAAW;AAElB,SAASC,iBAAA,QAAyB;AAS3B,SAASC,aAAa;EAC3BC,OAAA;EACAC,KAAA;EACAC;AACF,GAIG;EACD,MAAM;MAAEC,EAAA;MAAIC,YAAA;MAAcC,KAAA;MAAOC;IAAa,IAAIL,KAAA;IAC5CM,UAAA,GAAaV,KAAA,CAAMW,MAAA,CAAOH,KAAA,IAASC,YAAA,IAAgB,EAAE;IACrDG,mBAAA,GAAsBZ,KAAA,CAAMW,MAAA,CAA+B;IAE3DE,cAAA,GAAiBb,KAAA,CAAMc,WAAA,CAAaC,KAAA,IAAe;MACvDA,KAAA,CAAMC,KAAA,CAAM,GACRD,KAAA,CAAME,YAAA,IAAgB,OAAOP,UAAA,CAAWQ,OAAA,IAAY,YACtDH,KAAA,CAAME,YAAA,CAAa,GAAGP,UAAA,CAAWQ,OAAA,CAAQC,MAAM;IAEnD,GAAG,EAAE;IAECC,wBAAA,GAA2BpB,KAAA,CAAMc,WAAA,CACpCC,KAAA,IAAe;MACV,CAACT,EAAA,IAAM,CAACS,KAAA,KAEZH,mBAAA,CAAoBM,OAAA,GAAU,GAC9BN,mBAAA,CAAoBM,OAAA,GAAUjB,iBAAA,CAAkBK,EAAA,EAAI;QAClDU,KAAA,EAAOD,KAAA,CAAMC,KAAA;QACb,IAAIb,OAAA,IAAW;UACbU,cAAA,EAAgBA,CAAA,KAAMA,cAAA,CAAeE,KAAK;QAC5C;MACF,CAAC;IACH,GACA,CAACT,EAAA,EAAIH,OAAA,EAASU,cAAc,CAC9B;IAEMQ,QAAA,GAAWrB,KAAA,CAAMc,WAAA,CACpBC,KAAA,IAAe;MACVA,KAAA,IACFK,wBAAA,CAAyBL,KAAK;IAElC,GACA,CAACK,wBAAwB,CAC3B;IAEME,gBAAA,GAAmBvB,QAAA,CAAUwB,MAAA,IAAkB;MACnDb,UAAA,CAAWQ,OAAA,GAAUK,MAAA,EACrBhB,YAAA,GAAegB,MAAK;IACtB,CAAC;EAED,OAAAvB,KAAA,CAAMwB,SAAA,CAAU,MACP,MAAM;IACXZ,mBAAA,CAAoBM,OAAA,GAAU;EAChC,GACC,EAAE,GAEE;IACLb,GAAA,EAAKL,KAAA,CAAMyB,OAAA,CAAQ,MAAM3B,WAAA,CAAYO,GAAA,EAAKgB,QAAQ,GAAG,CAAChB,GAAA,EAAKgB,QAAQ,CAAC;IACpEd,YAAA,EAAce;EAChB;AACF","ignoreList":[]}
|
|
@@ -3,31 +3,42 @@ import { useEvent } from "@tamagui/web";
|
|
|
3
3
|
import React from "react";
|
|
4
4
|
import { registerFocusable } from "./registerFocusable";
|
|
5
5
|
function useFocusable(param) {
|
|
6
|
-
var { isInput, props, ref } = param, { id, onChangeText, value, defaultValue } = props, inputValue = React.useRef(value || defaultValue || ""), unregisterFocusable = React.useRef(),
|
|
6
|
+
var { isInput, props, ref } = param, { id, onChangeText, value, defaultValue } = props, inputValue = React.useRef(value || defaultValue || ""), unregisterFocusable = React.useRef(), focusAndSelect = React.useCallback(function(input) {
|
|
7
|
+
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
8
|
+
}, []), registerFocusableHandler = React.useCallback(function(input) {
|
|
7
9
|
var _unregisterFocusable_current;
|
|
8
|
-
id
|
|
10
|
+
!id || !input || ((_unregisterFocusable_current = unregisterFocusable.current) === null || _unregisterFocusable_current === void 0 || _unregisterFocusable_current.call(unregisterFocusable), unregisterFocusable.current = registerFocusable(id, {
|
|
9
11
|
focus: input.focus,
|
|
10
12
|
...isInput && {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
input.focus(), input.setSelection && typeof inputValue.current == "string" && input.setSelection(0, inputValue.current.length);
|
|
13
|
+
focusAndSelect: function() {
|
|
14
|
+
return focusAndSelect(input);
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
}));
|
|
17
18
|
}, [
|
|
19
|
+
id,
|
|
18
20
|
isInput,
|
|
19
|
-
|
|
20
|
-
]),
|
|
21
|
+
focusAndSelect
|
|
22
|
+
]), inputRef = React.useCallback(function(input) {
|
|
23
|
+
input && registerFocusableHandler(input);
|
|
24
|
+
}, [
|
|
25
|
+
registerFocusableHandler
|
|
26
|
+
]), handleChangeText = useEvent(function(value2) {
|
|
27
|
+
inputValue.current = value2, onChangeText == null || onChangeText(value2);
|
|
28
|
+
});
|
|
21
29
|
return React.useEffect(function() {
|
|
22
30
|
return function() {
|
|
23
31
|
var _unregisterFocusable_current;
|
|
24
32
|
(_unregisterFocusable_current = unregisterFocusable.current) === null || _unregisterFocusable_current === void 0 || _unregisterFocusable_current.call(unregisterFocusable);
|
|
25
33
|
};
|
|
26
34
|
}, []), {
|
|
27
|
-
ref:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
ref: React.useMemo(function() {
|
|
36
|
+
return composeRefs(ref, inputRef);
|
|
37
|
+
}, [
|
|
38
|
+
ref,
|
|
39
|
+
inputRef
|
|
40
|
+
]),
|
|
41
|
+
onChangeText: handleChangeText
|
|
31
42
|
};
|
|
32
43
|
}
|
|
33
44
|
export {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Users/n8/tamagui/code/ui/focusable/src/focusableInputHOC.tsx"],
|
|
4
|
-
"mappings": "AAAA,SAASA,mBAAmB;AAC5B,SAASC,gBAAgB;AAEzB,OAAOC,WAAW;AAElB,SAASC,yBAAyB;AAS3B,SAASC,aAAa,
|
|
5
|
-
"names": ["composeRefs", "useEvent", "React", "registerFocusable", "useFocusable", "isInput", "props", "ref", "id", "onChangeText", "value", "defaultValue", "inputValue", "useRef",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AAQ,WAAA;aAAM1B,YAAYO,KAAKgB,QAAAA;OAAW;MAAChB;MAAKgB;KAAS;IACpEd,cAAce;EAChB;AACF;",
|
|
5
|
+
"names": ["composeRefs", "useEvent", "React", "registerFocusable", "useFocusable", "isInput", "props", "ref", "id", "onChangeText", "value", "defaultValue", "inputValue", "useRef", "unregisterFocusable", "focusAndSelect", "useCallback", "input", "focus", "setSelection", "current", "length", "registerFocusableHandler", "inputRef", "handleChangeText", "useEffect", "useMemo"]
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/focusable",
|
|
3
|
-
"version": "1.125.
|
|
3
|
+
"version": "1.125.21",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@tamagui/compose-refs": "1.125.
|
|
39
|
-
"@tamagui/web": "1.125.
|
|
38
|
+
"@tamagui/compose-refs": "1.125.21",
|
|
39
|
+
"@tamagui/web": "1.125.21"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@tamagui/build": "1.125.
|
|
42
|
+
"@tamagui/build": "1.125.21",
|
|
43
43
|
"react": "*"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
@@ -16,34 +16,50 @@ export function useFocusable({
|
|
|
16
16
|
isInput,
|
|
17
17
|
props,
|
|
18
18
|
ref,
|
|
19
|
-
}: {
|
|
19
|
+
}: {
|
|
20
|
+
isInput?: boolean
|
|
21
|
+
props: FocusableProps
|
|
22
|
+
ref?: MutableRefObject<any>
|
|
23
|
+
}) {
|
|
20
24
|
const { id, onChangeText, value, defaultValue } = props
|
|
21
25
|
const inputValue = React.useRef(value || defaultValue || '')
|
|
22
26
|
const unregisterFocusable = React.useRef<() => void | undefined>()
|
|
23
27
|
|
|
24
|
-
const
|
|
25
|
-
(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
const focusAndSelect = React.useCallback((input: any) => {
|
|
29
|
+
input.focus()
|
|
30
|
+
if (input.setSelection && typeof inputValue.current === 'string') {
|
|
31
|
+
input.setSelection(0, inputValue.current.length)
|
|
32
|
+
}
|
|
33
|
+
}, [])
|
|
34
|
+
|
|
35
|
+
const registerFocusableHandler = React.useCallback(
|
|
36
|
+
(input: any) => {
|
|
37
|
+
if (!id || !input) return
|
|
38
|
+
|
|
28
39
|
unregisterFocusable.current?.()
|
|
29
40
|
unregisterFocusable.current = registerFocusable(id, {
|
|
30
41
|
focus: input.focus,
|
|
31
|
-
|
|
32
42
|
...(isInput && {
|
|
33
|
-
|
|
34
|
-
focusAndSelect() {
|
|
35
|
-
input.focus()
|
|
36
|
-
if (input.setSelection && typeof inputValue.current === 'string') {
|
|
37
|
-
input.setSelection(0, inputValue.current.length)
|
|
38
|
-
}
|
|
39
|
-
},
|
|
43
|
+
focusAndSelect: () => focusAndSelect(input),
|
|
40
44
|
}),
|
|
41
45
|
})
|
|
42
46
|
},
|
|
43
|
-
[isInput,
|
|
47
|
+
[id, isInput, focusAndSelect]
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
const inputRef = React.useCallback(
|
|
51
|
+
(input: any) => {
|
|
52
|
+
if (input) {
|
|
53
|
+
registerFocusableHandler(input)
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
[registerFocusableHandler]
|
|
44
57
|
)
|
|
45
58
|
|
|
46
|
-
const
|
|
59
|
+
const handleChangeText = useEvent((value: string) => {
|
|
60
|
+
inputValue.current = value
|
|
61
|
+
onChangeText?.(value)
|
|
62
|
+
})
|
|
47
63
|
|
|
48
64
|
React.useEffect(() => {
|
|
49
65
|
return () => {
|
|
@@ -52,10 +68,7 @@ export function useFocusable({
|
|
|
52
68
|
}, [])
|
|
53
69
|
|
|
54
70
|
return {
|
|
55
|
-
ref:
|
|
56
|
-
onChangeText:
|
|
57
|
-
inputValue.current = value
|
|
58
|
-
onChangeText?.(value)
|
|
59
|
-
}),
|
|
71
|
+
ref: React.useMemo(() => composeRefs(ref, inputRef), [ref, inputRef]),
|
|
72
|
+
onChangeText: handleChangeText,
|
|
60
73
|
}
|
|
61
74
|
}
|
|
@@ -11,7 +11,7 @@ export declare function useFocusable({ isInput, props, ref, }: {
|
|
|
11
11
|
ref?: MutableRefObject<any>;
|
|
12
12
|
}): {
|
|
13
13
|
ref: (node: any) => void;
|
|
14
|
-
onChangeText: (value:
|
|
14
|
+
onChangeText: (value: string) => void;
|
|
15
15
|
};
|
|
16
16
|
export {};
|
|
17
17
|
//# sourceMappingURL=focusableInputHOC.d.ts.map
|
package/types/focusable.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"focusable.d.ts","sourceRoot":"","sources":["../src/focusable.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,cAAc,CAAC,EAAE,QAAQ,CAAA;CAAE,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"focusableInputHOC.d.ts","sourceRoot":"","sources":["../src/focusableInputHOC.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AAK7C,KAAK,cAAc,GAAG;IACpB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IACpC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,wBAAgB,YAAY,CAAC,EAC3B,OAAO,EACP,KAAK,EACL,GAAG,GACJ,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,cAAc,CAAC;IAAC,GAAG,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAA;CAAE;;;EA0C3E"}
|
package/types/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registerFocusable.d.ts","sourceRoot":"","sources":["../src/registerFocusable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,eAAO,MAAM,iBAAiB,OAAQ,MAAM,SAAS,SAAS,eAE7D,CAAA;AAED,eAAO,MAAM,mBAAmB,OAAQ,MAAM,SAE7C,CAAA;AAED,eAAO,MAAM,cAAc,OAAQ,MAAM,SAExC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registerFocusable.native.d.ts","sourceRoot":"","sources":["../src/registerFocusable.native.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAI5C,eAAO,MAAM,iBAAiB,OAAQ,MAAM,SAAS,SAAS,eAU7D,CAAA;AAED,eAAO,MAAM,mBAAmB,OAAQ,MAAM,SAE7C,CAAA;AAED,eAAO,MAAM,cAAc,OAAQ,MAAM,2BAaxC,CAAA"}
|