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

feat(browser): reader mode #1865

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 9 additions & 8 deletions browser/README.md
Expand Up @@ -140,14 +140,15 @@ Remove all native listeners for this plugin.

Represents the options passed to `open`.

| Prop | Type | Description | Since |
| ----------------------- | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ----- |
| **`url`** | <code>string</code> | The URL to which the browser is opened. | 1.0.0 |
| **`windowName`** | <code>string</code> | Web only: Optional target for browser open. Follows the `target` property for window.open. Defaults to _blank. Ignored on other platforms. | 1.0.0 |
| **`toolbarColor`** | <code>string</code> | A hex color to which the toolbar color is set. | 1.0.0 |
| **`presentationStyle`** | <code>'fullscreen' \| 'popover'</code> | iOS only: The presentation style of the browser. Defaults to fullscreen. Ignored on other platforms. | 1.0.0 |
| **`width`** | <code>number</code> | iOS only: The width the browser when using presentationStyle 'popover' on iPads. Ignored on other platforms. | 4.0.0 |
| **`height`** | <code>number</code> | iOS only: The height the browser when using presentationStyle 'popover' on iPads. Ignored on other platforms. | 4.0.0 |
| Prop | Type | Description | Since |
| ----------------------------- | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ----- |
| **`url`** | <code>string</code> | The URL to which the browser is opened. | 1.0.0 |
| **`windowName`** | <code>string</code> | Web only: Optional target for browser open. Follows the `target` property for window.open. Defaults to _blank. Ignored on other platforms. | 1.0.0 |
| **`toolbarColor`** | <code>string</code> | A hex color to which the toolbar color is set. | 1.0.0 |
| **`presentationStyle`** | <code>'fullscreen' \| 'popover'</code> | iOS only: The presentation style of the browser. Defaults to fullscreen. Ignored on other platforms. | 1.0.0 |
| **`width`** | <code>number</code> | iOS only: The width the browser when using presentationStyle 'popover' on iPads. Ignored on other platforms. | 4.0.0 |
| **`height`** | <code>number</code> | iOS only: The height the browser when using presentationStyle 'popover' on iPads. Ignored on other platforms. | 4.0.0 |
| **`entersReaderIfAvailable`** | <code>boolean</code> | iOS only: Whether to automatically enter Reader mode if available for the url Ignored on other platforms. | 4.0.0 |


#### PluginListenerHandle
Expand Down
7 changes: 5 additions & 2 deletions browser/ios/Sources/BrowserPlugin/Browser.swift
Expand Up @@ -15,9 +15,12 @@ import SafariServices
return safariViewController
}

@objc public func prepare(for url: URL, withTint tint: UIColor? = nil, modalPresentation style: UIModalPresentationStyle = .fullScreen) -> Bool {
@objc public func prepare(for url: URL, withTint tint: UIColor? = nil, modalPresentation style: UIModalPresentationStyle = .fullScreen, entersReaderIfAvailable: Bool = false) -> Bool {
if safariViewController == nil, let scheme = url.scheme?.lowercased(), ["http", "https"].contains(scheme) {
let safariVC = SFSafariViewController(url: url)
let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = entersReaderIfAvailable

let safariVC = SFSafariViewController(url: url, configuration: config)
safariVC.delegate = self
if let color = tint {
safariVC.preferredBarTintColor = color
Expand Down
3 changes: 2 additions & 1 deletion browser/ios/Sources/BrowserPlugin/BrowserPlugin.swift
Expand Up @@ -23,8 +23,9 @@ public class CAPBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
color = UIColor.capacitor.color(fromHex: toolbarColor)
}
let style = self.presentationStyle(for: call.getString("presentationStyle"))
let entersReaderIfAvailable = call.getBool("entersReaderIfAvailable") ?? false
// prepare for display
guard implementation.prepare(for: url, withTint: color, modalPresentation: style), let viewController = implementation.viewController else {
guard implementation.prepare(for: url, withTint: color, modalPresentation: style, entersReaderIfAvailable: entersReaderIfAvailable), let viewController = implementation.viewController else {
call.reject("Unable to display URL")
return
}
Expand Down
9 changes: 9 additions & 0 deletions browser/src/definitions.ts
Expand Up @@ -105,6 +105,15 @@ export interface OpenOptions {
* @since 4.0.0
*/
height?: number;

/**
* iOS only: Whether to automatically enter Reader mode if available for the url
*
* Ignored on other platforms.
*
* @since 5.0.0
*/
entersReaderIfAvailable?: boolean;
}

/**
Expand Down