Skip to content

Commit

Permalink
Add iOS native reader mode setting
Browse files Browse the repository at this point in the history
Resolves #701
  • Loading branch information
aeharding committed Feb 19, 2024
1 parent 347c4e5 commit f0ad1f0
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 32 deletions.
2 changes: 1 addition & 1 deletion android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include ':capacitor-app'
project(':capacitor-app').projectDir = new File('../node_modules/.pnpm/@capacitor+app@5.0.7_@capacitor+core@5.7.0/node_modules/@capacitor/app/android')

include ':capacitor-browser'
project(':capacitor-browser').projectDir = new File('../node_modules/.pnpm/@capacitor+browser@5.2.0_@capacitor+core@5.7.0/node_modules/@capacitor/browser/android')
project(':capacitor-browser').projectDir = new File('../node_modules/.pnpm/@capacitor+browser@5.2.0_patch_hash=bc25ohpkb4iimysp77pbkkz45i_@capacitor+core@5.7.0/node_modules/@capacitor/browser/android')

include ':capacitor-filesystem'
project(':capacitor-filesystem').projectDir = new File('../node_modules/.pnpm/@capacitor+filesystem@5.2.1_@capacitor+core@5.7.0/node_modules/@capacitor/filesystem/android')
Expand Down
2 changes: 1 addition & 1 deletion ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def capacitor_pods
pod 'CapacitorCordova', :path => '../../node_modules/.pnpm/@capacitor+ios@5.7.0_@capacitor+core@5.7.0/node_modules/@capacitor/ios'
pod 'CapacitorCommunityAppIcon', :path => '../../node_modules/.pnpm/@capacitor-community+app-icon@4.1.1_@capacitor+core@5.7.0/node_modules/@capacitor-community/app-icon'
pod 'CapacitorApp', :path => '../../node_modules/.pnpm/@capacitor+app@5.0.7_@capacitor+core@5.7.0/node_modules/@capacitor/app'
pod 'CapacitorBrowser', :path => '../../node_modules/.pnpm/@capacitor+browser@5.2.0_@capacitor+core@5.7.0/node_modules/@capacitor/browser'
pod 'CapacitorBrowser', :path => '../../node_modules/.pnpm/@capacitor+browser@5.2.0_patch_hash=bc25ohpkb4iimysp77pbkkz45i_@capacitor+core@5.7.0/node_modules/@capacitor/browser'
pod 'CapacitorFilesystem', :path => '../../node_modules/.pnpm/@capacitor+filesystem@5.2.1_@capacitor+core@5.7.0/node_modules/@capacitor/filesystem'
pod 'CapacitorHaptics', :path => '../../node_modules/.pnpm/voyager-capacitor-haptics@5.0.7_@capacitor+core@5.7.0/node_modules/voyager-capacitor-haptics'
pod 'CapacitorKeyboard', :path => '../../node_modules/.pnpm/@capacitor+keyboard@5.0.8_@capacitor+core@5.7.0/node_modules/@capacitor/keyboard'
Expand Down
6 changes: 3 additions & 3 deletions ios/App/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ DEPENDENCIES:
- "CapacitorApp (from `../../node_modules/.pnpm/@capacitor+app@5.0.7_@capacitor+core@5.7.0/node_modules/@capacitor/app`)"
- "CapacitorApplicationContext (from `../../node_modules/.pnpm/capacitor-application-context@0.0.1_@capacitor+core@5.7.0/node_modules/capacitor-application-context`)"
- "CapacitorBiometricLock (from `../../node_modules/.pnpm/capacitor-biometric-lock@0.1.1_@capacitor+core@5.7.0/node_modules/capacitor-biometric-lock`)"
- "CapacitorBrowser (from `../../node_modules/.pnpm/@capacitor+browser@5.2.0_@capacitor+core@5.7.0/node_modules/@capacitor/browser`)"
- "CapacitorBrowser (from `../../node_modules/.pnpm/@capacitor+browser@5.2.0_patch_hash=bc25ohpkb4iimysp77pbkkz45i_@capacitor+core@5.7.0/node_modules/@capacitor/browser`)"
- "CapacitorCommunityAppIcon (from `../../node_modules/.pnpm/@capacitor-community+app-icon@4.1.1_@capacitor+core@5.7.0/node_modules/@capacitor-community/app-icon`)"
- "CapacitorCordova (from `../../node_modules/.pnpm/@capacitor+ios@5.7.0_@capacitor+core@5.7.0/node_modules/@capacitor/ios`)"
- "CapacitorFilesystem (from `../../node_modules/.pnpm/@capacitor+filesystem@5.2.1_@capacitor+core@5.7.0/node_modules/@capacitor/filesystem`)"
Expand Down Expand Up @@ -72,7 +72,7 @@ EXTERNAL SOURCES:
CapacitorBiometricLock:
:path: "../../node_modules/.pnpm/capacitor-biometric-lock@0.1.1_@capacitor+core@5.7.0/node_modules/capacitor-biometric-lock"
CapacitorBrowser:
:path: "../../node_modules/.pnpm/@capacitor+browser@5.2.0_@capacitor+core@5.7.0/node_modules/@capacitor/browser"
:path: "../../node_modules/.pnpm/@capacitor+browser@5.2.0_patch_hash=bc25ohpkb4iimysp77pbkkz45i_@capacitor+core@5.7.0/node_modules/@capacitor/browser"
CapacitorCommunityAppIcon:
:path: "../../node_modules/.pnpm/@capacitor-community+app-icon@4.1.1_@capacitor+core@5.7.0/node_modules/@capacitor-community/app-icon"
CapacitorCordova:
Expand Down Expand Up @@ -116,6 +116,6 @@ SPEC CHECKSUMS:
CapacitorTips: 045758a9354574aa4807265e1bccbca0919ad861
SDWebImage: 750adf017a315a280c60fde706ab1e552a3ae4e9

