Skip to content

Commit 453cf2c

Browse files
authored
feat: Make getPortal accessible via the JS interface. (#32)
Fixes discrepancies between the two platforms with regards to how they are called from JS.
1 parent 2b0e5b5 commit 453cf2c

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

ios/PortalManager.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ @interface RCT_EXTERN_MODULE(IONPortalsReactNative, NSObject)
1313
RCT_EXTERN_METHOD(enableSecureLiveUpdates: (NSString *) publicKeyPath resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
1414
RCT_EXTERN_METHOD(addPortal: (NSDictionary) portal resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
1515
RCT_EXTERN_METHOD(addPortals: (NSArray) portals resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
16-
RCT_EXTERN_METHOD(getPortalNamed: (NSString *) name resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
16+
RCT_EXTERN_METHOD(getPortal: (NSString *) name resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
1717
RCT_EXTERN_METHOD(syncOne: (NSString *) appId resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
1818
RCT_EXTERN_METHOD(syncSome: (NSArray) appIds resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
1919
RCT_EXTERN_METHOD(syncAll: (RCTPromiseResolveBlock) resolver)

ios/PortalsReactNative.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class PortalsReactNative: NSObject {
4545
resolver(())
4646
}
4747

48-
@objc func enableSecureLiveUpdates(_ publicKeyPath: String, resolver: RCTPromiseResolveBlock) {
48+
@objc func enableSecureLiveUpdates(_ publicKeyPath: String, resolver: RCTPromiseResolveBlock, rejector: RCTPromiseRejectBlock) {
4949
guard let publicKeyUrl = Bundle.main.url(forResource: publicKeyPath, withExtension: nil) else { fatalError("Public key not found at \(publicKeyPath)") }
5050
lum = SecureLiveUpdateManager(named: "secure-updates", publicKeyUrl: publicKeyUrl)
5151
resolver(())
@@ -69,7 +69,7 @@ public class PortalsReactNative: NSObject {
6969

7070
static func getPortal(named name: String) -> Portal? { portals[name] }
7171

72-
@objc func getPortalNamed(name: String, resolver: RCTPromiseResolveBlock, rejector: RCTPromiseRejectBlock) {
72+
@objc func getPortal(_ name: String, resolver: RCTPromiseResolveBlock, rejector: RCTPromiseRejectBlock) {
7373
guard let portal = Self.getPortal(named: name) else { return rejector(nil, "Portal named \(name) not registered", nil) }
7474
resolver(portal.dict)
7575
}

src/index.ts

+19
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const publish = (topic: string, data: any) => {
8181
/**
8282
* Validates that a valid registration key has been procured from http://ionic.io/register-portals
8383
* @param key The registration key
84+
* @returns Promise<void>
8485
*/
8586
export const register = async (key: string): Promise<void> => {
8687
return IONPortalsReactNative.register(key);
@@ -125,15 +126,32 @@ export type PortalProps = PortalProp & ViewProps;
125126
* Adds a Portal to an internal registry. Must be called before attempting to render a {@link PortalView}.
126127
*
127128
* @param portal The portal to add to the internal registry.
129+
* @returns Promise containing the Portal that was added to the registry.
128130
*/
129131
export const addPortal = async (portal: Portal): Promise<Portal> => {
130132
return IONPortalsReactNative.addPortal(portal);
131133
};
132134

135+
/**
136+
* Adds all portals to an internal registry. This or {@link addPortal} must be called before attempting to render a {@link PortalView}
137+
*
138+
* @param portals The portals to add to the internal registry.
139+
* @returns Promise containing the Portals that were added to the registry.
140+
*/
133141
export const addPortals = async (portals: Portal[]): Promise<Portal[]> => {
134142
return IONPortalsReactNative.addPortals(portals);
135143
};
136144

145+
/**
146+
* Gets a {@link Portal} previously registered via {@link addPortal} or {@link addPortals}.
147+
*
148+
* @param name The portal name to retrieve from the internal registry.
149+
* @returns Promise containing the registered {@link Portal}. If the {@link Portal} was not registered, the Promise will fail.
150+
*/
151+
export const getPortal = async (name: string): Promise<Portal> => {
152+
return IONPortalsReactNative.getPortal(name);
153+
};
154+
137155
export interface LiveUpdate {
138156
/** The AppFlow application ID */
139157
appId: string;
@@ -165,6 +183,7 @@ export interface SyncResults {
165183
*
166184
* @param pathToKey The *relative* path to the public key for verification.
167185
* This path should be the same relatibe to the main application bundle on iOS and the assets directory on Android.
186+
* @returns Promise<void>
168187
*/
169188
export const enableSecureLiveUpdates = async (
170189
pathToKey: string

0 commit comments

Comments
 (0)