Skip to content

Commit 2c5afba

Browse files
skam22mikehardy
authored andcommitted
feat(dynamic-links): support other platform parameters (OFL)
1 parent 19304d5 commit 2c5afba

File tree

5 files changed

+79
-1
lines changed

5 files changed

+79
-1
lines changed

packages/dynamic-links/android/src/main/java/io/invertase/firebase/dynamiclinks/ReactNativeFirebaseDynamicLinksModule.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,15 @@ private DynamicLink.Builder createDynamicLinkBuilder(final ReadableMap dynamicLi
291291
buildNavigationParameters(dynamicLinkMap.getMap("navigation"), builder);
292292
}
293293

294+
if (dynamicLinkMap.hasKey("otherPlatform")) {
295+
if (dynamicLinkMap.getMap("otherPlatform").hasKey("fallbackUrl")) {
296+
String OTHER_PLATFORM_LINK_KEY = "ofl";
297+
String linkUrl = String.valueOf(builder.buildDynamicLink().getUri());
298+
linkUrl += '&' + OTHER_PLATFORM_LINK_KEY + '=' + dynamicLinkMap.getMap("otherPlatform").getString("fallbackUrl");
299+
builder.setLongLink(Uri.parse(linkUrl));
300+
}
301+
}
302+
294303
return builder;
295304
}
296305

packages/dynamic-links/ios/RNFBDynamicLinks/RNFBDynamicLinksModule.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ - (FIRDynamicLinkComponents *)createDynamicLinkComponents:(NSDictionary *)dynami
276276
[self buildItunesParameters:dynamicLinkDict[@"itunes"] components:linkComponents];
277277
[self buildNavigationParameters:dynamicLinkDict[@"navigation"] components:linkComponents];
278278
[self buildSocialParameters:dynamicLinkDict[@"social"] components:linkComponents];
279+
[self buildOtherPlatformParameters:dynamicLinkDict[@"otherPlatform"] components:linkComponents];
279280

280281
return linkComponents;
281282
}
@@ -419,6 +420,18 @@ - (void)buildSocialParameters:(NSDictionary *)socialDict
419420
linkComponents.socialMetaTagParameters = socialParams;
420421
}
421422

423+
- (void)buildOtherPlatformParameters:(NSDictionary *)otherDict
424+
components:(FIRDynamicLinkComponents *)linkComponents {
425+
if (otherDict == nil) return;
426+
427+
FIRDynamicLinkOtherPlatformParameters *otherParams =
428+
[FIRDynamicLinkOtherPlatformParameters parameters];
429+
if (otherDict[@"fallbackUrl"]) {
430+
otherParams.fallbackUrl = [NSURL URLWithString:otherDict[@"fallbackUrl"]];
431+
}
432+
linkComponents.otherPlatformParameters = otherParams;
433+
}
434+
422435
- (NSArray<NSString *> *)supportedEvents {
423436
return @[];
424437
}

packages/dynamic-links/lib/builder.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ import buildIos from './builders/ios';
2222
import buildItunes from './builders/itunes';
2323
import buildNavigation from './builders/navigation';
2424
import buildSocial from './builders/social';
25+
import buildOtherPlatform from './builders/otherPlatform';
2526

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

31-
const { link, domainUriPrefix, android, analytics, ios, itunes, navigation, social } =
32+
const { link, domainUriPrefix, android, analytics, ios, itunes, navigation, social, otherPlatform } =
3233
dynamicLinksParams;
3334

3435
if (!link) {
@@ -87,5 +88,9 @@ export default function build(dynamicLinksParams) {
8788
params.social = buildSocial(social);
8889
}
8990

91+
if (otherPlatform) {
92+
params.otherPlatform = buildOtherPlatform(otherPlatform);
93+
}
94+
9095
return params;
9196
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { isObject, isString } from '@react-native-firebase/app/lib/common';
2+
3+
export default function buildOtherPlatform(otherPlatformParameters) {
4+
if (!isObject(otherPlatformParameters)) {
5+
throw new Error("'dynamicLinksParams.otherPlatform' must be an object.");
6+
}
7+
8+
const params = {}
9+
10+
if (otherPlatformParameters.fallbackUrl) {
11+
if (!isString(otherPlatformParameters.fallbackUrl)) {
12+
throw new Error("'dynamicLinksParams.otherPlatform.fallbackUrl' must be a string.");
13+
}
14+
15+
params.fallbackUrl = otherPlatformParameters.fallbackUrl;
16+
}
17+
18+
return params
19+
}

packages/dynamic-links/lib/index.d.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,33 @@ export namespace FirebaseDynamicLinksTypes {
302302
title?: string;
303303
}
304304

305+
/**
306+
* The DynamicLinkOtherPlatformParameters interface provides functionality to
307+
* open a custom URL on platforms beside Android and iOS. This is useful to
308+
* specify a different behavior on desktop, like displaying a full web page
309+
* of the app content/payload (as specified by param link) with another dynamic
310+
* link to install the app.
311+
*
312+
* #### Example
313+
*
314+
* ```js
315+
* const link = await firebase.dynamicLinks().buildLink({
316+
* link: 'https://invertase.io',
317+
* domainUriPrefix: 'https://xyz.page.link',
318+
* otherPlatform: {
319+
* fallbackUrl: 'https://www.google.com/',
320+
* }
321+
* });
322+
* ```
323+
*/
324+
export interface DynamicLinkOtherPlatformParameters {
325+
/**
326+
* The URL to open on desktop.
327+
*/
328+
fallbackUrl?: string;
329+
}
330+
331+
305332
/**
306333
* The DynamicLinkParameters interface provides access to the Dynamic Link builder classes
307334
* used to configure a created link.
@@ -359,6 +386,11 @@ export namespace FirebaseDynamicLinksTypes {
359386
* Access social specific link parameters.
360387
*/
361388
social?: DynamicLinkSocialParameters;
389+
390+
/**
391+
* Access other platform specific link parameters.
392+
*/
393+
otherPlatform?: DynamicLinkOtherPlatformParameters
362394
}
363395

364396
/**

0 commit comments

Comments
 (0)