@react-navigation/elements 2.8.0 → 2.8.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/lib/module/Lazy.js +30 -9
- package/lib/module/Lazy.js.map +1 -1
- package/lib/typescript/src/Lazy.d.ts +25 -2
- package/lib/typescript/src/Lazy.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/Lazy.tsx +45 -10
package/lib/module/Lazy.js
CHANGED
|
@@ -1,20 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
+
/**
|
|
5
|
+
* Render content lazily based on visibility.
|
|
6
|
+
*
|
|
7
|
+
* When enabled:
|
|
8
|
+
* - If content is visible, it will render immediately
|
|
9
|
+
* - If content is not visible, it won't render until it becomes visible
|
|
10
|
+
*
|
|
11
|
+
* Otherwise:
|
|
12
|
+
* - If content is visible, it will render immediately
|
|
13
|
+
* - If content is not visible, it will defer rendering until idle
|
|
14
|
+
*
|
|
15
|
+
* Once rendered, the content remains rendered.
|
|
16
|
+
*/
|
|
4
17
|
export function Lazy({
|
|
5
18
|
enabled,
|
|
6
|
-
|
|
19
|
+
visible,
|
|
20
|
+
children
|
|
7
21
|
}) {
|
|
8
|
-
const [rendered, setRendered] = React.useState(enabled);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
const [rendered, setRendered] = React.useState(enabled ? visible : false);
|
|
23
|
+
const shouldRenderInIdle = !(enabled || visible || rendered);
|
|
24
|
+
React.useEffect(() => {
|
|
25
|
+
if (shouldRenderInIdle === false) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const id = requestIdleCallback(() => {
|
|
29
|
+
setRendered(true);
|
|
14
30
|
});
|
|
15
|
-
|
|
31
|
+
return () => cancelIdleCallback(id);
|
|
32
|
+
}, [shouldRenderInIdle]);
|
|
33
|
+
if (visible && rendered === false) {
|
|
34
|
+
setRendered(true);
|
|
35
|
+
return children;
|
|
36
|
+
}
|
|
16
37
|
if (rendered) {
|
|
17
|
-
return
|
|
38
|
+
return children;
|
|
18
39
|
}
|
|
19
40
|
return null;
|
|
20
41
|
}
|
package/lib/module/Lazy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Lazy","enabled","
|
|
1
|
+
{"version":3,"names":["React","Lazy","enabled","visible","children","rendered","setRendered","useState","shouldRenderInIdle","useEffect","id","requestIdleCallback","cancelIdleCallback"],"sourceRoot":"../../src","sources":["Lazy.tsx"],"mappings":";;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAiB9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,IAAIA,CAAC;EAAEC,OAAO;EAAEC,OAAO;EAAEC;AAAgB,CAAC,EAAE;EAC1D,MAAM,CAACC,QAAQ,EAAEC,WAAW,CAAC,GAAGN,KAAK,CAACO,QAAQ,CAACL,OAAO,GAAGC,OAAO,GAAG,KAAK,CAAC;EAEzE,MAAMK,kBAAkB,GAAG,EAAEN,OAAO,IAAIC,OAAO,IAAIE,QAAQ,CAAC;EAE5DL,KAAK,CAACS,SAAS,CAAC,MAAM;IACpB,IAAID,kBAAkB,KAAK,KAAK,EAAE;MAChC;IACF;IAEA,MAAME,EAAE,GAAGC,mBAAmB,CAAC,MAAM;MACnCL,WAAW,CAAC,IAAI,CAAC;IACnB,CAAC,CAAC;IAEF,OAAO,MAAMM,kBAAkB,CAACF,EAAE,CAAC;EACrC,CAAC,EAAE,CAACF,kBAAkB,CAAC,CAAC;EAExB,IAAIL,OAAO,IAAIE,QAAQ,KAAK,KAAK,EAAE;IACjCC,WAAW,CAAC,IAAI,CAAC;IAEjB,OAAOF,QAAQ;EACjB;EAEA,IAAIC,QAAQ,EAAE;IACZ,OAAOD,QAAQ;EACjB;EAEA,OAAO,IAAI;AACb","ignoreList":[]}
|
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
type Props = {
|
|
3
|
+
/**
|
|
4
|
+
* Whether lazy rendering is enabled.
|
|
5
|
+
*/
|
|
3
6
|
enabled: boolean;
|
|
4
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Whether the component is visible.
|
|
9
|
+
*/
|
|
10
|
+
visible: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Content to render.
|
|
13
|
+
*/
|
|
14
|
+
children: React.ReactElement;
|
|
5
15
|
};
|
|
6
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Render content lazily based on visibility.
|
|
18
|
+
*
|
|
19
|
+
* When enabled:
|
|
20
|
+
* - If content is visible, it will render immediately
|
|
21
|
+
* - If content is not visible, it won't render until it becomes visible
|
|
22
|
+
*
|
|
23
|
+
* Otherwise:
|
|
24
|
+
* - If content is visible, it will render immediately
|
|
25
|
+
* - If content is not visible, it will defer rendering until idle
|
|
26
|
+
*
|
|
27
|
+
* Once rendered, the content remains rendered.
|
|
28
|
+
*/
|
|
29
|
+
export declare function Lazy({ enabled, visible, children }: Props): React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | null;
|
|
7
30
|
export {};
|
|
8
31
|
//# sourceMappingURL=Lazy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lazy.d.ts","sourceRoot":"","sources":["../../../src/Lazy.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,KAAK,KAAK,GAAG;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,
|
|
1
|
+
{"version":3,"file":"Lazy.d.ts","sourceRoot":"","sources":["../../../src/Lazy.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,KAAK,KAAK,GAAG;IACX;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,KAAK,iFA4BzD"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-navigation/elements",
|
|
3
3
|
"description": "UI Components for React Navigation",
|
|
4
|
-
"version": "2.8.
|
|
4
|
+
"version": "2.8.1",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
7
7
|
"react-navigation",
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
]
|
|
92
92
|
]
|
|
93
93
|
},
|
|
94
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "85fa1e22e5b9af9004354ae7f74cc7d0a0fa6009"
|
|
95
95
|
}
|
package/src/Lazy.tsx
CHANGED
|
@@ -1,23 +1,58 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
3
|
type Props = {
|
|
4
|
+
/**
|
|
5
|
+
* Whether lazy rendering is enabled.
|
|
6
|
+
*/
|
|
4
7
|
enabled: boolean;
|
|
5
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Whether the component is visible.
|
|
10
|
+
*/
|
|
11
|
+
visible: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Content to render.
|
|
14
|
+
*/
|
|
15
|
+
children: React.ReactElement;
|
|
6
16
|
};
|
|
7
17
|
|
|
8
|
-
|
|
9
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Render content lazily based on visibility.
|
|
20
|
+
*
|
|
21
|
+
* When enabled:
|
|
22
|
+
* - If content is visible, it will render immediately
|
|
23
|
+
* - If content is not visible, it won't render until it becomes visible
|
|
24
|
+
*
|
|
25
|
+
* Otherwise:
|
|
26
|
+
* - If content is visible, it will render immediately
|
|
27
|
+
* - If content is not visible, it will defer rendering until idle
|
|
28
|
+
*
|
|
29
|
+
* Once rendered, the content remains rendered.
|
|
30
|
+
*/
|
|
31
|
+
export function Lazy({ enabled, visible, children }: Props) {
|
|
32
|
+
const [rendered, setRendered] = React.useState(enabled ? visible : false);
|
|
10
33
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
34
|
+
const shouldRenderInIdle = !(enabled || visible || rendered);
|
|
35
|
+
|
|
36
|
+
React.useEffect(() => {
|
|
37
|
+
if (shouldRenderInIdle === false) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const id = requestIdleCallback(() => {
|
|
42
|
+
setRendered(true);
|
|
16
43
|
});
|
|
17
|
-
|
|
44
|
+
|
|
45
|
+
return () => cancelIdleCallback(id);
|
|
46
|
+
}, [shouldRenderInIdle]);
|
|
47
|
+
|
|
48
|
+
if (visible && rendered === false) {
|
|
49
|
+
setRendered(true);
|
|
50
|
+
|
|
51
|
+
return children;
|
|
52
|
+
}
|
|
18
53
|
|
|
19
54
|
if (rendered) {
|
|
20
|
-
return
|
|
55
|
+
return children;
|
|
21
56
|
}
|
|
22
57
|
|
|
23
58
|
return null;
|