Skip to content
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

Web browser improvements #7218

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions docs/pages/versions/unversioned/sdk/webbrowser.md
Expand Up @@ -68,12 +68,15 @@ Opens the url with Safari in a modal on iOS using [`SFSafariViewController`](htt
- **browserParams (_object_)** (_optional_) --
A dictionary with following key-value pairs:

- **toolbarColor (_optional_) (_string_)** -- color of the toolbar in either `#AARRGGBB` or `#RRGGBB` format.
- **enableBarCollapsing (_optional_) (_boolean_)** -- a boolean determining whether the toolbar should be hiding when a user scrolls the website
- **showInRecents (_optional_) (_boolean_)** -- (_Android only_) a boolean determining whether browsed website should be shown as separate entry in Android recents/multitasking view. Default: `false`
- **controlsColor (_optional_) (_string_)** -- (_iOS only_) tint color for controls in SKSafariViewController in `#AARRGGBB` or `#RRGGBB` format.
- **showTitle (_optional_) (_boolean_)** -- (_Android only_) a boolean determining whether the browser should show the title of website on the toolbar
- **dismissButtonStyle (_optional_) (_string_)** -- (_iOS only_) The style of the dismiss button. Should be one of: `done`, `close`, or `cancel`.
- **enableBarCollapsing (_optional_) (_boolean_)** -- a boolean determining whether the toolbar should be hiding when a user scrolls the website.
- **enableDefaultShare (_optional_) (_boolean_)** -- (_Android only_) a boolean determining whether a default share item should be added to the menu.
- **package (_optional_) (_string_)** -- (_Android only_). Package name of a browser to be used to handle Custom Tabs. List of available packages is to be queried by [getCustomTabsSupportingBrowsers](#webbrowsergetcustomtabssupportingbrowsers) method.
- **readerMode (_optional_) (_boolean_)** -- (_iOS only_) a boolean determining whether Safari should enter Reader mode, if it is available.
- **showInRecents (_optional_) (_boolean_)** -- (_Android only_) a boolean determining whether browsed website should be shown as separate entry in Android recents/multitasking view. Default: `false`
- **showTitle (_optional_) (_boolean_)** -- (_Android only_) a boolean determining whether the browser should show the title of website on the toolbar.
- **toolbarColor (_optional_) (_string_)** -- color of the toolbar in either `#AARRGGBB` or `#RRGGBB` format.

Note that behavior customization options depend on the actual browser and its version. Some or all of the arguments may be ignored.

Expand Down
Expand Up @@ -34,6 +34,7 @@ public class WebBrowserModule extends ExportedModule {

private final static String SHOW_IN_RECENTS = "showInRecents";

private final static String DEFAULT_SHARE_MENU_ITEM_KEY = "enableDefaultShare";
private final static String TOOLBAR_COLOR_KEY = "toolbarColor";
private final static String ERROR_CODE = "EXWebBrowser";
private static final String TAG = "ExpoWebBrowser";
Expand Down Expand Up @@ -163,6 +164,10 @@ private Intent createCustomTabsIntent(ReadableArguments arguments) {

builder.setShowTitle(arguments.getBoolean(SHOW_TITLE_KEY, false));

if (arguments.hasKey(DEFAULT_SHARE_MENU_ITEM_KEY) && options.getBoolean(KEY_DEFAULT_SHARE_MENU_ITEM)) {
builder.addDefaultShareMenuItem();
}

Intent intent = builder.build().intent;

// We cannot use builder's method enableUrlBarHiding, because there is no corresponding disable method and some browsers enables it by default.
Expand Down
20 changes: 18 additions & 2 deletions packages/expo-web-browser/ios/EXWebBrowser/EXWebBrowser.m
Expand Up @@ -89,13 +89,29 @@ - (dispatch_queue_t)methodQueue
}

NSURL *url = [[NSURL alloc] initWithString:authURL];
BOOL readerMode = [arguments[@"readerMode"] boolValue];
BOOL enableBarCollapsing = [arguments[@"enableBarCollapsing"] boolValue];
SFSafariViewController *safariVC = nil;
if (@available(iOS 11, *)) {
SFSafariViewControllerConfiguration *config = [[SFSafariViewControllerConfiguration alloc] init];
config.barCollapsingEnabled = [arguments[@"enableBarCollapsing"] boolValue];
config.barCollapsingEnabled = enableBarCollapsing;
config.entersReaderIfAvailable = readerMode;
safariVC = [[SFSafariViewController alloc] initWithURL:url configuration:config];
} else {
safariVC = [[SFSafariViewController alloc] initWithURL:url];
safariVC = [[SFSafariViewController alloc] initWithURL:url entersReaderIfAvailable:readerMode];
}

if (@available(iOS 11.0, *)) {
NSString *dismissButtonStyle = [arguments valueForKey:@"dismissButtonStyle"];
if ([dismissButtonStyle isEqualToString:@"done"]) {
safariVC.dismissButtonStyle = SFSafariViewControllerDismissButtonStyleDone;
}
else if ([dismissButtonStyle isEqualToString:@"close"]) {
safariVC.dismissButtonStyle = SFSafariViewControllerDismissButtonStyleClose;
}
else if ([dismissButtonStyle isEqualToString:@"cancel"]) {
safariVC.dismissButtonStyle = SFSafariViewControllerDismissButtonStyleCancel;
}
}

if([[arguments allKeys] containsObject:WebBrowserToolbarColorKey]) {
Expand Down
3 changes: 3 additions & 0 deletions packages/expo-web-browser/src/WebBrowser.types.ts
Expand Up @@ -9,10 +9,13 @@ export type WebBrowserOpenOptions = {
showTitle?: boolean;

/** Android only */
enableDefaultShare?: boolean;
showInRecents?: boolean;

/** iOS only */
controlsColor?: string;
dismissButtonStyle?: 'done' | 'close' | 'cancel';
readerMode?: boolean;

// Web
windowName?: string;
Expand Down