Skip to content

Commit

Permalink
feat(dynamic-links): support other platform parameters (OFL)
Browse files Browse the repository at this point in the history
  • Loading branch information
skam22 authored and mikehardy committed Sep 30, 2022
1 parent 19304d5 commit 2c5afba
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,15 @@ private DynamicLink.Builder createDynamicLinkBuilder(final ReadableMap dynamicLi
buildNavigationParameters(dynamicLinkMap.getMap("navigation"), builder);
}

if (dynamicLinkMap.hasKey("otherPlatform")) {
if (dynamicLinkMap.getMap("otherPlatform").hasKey("fallbackUrl")) {
String OTHER_PLATFORM_LINK_KEY = "ofl";
String linkUrl = String.valueOf(builder.buildDynamicLink().getUri());
linkUrl += '&' + OTHER_PLATFORM_LINK_KEY + '=' + dynamicLinkMap.getMap("otherPlatform").getString("fallbackUrl");
builder.setLongLink(Uri.parse(linkUrl));
}
}

return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ - (FIRDynamicLinkComponents *)createDynamicLinkComponents:(NSDictionary *)dynami
[self buildItunesParameters:dynamicLinkDict[@"itunes"] components:linkComponents];
[self buildNavigationParameters:dynamicLinkDict[@"navigation"] components:linkComponents];
[self buildSocialParameters:dynamicLinkDict[@"social"] components:linkComponents];
[self buildOtherPlatformParameters:dynamicLinkDict[@"otherPlatform"] components:linkComponents];

return linkComponents;
}
Expand Down Expand Up @@ -419,6 +420,18 @@ - (void)buildSocialParameters:(NSDictionary *)socialDict
linkComponents.socialMetaTagParameters = socialParams;
}

- (void)buildOtherPlatformParameters:(NSDictionary *)otherDict
components:(FIRDynamicLinkComponents *)linkComponents {
if (otherDict == nil) return;

FIRDynamicLinkOtherPlatformParameters *otherParams =
[FIRDynamicLinkOtherPlatformParameters parameters];
if (otherDict[@"fallbackUrl"]) {
otherParams.fallbackUrl = [NSURL URLWithString:otherDict[@"fallbackUrl"]];
}
linkComponents.otherPlatformParameters = otherParams;
}

- (NSArray<NSString *> *)supportedEvents {
return @[];
}
Expand Down
7 changes: 6 additions & 1 deletion packages/dynamic-links/lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import buildIos from './builders/ios';
import buildItunes from './builders/itunes';
import buildNavigation from './builders/navigation';
import buildSocial from './builders/social';
import buildOtherPlatform from './builders/otherPlatform';

export default function build(dynamicLinksParams) {
if (!isObject(dynamicLinksParams)) {
throw new Error("'dynamicLinksParams' must be an object.");
}

const { link, domainUriPrefix, android, analytics, ios, itunes, navigation, social } =
const { link, domainUriPrefix, android, analytics, ios, itunes, navigation, social, otherPlatform } =
dynamicLinksParams;

if (!link) {
Expand Down Expand Up @@ -87,5 +88,9 @@ export default function build(dynamicLinksParams) {
params.social = buildSocial(social);
}

if (otherPlatform) {
params.otherPlatform = buildOtherPlatform(otherPlatform);
}

return params;
}
19 changes: 19 additions & 0 deletions packages/dynamic-links/lib/builders/otherPlatform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { isObject, isString } from '@react-native-firebase/app/lib/common';

export default function buildOtherPlatform(otherPlatformParameters) {
if (!isObject(otherPlatformParameters)) {
throw new Error("'dynamicLinksParams.otherPlatform' must be an object.");
}

const params = {}

if (otherPlatformParameters.fallbackUrl) {
if (!isString(otherPlatformParameters.fallbackUrl)) {
throw new Error("'dynamicLinksParams.otherPlatform.fallbackUrl' must be a string.");
}

params.fallbackUrl = otherPlatformParameters.fallbackUrl;
}

return params
}
32 changes: 32 additions & 0 deletions packages/dynamic-links/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,33 @@ export namespace FirebaseDynamicLinksTypes {
title?: string;
}

/**
* The DynamicLinkOtherPlatformParameters interface provides functionality to
* open a custom URL on platforms beside Android and iOS. This is useful to
* specify a different behavior on desktop, like displaying a full web page
* of the app content/payload (as specified by param link) with another dynamic
* link to install the app.
*
* #### Example
*
* ```js
* const link = await firebase.dynamicLinks().buildLink({
* link: 'https://invertase.io',
* domainUriPrefix: 'https://xyz.page.link',
* otherPlatform: {
* fallbackUrl: 'https://www.google.com/',
* }
* });
* ```
*/
export interface DynamicLinkOtherPlatformParameters {
/**
* The URL to open on desktop.
*/
fallbackUrl?: string;
}


/**
* The DynamicLinkParameters interface provides access to the Dynamic Link builder classes
* used to configure a created link.
Expand Down Expand Up @@ -359,6 +386,11 @@ export namespace FirebaseDynamicLinksTypes {
* Access social specific link parameters.
*/
social?: DynamicLinkSocialParameters;

/**
* Access other platform specific link parameters.
*/
otherPlatform?: DynamicLinkOtherPlatformParameters
}

/**
Expand Down

0 comments on commit 2c5afba

Please sign in to comment.