PODFILE CHECKSUM: 60e067b3584bd11d5c774c089886aebd272632db
PODFILE CHECKSUM: 7bbc79e4b01b6183e68d41416625999cc78f4bc7

COCOAPODS: 1.12.1
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"pnpm": {
"overrides": {
"@ionic/core": "npm:voyager-ionic-core"
},
"patchedDependencies": {
"@capacitor/browser@5.2.0": "patches/@capacitor__browser@5.2.0.patch"
}
},
"dependencies": {
Expand Down
61 changes: 61 additions & 0 deletions patches/@capacitor__browser@5.2.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
diff --git a/dist/esm/definitions.d.ts b/dist/esm/definitions.d.ts
index 9cd84087179ce4fc2139e3d771506552b0d82254..1c158d3ec3cfcff6d7f3aec0e1a3b2b99160a53a 100644
--- a/dist/esm/definitions.d.ts
+++ b/dist/esm/definitions.d.ts
@@ -88,6 +88,7 @@ export interface OpenOptions {
* @since 4.0.0
*/
height?: number;
+ entersReaderIfAvailable?: boolean;
}
/**
* @deprecated Use `OpenOptions`.
diff --git a/ios/Plugin/Browser.swift b/ios/Plugin/Browser.swift
index 3f1d1ade3e05d142a2295b354228d0a21ba0a01f..225101acfe73c068705fb18074460d8bd3c815a8 100644
--- a/ios/Plugin/Browser.swift
+++ b/ios/Plugin/Browser.swift
@@ -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
diff --git a/ios/Plugin/BrowserPlugin.swift b/ios/Plugin/BrowserPlugin.swift
index f6be40dd72cdd1ced0fe43869d26d9188ca08ea8..ae31df607cc96589ed9de959d6d926174ed24a5d 100644
--- a/ios/Plugin/BrowserPlugin.swift
+++ b/ios/Plugin/BrowserPlugin.swift
@@ -2,7 +2,13 @@ import Foundation
import Capacitor

@objc(CAPBrowserPlugin)
-public class CAPBrowserPlugin: CAPPlugin {
+public class CAPBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
+ public let identifier = "CAPBrowserPlugin"
+ public let jsName = "Browser"
+ public let pluginMethods: [CAPPluginMethod] = [
+ CAPPluginMethod(name: "open", returnType: CAPPluginReturnPromise),
+ CAPPluginMethod(name: "close", returnType: CAPPluginReturnPromise),
+ ]
private let implementation = Browser()

@objc func open(_ call: CAPPluginCall) {
@@ -17,8 +23,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
}
58 changes: 32 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/features/settings/general/GeneralSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import Comments from "./comments/Comments";
import Other from "./other/Other";
import Posts from "./posts/Posts";
import Safari from "./safari/Safari";

export default function GeneralSettings() {
return (
<>
<Posts />
<Comments />
<Safari />
<Other />
</>
);
Expand Down

0 comments on commit f0ad1f0

Please sign in to comment.