Skip to content

Commit 3cf3b0c

Browse files
authored
Merge pull request #103 from proyecto26/develop
Add waitForRedirectDelay option from Android to wait the redirection
2 parents 458cc71 + 7391422 commit 3cf3b0c

File tree

8 files changed

+46
-6538
lines changed

8 files changed

+46
-6538
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ in case of vulnerabilities.
2222

2323
## [Unreleased]
2424

25+
## [3.1.0] - 2019-09-03
26+
27+
### Added
28+
- 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)).
29+
2530
## [3.0.1] - 2019-08-16
2631

2732
### Added

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ Property | Description
152152
`animations` (Object) | Sets the start and exit animations. [`{ startEnter, startExit, endEnter, endExit }`]
153153
`headers` (Object) | The data are key/value pairs, they will be sent in the HTTP request headers for the provided url. [`{ 'Authorization': 'Bearer ...' }`]
154154
`forceCloseOnRedirection` (Boolean) | Open Custom Tab in a new task to avoid issues redirecting back to app scheme. [`true`/`false`]
155+
`waitForRedirectDelay` (Number) | Sets a delay for wait the redirection using `openAuth` method.
155156
156157
### Demo
157158
@@ -191,7 +192,8 @@ import InAppBrowser from 'react-native-inappbrowser-reborn'
191192
},
192193
headers: {
193194
'my-custom-header': 'my custom header value'
194-
}
195+
},
196+
waitForRedirectDelay: 0
195197
})
196198
Alert.alert(JSON.stringify(result))
197199
}
@@ -264,6 +266,7 @@ import { getDeepLink } from './utilities'
264266
showTitle: false,
265267
enableUrlBarHiding: true,
266268
enableDefaultShare: true,
269+
waitForRedirectDelay: 1000
267270
}).then((response) => {
268271
if (response.type === 'success' &&
269272
response.url) {

example/App.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,19 @@ export default class App extends Component {
102102
}
103103

104104
async tryDeepLinking() {
105-
const loginUrl =
106-
'https://proyecto26.github.io/react-native-inappbrowser/';
105+
const loginUrl = 'https://proyecto26.github.io/react-native-inappbrowser/';
107106
const redirectUrl = encodeURIComponent(this.getDeepLink('home'));
108107
const url = `${loginUrl}?redirect_url=${redirectUrl}`;
109108
try {
110109
if (await InAppBrowser.isAvailable()) {
111-
const result = await InAppBrowser.openAuth(url, redirectUrl);
110+
const result = await InAppBrowser.openAuth(url, redirectUrl, {
111+
showTitle: true,
112+
toolbarColor: '#6200EE',
113+
secondaryToolbarColor: 'black',
114+
enableUrlBarHiding: true,
115+
enableDefaultShare: true,
116+
waitForRedirectDelay: 1000
117+
});
112118
await this.sleep(800);
113119
Alert.alert('Response', JSON.stringify(result));
114120
} else {

example/yarn.lock

Lines changed: 0 additions & 6515 deletions
This file was deleted.

index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ declare module 'react-native-inappbrowser-reborn' {
4949
endEnter: string,
5050
endExit: string
5151
},
52-
headers?: { [key: string]: string }
52+
headers?: { [key: string]: string },
53+
waitForRedirectDelay?: number
5354
}
5455

5556
export type InAppBrowserOptions = InAppBrowserAndroidOptions | InAppBrowseriOSOptions;

index.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ type InAppBrowserAndroidOptions = {
5555
endEnter: string,
5656
endExit: string
5757
},
58-
headers?: { [key: string]: string }
58+
headers?: { [key: string]: string },
59+
waitForRedirectDelay?: number
5960
};
6061

6162
type InAppBrowserOptions = InAppBrowserAndroidOptions | InAppBrowseriOSOptions;
@@ -66,25 +67,26 @@ async function open(
6667
): Promise<BrowserResult> {
6768
const modalEnabled =
6869
options.modalEnabled !== undefined ? options.modalEnabled : true;
69-
const inAppBrowseroptions = {
70+
const inAppBrowserOptions = {
7071
...options,
7172
url,
7273
dismissButtonStyle: options.dismissButtonStyle || 'close',
7374
readerMode: options.readerMode !== undefined ? options.readerMode : false,
7475
animated: options.animated !== undefined ? options.animated : true,
75-
modalEnabled
76+
modalEnabled,
77+
waitForRedirectDelay: options.waitForRedirectDelay || 0
7678
};
77-
if (inAppBrowseroptions.preferredBarTintColor) {
78-
inAppBrowseroptions.preferredBarTintColor = processColor(
79-
inAppBrowseroptions.preferredBarTintColor
79+
if (inAppBrowserOptions.preferredBarTintColor) {
80+
inAppBrowserOptions.preferredBarTintColor = processColor(
81+
inAppBrowserOptions.preferredBarTintColor
8082
);
8183
}
82-
if (inAppBrowseroptions.preferredControlTintColor) {
83-
inAppBrowseroptions.preferredControlTintColor = processColor(
84-
inAppBrowseroptions.preferredControlTintColor
84+
if (inAppBrowserOptions.preferredControlTintColor) {
85+
inAppBrowserOptions.preferredControlTintColor = processColor(
86+
inAppBrowserOptions.preferredControlTintColor
8587
);
8688
}
87-
return RNInAppBrowser.open(inAppBrowseroptions);
89+
return RNInAppBrowser.open(inAppBrowserOptions);
8890
}
8991

9092
function close(): void {
@@ -134,17 +136,23 @@ async function _openAuthSessionPolyfillAsync(
134136
!_redirectHandler,
135137
'InAppBrowser.openAuth is in a bad state. _redirectHandler is defined when it should not be.'
136138
);
137-
139+
let response = null;
138140
try {
139-
return await Promise.race([
140-
open(startUrl, options),
141+
response = await Promise.race([
142+
open(startUrl, options).then(result => {
143+
return new Promise(resolve => {
144+
// A delay to wait for the redirection or dismiss the browser instead
145+
setTimeout(() => resolve(result), options.waitForRedirectDelay);
146+
});
147+
}),
141148
_waitForRedirectAsync(returnUrl)
142149
]);
143150
} finally {
144151
close();
145152
Linking.removeEventListener('url', _redirectHandler);
146153
_redirectHandler = null;
147154
}
155+
return response;
148156
}
149157

150158
function _waitForRedirectAsync(returnUrl: string): Promise<RedirectResult> {

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-inappbrowser-reborn",
3-
"version": "3.0.1",
3+
"version": "3.1.0",
44
"description": "InAppBrowser for React Native",
55
"main": "index.js",
66
"readmeFilename": "README.md",

0 commit comments

Comments
 (0)