Skip to content

Commit

Permalink
FEN-626: Fix Android webview-client to listen for URL redirects (#102)
Browse files Browse the repository at this point in the history
* FEN-626: Fix Android webview-client to listen for URL redirects

* 3.0.7
  • Loading branch information
kingisaac95 authored Oct 11, 2024
1 parent 51d5aba commit a26c428
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"main": "src/components/LinkSDK/index.js",
"name": "lean-react-native",
"version": "3.0.7-alpha.3",
"version": "3.0.7",
"description": "A React Native wrapper for Lean's LinkSDK",
"repository": {
"type": "git",
Expand Down
18 changes: 8 additions & 10 deletions src/components/LinkSDK/LeanWebClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ class LeanWebClient {
},
};
}



static handleOverrideUrlLoading(request, callback) {
Logger.info('handleOverrideUrlLoading', request.url);

if (request.url.startsWith('file://') || request.url === 'about:blank') {
static handleOverrideUrlLoading(event, callback) {
Logger.info('handleOverrideUrlLoading', event.url);

if (event.url.startsWith('file://') || event.url === 'about:blank') {
return false;
}

if (request.url.includes('https://cdn.leantech.me/link/loader')) {
if (event.url.includes('https://cdn.leantech.me/link/loader')) {
return true;
}

Expand All @@ -52,7 +50,7 @@ class LeanWebClient {
this.responseListener = callback;
}

const urlObject = new URL(request.url);
const urlObject = new URL(event.url);

/**
* Standard redirect URI from hosted HTML has three parts
Expand Down Expand Up @@ -83,14 +81,14 @@ class LeanWebClient {
}

// Send response back caller for proper handling
this.onRedirectResponse(this.getResponseFromParams(request.url));
this.onRedirectResponse(this.getResponseFromParams(event.url));

// Do not override URL loading
return false;
}

// Open all URLs in default web browser
Linking.openURL(request.url);
Linking.openURL(event.url);

// Do not override URL loading
return false;
Expand Down
11 changes: 6 additions & 5 deletions src/components/LinkSDK/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ const LinkSDK = forwardRef((props, ref) => {
originWhitelist={['*']}
source={{uri: initializationURL}}
allowsInlineMediaPlayback={true}
setSupportMultipleWindows={false}
mediaPlaybackRequiresUserAction={false}
onShouldStartLoadWithRequest={request =>
LeanWebClient.handleOverrideUrlLoading(
request,
responseCallbackHandler,
)
onShouldStartLoadWithRequest={event =>
LeanWebClient.handleOverrideUrlLoading(event, responseCallbackHandler)
}
onNavigationStateChange={event =>
LeanWebClient.handleOverrideUrlLoading(event, responseCallbackHandler)
}
cacheEnabled={false}
javaScriptEnabledAndroid={true}
Expand Down

0 comments on commit a26c428

Please sign in to comment.