-
-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Normal open function returns incredibly slowly when canceling under certain circumstances on Android #155
Comments
Can you share your code with the options you're using? |
I'll try.. So, on the one hand, I've built a wrapper class around the if (Platform.OS === 'ios') {
// return first param
} else if (Platform.OS === 'android') {
// return second param
} Here it goes: import {Linking, Alert} from 'react-native';
import InAppBrowser from 'react-native-inappbrowser-reborn';
// Module registry and config
import {theme} from 'root/app-config';
// Utils
import {Platform} from '@cineorder/utils/helpers';
// Themes and styles
import {Colors} from '@cineorder/themes';
class Browser {
constructor() {
this.isAvailable = null;
}
checkForAvailability = async () => {
this.isAvailable = await InAppBrowser.isAvailable();
};
openLink = async (url, auth = false, redirectUrl?, options?) => {
try {
let result;
if (this.isAvailable) {
console.log(
`opening ${Platform.setOnIosAndAndroid(
'Safari View Controller',
'Chrome Custom Tab',
)}...`,
);
let browserConfig = Platform.setOnIosAndAndroid(
{
dismissButtonStyle: auth ? 'cancel' : 'close',
readerMode: false,
animated: true,
modalEnabled: true,
},
{
showTitle: false,
toolbarColor: Colors[options?.theme ?? theme].background.regular,
secondaryToolbarColor: Colors.snow,
enableUrlBarHiding: true,
enableDefaultShare: false,
forceCloseOnRedirection: false,
animations: {
startEnter: 'slide_in_down',
startExit: 'slide_out_up',
endEnter: 'slide_in_up',
endExit: 'slide_out_down',
},
},
);
if (options) {
browserConfig = {
...browserConfig,
...options,
};
}
if (auth) {
console.log('opening Link in auth window...');
result = await InAppBrowser.openAuth(url, redirectUrl, browserConfig);
console.log('result:', result);
} else {
console.log('opening Link in normal window...');
result = await InAppBrowser.open(url, browserConfig);
console.log('result:', result);
}
} else {
console.log(
`unfortunately, not able to open ${Platform.setOnIosAndAndroid(
'Safari View Controller',
'Chrome Custom Tab',
)}...`,
);
Linking.openURL(url);
}
return result;
} catch (e) {
console.error('An error occured in InAppBrowser:', e.message);
Alert.alert('Error occured in InAppBrowser', e.message);
}
};
}
export default new Browser(); Under normal circumstances, the code for the actual opening of the browser windows is written like this: if (auth) {
console.log('opening Link in auth window...');
return await InAppBrowser.openAuth(url, redirectUrl, browserConfig);
}
console.log('opening Link in normal window...');
return await InAppBrowser.open(url, browserConfig); But for debugging purposes I funneled the result into a variable and console.logged it. Then, when calling it, I call it like this. Analogous to the aforementioned if (Platform.OS === 'android') {
// return param
} else {
return undefined
} Here's the call: Browser.openLink(
props.children.url,
false,
null,
Platform.setOnAndroid({
toolbarColor: props.children.browserColor ?? Colors[theme].primary,
theme,
}),
); I console.logged the calls and the options for the first three calls (which were all without auth) are as follows: {
animations: {
startEnter: 'slide_in_down',
startExit: 'slide_out_up',
endEnter: 'slide_in_up',
endExit: 'slide_out_down',
},
enableDefaultShare: false,
enableUrlBarHiding: true,
forceCloseOnRedirection: false,
secondaryToolbarColor: 'white',
showTitle: false,
theme: /* 'light' or 'dark', depending on the calling screen */
toolbarColor: '#28A3D9',
} The {
animations: {
startEnter: 'slide_in_down',
startExit: 'slide_out_up',
endEnter: 'slide_in_up',
endExit: 'slide_out_down',
},
enableDefaultShare: false,
enableUrlBarHiding: true,
forceCloseOnRedirection: false,
secondaryToolbarColor: 'white',
showTitle: false,
theme: 'light',
toolbarColor: '#0070BA', // PayPal blue; only difference
} I hope this helps. If you need anything else, let me know! |
This is not an issue on iOS. I have updated the initial post. |
Did some more digging and it turns out that it doesn't have to do anything with whether |
@TheWirv I don't think because this plugin don't have React components, it's only a wrapper to call a native component of the device by just calling native code, also without using EventEmitters or something like that |
I thought exactly the same. On the other hand, I suspected the And if it's not that, what could be the reason? I could easily look a bit more into it, if you can give me some direction as to where exactly I should check. |
Do you have this configuration? https://github.com/proyecto26/react-native-inappbrowser/blob/master/example/android/app/src/main/AndroidManifest.xml#L18 |
Yes, this is my <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.compeso.cineorder">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:windowSoftInputMode="stateHidden|adjustNothing"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="cineorder" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}"
android:grantUriPermissions="true"
android:exported="false"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/passkit_file_paths"
tools:replace="android:resource" />
</provider>
</application>
</manifest> |
mmm very odd, and without a demo project I can't reproduce that issue here :( |
I'll see if there's any possibility for you to reproduce this issue. |
I think |
Hi, I have the strange problem that, after canceling on Android, the
InAppBrowser.open
function takes a very long time to return with the result ({type: "cancel"}
) under certain circumstances. The worst thing is that I can't really pin down said circumstances. All I know for sure is that, in contrast,InAppBrowser.openAuth
returns instantly after being canceled.I made a video of it all and uploaded it to YouTube. What I did was the following:
InAppBrowser.open
imprint link (dark theme); then close and waitInAppBrowser.open
privacy policy link (dark theme); then close and waitInAppBrowser.open
(the same) imprint link (light theme); then close and wait (a long time)InAppBrowser.openAuth
PayPal (light theme); then close@jdnichollsc Do you have an inkling of an idea what could be the cause of this delay? It's almost ten seconds. Additionally, it has the effect that during that duration any other call to
open
fails, or rather theopen
call from before finally returns with{type: "cancel"}
which, I guess, directly cancels the new call.The code is rather distributed and would therefore be difficult to share, but if that would be of substantial help I could pull out a few snippets, I guess.
Which platform(s) does your issue occur on?
open
andopenAuth
return in an instant, no matter what.Please, provide the following version numbers that your issue occurs with:
npx react-native --version
to fetch it, instead ofreact-native --version
)The text was updated successfully, but these errors were encountered: