Skip to content

Commit

Permalink
Add Browser.open entersReaderIfAvailable option
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding committed Oct 31, 2023
1 parent 27e7825 commit e08e9d6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
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/Plugin/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/Plugin/BrowserPlugin.swift
Expand Up @@ -17,8 +17,9 @@ public class CAPBrowserPlugin: CAPPlugin {
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

0 comments on commit e08e9d6

Please sign in to comment.