@tamagui/use-presence 3.0.0-beta.765.1 → 3.0.0-beta.804.1
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/usePresence.cjs +17 -10
- package/dist/cjs/usePresence.native.cjs +17 -10
- package/dist/cjs/usePresence.native.js +17 -10
- package/dist/cjs/usePresence.native.js.map +1 -1
- package/dist/esm/usePresence.mjs +17 -10
- package/dist/esm/usePresence.mjs.map +1 -1
- package/dist/esm/usePresence.native.js +17 -10
- package/dist/esm/usePresence.native.js.map +1 -1
- package/package.json +3 -3
- package/src/usePresence.ts +34 -9
- package/types/usePresence.d.ts +2 -2
- package/types/usePresence.d.ts.map +2 -2
package/dist/cjs/usePresence.cjs
CHANGED
|
@@ -33,17 +33,24 @@ __export(usePresence_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(usePresence_exports);
|
|
34
34
|
var React = __toESM(require("react"), 1);
|
|
35
35
|
var import_PresenceContext = require("./PresenceContext.cjs");
|
|
36
|
-
function usePresence() {
|
|
36
|
+
function usePresence(registration) {
|
|
37
37
|
const context = React.useContext(import_PresenceContext.PresenceContext);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
const unregister = React.useRef(void 0);
|
|
39
|
+
React.useEffect(() => {
|
|
40
|
+
if (!unregister.current && context && (registration ? registration.shouldRegisterPresence : true)) {
|
|
41
|
+
unregister.current = context.register(context.id);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
React.useEffect(() => () => {
|
|
45
|
+
if (typeof unregister.current === "function") unregister.current();
|
|
46
|
+
unregister.current = void 0;
|
|
47
|
+
}, []);
|
|
48
|
+
if (!context) return [
|
|
49
|
+
true,
|
|
50
|
+
null,
|
|
51
|
+
context
|
|
52
|
+
];
|
|
53
|
+
const { id, isPresent: isPresent2, onExitComplete } = context;
|
|
47
54
|
const safeToRemove = () => onExitComplete?.(id);
|
|
48
55
|
return !isPresent2 && onExitComplete ? [
|
|
49
56
|
false,
|
|
@@ -35,19 +35,26 @@ __export(usePresence_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(usePresence_exports);
|
|
36
36
|
var React = __toESM(require("react"), 1);
|
|
37
37
|
var import_PresenceContext = require("./PresenceContext.native.js");
|
|
38
|
-
function usePresence() {
|
|
38
|
+
function usePresence(registration) {
|
|
39
39
|
var context = React.useContext(import_PresenceContext.PresenceContext);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
var { id, isPresent: isPresent2, onExitComplete, register } = context;
|
|
40
|
+
var unregister = React.useRef(void 0);
|
|
41
|
+
React.useEffect(function() {
|
|
42
|
+
if (!unregister.current && context && (registration ? registration.shouldRegisterPresence : true)) {
|
|
43
|
+
unregister.current = context.register(context.id);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
48
46
|
React.useEffect(function() {
|
|
49
|
-
return
|
|
47
|
+
return function() {
|
|
48
|
+
if (typeof unregister.current === "function") unregister.current();
|
|
49
|
+
unregister.current = void 0;
|
|
50
|
+
};
|
|
50
51
|
}, []);
|
|
52
|
+
if (!context) return [
|
|
53
|
+
true,
|
|
54
|
+
null,
|
|
55
|
+
context
|
|
56
|
+
];
|
|
57
|
+
var { id, isPresent: isPresent2, onExitComplete } = context;
|
|
51
58
|
var safeToRemove = function() {
|
|
52
59
|
return onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete(id);
|
|
53
60
|
};
|
|
@@ -35,19 +35,26 @@ __export(usePresence_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(usePresence_exports);
|
|
36
36
|
var React = __toESM(require("react"), 1);
|
|
37
37
|
var import_PresenceContext = require("./PresenceContext.native.js");
|
|
38
|
-
function usePresence() {
|
|
38
|
+
function usePresence(registration) {
|
|
39
39
|
var context = React.useContext(import_PresenceContext.PresenceContext);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
var { id, isPresent: isPresent2, onExitComplete, register } = context;
|
|
40
|
+
var unregister = React.useRef(void 0);
|
|
41
|
+
React.useEffect(function() {
|
|
42
|
+
if (!unregister.current && context && (registration ? registration.shouldRegisterPresence : true)) {
|
|
43
|
+
unregister.current = context.register(context.id);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
48
46
|
React.useEffect(function() {
|
|
49
|
-
return
|
|
47
|
+
return function() {
|
|
48
|
+
if (typeof unregister.current === "function") unregister.current();
|
|
49
|
+
unregister.current = void 0;
|
|
50
|
+
};
|
|
50
51
|
}, []);
|
|
52
|
+
if (!context) return [
|
|
53
|
+
true,
|
|
54
|
+
null,
|
|
55
|
+
context
|
|
56
|
+
];
|
|
57
|
+
var { id, isPresent: isPresent2, onExitComplete } = context;
|
|
51
58
|
var safeToRemove = function() {
|
|
52
59
|
return onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete(id);
|
|
53
60
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePresence.native.js","names":[],"sources":["cjs/usePresence.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar usePresence_exports = {};\n__export(usePresence_exports, {\n isPresent: () => isPresent,\n useIsPresent: () => useIsPresent,\n usePresence: () => usePresence\n});\nmodule.exports = __toCommonJS(usePresence_exports);\nvar React = __toESM(require(\"react\"), 1);\nvar import_PresenceContext = require(\"./PresenceContext\");\nfunction usePresence() {\n var context = React.useContext(import_PresenceContext.PresenceContext);\n
|
|
1
|
+
{"version":3,"file":"usePresence.native.js","names":[],"sources":["cjs/usePresence.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar usePresence_exports = {};\n__export(usePresence_exports, {\n isPresent: () => isPresent,\n useIsPresent: () => useIsPresent,\n usePresence: () => usePresence\n});\nmodule.exports = __toCommonJS(usePresence_exports);\nvar React = __toESM(require(\"react\"), 1);\nvar import_PresenceContext = require(\"./PresenceContext\");\nfunction usePresence(registration) {\n var context = React.useContext(import_PresenceContext.PresenceContext);\n var unregister = React.useRef(void 0);\n React.useEffect(function() {\n if (!unregister.current && context && (registration ? registration.shouldRegisterPresence : true)) {\n unregister.current = context.register(context.id);\n }\n });\n React.useEffect(function() {\n return function() {\n if (typeof unregister.current === \"function\") unregister.current();\n unregister.current = void 0;\n };\n }, []);\n if (!context) return [\n true,\n null,\n context\n ];\n var { id, isPresent: isPresent2, onExitComplete } = context;\n var safeToRemove = function() {\n return onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete(id);\n };\n return !isPresent2 && onExitComplete ? [\n false,\n safeToRemove,\n context\n ] : [\n true,\n void 0,\n context\n ];\n}\nfunction useIsPresent() {\n return isPresent(React.useContext(import_PresenceContext.PresenceContext));\n}\nfunction isPresent(context) {\n return context === null ? true : context.isPresent;\n}\n//# sourceMappingURL=usePresence.js.map\n"],"mappings":";;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO;AAC1B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,WAAW,KAAK,YAAY,YAAY,SAAS,OAAO,OAAO,SAAS,aAAa,GAAG,CAAC,IAAI,CAAC,GAAG,YAKnG,cAAc,CAAC,OAAO,CAAC,IAAI,aAAa,UAAU,QAAQ,WAAW;CAAE,OAAO;CAAK,YAAY;AAAK,CAAC,IAAI,QACzG,GACF;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,sBAAsB,CAAC;AAC3B,SAAS,qBAAqB;CAC5B,iBAAiB;CACjB,oBAAoB;CACpB,mBAAmB;AACrB,CAAC;AACD,OAAO,UAAU,aAAa,mBAAmB;AACjD,IAAI,QAAQ,QAAQ,QAAQ,OAAO,GAAG,CAAC;AACvC,IAAI,yBAAyB,QAAQ,6BAAmB;AACxD,SAAS,YAAY,cAAc;CACjC,IAAI,UAAU,MAAM,WAAW,uBAAuB,eAAe;CACrE,IAAI,aAAa,MAAM,OAAO,KAAK,CAAC;CACpC,MAAM,UAAU,WAAW;EACzB,IAAI,CAAC,WAAW,WAAW,YAAY,eAAe,aAAa,yBAAyB,OAAO;GACjG,WAAW,UAAU,QAAQ,SAAS,QAAQ,EAAE;EAClD;CACF,CAAC;CACD,MAAM,UAAU,WAAW;EACzB,OAAO,WAAW;GAChB,IAAI,OAAO,WAAW,YAAY,YAAY,WAAW,QAAQ;GACjE,WAAW,UAAU,KAAK;EAC5B;CACF,GAAG,CAAC,CAAC;CACL,IAAI,CAAC,SAAS,OAAO;EACnB;EACA;EACA;CACF;CACA,IAAI,EAAE,IAAI,WAAW,YAAY,mBAAmB;CACpD,IAAI,eAAe,WAAW;EAC5B,OAAO,mBAAmB,QAAQ,mBAAmB,KAAK,IAAI,KAAK,IAAI,eAAe,EAAE;CAC1F;CACA,OAAO,CAAC,cAAc,iBAAiB;EACrC;EACA;EACA;CACF,IAAI;EACF;EACA,KAAK;EACL;CACF;AACF;AACA,SAAS,eAAe;CACtB,OAAO,UAAU,MAAM,WAAW,uBAAuB,eAAe,CAAC;AAC3E;AACA,SAAS,UAAU,SAAS;CAC1B,OAAO,YAAY,OAAO,OAAO,QAAQ;AAC3C"}
|
package/dist/esm/usePresence.mjs
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { PresenceContext } from "./PresenceContext.mjs";
|
|
3
3
|
|
|
4
|
-
function usePresence() {
|
|
4
|
+
function usePresence(registration) {
|
|
5
5
|
const context = React.useContext(PresenceContext);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
const unregister = React.useRef(void 0);
|
|
7
|
+
React.useEffect(() => {
|
|
8
|
+
if (!unregister.current && context && (registration ? registration.shouldRegisterPresence : true)) {
|
|
9
|
+
unregister.current = context.register(context.id);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
React.useEffect(() => () => {
|
|
13
|
+
if (typeof unregister.current === "function") unregister.current();
|
|
14
|
+
unregister.current = void 0;
|
|
15
|
+
}, []);
|
|
16
|
+
if (!context) return [
|
|
17
|
+
true,
|
|
18
|
+
null,
|
|
19
|
+
context
|
|
20
|
+
];
|
|
21
|
+
const { id, isPresent: isPresent2, onExitComplete } = context;
|
|
15
22
|
const safeToRemove = () => onExitComplete?.(id);
|
|
16
23
|
return !isPresent2 && onExitComplete ? [
|
|
17
24
|
false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePresence.js","names":[],"sources":["esm/usePresence.js"],"sourcesContent":["import * as React from \"react\";\nimport { PresenceContext } from \"./PresenceContext\";\nfunction usePresence() {\n const context = React.useContext(PresenceContext);\n if (!context) {\n return [true, null, context];\n
|
|
1
|
+
{"version":3,"file":"usePresence.js","names":[],"sources":["esm/usePresence.js"],"sourcesContent":["import * as React from \"react\";\nimport { PresenceContext } from \"./PresenceContext\";\nfunction usePresence(registration) {\n const context = React.useContext(PresenceContext);\n const unregister = React.useRef(void 0);\n React.useEffect(() => {\n if (!unregister.current && context && (registration ? registration.shouldRegisterPresence : true)) {\n unregister.current = context.register(context.id);\n }\n });\n React.useEffect(\n () => () => {\n if (typeof unregister.current === \"function\") unregister.current();\n unregister.current = void 0;\n },\n []\n );\n if (!context) return [true, null, context];\n const { id, isPresent: isPresent2, onExitComplete } = context;\n const safeToRemove = () => onExitComplete?.(id);\n return !isPresent2 && onExitComplete ? [false, safeToRemove, context] : [true, void 0, context];\n}\nfunction useIsPresent() {\n return isPresent(React.useContext(PresenceContext));\n}\nfunction isPresent(context) {\n return context === null ? true : context.isPresent;\n}\nexport {\n isPresent,\n useIsPresent,\n usePresence\n};\n//# sourceMappingURL=usePresence.js.map\n"],"mappings":";;;;AAEA,SAAS,YAAY,cAAc;CACjC,MAAM,UAAU,MAAM,WAAW,eAAe;CAChD,MAAM,aAAa,MAAM,OAAO,KAAK,CAAC;CACtC,MAAM,gBAAgB;EACpB,IAAI,CAAC,WAAW,WAAW,YAAY,eAAe,aAAa,yBAAyB,OAAO;GACjG,WAAW,UAAU,QAAQ,SAAS,QAAQ,EAAE;EAClD;CACF,CAAC;CACD,MAAM,sBACQ;EACV,IAAI,OAAO,WAAW,YAAY,YAAY,WAAW,QAAQ;EACjE,WAAW,UAAU,KAAK;CAC5B,GACA,CAAC,CACH;CACA,IAAI,CAAC,SAAS,OAAO;EAAC;EAAM;EAAM;CAAO;CACzC,MAAM,EAAE,IAAI,WAAW,YAAY,mBAAmB;CACtD,MAAM,qBAAqB,iBAAiB,EAAE;CAC9C,OAAO,CAAC,cAAc,iBAAiB;EAAC;EAAO;EAAc;CAAO,IAAI;EAAC;EAAM,KAAK;EAAG;CAAO;AAChG;AACA,SAAS,eAAe;CACtB,OAAO,UAAU,MAAM,WAAW,eAAe,CAAC;AACpD;AACA,SAAS,UAAU,SAAS;CAC1B,OAAO,YAAY,OAAO,OAAO,QAAQ;AAC3C"}
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { PresenceContext } from "./PresenceContext.native.js";
|
|
3
3
|
|
|
4
|
-
function usePresence() {
|
|
4
|
+
function usePresence(registration) {
|
|
5
5
|
var context = React.useContext(PresenceContext);
|
|
6
|
-
|
|
7
|
-
return [
|
|
8
|
-
true,
|
|
9
|
-
null,
|
|
10
|
-
context
|
|
11
|
-
];
|
|
12
|
-
}
|
|
13
|
-
var { id, isPresent: isPresent2, onExitComplete, register } = context;
|
|
6
|
+
var unregister = React.useRef(void 0);
|
|
14
7
|
React.useEffect(function() {
|
|
15
|
-
|
|
8
|
+
if (!unregister.current && context && (registration ? registration.shouldRegisterPresence : true)) {
|
|
9
|
+
unregister.current = context.register(context.id);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
React.useEffect(function() {
|
|
13
|
+
return function() {
|
|
14
|
+
if (typeof unregister.current === "function") unregister.current();
|
|
15
|
+
unregister.current = void 0;
|
|
16
|
+
};
|
|
16
17
|
}, []);
|
|
18
|
+
if (!context) return [
|
|
19
|
+
true,
|
|
20
|
+
null,
|
|
21
|
+
context
|
|
22
|
+
];
|
|
23
|
+
var { id, isPresent: isPresent2, onExitComplete } = context;
|
|
17
24
|
var safeToRemove = function() {
|
|
18
25
|
return onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete(id);
|
|
19
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePresence.native.js","names":[],"sources":["esm/usePresence.native.js"],"sourcesContent":["import * as React from \"react\";\nimport { PresenceContext } from \"./PresenceContext\";\nfunction usePresence() {\n var context = React.useContext(PresenceContext);\n
|
|
1
|
+
{"version":3,"file":"usePresence.native.js","names":[],"sources":["esm/usePresence.native.js"],"sourcesContent":["import * as React from \"react\";\nimport { PresenceContext } from \"./PresenceContext\";\nfunction usePresence(registration) {\n var context = React.useContext(PresenceContext);\n var unregister = React.useRef(void 0);\n React.useEffect(function() {\n if (!unregister.current && context && (registration ? registration.shouldRegisterPresence : true)) {\n unregister.current = context.register(context.id);\n }\n });\n React.useEffect(function() {\n return function() {\n if (typeof unregister.current === \"function\") unregister.current();\n unregister.current = void 0;\n };\n }, []);\n if (!context) return [\n true,\n null,\n context\n ];\n var { id, isPresent: isPresent2, onExitComplete } = context;\n var safeToRemove = function() {\n return onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete(id);\n };\n return !isPresent2 && onExitComplete ? [\n false,\n safeToRemove,\n context\n ] : [\n true,\n void 0,\n context\n ];\n}\nfunction useIsPresent() {\n return isPresent(React.useContext(PresenceContext));\n}\nfunction isPresent(context) {\n return context === null ? true : context.isPresent;\n}\nexport {\n isPresent,\n useIsPresent,\n usePresence\n};\n//# sourceMappingURL=usePresence.js.map\n"],"mappings":";;;;AAEA,SAAS,YAAY,cAAc;CACjC,IAAI,UAAU,MAAM,WAAW,eAAe;CAC9C,IAAI,aAAa,MAAM,OAAO,KAAK,CAAC;CACpC,MAAM,UAAU,WAAW;EACzB,IAAI,CAAC,WAAW,WAAW,YAAY,eAAe,aAAa,yBAAyB,OAAO;GACjG,WAAW,UAAU,QAAQ,SAAS,QAAQ,EAAE;EAClD;CACF,CAAC;CACD,MAAM,UAAU,WAAW;EACzB,OAAO,WAAW;GAChB,IAAI,OAAO,WAAW,YAAY,YAAY,WAAW,QAAQ;GACjE,WAAW,UAAU,KAAK;EAC5B;CACF,GAAG,CAAC,CAAC;CACL,IAAI,CAAC,SAAS,OAAO;EACnB;EACA;EACA;CACF;CACA,IAAI,EAAE,IAAI,WAAW,YAAY,mBAAmB;CACpD,IAAI,eAAe,WAAW;EAC5B,OAAO,mBAAmB,QAAQ,mBAAmB,KAAK,IAAI,KAAK,IAAI,eAAe,EAAE;CAC1F;CACA,OAAO,CAAC,cAAc,iBAAiB;EACrC;EACA;EACA;CACF,IAAI;EACF;EACA,KAAK;EACL;CACF;AACF;AACA,SAAS,eAAe;CACtB,OAAO,UAAU,MAAM,WAAW,eAAe,CAAC;AACpD;AACA,SAAS,UAAU,SAAS;CAC1B,OAAO,YAAY,OAAO,OAAO,QAAQ;AAC3C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/use-presence",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.804.1",
|
|
4
4
|
"files": [
|
|
5
5
|
"src",
|
|
6
6
|
"types",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"clean:build": "tamagui-build clean:build"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@tamagui/web": "3.0.0-beta.
|
|
36
|
+
"@tamagui/web": "3.0.0-beta.804.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@tamagui/build": "3.0.0-beta.
|
|
39
|
+
"@tamagui/build": "3.0.0-beta.804.1",
|
|
40
40
|
"react": "19.2.3"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
package/src/usePresence.ts
CHANGED
|
@@ -1,18 +1,43 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
PresenceContextProps,
|
|
3
|
+
PresenceRegistration,
|
|
4
|
+
UsePresenceResult,
|
|
5
|
+
} from '@tamagui/web'
|
|
2
6
|
import * as React from 'react'
|
|
3
7
|
|
|
4
8
|
import { PresenceContext } from './PresenceContext'
|
|
5
9
|
|
|
6
|
-
export function usePresence(): UsePresenceResult {
|
|
10
|
+
export function usePresence(registration?: PresenceRegistration): UsePresenceResult {
|
|
7
11
|
const context = React.useContext(PresenceContext)
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
// the style pass completes later in the same render, so the registration
|
|
14
|
+
// decision is read in a passive effect: every component calls this hook in a
|
|
15
|
+
// fixed position while only frames that animate join presence bookkeeping.
|
|
16
|
+
// Registration is sticky — it happens once and unregisters only at unmount,
|
|
17
|
+
// never between commits (a mid-exit unregister completes the exit instantly
|
|
18
|
+
// and the exit animation never plays). A public caller with no registration
|
|
19
|
+
// handle keeps the always-register contract.
|
|
20
|
+
const unregister = React.useRef<undefined | void | (() => void)>(undefined)
|
|
21
|
+
React.useEffect(() => {
|
|
22
|
+
if (
|
|
23
|
+
!unregister.current &&
|
|
24
|
+
context &&
|
|
25
|
+
(registration ? registration.shouldRegisterPresence : true)
|
|
26
|
+
) {
|
|
27
|
+
unregister.current = context.register(context.id)
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
React.useEffect(
|
|
31
|
+
() => () => {
|
|
32
|
+
if (typeof unregister.current === 'function') unregister.current()
|
|
33
|
+
unregister.current = undefined
|
|
34
|
+
},
|
|
35
|
+
[]
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
if (!context) return [true, null, context]
|
|
39
|
+
|
|
40
|
+
const { id, isPresent, onExitComplete } = context
|
|
16
41
|
|
|
17
42
|
const safeToRemove = () => onExitComplete?.(id)
|
|
18
43
|
|
package/types/usePresence.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PresenceContextProps, UsePresenceResult } from "@tamagui/web";
|
|
2
|
-
export declare function usePresence(): UsePresenceResult;
|
|
1
|
+
import type { PresenceContextProps, PresenceRegistration, UsePresenceResult } from "@tamagui/web";
|
|
2
|
+
export declare function usePresence(registration?: PresenceRegistration): UsePresenceResult;
|
|
3
3
|
/**
|
|
4
4
|
* Similar to `usePresence`, except `useIsPresent` simply returns whether or not the component is present.
|
|
5
5
|
* There is no `safeToRemove` function.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"mappings": "AAAA,
|
|
2
|
+
"mappings": "AAAA,cACE,sBACA,sBACA,yBACK;AAKP,OAAO,iBAAS,YAAY,eAAe,uBAAuB;;;;;AA2ClE,OAAO,iBAAS;AAIhB,OAAO,iBAAS,UAAU,SAAS",
|
|
3
3
|
"names": [],
|
|
4
4
|
"sources": [
|
|
5
5
|
"src/usePresence.ts"
|
|
6
6
|
],
|
|
7
7
|
"version": 3,
|
|
8
8
|
"sourcesContent": [
|
|
9
|
-
"import type {
|
|
9
|
+
"import type {\n PresenceContextProps,\n PresenceRegistration,\n UsePresenceResult,\n} from '@tamagui/web'\nimport * as React from 'react'\n\nimport { PresenceContext } from './PresenceContext'\n\nexport function usePresence(registration?: PresenceRegistration): UsePresenceResult {\n const context = React.useContext(PresenceContext)\n\n // the style pass completes later in the same render, so the registration\n // decision is read in a passive effect: every component calls this hook in a\n // fixed position while only frames that animate join presence bookkeeping.\n // Registration is sticky — it happens once and unregisters only at unmount,\n // never between commits (a mid-exit unregister completes the exit instantly\n // and the exit animation never plays). A public caller with no registration\n // handle keeps the always-register contract.\n const unregister = React.useRef<undefined | void | (() => void)>(undefined)\n React.useEffect(() => {\n if (\n !unregister.current &&\n context &&\n (registration ? registration.shouldRegisterPresence : true)\n ) {\n unregister.current = context.register(context.id)\n }\n })\n React.useEffect(\n () => () => {\n if (typeof unregister.current === 'function') unregister.current()\n unregister.current = undefined\n },\n []\n )\n\n if (!context) return [true, null, context]\n\n const { id, isPresent, onExitComplete } = context\n\n const safeToRemove = () => onExitComplete?.(id)\n\n return !isPresent && onExitComplete\n ? [false, safeToRemove, context]\n : [true, undefined, context]\n}\n\n/**\n * Similar to `usePresence`, except `useIsPresent` simply returns whether or not the component is present.\n * There is no `safeToRemove` function.\n */\nexport function useIsPresent(): boolean {\n return isPresent(React.useContext(PresenceContext))\n}\n\nexport function isPresent(context: PresenceContextProps | null): boolean {\n return context === null ? true : context.isPresent\n}\n"
|
|
10
10
|
]
|
|
11
11
|
}
|