diff --git a/packages/dynamic-links/android/src/main/java/io/invertase/firebase/dynamiclinks/ReactNativeFirebaseDynamicLinksModule.java b/packages/dynamic-links/android/src/main/java/io/invertase/firebase/dynamiclinks/ReactNativeFirebaseDynamicLinksModule.java index b806de3543..661108afbe 100644 --- a/packages/dynamic-links/android/src/main/java/io/invertase/firebase/dynamiclinks/ReactNativeFirebaseDynamicLinksModule.java +++ b/packages/dynamic-links/android/src/main/java/io/invertase/firebase/dynamiclinks/ReactNativeFirebaseDynamicLinksModule.java @@ -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; } diff --git a/packages/dynamic-links/ios/RNFBDynamicLinks/RNFBDynamicLinksModule.m b/packages/dynamic-links/ios/RNFBDynamicLinks/RNFBDynamicLinksModule.m index 17aff6c164..5aa23d234c 100644 --- a/packages/dynamic-links/ios/RNFBDynamicLinks/RNFBDynamicLinksModule.m +++ b/packages/dynamic-links/ios/RNFBDynamicLinks/RNFBDynamicLinksModule.m @@ -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; } @@ -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 *)supportedEvents { return @[]; } diff --git a/packages/dynamic-links/lib/builder.js b/packages/dynamic-links/lib/builder.js index 2b04224265..10bf047017 100644 --- a/packages/dynamic-links/lib/builder.js +++ b/packages/dynamic-links/lib/builder.js @@ -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) { @@ -87,5 +88,9 @@ export default function build(dynamicLinksParams) { params.social = buildSocial(social); } + if (otherPlatform) { + params.otherPlatform = buildOtherPlatform(otherPlatform); + } + return params; } diff --git a/packages/dynamic-links/lib/builders/otherPlatform.js b/packages/dynamic-links/lib/builders/otherPlatform.js new file mode 100644 index 0000000000..04de2984cd --- /dev/null +++ b/packages/dynamic-links/lib/builders/otherPlatform.js @@ -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 + } \ No newline at end of file diff --git a/packages/dynamic-links/lib/index.d.ts b/packages/dynamic-links/lib/index.d.ts index 2f13c96e79..a818e2c507 100644 --- a/packages/dynamic-links/lib/index.d.ts +++ b/packages/dynamic-links/lib/index.d.ts @@ -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. @@ -359,6 +386,11 @@ export namespace FirebaseDynamicLinksTypes { * Access social specific link parameters. */ social?: DynamicLinkSocialParameters; + + /** + * Access other platform specific link parameters. + */ + otherPlatform?: DynamicLinkOtherPlatformParameters } /**