Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ios/TrustlyReactNativeExample/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#import <React/RCTBundleURLProvider.h>

#import <React/RCTLinkingManager.h>


@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Expand All @@ -14,6 +17,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}


- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
return [RCTLinkingManager application:application openURL:url options:options];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
Expand Down
21 changes: 15 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ const ResultScreen = ({ title, returnParameters, onBackToWidget }) => (
);

export default class App extends Component {
trustlyWebView = null;

trustlyWebView: WebView | null = null;
deepLinkEventListener: any = null;

// Initialize payment data
establishData: EstablishData = {
Expand Down Expand Up @@ -75,10 +77,19 @@ export default class App extends Component {
returnParameters: '',
};

constructor(props) {
super(props);
componentDidMount() {
this.deepLinkEventListener = Linking.addEventListener('url', this.handleDeepLink);
}

componentWillUnmount() {
this.deepLinkEventListener.remove()
}

// Handle the deep link URL here
handleDeepLink = () => {
InAppBrowser.closeAuth(); // Close the InAppBrowser when a deep link is detected
};

// Open the provided URL in InAppBrowser or default browser if not available
async openLink(url: string) {
try {
Expand Down Expand Up @@ -155,9 +166,7 @@ export default class App extends Component {

// Handle the OAuth result
handleOAuthResult = (result: any) => {
if (result.type === 'success') {
this.trustlyWebView.injectJavaScript('window.Trustly.proceedToChooseAccount();'); // Proceed with the transaction
}
this.trustlyWebView.injectJavaScript('window.Trustly.proceedToChooseAccount();'); // Proceed with the transaction
};

// Update the amount when the user inputs a new value
Expand Down
Loading