@ionic/portals-react-native 0.0.1 → 0.0.2
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/README.md +3 -3
- package/ReactNativePortals.podspec +2 -1
- package/lib/commonjs/PortalView.android.js +1 -1
- package/lib/commonjs/PortalView.android.js.map +1 -1
- package/lib/commonjs/PortalView.js.map +1 -1
- package/lib/commonjs/index.js +13 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/PortalView.android.js +1 -1
- package/lib/module/PortalView.android.js.map +1 -1
- package/lib/module/PortalView.js.map +1 -1
- package/lib/module/index.js +13 -3
- package/lib/module/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +23 -5
package/README.md
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
<br />
|
|
9
9
|
<p align="center">
|
|
10
10
|
<a href="https://github.com/ionic-team/react-native-ionic-portals/actions?query=workflow%3ACI"><img src="https://img.shields.io/github/workflow/status/ionic-team/ionic-portals/CI?style=flat-square" /></a>
|
|
11
|
-
<a href="https://www.npmjs.com/package/@ionic/react-native
|
|
12
|
-
<a href="https://www.npmjs.com/package/@ionic/react-native
|
|
11
|
+
<a href="https://www.npmjs.com/package/@ionic/portals-react-native"><img src="https://img.shields.io/npm/l/@ionic/portals-react-native?style=flat-square" /></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/@ionic/portals-react-native"><img src="https://img.shields.io/npm/v/@ionic/portals-react-native?style=flat-square" /></a>
|
|
13
13
|
</p>
|
|
14
14
|
<p align="center">
|
|
15
15
|
<a href="https://ionic.io/docs/portals"><img src="https://img.shields.io/static/v1?label=docs&message=ionic.io/portals&color=blue&style=flat-square" /></a>
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
21
|
-
Ionic Portals is a supercharged native Web View component for iOS and Android that lets you add web-based experiences to
|
|
21
|
+
Ionic Portals is a supercharged native Web View component for iOS and Android that lets you add web-based experiences to React Native mobile apps. It enables React Native and web teams to better collaborate and bring new and existing web experiences to mobile in a safe, controlled way.
|
|
22
22
|
|
|
23
23
|
## Getting Started
|
|
24
24
|
|
|
@@ -13,7 +13,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
13
13
|
|
|
14
14
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
15
|
|
|
16
|
-
function _extends() { _extends = Object.assign
|
|
16
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
17
17
|
|
|
18
18
|
const PortalViewManager = (0, _reactNative.requireNativeComponent)('AndroidPortalView');
|
|
19
19
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["PortalViewManager","requireNativeComponent","createFragment","viewId","UIManager","dispatchViewManagerCommand","AndroidPortalView","Commands","create","toString","PortalView","props","ref","useRef","useEffect","findNodeHandle","current"],"sources":["PortalView.android.tsx"],"sourcesContent":["import React, { useEffect, useRef } from 'react';\nimport {\n findNodeHandle,\n requireNativeComponent,\n UIManager,\n} from 'react-native';\nimport type { PortalProps } from '.';\n\nconst PortalViewManager = requireNativeComponent('AndroidPortalView');\n\nconst createFragment = (viewId: number | null) =>\n UIManager.dispatchViewManagerCommand(\n viewId,\n // we are calling the 'create' command\n // @ts-expect-error\n UIManager.AndroidPortalView.Commands.create.toString(),\n [viewId]\n );\n\nconst PortalView = (props: PortalProps) => {\n const ref = useRef(null);\n\n useEffect(() => {\n const viewId = findNodeHandle(ref.current);\n createFragment(viewId);\n }, []);\n\n return <PortalViewManager {...props} ref={ref} />;\n};\n\nexport default PortalView;\n"],"mappings":";;;;;;;AAAA;;AACA;;;;;;;;AAOA,MAAMA,iBAAiB,GAAG,IAAAC,mCAAA,EAAuB,mBAAvB,CAA1B;;AAEA,MAAMC,cAAc,GAAIC,MAAD,IACrBC,sBAAA,CAAUC,0BAAV,CACEF,MADF,EAEE;AACA;AACAC,sBAAA,CAAUE,iBAAV,CAA4BC,QAA5B,CAAqCC,MAArC,CAA4CC,QAA5C,EAJF,EAKE,CAACN,MAAD,CALF,CADF;;AASA,MAAMO,UAAU,GAAIC,KAAD,IAAwB;EACzC,MAAMC,GAAG,GAAG,IAAAC,aAAA,EAAO,IAAP,CAAZ;EAEA,IAAAC,gBAAA,EAAU,MAAM;IACd,MAAMX,MAAM,GAAG,IAAAY,2BAAA,EAAeH,GAAG,CAACI,OAAnB,CAAf;IACAd,cAAc,CAACC,MAAD,CAAd;EACD,CAHD,EAGG,EAHH;EAKA,oBAAO,6BAAC,iBAAD,eAAuBQ,KAAvB;IAA8B,GAAG,EAAEC;EAAnC,GAAP;AACD,CATD;;eAWeF,U"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["HostComponentPortal","requireNativeComponent","PortalView","props"],"sources":["PortalView.tsx"],"sourcesContent":["import React from 'react';\nimport { requireNativeComponent } from 'react-native';\nimport type { PortalProps } from '.';\n\nconst HostComponentPortal = requireNativeComponent('IONPortalView');\n\nconst PortalView = (props: PortalProps) => {\n return <HostComponentPortal {...props} />;\n};\n\nexport default PortalView;\n"],"mappings":";;;;;;;AAAA;;AACA;;;;AAGA,MAAMA,mBAAmB,GAAG,IAAAC,mCAAA,EAAuB,eAAvB,CAA5B;;AAEA,MAAMC,UAAU,GAAIC,KAAD,IAAwB;EACzC,oBAAO,6BAAC,mBAAD,EAAyBA,KAAzB,CAAP;AACD,CAFD;;eAIeD,U"}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -22,11 +22,16 @@ const {
|
|
|
22
22
|
IONPortalManager
|
|
23
23
|
} = _reactNative.NativeModules;
|
|
24
24
|
const PortalsPubSub = new _reactNative.NativeEventEmitter(IONPortalsPubSub);
|
|
25
|
-
|
|
25
|
+
const subscriptionMap = new Map();
|
|
26
26
|
|
|
27
27
|
const subscribe = async (topic, onMessageReceived) => {
|
|
28
28
|
const subscriptionRef = await IONPortalsPubSub.subscribe(topic);
|
|
29
|
-
|
|
29
|
+
const subscriber = PortalsPubSub.addListener('PortalsSubscription', message => {
|
|
30
|
+
if (message.topic === topic) {
|
|
31
|
+
onMessageReceived(message);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
subscriptionMap.set(subscriptionRef, subscriber);
|
|
30
35
|
return subscriptionRef;
|
|
31
36
|
};
|
|
32
37
|
|
|
@@ -34,7 +39,12 @@ exports.subscribe = subscribe;
|
|
|
34
39
|
|
|
35
40
|
const unsubscribe = (topic, subRef) => {
|
|
36
41
|
IONPortalsPubSub.unsubscribe(topic, subRef);
|
|
37
|
-
|
|
42
|
+
const subscription = subscriptionMap.get(subRef);
|
|
43
|
+
|
|
44
|
+
if (subscription !== undefined) {
|
|
45
|
+
subscription.remove();
|
|
46
|
+
subscriptionMap.delete(subRef);
|
|
47
|
+
}
|
|
38
48
|
};
|
|
39
49
|
|
|
40
50
|
exports.unsubscribe = unsubscribe;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["IONPortalsPubSub","IONPortalManager","NativeModules","PortalsPubSub","NativeEventEmitter","subscriptionMap","Map","subscribe","topic","onMessageReceived","subscriptionRef","subscriber","addListener","message","set","unsubscribe","subRef","subscription","get","undefined","remove","delete","publish","data","msg","register","key","addPortal","portal"],"sources":["index.ts"],"sourcesContent":["import {\n EmitterSubscription,\n NativeEventEmitter,\n NativeModules,\n ViewProps,\n} from 'react-native';\n\nconst { IONPortalsPubSub, IONPortalManager } = NativeModules;\n\nexport { default as PortalView } from './PortalView';\n\nexport interface Message {\n subscriptionRef: number;\n data: any;\n topic: string;\n}\n\nconst PortalsPubSub = new NativeEventEmitter(IONPortalsPubSub);\n\nconst subscriptionMap = new Map<number, EmitterSubscription>();\n\nexport const subscribe = async (\n topic: string,\n onMessageReceived: (message: Message) => void\n): Promise<number> => {\n const subscriptionRef = await IONPortalsPubSub.subscribe(topic);\n\n const subscriber = PortalsPubSub.addListener(\n 'PortalsSubscription',\n (message: Message) => {\n if (message.topic === topic) {\n onMessageReceived(message);\n }\n }\n );\n\n subscriptionMap.set(subscriptionRef, subscriber);\n\n return subscriptionRef;\n};\n\nexport const unsubscribe = (topic: string, subRef: number) => {\n IONPortalsPubSub.unsubscribe(topic, subRef);\n\n const subscription = subscriptionMap.get(subRef);\n if (subscription !== undefined) {\n subscription.remove();\n subscriptionMap.delete(subRef);\n }\n};\n\nexport const publish = (topic: string, data: any) => {\n const msg = { message: data };\n IONPortalsPubSub.publish(topic, msg);\n};\n\nexport const register = (key: string) => {\n IONPortalManager.register(key);\n};\n\nexport interface Portal {\n name: string;\n startDir?: string;\n initialContext?: any;\n}\n\nexport type PortalProps = Pick<Portal, 'name' | 'initialContext'> & ViewProps;\n\nexport const addPortal = (portal: Portal) => {\n IONPortalManager.addPortal(portal);\n};\n"],"mappings":";;;;;;;;;;;;;AAAA;;AASA;;;;AAFA,MAAM;EAAEA,gBAAF;EAAoBC;AAApB,IAAyCC,0BAA/C;AAUA,MAAMC,aAAa,GAAG,IAAIC,+BAAJ,CAAuBJ,gBAAvB,CAAtB;AAEA,MAAMK,eAAe,GAAG,IAAIC,GAAJ,EAAxB;;AAEO,MAAMC,SAAS,GAAG,OACvBC,KADuB,EAEvBC,iBAFuB,KAGH;EACpB,MAAMC,eAAe,GAAG,MAAMV,gBAAgB,CAACO,SAAjB,CAA2BC,KAA3B,CAA9B;EAEA,MAAMG,UAAU,GAAGR,aAAa,CAACS,WAAd,CACjB,qBADiB,EAEhBC,OAAD,IAAsB;IACpB,IAAIA,OAAO,CAACL,KAAR,KAAkBA,KAAtB,EAA6B;MAC3BC,iBAAiB,CAACI,OAAD,CAAjB;IACD;EACF,CANgB,CAAnB;EASAR,eAAe,CAACS,GAAhB,CAAoBJ,eAApB,EAAqCC,UAArC;EAEA,OAAOD,eAAP;AACD,CAlBM;;;;AAoBA,MAAMK,WAAW,GAAG,CAACP,KAAD,EAAgBQ,MAAhB,KAAmC;EAC5DhB,gBAAgB,CAACe,WAAjB,CAA6BP,KAA7B,EAAoCQ,MAApC;EAEA,MAAMC,YAAY,GAAGZ,eAAe,CAACa,GAAhB,CAAoBF,MAApB,CAArB;;EACA,IAAIC,YAAY,KAAKE,SAArB,EAAgC;IAC9BF,YAAY,CAACG,MAAb;IACAf,eAAe,CAACgB,MAAhB,CAAuBL,MAAvB;EACD;AACF,CARM;;;;AAUA,MAAMM,OAAO,GAAG,CAACd,KAAD,EAAgBe,IAAhB,KAA8B;EACnD,MAAMC,GAAG,GAAG;IAAEX,OAAO,EAAEU;EAAX,CAAZ;EACAvB,gBAAgB,CAACsB,OAAjB,CAAyBd,KAAzB,EAAgCgB,GAAhC;AACD,CAHM;;;;AAKA,MAAMC,QAAQ,GAAIC,GAAD,IAAiB;EACvCzB,gBAAgB,CAACwB,QAAjB,CAA0BC,GAA1B;AACD,CAFM;;;;AAYA,MAAMC,SAAS,GAAIC,MAAD,IAAoB;EAC3C3B,gBAAgB,CAAC0B,SAAjB,CAA2BC,MAA3B;AACD,CAFM"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
3
|
import React, { useEffect, useRef } from 'react';
|
|
4
4
|
import { findNodeHandle, requireNativeComponent, UIManager } from 'react-native';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["React","useEffect","useRef","findNodeHandle","requireNativeComponent","UIManager","PortalViewManager","createFragment","viewId","dispatchViewManagerCommand","AndroidPortalView","Commands","create","toString","PortalView","props","ref","current"],"sources":["PortalView.android.tsx"],"sourcesContent":["import React, { useEffect, useRef } from 'react';\nimport {\n findNodeHandle,\n requireNativeComponent,\n UIManager,\n} from 'react-native';\nimport type { PortalProps } from '.';\n\nconst PortalViewManager = requireNativeComponent('AndroidPortalView');\n\nconst createFragment = (viewId: number | null) =>\n UIManager.dispatchViewManagerCommand(\n viewId,\n // we are calling the 'create' command\n // @ts-expect-error\n UIManager.AndroidPortalView.Commands.create.toString(),\n [viewId]\n );\n\nconst PortalView = (props: PortalProps) => {\n const ref = useRef(null);\n\n useEffect(() => {\n const viewId = findNodeHandle(ref.current);\n createFragment(viewId);\n }, []);\n\n return <PortalViewManager {...props} ref={ref} />;\n};\n\nexport default PortalView;\n"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,SAAhB,EAA2BC,MAA3B,QAAyC,OAAzC;AACA,SACEC,cADF,EAEEC,sBAFF,EAGEC,SAHF,QAIO,cAJP;AAOA,MAAMC,iBAAiB,GAAGF,sBAAsB,CAAC,mBAAD,CAAhD;;AAEA,MAAMG,cAAc,GAAIC,MAAD,IACrBH,SAAS,CAACI,0BAAV,CACED,MADF,EAEE;AACA;AACAH,SAAS,CAACK,iBAAV,CAA4BC,QAA5B,CAAqCC,MAArC,CAA4CC,QAA5C,EAJF,EAKE,CAACL,MAAD,CALF,CADF;;AASA,MAAMM,UAAU,GAAIC,KAAD,IAAwB;EACzC,MAAMC,GAAG,GAAGd,MAAM,CAAC,IAAD,CAAlB;EAEAD,SAAS,CAAC,MAAM;IACd,MAAMO,MAAM,GAAGL,cAAc,CAACa,GAAG,CAACC,OAAL,CAA7B;IACAV,cAAc,CAACC,MAAD,CAAd;EACD,CAHQ,EAGN,EAHM,CAAT;EAKA,oBAAO,oBAAC,iBAAD,eAAuBO,KAAvB;IAA8B,GAAG,EAAEC;EAAnC,GAAP;AACD,CATD;;AAWA,eAAeF,UAAf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["React","requireNativeComponent","HostComponentPortal","PortalView","props"],"sources":["PortalView.tsx"],"sourcesContent":["import React from 'react';\nimport { requireNativeComponent } from 'react-native';\nimport type { PortalProps } from '.';\n\nconst HostComponentPortal = requireNativeComponent('IONPortalView');\n\nconst PortalView = (props: PortalProps) => {\n return <HostComponentPortal {...props} />;\n};\n\nexport default PortalView;\n"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,sBAAT,QAAuC,cAAvC;AAGA,MAAMC,mBAAmB,GAAGD,sBAAsB,CAAC,eAAD,CAAlD;;AAEA,MAAME,UAAU,GAAIC,KAAD,IAAwB;EACzC,oBAAO,oBAAC,mBAAD,EAAyBA,KAAzB,CAAP;AACD,CAFD;;AAIA,eAAeD,UAAf"}
|
package/lib/module/index.js
CHANGED
|
@@ -5,15 +5,25 @@ const {
|
|
|
5
5
|
} = NativeModules;
|
|
6
6
|
export { default as PortalView } from './PortalView';
|
|
7
7
|
const PortalsPubSub = new NativeEventEmitter(IONPortalsPubSub);
|
|
8
|
-
|
|
8
|
+
const subscriptionMap = new Map();
|
|
9
9
|
export const subscribe = async (topic, onMessageReceived) => {
|
|
10
10
|
const subscriptionRef = await IONPortalsPubSub.subscribe(topic);
|
|
11
|
-
|
|
11
|
+
const subscriber = PortalsPubSub.addListener('PortalsSubscription', message => {
|
|
12
|
+
if (message.topic === topic) {
|
|
13
|
+
onMessageReceived(message);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
subscriptionMap.set(subscriptionRef, subscriber);
|
|
12
17
|
return subscriptionRef;
|
|
13
18
|
};
|
|
14
19
|
export const unsubscribe = (topic, subRef) => {
|
|
15
20
|
IONPortalsPubSub.unsubscribe(topic, subRef);
|
|
16
|
-
|
|
21
|
+
const subscription = subscriptionMap.get(subRef);
|
|
22
|
+
|
|
23
|
+
if (subscription !== undefined) {
|
|
24
|
+
subscription.remove();
|
|
25
|
+
subscriptionMap.delete(subRef);
|
|
26
|
+
}
|
|
17
27
|
};
|
|
18
28
|
export const publish = (topic, data) => {
|
|
19
29
|
const msg = {
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["NativeEventEmitter","NativeModules","IONPortalsPubSub","IONPortalManager","default","PortalView","PortalsPubSub","subscriptionMap","Map","subscribe","topic","onMessageReceived","subscriptionRef","subscriber","addListener","message","set","unsubscribe","subRef","subscription","get","undefined","remove","delete","publish","data","msg","register","key","addPortal","portal"],"sources":["index.ts"],"sourcesContent":["import {\n EmitterSubscription,\n NativeEventEmitter,\n NativeModules,\n ViewProps,\n} from 'react-native';\n\nconst { IONPortalsPubSub, IONPortalManager } = NativeModules;\n\nexport { default as PortalView } from './PortalView';\n\nexport interface Message {\n subscriptionRef: number;\n data: any;\n topic: string;\n}\n\nconst PortalsPubSub = new NativeEventEmitter(IONPortalsPubSub);\n\nconst subscriptionMap = new Map<number, EmitterSubscription>();\n\nexport const subscribe = async (\n topic: string,\n onMessageReceived: (message: Message) => void\n): Promise<number> => {\n const subscriptionRef = await IONPortalsPubSub.subscribe(topic);\n\n const subscriber = PortalsPubSub.addListener(\n 'PortalsSubscription',\n (message: Message) => {\n if (message.topic === topic) {\n onMessageReceived(message);\n }\n }\n );\n\n subscriptionMap.set(subscriptionRef, subscriber);\n\n return subscriptionRef;\n};\n\nexport const unsubscribe = (topic: string, subRef: number) => {\n IONPortalsPubSub.unsubscribe(topic, subRef);\n\n const subscription = subscriptionMap.get(subRef);\n if (subscription !== undefined) {\n subscription.remove();\n subscriptionMap.delete(subRef);\n }\n};\n\nexport const publish = (topic: string, data: any) => {\n const msg = { message: data };\n IONPortalsPubSub.publish(topic, msg);\n};\n\nexport const register = (key: string) => {\n IONPortalManager.register(key);\n};\n\nexport interface Portal {\n name: string;\n startDir?: string;\n initialContext?: any;\n}\n\nexport type PortalProps = Pick<Portal, 'name' | 'initialContext'> & ViewProps;\n\nexport const addPortal = (portal: Portal) => {\n IONPortalManager.addPortal(portal);\n};\n"],"mappings":"AAAA,SAEEA,kBAFF,EAGEC,aAHF,QAKO,cALP;AAOA,MAAM;EAAEC,gBAAF;EAAoBC;AAApB,IAAyCF,aAA/C;AAEA,SAASG,OAAO,IAAIC,UAApB,QAAsC,cAAtC;AAQA,MAAMC,aAAa,GAAG,IAAIN,kBAAJ,CAAuBE,gBAAvB,CAAtB;AAEA,MAAMK,eAAe,GAAG,IAAIC,GAAJ,EAAxB;AAEA,OAAO,MAAMC,SAAS,GAAG,OACvBC,KADuB,EAEvBC,iBAFuB,KAGH;EACpB,MAAMC,eAAe,GAAG,MAAMV,gBAAgB,CAACO,SAAjB,CAA2BC,KAA3B,CAA9B;EAEA,MAAMG,UAAU,GAAGP,aAAa,CAACQ,WAAd,CACjB,qBADiB,EAEhBC,OAAD,IAAsB;IACpB,IAAIA,OAAO,CAACL,KAAR,KAAkBA,KAAtB,EAA6B;MAC3BC,iBAAiB,CAACI,OAAD,CAAjB;IACD;EACF,CANgB,CAAnB;EASAR,eAAe,CAACS,GAAhB,CAAoBJ,eAApB,EAAqCC,UAArC;EAEA,OAAOD,eAAP;AACD,CAlBM;AAoBP,OAAO,MAAMK,WAAW,GAAG,CAACP,KAAD,EAAgBQ,MAAhB,KAAmC;EAC5DhB,gBAAgB,CAACe,WAAjB,CAA6BP,KAA7B,EAAoCQ,MAApC;EAEA,MAAMC,YAAY,GAAGZ,eAAe,CAACa,GAAhB,CAAoBF,MAApB,CAArB;;EACA,IAAIC,YAAY,KAAKE,SAArB,EAAgC;IAC9BF,YAAY,CAACG,MAAb;IACAf,eAAe,CAACgB,MAAhB,CAAuBL,MAAvB;EACD;AACF,CARM;AAUP,OAAO,MAAMM,OAAO,GAAG,CAACd,KAAD,EAAgBe,IAAhB,KAA8B;EACnD,MAAMC,GAAG,GAAG;IAAEX,OAAO,EAAEU;EAAX,CAAZ;EACAvB,gBAAgB,CAACsB,OAAjB,CAAyBd,KAAzB,EAAgCgB,GAAhC;AACD,CAHM;AAKP,OAAO,MAAMC,QAAQ,GAAIC,GAAD,IAAiB;EACvCzB,gBAAgB,CAACwB,QAAjB,CAA0BC,GAA1B;AACD,CAFM;AAYP,OAAO,MAAMC,SAAS,GAAIC,MAAD,IAAoB;EAC3C3B,gBAAgB,CAAC0B,SAAjB,CAA2BC,MAA3B;AACD,CAFM"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
EmitterSubscription,
|
|
3
|
+
NativeEventEmitter,
|
|
4
|
+
NativeModules,
|
|
5
|
+
ViewProps,
|
|
6
|
+
} from 'react-native';
|
|
2
7
|
|
|
3
8
|
const { IONPortalsPubSub, IONPortalManager } = NativeModules;
|
|
4
9
|
|
|
@@ -12,23 +17,36 @@ export interface Message {
|
|
|
12
17
|
|
|
13
18
|
const PortalsPubSub = new NativeEventEmitter(IONPortalsPubSub);
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
const subscriptionMap = new Map<number, EmitterSubscription>();
|
|
16
21
|
|
|
17
22
|
export const subscribe = async (
|
|
18
23
|
topic: string,
|
|
19
24
|
onMessageReceived: (message: Message) => void
|
|
20
25
|
): Promise<number> => {
|
|
21
26
|
const subscriptionRef = await IONPortalsPubSub.subscribe(topic);
|
|
22
|
-
|
|
27
|
+
|
|
28
|
+
const subscriber = PortalsPubSub.addListener(
|
|
23
29
|
'PortalsSubscription',
|
|
24
|
-
|
|
30
|
+
(message: Message) => {
|
|
31
|
+
if (message.topic === topic) {
|
|
32
|
+
onMessageReceived(message);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
25
35
|
);
|
|
36
|
+
|
|
37
|
+
subscriptionMap.set(subscriptionRef, subscriber);
|
|
38
|
+
|
|
26
39
|
return subscriptionRef;
|
|
27
40
|
};
|
|
28
41
|
|
|
29
42
|
export const unsubscribe = (topic: string, subRef: number) => {
|
|
30
43
|
IONPortalsPubSub.unsubscribe(topic, subRef);
|
|
31
|
-
|
|
44
|
+
|
|
45
|
+
const subscription = subscriptionMap.get(subRef);
|
|
46
|
+
if (subscription !== undefined) {
|
|
47
|
+
subscription.remove();
|
|
48
|
+
subscriptionMap.delete(subRef);
|
|
49
|
+
}
|
|
32
50
|
};
|
|
33
51
|
|
|
34
52
|
export const publish = (topic: string, data: any) => {
|