Skip to content

Commit

Permalink
Merge pull request #103 from proyecto26/develop
Browse files Browse the repository at this point in the history
Add waitForRedirectDelay option from Android to wait the redirection
  • Loading branch information
jdnichollsc authored Sep 3, 2019
2 parents 458cc71 + 7391422 commit 3cf3b0c
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 6,538 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ in case of vulnerabilities.

## [Unreleased]

## [3.1.0] - 2019-09-03

### Added
- Add `waitForRedirectDelay` option for **Android** to fix issues dismissing the browser before detecting the redirection with `Linking` ([817f6ec](https://github.com/proyecto26/react-native-inappbrowser/commit/817f6ece140c0f2f84e21a537d5030403e652bc1)).

## [3.0.1] - 2019-08-16

### Added
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Property | Description
`animations` (Object) | Sets the start and exit animations. [`{ startEnter, startExit, endEnter, endExit }`]
`headers` (Object) | The data are key/value pairs, they will be sent in the HTTP request headers for the provided url. [`{ 'Authorization': 'Bearer ...' }`]
`forceCloseOnRedirection` (Boolean) | Open Custom Tab in a new task to avoid issues redirecting back to app scheme. [`true`/`false`]
`waitForRedirectDelay` (Number) | Sets a delay for wait the redirection using `openAuth` method.
### Demo
Expand Down Expand Up @@ -191,7 +192,8 @@ import InAppBrowser from 'react-native-inappbrowser-reborn'
},
headers: {
'my-custom-header': 'my custom header value'
}
},
waitForRedirectDelay: 0
})
Alert.alert(JSON.stringify(result))
}
Expand Down Expand Up @@ -264,6 +266,7 @@ import { getDeepLink } from './utilities'
showTitle: false,
enableUrlBarHiding: true,
enableDefaultShare: true,
waitForRedirectDelay: 1000
}).then((response) => {
if (response.type === 'success' &&
response.url) {
Expand Down
12 changes: 9 additions & 3 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,19 @@ export default class App extends Component {
}

async tryDeepLinking() {
const loginUrl =
'https://proyecto26.github.io/react-native-inappbrowser/';
const loginUrl = 'https://proyecto26.github.io/react-native-inappbrowser/';
const redirectUrl = encodeURIComponent(this.getDeepLink('home'));
const url = `${loginUrl}?redirect_url=${redirectUrl}`;
try {
if (await InAppBrowser.isAvailable()) {
const result = await InAppBrowser.openAuth(url, redirectUrl);
const result = await InAppBrowser.openAuth(url, redirectUrl, {
showTitle: true,
toolbarColor: '#6200EE',
secondaryToolbarColor: 'black',
enableUrlBarHiding: true,
enableDefaultShare: true,
waitForRedirectDelay: 1000
});
await this.sleep(800);
Alert.alert('Response', JSON.stringify(result));
} else {
Expand Down
6,515 changes: 0 additions & 6,515 deletions example/yarn.lock

This file was deleted.

3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ declare module 'react-native-inappbrowser-reborn' {
endEnter: string,
endExit: string
},
headers?: { [key: string]: string }
headers?: { [key: string]: string },
waitForRedirectDelay?: number
}

export type InAppBrowserOptions = InAppBrowserAndroidOptions | InAppBrowseriOSOptions;
Expand Down
34 changes: 21 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ type InAppBrowserAndroidOptions = {
endEnter: string,
endExit: string
},
headers?: { [key: string]: string }
headers?: { [key: string]: string },
waitForRedirectDelay?: number
};

type InAppBrowserOptions = InAppBrowserAndroidOptions | InAppBrowseriOSOptions;
Expand All @@ -66,25 +67,26 @@ async function open(
): Promise<BrowserResult> {
const modalEnabled =
options.modalEnabled !== undefined ? options.modalEnabled : true;
const inAppBrowseroptions = {
const inAppBrowserOptions = {
...options,
url,
dismissButtonStyle: options.dismissButtonStyle || 'close',
readerMode: options.readerMode !== undefined ? options.readerMode : false,
animated: options.animated !== undefined ? options.animated : true,
modalEnabled
modalEnabled,
waitForRedirectDelay: options.waitForRedirectDelay || 0
};
if (inAppBrowseroptions.preferredBarTintColor) {
inAppBrowseroptions.preferredBarTintColor = processColor(
inAppBrowseroptions.preferredBarTintColor
if (inAppBrowserOptions.preferredBarTintColor) {
inAppBrowserOptions.preferredBarTintColor = processColor(
inAppBrowserOptions.preferredBarTintColor
);
}
if (inAppBrowseroptions.preferredControlTintColor) {
inAppBrowseroptions.preferredControlTintColor = processColor(
inAppBrowseroptions.preferredControlTintColor
if (inAppBrowserOptions.preferredControlTintColor) {
inAppBrowserOptions.preferredControlTintColor = processColor(
inAppBrowserOptions.preferredControlTintColor
);
}
return RNInAppBrowser.open(inAppBrowseroptions);
return RNInAppBrowser.open(inAppBrowserOptions);
}

function close(): void {
Expand Down Expand Up @@ -134,17 +136,23 @@ async function _openAuthSessionPolyfillAsync(
!_redirectHandler,
'InAppBrowser.openAuth is in a bad state. _redirectHandler is defined when it should not be.'
);

let response = null;
try {
return await Promise.race([
open(startUrl, options),
response = await Promise.race([
open(startUrl, options).then(result => {
return new Promise(resolve => {
// A delay to wait for the redirection or dismiss the browser instead
setTimeout(() => resolve(result), options.waitForRedirectDelay);
});
}),
_waitForRedirectAsync(returnUrl)
]);
} finally {
close();
Linking.removeEventListener('url', _redirectHandler);
_redirectHandler = null;
}
return response;
}

function _waitForRedirectAsync(returnUrl: string): Promise<RedirectResult> {
Expand Down
8 changes: 4 additions & 4 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,6 +1,6 @@
{
"name": "react-native-inappbrowser-reborn",
"version": "3.0.1",
"version": "3.1.0",
"description": "InAppBrowser for React Native",
"main": "index.js",
"readmeFilename": "README.md",
Expand Down

0 comments on commit 3cf3b0c

Please sign in to comment.