Skip to content

Commit

Permalink
Merge pull request #1 from 6DegreeLabs/ImplementDeferredDeeplinking
Browse files Browse the repository at this point in the history
Implement deferred deep linking modules
  • Loading branch information
briandeweese authored May 15, 2020
2 parents ac68b77 + 9d0f25d commit 884a3e1
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
* copy, modify, and distribute this software in source code or binary form for use
* in connection with the web services and APIs provided by Facebook.
*
* As with any software that integrates with the Facebook platform, your use of
* this software is subject to the Facebook Developer Principles and Policies
* [http://developers.facebook.com/policy/]. This copyright notice shall be
* included in all copies or substantial portions of the software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.facebook.reactnative.androidsdk;

import android.support.annotation.Nullable;

import com.facebook.applinks.AppLinkData;
import com.facebook.applinks.FacebookAppLinkResolver;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;

public class FBAppLinkDataModule extends ReactContextBaseJavaModule {

private class CompletionHandler implements AppLinkData.CompletionHandler {

private Promise mPromise;

public CompletionHandler(final Promise promise) {
mPromise = promise;
}

/**
* This method is called when deferred app link data has been fetched. If no app link data
* was found, this method is called with null
*
* @param appLinkData The app link data that was fetched. Null if none was found.
*/
@Override
void onDeferredAppLinkDataFetched(AppLinkData appLinkData) {
if (appLinkData == null) {
mPromise.resolve(null);
} else {
mPromise.resolve(appLinkData.getTargetUri().toString());
}
}
}

private ReactApplicationContext mReactContext;

public FBAppLinkDataModule(ReactApplicationContext reactContext) {
super(reactContext);
mReactContext = reactContext;
}

public String getName() {
return "FBAppLinkData";
}

@ReactMethod
public void fetchDeferredAppLinkData(final Promise promise) {
AppLinkData.fetchDeferredAppLinkData(mReactContext, new CompletionHandler(promise));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public List<NativeModule> createNativeModules(
new FBLoginManagerModule(reactContext, mCallbackManager),
new FBMessageDialogModule(reactContext, mCallbackManager),
new FBShareAPIModule(reactContext),
new FBShareDialogModule(reactContext, mCallbackManager)
new FBShareDialogModule(reactContext, mCallbackManager),
new FBAppLinkDataModule(reactContext)
);
}

Expand Down
6 changes: 6 additions & 0 deletions ios/RCTFBSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
93E005151CE3D2D3000598E3 /* RCTFBSDKShareDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = 93E005081CE3D2D3000598E3 /* RCTFBSDKShareDialog.m */; };
93E005161CE3D2D3000598E3 /* RCTFBSDKShareHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 93E0050A1CE3D2D3000598E3 /* RCTFBSDKShareHelper.m */; };
93E005311CE3D63D000598E3 /* RCTFBSDKInitializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 93E005301CE3D63D000598E3 /* RCTFBSDKInitializer.m */; };
EC3D0E9C246CF88200E35EB7 /* RCTFBSDKAppLinkManager.m in Sources */ = {isa = PBXBuildFile; fileRef = EC3D0E9B246CF88200E35EB7 /* RCTFBSDKAppLinkManager.m */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -85,6 +86,8 @@
93E005091CE3D2D3000598E3 /* RCTFBSDKShareHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RCTFBSDKShareHelper.h; path = share/RCTFBSDKShareHelper.h; sourceTree = "<group>"; };
93E0050A1CE3D2D3000598E3 /* RCTFBSDKShareHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RCTFBSDKShareHelper.m; path = share/RCTFBSDKShareHelper.m; sourceTree = "<group>"; };
93E005301CE3D63D000598E3 /* RCTFBSDKInitializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RCTFBSDKInitializer.m; path = core/RCTFBSDKInitializer.m; sourceTree = "<group>"; };
EC3D0E9A246CF7F500E35EB7 /* RCTFBSDKAppLinkManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTFBSDKAppLinkManager.h; sourceTree = "<group>"; };
EC3D0E9B246CF88200E35EB7 /* RCTFBSDKAppLinkManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = RCTFBSDKAppLinkManager.m; path = core/RCTFBSDKAppLinkManager.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -142,6 +145,8 @@
isa = PBXGroup;
children = (
93B905C01D2D987F0013CC92 /* RCTFBSDKGraphRequestConnectionContainer.h */,
EC3D0E9A246CF7F500E35EB7 /* RCTFBSDKAppLinkManager.h */,
EC3D0E9B246CF88200E35EB7 /* RCTFBSDKAppLinkManager.m */,
93B905C11D2D987F0013CC92 /* RCTFBSDKGraphRequestConnectionContainer.m */,
93E005301CE3D63D000598E3 /* RCTFBSDKInitializer.m */,
93E004DB1CE3D292000598E3 /* RCTConvert+FBSDKAccessToken.h */,
Expand Down Expand Up @@ -252,6 +257,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
EC3D0E9C246CF88200E35EB7 /* RCTFBSDKAppLinkManager.m in Sources */,
93E005151CE3D2D3000598E3 /* RCTFBSDKShareDialog.m in Sources */,
93E004E51CE3D292000598E3 /* RCTFBSDKAppEvents.m in Sources */,
93E004E61CE3D292000598E3 /* RCTFBSDKGraphRequestManager.m in Sources */,
Expand Down
24 changes: 24 additions & 0 deletions ios/RCTFBSDK/RCTFBSDKAppLinkManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2015-present, Facebook, Inc. All rights reserved.
//
// You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
// copy, modify, and distribute this software in source code or binary form for use
// in connection with the web services and APIs provided by Facebook.
//
// As with any software that integrates with the Facebook platform, your use of
// this software is subject to the Facebook Developer Principles and Policies
// [http://developers.facebook.com/policy/]. This copyright notice shall be
// included in all copies or substantial portions of the software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#import <React/RCTBridgeModule.h>

#import <FBSDKCoreKit/FBSDKCoreKit.h>

@interface RCTFBSDKAppLinkManager : NSObject <RCTBridgeModule>
@end
56 changes: 56 additions & 0 deletions ios/RCTFBSDK/core/RCTFBSDKAppLinkManager.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2015-present, Facebook, Inc. All rights reserved.
//
// You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
// copy, modify, and distribute this software in source code or binary form for use
// in connection with the web services and APIs provided by Facebook.
//
// As with any software that integrates with the Facebook platform, your use of
// this software is subject to the Facebook Developer Principles and Policies
// [http://developers.facebook.com/policy/]. This copyright notice shall be
// included in all copies or substantial portions of the software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


#import <Foundation/Foundation.h>

#import "RCTFBSDKAppLinkManager.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>

#import "RCTFBSDKAccessToken.h"

#import <React/RCTUtils.h>

#import "RCTConvert+FBSDKAccessToken.h"

@implementation RCTFBSDKAppLinkManager

RCT_EXPORT_MODULE(FBAppLinkData);

- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
}

