@ionic/portals-react-native 0.0.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.
Files changed (38) hide show
  1. package/LICENSE.md +67 -0
  2. package/README.md +192 -0
  3. package/ReactNativePortals.podspec +20 -0
  4. package/android/build.gradle +122 -0
  5. package/android/gradle.properties +4 -0
  6. package/android/src/main/AndroidManifest.xml +4 -0
  7. package/android/src/main/java/io/ionic/portals/reactnative/ReactNativePortalsModule.kt +203 -0
  8. package/android/src/main/java/io/ionic/portals/reactnative/ReactNativePortalsPackage.kt +20 -0
  9. package/ios/Podfile +14 -0
  10. package/ios/Podfile.lock +389 -0
  11. package/ios/PortalManager.m +14 -0
  12. package/ios/PortalView.m +14 -0
  13. package/ios/PortalsPubSub.m +16 -0
  14. package/ios/ReactNativePortals-Bridging-Header.h +3 -0
  15. package/ios/ReactNativePortals.swift +113 -0
  16. package/ios/ReactNativePortals.xcodeproj/project.pbxproj +417 -0
  17. package/ios/ReactNativePortals.xcodeproj/xcshareddata/xcschemes/ReactNativePortals.xcscheme +67 -0
  18. package/ios/ReactNativePortals.xcworkspace/contents.xcworkspacedata +10 -0
  19. package/ios/ReactNativePortals.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  20. package/lib/commonjs/PortalView.android.js +37 -0
  21. package/lib/commonjs/PortalView.android.js.map +1 -0
  22. package/lib/commonjs/PortalView.js +22 -0
  23. package/lib/commonjs/PortalView.js.map +1 -0
  24. package/lib/commonjs/index.js +62 -0
  25. package/lib/commonjs/index.js.map +1 -0
  26. package/lib/module/PortalView.android.js +23 -0
  27. package/lib/module/PortalView.android.js.map +1 -0
  28. package/lib/module/PortalView.js +10 -0
  29. package/lib/module/PortalView.js.map +1 -0
  30. package/lib/module/index.js +30 -0
  31. package/lib/module/index.js.map +1 -0
  32. package/lib/typescript/PortalView.android.d.ts +4 -0
  33. package/lib/typescript/PortalView.d.ts +4 -0
  34. package/lib/typescript/index.d.ts +18 -0
  35. package/package.json +133 -0
  36. package/src/PortalView.android.tsx +31 -0
  37. package/src/PortalView.tsx +11 -0
  38. package/src/index.ts +53 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["PortalView.android.tsx"],"names":["React","useEffect","useRef","findNodeHandle","requireNativeComponent","UIManager","PortalViewManager","createFragment","viewId","dispatchViewManagerCommand","AndroidPortalView","Commands","create","toString","PortalView","props","ref","current"],"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;AACzC,QAAMC,GAAG,GAAGd,MAAM,CAAC,IAAD,CAAlB;AAEAD,EAAAA,SAAS,CAAC,MAAM;AACd,UAAMO,MAAM,GAAGL,cAAc,CAACa,GAAG,CAACC,OAAL,CAA7B;AACAV,IAAAA,cAAc,CAACC,MAAD,CAAd;AACD,GAHQ,EAGN,EAHM,CAAT;AAKA,sBAAO,oBAAC,iBAAD,eAAuBO,KAAvB;AAA8B,IAAA,GAAG,EAAEC;AAAnC,KAAP;AACD,CATD;;AAWA,eAAeF,UAAf","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"]}
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { requireNativeComponent } from 'react-native';
3
+ const HostComponentPortal = requireNativeComponent('IONPortalView');
4
+
5
+ const PortalView = props => {
6
+ return /*#__PURE__*/React.createElement(HostComponentPortal, props);
7
+ };
8
+
9
+ export default PortalView;
10
+ //# sourceMappingURL=PortalView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["PortalView.tsx"],"names":["React","requireNativeComponent","HostComponentPortal","PortalView","props"],"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;AACzC,sBAAO,oBAAC,mBAAD,EAAyBA,KAAzB,CAAP;AACD,CAFD;;AAIA,eAAeD,UAAf","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"]}
@@ -0,0 +1,30 @@
1
+ import { NativeEventEmitter, NativeModules } from 'react-native';
2
+ const {
3
+ IONPortalsPubSub,
4
+ IONPortalManager
5
+ } = NativeModules;
6
+ export { default as PortalView } from './PortalView';
7
+ const PortalsPubSub = new NativeEventEmitter(IONPortalsPubSub);
8
+ let subscriptionRefDict = {};
9
+ export const subscribe = async (topic, onMessageReceived) => {
10
+ const subscriptionRef = await IONPortalsPubSub.subscribe(topic);
11
+ subscriptionRefDict[subscriptionRef] = PortalsPubSub.addListener('PortalsSubscription', onMessageReceived);
12
+ return subscriptionRef;
13
+ };
14
+ export const unsubscribe = (topic, subRef) => {
15
+ IONPortalsPubSub.unsubscribe(topic, subRef);
16
+ subscriptionRefDict[subRef] = null;
17
+ };
18
+ export const publish = (topic, data) => {
19
+ const msg = {
20
+ message: data
21
+ };
22
+ IONPortalsPubSub.publish(topic, msg);
23
+ };
24
+ export const register = key => {
25
+ IONPortalManager.register(key);
26
+ };
27
+ export const addPortal = portal => {
28
+ IONPortalManager.addPortal(portal);
29
+ };
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":["NativeEventEmitter","NativeModules","IONPortalsPubSub","IONPortalManager","default","PortalView","PortalsPubSub","subscriptionRefDict","subscribe","topic","onMessageReceived","subscriptionRef","addListener","unsubscribe","subRef","publish","data","msg","message","register","key","addPortal","portal"],"mappings":"AAAA,SAASA,kBAAT,EAA6BC,aAA7B,QAA6D,cAA7D;AAEA,MAAM;AAAEC,EAAAA,gBAAF;AAAoBC,EAAAA;AAApB,IAAyCF,aAA/C;AAEA,SAASG,OAAO,IAAIC,UAApB,QAAsC,cAAtC;AAQA,MAAMC,aAAa,GAAG,IAAIN,kBAAJ,CAAuBE,gBAAvB,CAAtB;AAEA,IAAIK,mBAAwB,GAAG,EAA/B;AAEA,OAAO,MAAMC,SAAS,GAAG,OACvBC,KADuB,EAEvBC,iBAFuB,KAGH;AACpB,QAAMC,eAAe,GAAG,MAAMT,gBAAgB,CAACM,SAAjB,CAA2BC,KAA3B,CAA9B;AACAF,EAAAA,mBAAmB,CAACI,eAAD,CAAnB,GAAuCL,aAAa,CAACM,WAAd,CACrC,qBADqC,EAErCF,iBAFqC,CAAvC;AAIA,SAAOC,eAAP;AACD,CAVM;AAYP,OAAO,MAAME,WAAW,GAAG,CAACJ,KAAD,EAAgBK,MAAhB,KAAmC;AAC5DZ,EAAAA,gBAAgB,CAACW,WAAjB,CAA6BJ,KAA7B,EAAoCK,MAApC;AACAP,EAAAA,mBAAmB,CAACO,MAAD,CAAnB,GAA8B,IAA9B;AACD,CAHM;AAKP,OAAO,MAAMC,OAAO,GAAG,CAACN,KAAD,EAAgBO,IAAhB,KAA8B;AACnD,QAAMC,GAAG,GAAG;AAAEC,IAAAA,OAAO,EAAEF;AAAX,GAAZ;AACAd,EAAAA,gBAAgB,CAACa,OAAjB,CAAyBN,KAAzB,EAAgCQ,GAAhC;AACD,CAHM;AAKP,OAAO,MAAME,QAAQ,GAAIC,GAAD,IAAiB;AACvCjB,EAAAA,gBAAgB,CAACgB,QAAjB,CAA0BC,GAA1B;AACD,CAFM;AAYP,OAAO,MAAMC,SAAS,GAAIC,MAAD,IAAoB;AAC3CnB,EAAAA,gBAAgB,CAACkB,SAAjB,CAA2BC,MAA3B;AACD,CAFM","sourcesContent":["import { NativeEventEmitter, NativeModules, ViewProps } 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\nlet subscriptionRefDict: any = {};\n\nexport const subscribe = async (\n topic: string,\n onMessageReceived: (message: Message) => void\n): Promise<number> => {\n const subscriptionRef = await IONPortalsPubSub.subscribe(topic);\n subscriptionRefDict[subscriptionRef] = PortalsPubSub.addListener(\n 'PortalsSubscription',\n onMessageReceived\n );\n return subscriptionRef;\n};\n\nexport const unsubscribe = (topic: string, subRef: number) => {\n IONPortalsPubSub.unsubscribe(topic, subRef);\n subscriptionRefDict[subRef] = null;\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"]}
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import type { PortalProps } from '.';
3
+ declare const PortalView: (props: PortalProps) => JSX.Element;
4
+ export default PortalView;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import type { PortalProps } from '.';
3
+ declare const PortalView: (props: PortalProps) => JSX.Element;
4
+ export default PortalView;
@@ -0,0 +1,18 @@
1
+ import { ViewProps } from 'react-native';
2
+ export { default as PortalView } from './PortalView';
3
+ export interface Message {
4
+ subscriptionRef: number;
5
+ data: any;
6
+ topic: string;
7
+ }
8
+ export declare const subscribe: (topic: string, onMessageReceived: (message: Message) => void) => Promise<number>;
9
+ export declare const unsubscribe: (topic: string, subRef: number) => void;
10
+ export declare const publish: (topic: string, data: any) => void;
11
+ export declare const register: (key: string) => void;
12
+ export interface Portal {
13
+ name: string;
14
+ startDir?: string;
15
+ initialContext?: any;
16
+ }
17
+ export declare type PortalProps = Pick<Portal, 'name' | 'initialContext'> & ViewProps;
18
+ export declare const addPortal: (portal: Portal) => void;
package/package.json ADDED
@@ -0,0 +1,133 @@
1
+ {
2
+ "name": "@ionic/portals-react-native",
3
+ "version": "0.0.1",
4
+ "description": "Ionic Portals for React Native",
5
+ "main": "lib/commonjs/index",
6
+ "module": "lib/module/index",
7
+ "types": "lib/typescript/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "files": [
11
+ "src",
12
+ "lib",
13
+ "android/build.gradle",
14
+ "android/gradle.properties",
15
+ "android/src/main",
16
+ "ios",
17
+ "cpp",
18
+ "ReactNativePortals.podspec",
19
+ "!lib/typescript/example",
20
+ "!ios/build",
21
+ "!ios/Pods",
22
+ "!ios/**/xcuserdata",
23
+ "!**/__tests__",
24
+ "!**/__fixtures__",
25
+ "!**/__mocks__"
26
+ ],
27
+ "scripts": {
28
+ "test": "jest",
29
+ "typescript": "tsc --noEmit",
30
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
31
+ "lint:fix": "eslint \"**/*.{js,ts,tsx}\" --fix",
32
+ "prepare": "bob build",
33
+ "release": "release-it",
34
+ "example": "yarn --cwd example",
35
+ "pods": "cd example && pod-install --quiet",
36
+ "bootstrap": "yarn example && yarn && yarn pods"
37
+ },
38
+ "keywords": [
39
+ "react-native",
40
+ "ios",
41
+ "android"
42
+ ],
43
+ "repository": "https://github.com/ionic-team/react-native-ionic-portals",
44
+ "author": "Ionic <hi@ionicframework.com> (https://ionic.io/portals)",
45
+ "license": "Commercial",
46
+ "bugs": {
47
+ "url": "https://github.com/ionic-team/react-native-ionic-portals/issues"
48
+ },
49
+ "homepage": "https://github.com/ionic-team/react-native-ionic-portals#readme",
50
+ "publishConfig": {
51
+ "registry": "https://registry.npmjs.org/"
52
+ },
53
+ "devDependencies": {
54
+ "@commitlint/config-conventional": "^11.0.0",
55
+ "@react-native-community/eslint-config": "^2.0.0",
56
+ "@release-it/conventional-changelog": "^2.0.0",
57
+ "@types/jest": "^26.0.0",
58
+ "@types/react": "^16.9.19",
59
+ "@types/react-native": "0.62.13",
60
+ "commitlint": "^11.0.0",
61
+ "eslint": "^7.2.0",
62
+ "eslint-config-prettier": "^7.0.0",
63
+ "eslint-plugin-prettier": "^3.1.3",
64
+ "husky": "^6.0.0",
65
+ "jest": "^26.0.1",
66
+ "pod-install": "^0.1.0",
67
+ "prettier": "^2.0.5",
68
+ "react": "16.13.1",
69
+ "react-native": "0.63.4",
70
+ "react-native-builder-bob": "^0.18.2",
71
+ "typescript": "^4.1.3"
72
+ },
73
+ "peerDependencies": {
74
+ "react": "*",
75
+ "react-native": "*"
76
+ },
77
+ "jest": {
78
+ "preset": "react-native",
79
+ "modulePathIgnorePatterns": [
80
+ "<rootDir>/example/node_modules",
81
+ "<rootDir>/lib/"
82
+ ]
83
+ },
84
+ "commitlint": {
85
+ "extends": [
86
+ "@commitlint/config-conventional"
87
+ ]
88
+ },
89
+ "eslintConfig": {
90
+ "root": true,
91
+ "extends": [
92
+ "@react-native-community",
93
+ "prettier"
94
+ ],
95
+ "rules": {
96
+ "prettier/prettier": [
97
+ "error",
98
+ {
99
+ "quoteProps": "consistent",
100
+ "singleQuote": true,
101
+ "tabWidth": 2,
102
+ "trailingComma": "es5",
103
+ "useTabs": false
104
+ }
105
+ ]
106
+ }
107
+ },
108
+ "eslintIgnore": [
109
+ "node_modules/",
110
+ "lib/"
111
+ ],
112
+ "prettier": {
113
+ "quoteProps": "consistent",
114
+ "singleQuote": true,
115
+ "tabWidth": 2,
116
+ "trailingComma": "es5",
117
+ "useTabs": false
118
+ },
119
+ "react-native-builder-bob": {
120
+ "source": "src",
121
+ "output": "lib",
122
+ "targets": [
123
+ "commonjs",
124
+ "module",
125
+ [
126
+ "typescript",
127
+ {
128
+ "project": "tsconfig.build.json"
129
+ }
130
+ ]
131
+ ]
132
+ }
133
+ }
@@ -0,0 +1,31 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import {
3
+ findNodeHandle,
4
+ requireNativeComponent,
5
+ UIManager,
6
+ } from 'react-native';
7
+ import type { PortalProps } from '.';
8
+
9
+ const PortalViewManager = requireNativeComponent('AndroidPortalView');
10
+
11
+ const createFragment = (viewId: number | null) =>
12
+ UIManager.dispatchViewManagerCommand(
13
+ viewId,
14
+ // we are calling the 'create' command
15
+ // @ts-expect-error
16
+ UIManager.AndroidPortalView.Commands.create.toString(),
17
+ [viewId]
18
+ );
19
+
20
+ const PortalView = (props: PortalProps) => {
21
+ const ref = useRef(null);
22
+
23
+ useEffect(() => {
24
+ const viewId = findNodeHandle(ref.current);
25
+ createFragment(viewId);
26
+ }, []);
27
+
28
+ return <PortalViewManager {...props} ref={ref} />;
29
+ };
30
+
31
+ export default PortalView;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { requireNativeComponent } from 'react-native';
3
+ import type { PortalProps } from '.';
4
+
5
+ const HostComponentPortal = requireNativeComponent('IONPortalView');
6
+
7
+ const PortalView = (props: PortalProps) => {
8
+ return <HostComponentPortal {...props} />;
9
+ };
10
+
11
+ export default PortalView;
package/src/index.ts ADDED
@@ -0,0 +1,53 @@
1
+ import { NativeEventEmitter, NativeModules, ViewProps } from 'react-native';
2
+
3
+ const { IONPortalsPubSub, IONPortalManager } = NativeModules;
4
+
5
+ export { default as PortalView } from './PortalView';
6
+
7
+ export interface Message {
8
+ subscriptionRef: number;
9
+ data: any;
10
+ topic: string;
11
+ }
12
+
13
+ const PortalsPubSub = new NativeEventEmitter(IONPortalsPubSub);
14
+
15
+ let subscriptionRefDict: any = {};
16
+
17
+ export const subscribe = async (
18
+ topic: string,
19
+ onMessageReceived: (message: Message) => void
20
+ ): Promise<number> => {
21
+ const subscriptionRef = await IONPortalsPubSub.subscribe(topic);
22
+ subscriptionRefDict[subscriptionRef] = PortalsPubSub.addListener(
23
+ 'PortalsSubscription',
24
+ onMessageReceived
25
+ );
26
+ return subscriptionRef;
27
+ };
28
+
29
+ export const unsubscribe = (topic: string, subRef: number) => {
30
+ IONPortalsPubSub.unsubscribe(topic, subRef);
31
+ subscriptionRefDict[subRef] = null;
32
+ };
33
+
34
+ export const publish = (topic: string, data: any) => {
35
+ const msg = { message: data };
36
+ IONPortalsPubSub.publish(topic, msg);
37
+ };
38
+
39
+ export const register = (key: string) => {
40
+ IONPortalManager.register(key);
41
+ };
42
+
43
+ export interface Portal {
44
+ name: string;
45
+ startDir?: string;
46
+ initialContext?: any;
47
+ }
48
+
49
+ export type PortalProps = Pick<Portal, 'name' | 'initialContext'> & ViewProps;
50
+
51
+ export const addPortal = (portal: Portal) => {
52
+ IONPortalManager.addPortal(portal);
53
+ };