@wordpress/compose 6.25.0 → 6.25.1-next.79a6196f.0
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/LICENSE.md +1 -1
- package/build/higher-order/with-network-connectivity/index.native.js +28 -0
- package/build/higher-order/with-network-connectivity/index.native.js.map +1 -0
- package/build/hooks/use-network-connectivity/index.native.js +58 -0
- package/build/hooks/use-network-connectivity/index.native.js.map +1 -0
- package/build/index.native.js +17 -1
- package/build/index.native.js.map +1 -1
- package/build-module/higher-order/with-network-connectivity/index.native.js +19 -0
- package/build-module/higher-order/with-network-connectivity/index.native.js.map +1 -0
- package/build-module/hooks/use-network-connectivity/index.native.js +52 -0
- package/build-module/hooks/use-network-connectivity/index.native.js.map +1 -0
- package/build-module/index.native.js +2 -0
- package/build-module/index.native.js.map +1 -1
- package/package.json +9 -9
- package/src/higher-order/with-network-connectivity/README.md +20 -0
- package/src/higher-order/with-network-connectivity/index.native.js +19 -0
- package/src/hooks/use-network-connectivity/index.native.js +59 -0
- package/src/hooks/use-network-connectivity/test/index.native.js +87 -0
- package/src/index.native.js +2 -0
package/LICENSE.md
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _createHigherOrderComponent = require("../../utils/create-higher-order-component");
|
|
10
|
+
var _useNetworkConnectivity = _interopRequireDefault(require("../../hooks/use-network-connectivity"));
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const withNetworkConnectivity = (0, _createHigherOrderComponent.createHigherOrderComponent)(WrappedComponent => {
|
|
16
|
+
return props => {
|
|
17
|
+
const {
|
|
18
|
+
isConnected
|
|
19
|
+
} = (0, _useNetworkConnectivity.default)();
|
|
20
|
+
return (0, _react.createElement)(WrappedComponent, {
|
|
21
|
+
...props,
|
|
22
|
+
isConnected: isConnected
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
}, 'withNetworkConnectivity');
|
|
26
|
+
var _default = withNetworkConnectivity;
|
|
27
|
+
exports.default = _default;
|
|
28
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_createHigherOrderComponent","require","_useNetworkConnectivity","_interopRequireDefault","withNetworkConnectivity","createHigherOrderComponent","WrappedComponent","props","isConnected","useNetworkConnectivity","_react","createElement","_default","exports","default"],"sources":["@wordpress/compose/src/higher-order/with-network-connectivity/index.native.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\nimport useNetworkConnectivity from '../../hooks/use-network-connectivity';\n\nconst withNetworkConnectivity = createHigherOrderComponent(\n\t( WrappedComponent ) => {\n\t\treturn ( props ) => {\n\t\t\tconst { isConnected } = useNetworkConnectivity();\n\t\t\treturn (\n\t\t\t\t<WrappedComponent { ...props } isConnected={ isConnected } />\n\t\t\t);\n\t\t};\n\t},\n\t'withNetworkConnectivity'\n);\n\nexport default withNetworkConnectivity;\n"],"mappings":";;;;;;;;AAGA,IAAAA,2BAAA,GAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAJA;AACA;AACA;;AAIA,MAAMG,uBAAuB,GAAG,IAAAC,sDAA0B,EACvDC,gBAAgB,IAAM;EACvB,OAASC,KAAK,IAAM;IACnB,MAAM;MAAEC;IAAY,CAAC,GAAG,IAAAC,+BAAsB,EAAC,CAAC;IAChD,OACC,IAAAC,MAAA,CAAAC,aAAA,EAACL,gBAAgB;MAAA,GAAMC,KAAK;MAAGC,WAAW,EAAGA;IAAa,CAAE,CAAC;EAE/D,CAAC;AACF,CAAC,EACD,yBACD,CAAC;AAAC,IAAAI,QAAA,GAEaR,uBAAuB;AAAAS,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useNetworkConnectivity;
|
|
7
|
+
var _element = require("@wordpress/element");
|
|
8
|
+
var _reactNativeBridge = require("@wordpress/react-native-bridge");
|
|
9
|
+
/**
|
|
10
|
+
* WordPress dependencies
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {Object} NetworkInformation
|
|
15
|
+
*
|
|
16
|
+
* @property {boolean} [isConnected] Whether the device is connected to a network.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Returns the current network connectivity status provided by the native bridge.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
*
|
|
24
|
+
* ```jsx
|
|
25
|
+
* const { isConnected } = useNetworkConnectivity();
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @return {NetworkInformation} Network information.
|
|
29
|
+
*/
|
|
30
|
+
function useNetworkConnectivity() {
|
|
31
|
+
const [isConnected, setIsConnected] = (0, _element.useState)(true);
|
|
32
|
+
(0, _element.useEffect)(() => {
|
|
33
|
+
let isCurrent = true;
|
|
34
|
+
(0, _reactNativeBridge.requestConnectionStatus)(isBridgeConnected => {
|
|
35
|
+
if (!isCurrent) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
setIsConnected(isBridgeConnected);
|
|
39
|
+
});
|
|
40
|
+
return () => {
|
|
41
|
+
isCurrent = false;
|
|
42
|
+
};
|
|
43
|
+
}, []);
|
|
44
|
+
(0, _element.useEffect)(() => {
|
|
45
|
+
const subscription = (0, _reactNativeBridge.subscribeConnectionStatus)(({
|
|
46
|
+
isConnected: isBridgeConnected
|
|
47
|
+
}) => {
|
|
48
|
+
setIsConnected(isBridgeConnected);
|
|
49
|
+
});
|
|
50
|
+
return () => {
|
|
51
|
+
subscription.remove();
|
|
52
|
+
};
|
|
53
|
+
}, []);
|
|
54
|
+
return {
|
|
55
|
+
isConnected
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_element","require","_reactNativeBridge","useNetworkConnectivity","isConnected","setIsConnected","useState","useEffect","isCurrent","requestConnectionStatus","isBridgeConnected","subscription","subscribeConnectionStatus","remove"],"sources":["@wordpress/compose/src/hooks/use-network-connectivity/index.native.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useState } from '@wordpress/element';\nimport {\n\trequestConnectionStatus,\n\tsubscribeConnectionStatus,\n} from '@wordpress/react-native-bridge';\n\n/**\n * @typedef {Object} NetworkInformation\n *\n * @property {boolean} [isConnected] Whether the device is connected to a network.\n */\n\n/**\n * Returns the current network connectivity status provided by the native bridge.\n *\n * @example\n *\n * ```jsx\n * const { isConnected } = useNetworkConnectivity();\n * ```\n *\n * @return {NetworkInformation} Network information.\n */\nexport default function useNetworkConnectivity() {\n\tconst [ isConnected, setIsConnected ] = useState( true );\n\n\tuseEffect( () => {\n\t\tlet isCurrent = true;\n\n\t\trequestConnectionStatus( ( isBridgeConnected ) => {\n\t\t\tif ( ! isCurrent ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetIsConnected( isBridgeConnected );\n\t\t} );\n\n\t\treturn () => {\n\t\t\tisCurrent = false;\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tconst subscription = subscribeConnectionStatus(\n\t\t\t( { isConnected: isBridgeConnected } ) => {\n\t\t\t\tsetIsConnected( isBridgeConnected );\n\t\t\t}\n\t\t);\n\n\t\treturn () => {\n\t\t\tsubscription.remove();\n\t\t};\n\t}, [] );\n\n\treturn { isConnected };\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,kBAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASE,sBAAsBA,CAAA,EAAG;EAChD,MAAM,CAAEC,WAAW,EAAEC,cAAc,CAAE,GAAG,IAAAC,iBAAQ,EAAE,IAAK,CAAC;EAExD,IAAAC,kBAAS,EAAE,MAAM;IAChB,IAAIC,SAAS,GAAG,IAAI;IAEpB,IAAAC,0CAAuB,EAAIC,iBAAiB,IAAM;MACjD,IAAK,CAAEF,SAAS,EAAG;QAClB;MACD;MAEAH,cAAc,CAAEK,iBAAkB,CAAC;IACpC,CAAE,CAAC;IAEH,OAAO,MAAM;MACZF,SAAS,GAAG,KAAK;IAClB,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,IAAAD,kBAAS,EAAE,MAAM;IAChB,MAAMI,YAAY,GAAG,IAAAC,4CAAyB,EAC7C,CAAE;MAAER,WAAW,EAAEM;IAAkB,CAAC,KAAM;MACzCL,cAAc,CAAEK,iBAAkB,CAAC;IACpC,CACD,CAAC;IAED,OAAO,MAAM;MACZC,YAAY,CAACE,MAAM,CAAC,CAAC;IACtB,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,OAAO;IAAET;EAAY,CAAC;AACvB"}
|
package/build/index.native.js
CHANGED
|
@@ -14,6 +14,7 @@ var _exportNames = {
|
|
|
14
14
|
withSafeTimeout: true,
|
|
15
15
|
withState: true,
|
|
16
16
|
withPreferredColorScheme: true,
|
|
17
|
+
withNetworkConnectivity: true,
|
|
17
18
|
useConstrainedTabbing: true,
|
|
18
19
|
__experimentalUseDragging: true,
|
|
19
20
|
__experimentalUseFocusOutside: true,
|
|
@@ -31,7 +32,8 @@ var _exportNames = {
|
|
|
31
32
|
useDebouncedInput: true,
|
|
32
33
|
useThrottle: true,
|
|
33
34
|
useMergeRefs: true,
|
|
34
|
-
useRefEffect: true
|
|
35
|
+
useRefEffect: true,
|
|
36
|
+
useNetworkConnectivity: true
|
|
35
37
|
};
|
|
36
38
|
Object.defineProperty(exports, "__experimentalUseDragging", {
|
|
37
39
|
enumerable: true,
|
|
@@ -117,6 +119,12 @@ Object.defineProperty(exports, "useMergeRefs", {
|
|
|
117
119
|
return _useMergeRefs.default;
|
|
118
120
|
}
|
|
119
121
|
});
|
|
122
|
+
Object.defineProperty(exports, "useNetworkConnectivity", {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
get: function () {
|
|
125
|
+
return _useNetworkConnectivity.default;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
120
128
|
Object.defineProperty(exports, "usePreferredColorScheme", {
|
|
121
129
|
enumerable: true,
|
|
122
130
|
get: function () {
|
|
@@ -177,6 +185,12 @@ Object.defineProperty(exports, "withInstanceId", {
|
|
|
177
185
|
return _withInstanceId.default;
|
|
178
186
|
}
|
|
179
187
|
});
|
|
188
|
+
Object.defineProperty(exports, "withNetworkConnectivity", {
|
|
189
|
+
enumerable: true,
|
|
190
|
+
get: function () {
|
|
191
|
+
return _withNetworkConnectivity.default;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
180
194
|
Object.defineProperty(exports, "withPreferredColorScheme", {
|
|
181
195
|
enumerable: true,
|
|
182
196
|
get: function () {
|
|
@@ -240,6 +254,7 @@ var _withInstanceId = _interopRequireDefault(require("./higher-order/with-instan
|
|
|
240
254
|
var _withSafeTimeout = _interopRequireDefault(require("./higher-order/with-safe-timeout"));
|
|
241
255
|
var _withState = _interopRequireDefault(require("./higher-order/with-state"));
|
|
242
256
|
var _withPreferredColorScheme = _interopRequireDefault(require("./higher-order/with-preferred-color-scheme"));
|
|
257
|
+
var _withNetworkConnectivity = _interopRequireDefault(require("./higher-order/with-network-connectivity"));
|
|
243
258
|
var _useConstrainedTabbing = _interopRequireDefault(require("./hooks/use-constrained-tabbing"));
|
|
244
259
|
var _useDragging = _interopRequireDefault(require("./hooks/use-dragging"));
|
|
245
260
|
var _useFocusOutside = _interopRequireDefault(require("./hooks/use-focus-outside"));
|
|
@@ -258,4 +273,5 @@ var _useDebouncedInput = _interopRequireDefault(require("./hooks/use-debounced-i
|
|
|
258
273
|
var _useThrottle = _interopRequireDefault(require("./hooks/use-throttle"));
|
|
259
274
|
var _useMergeRefs = _interopRequireDefault(require("./hooks/use-merge-refs"));
|
|
260
275
|
var _useRefEffect = _interopRequireDefault(require("./hooks/use-ref-effect"));
|
|
276
|
+
var _useNetworkConnectivity = _interopRequireDefault(require("./hooks/use-network-connectivity"));
|
|
261
277
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_createHigherOrderComponent","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_debounce","_throttle","_compose","_interopRequireDefault","_pipe","_ifCondition","_pure","_withGlobalEvents","_withInstanceId","_withSafeTimeout","_withState","_withPreferredColorScheme","_useConstrainedTabbing","_useDragging","_useFocusOutside","_useInstanceId","_useIsomorphicLayoutEffect","_useKeyboardShortcut","_useMediaQuery","_usePrevious","_useReducedMotion","_useViewportMatch","_usePreferredColorScheme","_usePreferredColorSchemeStyle","_useResizeObserver","_useDebounce","_useDebouncedInput","_useThrottle","_useMergeRefs","_useRefEffect"],"sources":["@wordpress/compose/src/index.native.js"],"sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n// The `throttle` helper and its types.\nexport * from './utils/throttle';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\nexport { default as withPreferredColorScheme } from './higher-order/with-preferred-color-scheme';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as usePreferredColorScheme } from './hooks/use-preferred-color-scheme';\nexport { default as usePreferredColorSchemeStyle } from './hooks/use-preferred-color-scheme-style';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useDebouncedInput } from './hooks/use-debounced-input';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_createHigherOrderComponent","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_debounce","_throttle","_compose","_interopRequireDefault","_pipe","_ifCondition","_pure","_withGlobalEvents","_withInstanceId","_withSafeTimeout","_withState","_withPreferredColorScheme","_withNetworkConnectivity","_useConstrainedTabbing","_useDragging","_useFocusOutside","_useInstanceId","_useIsomorphicLayoutEffect","_useKeyboardShortcut","_useMediaQuery","_usePrevious","_useReducedMotion","_useViewportMatch","_usePreferredColorScheme","_usePreferredColorSchemeStyle","_useResizeObserver","_useDebounce","_useDebouncedInput","_useThrottle","_useMergeRefs","_useRefEffect","_useNetworkConnectivity"],"sources":["@wordpress/compose/src/index.native.js"],"sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n// The `throttle` helper and its types.\nexport * from './utils/throttle';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\nexport { default as withPreferredColorScheme } from './higher-order/with-preferred-color-scheme';\nexport { default as withNetworkConnectivity } from './higher-order/with-network-connectivity';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as usePreferredColorScheme } from './hooks/use-preferred-color-scheme';\nexport { default as usePreferredColorSchemeStyle } from './hooks/use-preferred-color-scheme-style';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useDebouncedInput } from './hooks/use-debounced-input';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\nexport { default as useNetworkConnectivity } from './hooks/use-network-connectivity';\n"],"mappings":"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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createElement } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Internal dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { createHigherOrderComponent } from '../../utils/create-higher-order-component';
|
|
6
|
+
import useNetworkConnectivity from '../../hooks/use-network-connectivity';
|
|
7
|
+
const withNetworkConnectivity = createHigherOrderComponent(WrappedComponent => {
|
|
8
|
+
return props => {
|
|
9
|
+
const {
|
|
10
|
+
isConnected
|
|
11
|
+
} = useNetworkConnectivity();
|
|
12
|
+
return createElement(WrappedComponent, {
|
|
13
|
+
...props,
|
|
14
|
+
isConnected: isConnected
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}, 'withNetworkConnectivity');
|
|
18
|
+
export default withNetworkConnectivity;
|
|
19
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createHigherOrderComponent","useNetworkConnectivity","withNetworkConnectivity","WrappedComponent","props","isConnected","createElement"],"sources":["@wordpress/compose/src/higher-order/with-network-connectivity/index.native.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\nimport useNetworkConnectivity from '../../hooks/use-network-connectivity';\n\nconst withNetworkConnectivity = createHigherOrderComponent(\n\t( WrappedComponent ) => {\n\t\treturn ( props ) => {\n\t\t\tconst { isConnected } = useNetworkConnectivity();\n\t\t\treturn (\n\t\t\t\t<WrappedComponent { ...props } isConnected={ isConnected } />\n\t\t\t);\n\t\t};\n\t},\n\t'withNetworkConnectivity'\n);\n\nexport default withNetworkConnectivity;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,0BAA0B,QAAQ,2CAA2C;AACtF,OAAOC,sBAAsB,MAAM,sCAAsC;AAEzE,MAAMC,uBAAuB,GAAGF,0BAA0B,CACvDG,gBAAgB,IAAM;EACvB,OAASC,KAAK,IAAM;IACnB,MAAM;MAAEC;IAAY,CAAC,GAAGJ,sBAAsB,CAAC,CAAC;IAChD,OACCK,aAAA,CAACH,gBAAgB;MAAA,GAAMC,KAAK;MAAGC,WAAW,EAAGA;IAAa,CAAE,CAAC;EAE/D,CAAC;AACF,CAAC,EACD,yBACD,CAAC;AAED,eAAeH,uBAAuB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useEffect, useState } from '@wordpress/element';
|
|
5
|
+
import { requestConnectionStatus, subscribeConnectionStatus } from '@wordpress/react-native-bridge';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {Object} NetworkInformation
|
|
9
|
+
*
|
|
10
|
+
* @property {boolean} [isConnected] Whether the device is connected to a network.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Returns the current network connectivity status provided by the native bridge.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* ```jsx
|
|
19
|
+
* const { isConnected } = useNetworkConnectivity();
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @return {NetworkInformation} Network information.
|
|
23
|
+
*/
|
|
24
|
+
export default function useNetworkConnectivity() {
|
|
25
|
+
const [isConnected, setIsConnected] = useState(true);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
let isCurrent = true;
|
|
28
|
+
requestConnectionStatus(isBridgeConnected => {
|
|
29
|
+
if (!isCurrent) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
setIsConnected(isBridgeConnected);
|
|
33
|
+
});
|
|
34
|
+
return () => {
|
|
35
|
+
isCurrent = false;
|
|
36
|
+
};
|
|
37
|
+
}, []);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const subscription = subscribeConnectionStatus(({
|
|
40
|
+
isConnected: isBridgeConnected
|
|
41
|
+
}) => {
|
|
42
|
+
setIsConnected(isBridgeConnected);
|
|
43
|
+
});
|
|
44
|
+
return () => {
|
|
45
|
+
subscription.remove();
|
|
46
|
+
};
|
|
47
|
+
}, []);
|
|
48
|
+
return {
|
|
49
|
+
isConnected
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","useState","requestConnectionStatus","subscribeConnectionStatus","useNetworkConnectivity","isConnected","setIsConnected","isCurrent","isBridgeConnected","subscription","remove"],"sources":["@wordpress/compose/src/hooks/use-network-connectivity/index.native.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useState } from '@wordpress/element';\nimport {\n\trequestConnectionStatus,\n\tsubscribeConnectionStatus,\n} from '@wordpress/react-native-bridge';\n\n/**\n * @typedef {Object} NetworkInformation\n *\n * @property {boolean} [isConnected] Whether the device is connected to a network.\n */\n\n/**\n * Returns the current network connectivity status provided by the native bridge.\n *\n * @example\n *\n * ```jsx\n * const { isConnected } = useNetworkConnectivity();\n * ```\n *\n * @return {NetworkInformation} Network information.\n */\nexport default function useNetworkConnectivity() {\n\tconst [ isConnected, setIsConnected ] = useState( true );\n\n\tuseEffect( () => {\n\t\tlet isCurrent = true;\n\n\t\trequestConnectionStatus( ( isBridgeConnected ) => {\n\t\t\tif ( ! isCurrent ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetIsConnected( isBridgeConnected );\n\t\t} );\n\n\t\treturn () => {\n\t\t\tisCurrent = false;\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tconst subscription = subscribeConnectionStatus(\n\t\t\t( { isConnected: isBridgeConnected } ) => {\n\t\t\t\tsetIsConnected( isBridgeConnected );\n\t\t\t}\n\t\t);\n\n\t\treturn () => {\n\t\t\tsubscription.remove();\n\t\t};\n\t}, [] );\n\n\treturn { isConnected };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,oBAAoB;AACxD,SACCC,uBAAuB,EACvBC,yBAAyB,QACnB,gCAAgC;;AAEvC;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,sBAAsBA,CAAA,EAAG;EAChD,MAAM,CAAEC,WAAW,EAAEC,cAAc,CAAE,GAAGL,QAAQ,CAAE,IAAK,CAAC;EAExDD,SAAS,CAAE,MAAM;IAChB,IAAIO,SAAS,GAAG,IAAI;IAEpBL,uBAAuB,CAAIM,iBAAiB,IAAM;MACjD,IAAK,CAAED,SAAS,EAAG;QAClB;MACD;MAEAD,cAAc,CAAEE,iBAAkB,CAAC;IACpC,CAAE,CAAC;IAEH,OAAO,MAAM;MACZD,SAAS,GAAG,KAAK;IAClB,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEPP,SAAS,CAAE,MAAM;IAChB,MAAMS,YAAY,GAAGN,yBAAyB,CAC7C,CAAE;MAAEE,WAAW,EAAEG;IAAkB,CAAC,KAAM;MACzCF,cAAc,CAAEE,iBAAkB,CAAC;IACpC,CACD,CAAC;IAED,OAAO,MAAM;MACZC,YAAY,CAACC,MAAM,CAAC,CAAC;IACtB,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,OAAO;IAAEL;EAAY,CAAC;AACvB"}
|
|
@@ -17,6 +17,7 @@ export { default as withInstanceId } from './higher-order/with-instance-id';
|
|
|
17
17
|
export { default as withSafeTimeout } from './higher-order/with-safe-timeout';
|
|
18
18
|
export { default as withState } from './higher-order/with-state';
|
|
19
19
|
export { default as withPreferredColorScheme } from './higher-order/with-preferred-color-scheme';
|
|
20
|
+
export { default as withNetworkConnectivity } from './higher-order/with-network-connectivity';
|
|
20
21
|
|
|
21
22
|
// Hooks.
|
|
22
23
|
export { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';
|
|
@@ -37,4 +38,5 @@ export { default as useDebouncedInput } from './hooks/use-debounced-input';
|
|
|
37
38
|
export { default as useThrottle } from './hooks/use-throttle';
|
|
38
39
|
export { default as useMergeRefs } from './hooks/use-merge-refs';
|
|
39
40
|
export { default as useRefEffect } from './hooks/use-ref-effect';
|
|
41
|
+
export { default as useNetworkConnectivity } from './hooks/use-network-connectivity';
|
|
40
42
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["default","compose","pipe","ifCondition","pure","withGlobalEvents","withInstanceId","withSafeTimeout","withState","withPreferredColorScheme","useConstrainedTabbing","__experimentalUseDragging","__experimentalUseFocusOutside","useInstanceId","useIsomorphicLayoutEffect","useKeyboardShortcut","useMediaQuery","usePrevious","useReducedMotion","useViewportMatch","usePreferredColorScheme","usePreferredColorSchemeStyle","useResizeObserver","useDebounce","useDebouncedInput","useThrottle","useMergeRefs","useRefEffect"],"sources":["@wordpress/compose/src/index.native.js"],"sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n// The `throttle` helper and its types.\nexport * from './utils/throttle';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\nexport { default as withPreferredColorScheme } from './higher-order/with-preferred-color-scheme';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as usePreferredColorScheme } from './hooks/use-preferred-color-scheme';\nexport { default as usePreferredColorSchemeStyle } from './hooks/use-preferred-color-scheme-style';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useDebouncedInput } from './hooks/use-debounced-input';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\n"],"mappings":"AAAA;AACA,cAAc,uCAAuC;AACrD;AACA,cAAc,kBAAkB;AAChC;AACA,cAAc,kBAAkB;;AAEhC;AACA,SAASA,OAAO,IAAIC,OAAO,QAAQ,wBAAwB;AAC3D,SAASD,OAAO,IAAIE,IAAI,QAAQ,qBAAqB;;AAErD;AACA,SAASF,OAAO,IAAIG,WAAW,QAAQ,6BAA6B;AACpE,SAASH,OAAO,IAAII,IAAI,QAAQ,qBAAqB;AACrD,SAASJ,OAAO,IAAIK,gBAAgB,QAAQ,mCAAmC;AAC/E,SAASL,OAAO,IAAIM,cAAc,QAAQ,iCAAiC;AAC3E,SAASN,OAAO,IAAIO,eAAe,QAAQ,kCAAkC;AAC7E,SAASP,OAAO,IAAIQ,SAAS,QAAQ,2BAA2B;AAChE,SAASR,OAAO,IAAIS,wBAAwB,QAAQ,4CAA4C
|
|
1
|
+
{"version":3,"names":["default","compose","pipe","ifCondition","pure","withGlobalEvents","withInstanceId","withSafeTimeout","withState","withPreferredColorScheme","withNetworkConnectivity","useConstrainedTabbing","__experimentalUseDragging","__experimentalUseFocusOutside","useInstanceId","useIsomorphicLayoutEffect","useKeyboardShortcut","useMediaQuery","usePrevious","useReducedMotion","useViewportMatch","usePreferredColorScheme","usePreferredColorSchemeStyle","useResizeObserver","useDebounce","useDebouncedInput","useThrottle","useMergeRefs","useRefEffect","useNetworkConnectivity"],"sources":["@wordpress/compose/src/index.native.js"],"sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n// The `throttle` helper and its types.\nexport * from './utils/throttle';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\nexport { default as withPreferredColorScheme } from './higher-order/with-preferred-color-scheme';\nexport { default as withNetworkConnectivity } from './higher-order/with-network-connectivity';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as usePreferredColorScheme } from './hooks/use-preferred-color-scheme';\nexport { default as usePreferredColorSchemeStyle } from './hooks/use-preferred-color-scheme-style';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useDebouncedInput } from './hooks/use-debounced-input';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\nexport { default as useNetworkConnectivity } from './hooks/use-network-connectivity';\n"],"mappings":"AAAA;AACA,cAAc,uCAAuC;AACrD;AACA,cAAc,kBAAkB;AAChC;AACA,cAAc,kBAAkB;;AAEhC;AACA,SAASA,OAAO,IAAIC,OAAO,QAAQ,wBAAwB;AAC3D,SAASD,OAAO,IAAIE,IAAI,QAAQ,qBAAqB;;AAErD;AACA,SAASF,OAAO,IAAIG,WAAW,QAAQ,6BAA6B;AACpE,SAASH,OAAO,IAAII,IAAI,QAAQ,qBAAqB;AACrD,SAASJ,OAAO,IAAIK,gBAAgB,QAAQ,mCAAmC;AAC/E,SAASL,OAAO,IAAIM,cAAc,QAAQ,iCAAiC;AAC3E,SAASN,OAAO,IAAIO,eAAe,QAAQ,kCAAkC;AAC7E,SAASP,OAAO,IAAIQ,SAAS,QAAQ,2BAA2B;AAChE,SAASR,OAAO,IAAIS,wBAAwB,QAAQ,4CAA4C;AAChG,SAAST,OAAO,IAAIU,uBAAuB,QAAQ,0CAA0C;;AAE7F;AACA,SAASV,OAAO,IAAIW,qBAAqB,QAAQ,iCAAiC;AAClF,SAASX,OAAO,IAAIY,yBAAyB,QAAQ,sBAAsB;AAC3E,SAASZ,OAAO,IAAIa,6BAA6B,QAAQ,2BAA2B;AACpF,SAASb,OAAO,IAAIc,aAAa,QAAQ,yBAAyB;AAClE,SAASd,OAAO,IAAIe,yBAAyB,QAAQ,sCAAsC;AAC3F,SAASf,OAAO,IAAIgB,mBAAmB,QAAQ,+BAA+B;AAC9E,SAAShB,OAAO,IAAIiB,aAAa,QAAQ,yBAAyB;AAClE,SAASjB,OAAO,IAAIkB,WAAW,QAAQ,sBAAsB;AAC7D,SAASlB,OAAO,IAAImB,gBAAgB,QAAQ,4BAA4B;AACxE,SAASnB,OAAO,IAAIoB,gBAAgB,QAAQ,4BAA4B;AACxE,SAASpB,OAAO,IAAIqB,uBAAuB,QAAQ,oCAAoC;AACvF,SAASrB,OAAO,IAAIsB,4BAA4B,QAAQ,0CAA0C;AAClG,SAAStB,OAAO,IAAIuB,iBAAiB,QAAQ,6BAA6B;AAC1E,SAASvB,OAAO,IAAIwB,WAAW,QAAQ,sBAAsB;AAC7D,SAASxB,OAAO,IAAIyB,iBAAiB,QAAQ,6BAA6B;AAC1E,SAASzB,OAAO,IAAI0B,WAAW,QAAQ,sBAAsB;AAC7D,SAAS1B,OAAO,IAAI2B,YAAY,QAAQ,wBAAwB;AAChE,SAAS3B,OAAO,IAAI4B,YAAY,QAAQ,wBAAwB;AAChE,SAAS5B,OAAO,IAAI6B,sBAAsB,QAAQ,kCAAkC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/compose",
|
|
3
|
-
"version": "6.25.0",
|
|
3
|
+
"version": "6.25.1-next.79a6196f.0",
|
|
4
4
|
"description": "WordPress higher-order components (HOCs).",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/runtime": "^7.16.0",
|
|
33
33
|
"@types/mousetrap": "^1.6.8",
|
|
34
|
-
"@wordpress/deprecated": "^3.48.0",
|
|
35
|
-
"@wordpress/dom": "^3.48.0",
|
|
36
|
-
"@wordpress/element": "^5.25.0",
|
|
37
|
-
"@wordpress/is-shallow-equal": "^4.48.0",
|
|
38
|
-
"@wordpress/keycodes": "^3.48.0",
|
|
39
|
-
"@wordpress/priority-queue": "^2.48.0",
|
|
40
|
-
"@wordpress/undo-manager": "^0.8.0",
|
|
34
|
+
"@wordpress/deprecated": "^3.48.1-next.79a6196f.0",
|
|
35
|
+
"@wordpress/dom": "^3.48.1-next.79a6196f.0",
|
|
36
|
+
"@wordpress/element": "^5.25.1-next.79a6196f.0",
|
|
37
|
+
"@wordpress/is-shallow-equal": "^4.48.1-next.79a6196f.0",
|
|
38
|
+
"@wordpress/keycodes": "^3.48.1-next.79a6196f.0",
|
|
39
|
+
"@wordpress/priority-queue": "^2.48.1-next.79a6196f.0",
|
|
40
|
+
"@wordpress/undo-manager": "^0.8.1-next.79a6196f.0",
|
|
41
41
|
"change-case": "^4.1.2",
|
|
42
42
|
"clipboard": "^2.0.8",
|
|
43
43
|
"mousetrap": "^1.6.5",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "1e74b942ac0119a22ceaaf5c9594263f3ec516ab"
|
|
53
53
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# withNetworkConnectivity
|
|
2
|
+
|
|
3
|
+
`withNetworkConnectivity` provides a true/false mobile connectivity status based on the `useNetworkConnectivity` hook.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```jsx
|
|
8
|
+
/**
|
|
9
|
+
* WordPress dependencies
|
|
10
|
+
*/
|
|
11
|
+
import { withNetworkConnectivity } from '@wordpress/compose';
|
|
12
|
+
|
|
13
|
+
export class MyComponent extends Component {
|
|
14
|
+
if ( this.props.isConnected !== true ) {
|
|
15
|
+
console.log( 'You are currently offline.' )
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default withNetworkConnectivity( MyComponent )
|
|
20
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { createHigherOrderComponent } from '../../utils/create-higher-order-component';
|
|
5
|
+
import useNetworkConnectivity from '../../hooks/use-network-connectivity';
|
|
6
|
+
|
|
7
|
+
const withNetworkConnectivity = createHigherOrderComponent(
|
|
8
|
+
( WrappedComponent ) => {
|
|
9
|
+
return ( props ) => {
|
|
10
|
+
const { isConnected } = useNetworkConnectivity();
|
|
11
|
+
return (
|
|
12
|
+
<WrappedComponent { ...props } isConnected={ isConnected } />
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
'withNetworkConnectivity'
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export default withNetworkConnectivity;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useEffect, useState } from '@wordpress/element';
|
|
5
|
+
import {
|
|
6
|
+
requestConnectionStatus,
|
|
7
|
+
subscribeConnectionStatus,
|
|
8
|
+
} from '@wordpress/react-native-bridge';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {Object} NetworkInformation
|
|
12
|
+
*
|
|
13
|
+
* @property {boolean} [isConnected] Whether the device is connected to a network.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns the current network connectivity status provided by the native bridge.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
*
|
|
21
|
+
* ```jsx
|
|
22
|
+
* const { isConnected } = useNetworkConnectivity();
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @return {NetworkInformation} Network information.
|
|
26
|
+
*/
|
|
27
|
+
export default function useNetworkConnectivity() {
|
|
28
|
+
const [ isConnected, setIsConnected ] = useState( true );
|
|
29
|
+
|
|
30
|
+
useEffect( () => {
|
|
31
|
+
let isCurrent = true;
|
|
32
|
+
|
|
33
|
+
requestConnectionStatus( ( isBridgeConnected ) => {
|
|
34
|
+
if ( ! isCurrent ) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
setIsConnected( isBridgeConnected );
|
|
39
|
+
} );
|
|
40
|
+
|
|
41
|
+
return () => {
|
|
42
|
+
isCurrent = false;
|
|
43
|
+
};
|
|
44
|
+
}, [] );
|
|
45
|
+
|
|
46
|
+
useEffect( () => {
|
|
47
|
+
const subscription = subscribeConnectionStatus(
|
|
48
|
+
( { isConnected: isBridgeConnected } ) => {
|
|
49
|
+
setIsConnected( isBridgeConnected );
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return () => {
|
|
54
|
+
subscription.remove();
|
|
55
|
+
};
|
|
56
|
+
}, [] );
|
|
57
|
+
|
|
58
|
+
return { isConnected };
|
|
59
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { act, renderHook } from 'test/helpers';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
requestConnectionStatus,
|
|
11
|
+
subscribeConnectionStatus,
|
|
12
|
+
} from '@wordpress/react-native-bridge';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
import useNetworkConnectivity from '../index';
|
|
18
|
+
|
|
19
|
+
describe( 'useNetworkConnectivity', () => {
|
|
20
|
+
it( 'should optimisitically presume network connectivity', () => {
|
|
21
|
+
const { result } = renderHook( () => useNetworkConnectivity() );
|
|
22
|
+
|
|
23
|
+
expect( result.current.isConnected ).toBe( true );
|
|
24
|
+
} );
|
|
25
|
+
|
|
26
|
+
describe( 'when network connectivity is available', () => {
|
|
27
|
+
beforeAll( () => {
|
|
28
|
+
requestConnectionStatus.mockImplementation( ( callback ) => {
|
|
29
|
+
callback( true );
|
|
30
|
+
return { remove: jest.fn() };
|
|
31
|
+
} );
|
|
32
|
+
} );
|
|
33
|
+
|
|
34
|
+
it( 'should return true', () => {
|
|
35
|
+
const { result } = renderHook( () => useNetworkConnectivity() );
|
|
36
|
+
|
|
37
|
+
expect( result.current.isConnected ).toBe( true );
|
|
38
|
+
} );
|
|
39
|
+
|
|
40
|
+
it( 'should update the status when network connectivity changes', () => {
|
|
41
|
+
let subscriptionCallback;
|
|
42
|
+
subscribeConnectionStatus.mockImplementation( ( callback ) => {
|
|
43
|
+
subscriptionCallback = callback;
|
|
44
|
+
return { remove: jest.fn() };
|
|
45
|
+
} );
|
|
46
|
+
|
|
47
|
+
const { result } = renderHook( () => useNetworkConnectivity() );
|
|
48
|
+
|
|
49
|
+
expect( result.current.isConnected ).toBe( true );
|
|
50
|
+
|
|
51
|
+
act( () => subscriptionCallback( { isConnected: false } ) );
|
|
52
|
+
|
|
53
|
+
expect( result.current.isConnected ).toBe( false );
|
|
54
|
+
} );
|
|
55
|
+
} );
|
|
56
|
+
|
|
57
|
+
describe( 'when network connectivity is unavailable', () => {
|
|
58
|
+
beforeAll( () => {
|
|
59
|
+
requestConnectionStatus.mockImplementation( ( callback ) => {
|
|
60
|
+
callback( false );
|
|
61
|
+
return { remove: jest.fn() };
|
|
62
|
+
} );
|
|
63
|
+
} );
|
|
64
|
+
|
|
65
|
+
it( 'should return false', () => {
|
|
66
|
+
const { result } = renderHook( () => useNetworkConnectivity() );
|
|
67
|
+
|
|
68
|
+
expect( result.current.isConnected ).toBe( false );
|
|
69
|
+
} );
|
|
70
|
+
|
|
71
|
+
it( 'should update the status when network connectivity changes', () => {
|
|
72
|
+
let subscriptionCallback;
|
|
73
|
+
subscribeConnectionStatus.mockImplementation( ( callback ) => {
|
|
74
|
+
subscriptionCallback = callback;
|
|
75
|
+
return { remove: jest.fn() };
|
|
76
|
+
} );
|
|
77
|
+
|
|
78
|
+
const { result } = renderHook( () => useNetworkConnectivity() );
|
|
79
|
+
|
|
80
|
+
expect( result.current.isConnected ).toBe( false );
|
|
81
|
+
|
|
82
|
+
act( () => subscriptionCallback( { isConnected: true } ) );
|
|
83
|
+
|
|
84
|
+
expect( result.current.isConnected ).toBe( true );
|
|
85
|
+
} );
|
|
86
|
+
} );
|
|
87
|
+
} );
|
package/src/index.native.js
CHANGED
|
@@ -17,6 +17,7 @@ export { default as withInstanceId } from './higher-order/with-instance-id';
|
|
|
17
17
|
export { default as withSafeTimeout } from './higher-order/with-safe-timeout';
|
|
18
18
|
export { default as withState } from './higher-order/with-state';
|
|
19
19
|
export { default as withPreferredColorScheme } from './higher-order/with-preferred-color-scheme';
|
|
20
|
+
export { default as withNetworkConnectivity } from './higher-order/with-network-connectivity';
|
|
20
21
|
|
|
21
22
|
// Hooks.
|
|
22
23
|
export { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';
|
|
@@ -37,3 +38,4 @@ export { default as useDebouncedInput } from './hooks/use-debounced-input';
|
|
|
37
38
|
export { default as useThrottle } from './hooks/use-throttle';
|
|
38
39
|
export { default as useMergeRefs } from './hooks/use-merge-refs';
|
|
39
40
|
export { default as useRefEffect } from './hooks/use-ref-effect';
|
|
41
|
+
export { default as useNetworkConnectivity } from './hooks/use-network-connectivity';
|