#pragma mark - React Native Methods

RCT_EXPORT_METHOD(fetchDeferredAppLinkData:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
FBSDKDeferredAppLinkHandler handler = ^(NSURL *url, NSError *error) {
if (error) {
resolve(nil);
} else {
NSString *urlString = [url absoluteString];
resolve(urlString);
}
};

[FBSDKAppLinkUtility fetchDeferredAppLink:handler];
}

@end
31 changes: 31 additions & 0 deletions js/FBAppLinkData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
* copy, modify, and distribute this software in source code or binary form for use
* in connection with the web services and APIs provided by Facebook.
*
* As with any software that integrates with the Facebook platform, your use of
* this software is subject to the Facebook Developer Principles and Policies
* [http://developers.facebook.com/policy/]. This copyright notice shall be
* included in all copies or substantial portions of the software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* @flow
* @format
*/
'use strict';

const AppLinkData = require('react-native').NativeModules.FBAppLinkData;

module.exports = {
async fetchDeferredAppLinkData(): Promise<?string> {
return await AppLinkData.fetchDeferredAppLinkData();
},
};
3 changes: 3 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ module.exports = {
get AppInviteDialog() {
return require('./FBAppInviteDialog');
},
get AppLinkData() {
return require('./FBAppLinkData');
},
get GameRequestDialog() {
return require('./FBGameRequestDialog');
},
Expand Down

0 comments on commit 884a3e1

Please sign in to comment.