twodayslate / claw

A lobste.rs Reader
https://apps.apple.com/us/app/id1531645542
Other
35 stars 1 forks source link

Crash when opening up browser then story #22

Closed twodayslate closed 3 years ago

twodayslate commented 3 years ago

Example URL to assist with testing: https://lobste.rs/s/3qgyzp

Be in that story, then open the lobsters link in the comment in the web view. Then use the share sheet to in the webview to open the lobster link again but in the app using "Open in claw". None of the links then work and when you exit the view controller it crashes

When in a story, there is also a crash if you try to use the share sheet on a story and use the "Open in claw" action to open the same story. These are most likely related.

twodayslate commented 3 years ago

testflight_feedback.zip

twodayslate commented 3 years ago

Partially fixed in https://github.com/twodayslate/claw/commit/9c8baddd49c2b554a7f7358ee0d10c7f02666782

twodayslate commented 3 years ago

To reproduce the original report do the following steps:

  1. Open claw and any story
  2. Open safari and open https://lobste.rs/s/3qgyzp
  3. In Safari use the share sheet to open the current page in claw
  4. When the story open in the new VC go to the comment that says "Could probably be merged with " and deep press to click on share and open the share sheet.
  5. Open in claw via the share sheet.
twodayslate commented 3 years ago

AttributeGraph precondition failure: child already attached to new parent. Currently, only presenting a single sheet is supported.

twodayslate commented 3 years ago

The following seems to be the best solution so far.

diff --git a/claw.xcodeproj/xcuserdata/twodayslate.xcuserdatad/xcschemes/xcschememanagement.plist b/claw.xcodeproj/xcuserdata/twodayslate.xcuserdatad/xcschemes/xcschememanagement.plist
index 7e7b82e..2ddc0c9 100644
--- a/claw.xcodeproj/xcuserdata/twodayslate.xcuserdatad/xcschemes/xcschememanagement.plist
+++ b/claw.xcodeproj/xcuserdata/twodayslate.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -7,7 +7,7 @@
        <key>claw.xcscheme_^#shared#^_</key>
        <dict>
            <key>orderHint</key>
-           <integer>2</integer>
+           <integer>1</integer>
        </dict>
        <key>deleteme.xcscheme_^#shared#^_</key>
        <dict>
@@ -17,7 +17,7 @@
        <key>hottest.widgetExtension.xcscheme_^#shared#^_</key>
        <dict>
            <key>orderHint</key>
-           <integer>3</integer>
+           <integer>2</integer>
        </dict>
        <key>open-action.xcscheme_^#shared#^_</key>
        <dict>
@@ -27,7 +27,7 @@
        <key>opener-action.xcscheme_^#shared#^_</key>
        <dict>
            <key>orderHint</key>
-           <integer>1</integer>
+           <integer>0</integer>
        </dict>
        <key>share-extension.xcscheme_^#shared#^_</key>
        <dict>
diff --git a/claw/ContentView.swift b/claw/ContentView.swift
index da8a602..3842723 100644
--- a/claw/ContentView.swift
+++ b/claw/ContentView.swift
@@ -100,7 +100,6 @@ struct ContentView: View {
                                             }
                                             self._selection = $0
                                         })
-
         TabView(selection: selection) {
             NavigableTabViewItem(tabSelection: TabSelection.Hottest, content: {
                 HottestView()
@@ -131,6 +130,7 @@ struct ContentView: View {
             }).environmentObject(settings).environment(\.managedObjectContext, viewContext)
         }.environment(\.didReselect, didReselect.eraseToAnyPublisher()).accentColor(settings.accentColor).font(Font(.body, sizeModifier: CGFloat(settings.textSizeModifier))).onOpenURL(perform: { url in
             let _ = print(url, self.observableSheet.sheet)
+            //UIApplication.shared.windows.first?.rootViewController?.presentedViewController?.dismiss(animated: true, completion: nil)
             if url.host == "open", let comps = URLComponents(url: url, resolvingAgainstBaseURL: false), let items = comps.queryItems, let item = items.first, item.name == "url", let itemValue = item.value, let lobsters_url = URL(string: itemValue), lobsters_url.host == "lobste.rs" {
                 if lobsters_url.pathComponents.count > 2 {
                     if lobsters_url.pathComponents[1] == "s" {
@@ -180,7 +180,14 @@ struct ContentView: View {
             case .share(let url):
                 ShareSheet(activityItems: [url])
             default:
-                Text("Error: \(item.debugDescription)")
+                EZPanel {
+                    Text("Error: \(item.debugDescription)")
+                }
+                .environmentObject(urlToOpen)
+                .environmentObject(settings)
+                .environmentObject(self.observableSheet)
+                .environment(\.managedObjectContext, viewContext)
+                
             }
         })
         .environmentObject(settings)
@@ -188,15 +195,7 @@ struct ContentView: View {
         .environmentObject(self.observableSheet)
         .environmentObject(urlToOpen)

-        EmptyView().fullScreenCover(item: urlToOpen.bindingUrl, content: { url in
-            SafariView(
-                url: url,
-                configuration: SafariView.Configuration(
-                    entersReaderIfAvailable: settings.readerModeEnabled,
-                    barCollapsingEnabled: true
-                )
-            ).preferredControlAccentColor(settings.accentColor).dismissButtonStyle(.close)
-        })
+        
     }
 }

diff --git a/claw/Settings/SettingsLinkView.swift b/claw/Settings/SettingsLinkView.swift
index 5a59050..4dfaf15 100644
--- a/claw/Settings/SettingsLinkView.swift
+++ b/claw/Settings/SettingsLinkView.swift
@@ -1,5 +1,6 @@
 import Foundation
 import SwiftUI
+import BetterSafariView

 struct SettingsLinkView: View {
     var systemImage: String? = nil
@@ -21,6 +22,16 @@ struct SettingsLinkView: View {
             }, label: {
                 ZZLabel(iconBackgroundColor: iconColor, iconColor: .white, systemImage: systemImage, image: image, text: text)
         })
+            // this is necessary until multiple sheets can be displayed at one time. See #22
+            .fullScreenCover(item: urlToOpen.bindingUrl, content: { url in
+                SafariView(
+                    url: url,
+                    configuration: SafariView.Configuration(
+                        entersReaderIfAvailable: settings.readerModeEnabled,
+                        barCollapsingEnabled: true
+                    )
+                ).preferredControlAccentColor(settings.accentColor).dismissButtonStyle(.close)
+            })
     }
 }

diff --git a/claw/Settings/SettingsView.swift b/claw/Settings/SettingsView.swift
index b5c7c1a..f9ea588 100644
--- a/claw/Settings/SettingsView.swift
+++ b/claw/Settings/SettingsView.swift
@@ -7,6 +7,7 @@

 import SwiftUI
 import MessageUI
+import BetterSafariView

 struct AppIcon: Codable {
     var alternateIconName: String?
diff --git a/claw/Stories/StoryView.swift b/claw/Stories/StoryView.swift
index a2084d1..75eae1d 100644
--- a/claw/Stories/StoryView.swift
+++ b/claw/Stories/StoryView.swift
@@ -1,4 +1,5 @@
 import SwiftUI
+import BetterSafariView

 struct StoryView: View {
     var short_id: String
@@ -116,5 +117,15 @@ struct StoryView: View {
                 }
             })
         }
+        // this is necessary until multiple sheets can be displayed at one time. See #22
+        .fullScreenCover(item: urlToOpen.bindingUrl, content: { url in
+            SafariView(
+                url: url,
+                configuration: SafariView.Configuration(
+                    entersReaderIfAvailable: settings.readerModeEnabled,
+                    barCollapsingEnabled: true
+                )
+            ).preferredControlAccentColor(settings.accentColor).dismissButtonStyle(.close)
+        })
     }
 }
diff --git a/claw/URLView.swift b/claw/URLView.swift
index af352c7..fd28a61 100644
--- a/claw/URLView.swift
+++ b/claw/URLView.swift
@@ -6,6 +6,7 @@
 //

 import SwiftUI
+import BetterSafariView

 struct URLView: View {
     var link: HTMLLink
diff --git a/claw/User/UserView.swift b/claw/User/UserView.swift
index 8f39623..036ed7e 100644
--- a/claw/User/UserView.swift
+++ b/claw/User/UserView.swift
@@ -1,4 +1,5 @@
 import SwiftUI
+import BetterSafariView

 struct UserView: View {
     var user: NewestUser?
@@ -93,6 +94,16 @@ struct UserView: View {
                 self.presentationMode.wrappedValue.dismiss()
             }
         }
+        // this is necessary until multiple sheets can be displayed at one time. See #22
+        .fullScreenCover(item: urlToOpen.bindingUrl, content: { url in
+            SafariView(
+                url: url,
+                configuration: SafariView.Configuration(
+                    entersReaderIfAvailable: settings.readerModeEnabled,
+                    barCollapsingEnabled: true
+                )
+            ).preferredControlAccentColor(settings.accentColor).dismissButtonStyle(.close)
+        })
     }
 }

I now just get the following error libc++abi: terminating with uncaught exception of type NSException *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally a view controller <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x15dc5dda0> that is already being presented by <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x159805b10>.'

twodayslate commented 3 years ago
diff --git a/claw.xcodeproj/xcuserdata/twodayslate.xcuserdatad/xcschemes/xcschememanagement.plist b/claw.xcodeproj/xcuserdata/twodayslate.xcuserdatad/xcschemes/xcschememanagement.plist
index 7e7b82e..2ddc0c9 100644
--- a/claw.xcodeproj/xcuserdata/twodayslate.xcuserdatad/xcschemes/xcschememanagement.plist
+++ b/claw.xcodeproj/xcuserdata/twodayslate.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -7,7 +7,7 @@
        <key>claw.xcscheme_^#shared#^_</key>
        <dict>
            <key>orderHint</key>
-           <integer>2</integer>
+           <integer>1</integer>
        </dict>
        <key>deleteme.xcscheme_^#shared#^_</key>
        <dict>
@@ -17,7 +17,7 @@
        <key>hottest.widgetExtension.xcscheme_^#shared#^_</key>
        <dict>
            <key>orderHint</key>
-           <integer>3</integer>
+           <integer>2</integer>
        </dict>
        <key>open-action.xcscheme_^#shared#^_</key>
        <dict>
@@ -27,7 +27,7 @@
        <key>opener-action.xcscheme_^#shared#^_</key>
        <dict>
            <key>orderHint</key>
-           <integer>1</integer>
+           <integer>0</integer>
        </dict>
        <key>share-extension.xcscheme_^#shared#^_</key>
        <dict>
diff --git a/claw/ActiveSheet.swift b/claw/ActiveSheet.swift
index 19c95e1..4482ca8 100644
--- a/claw/ActiveSheet.swift
+++ b/claw/ActiveSheet.swift
@@ -11,8 +11,8 @@ enum ActiveSheet: Identifiable {
         switch self {
         case .share(let url): return "share:\(url.absoluteString)"
         case .safari(let url): return "safari:\(url.absoluteString)"
-        case .user(let id): return "user:\(id)"
-        case .story(let username): return "username:\(username)"
+        case .user(let username): return "user:\(username)"
+        case .story(let id): return "id:\(id)"
         case .url(let url): return "url\(url.absoluteString)"
         }
     }
diff --git a/claw/ContentView.swift b/claw/ContentView.swift
index da8a602..b3ff98a 100644
--- a/claw/ContentView.swift
+++ b/claw/ContentView.swift
@@ -100,7 +100,6 @@ struct ContentView: View {
                                             }
                                             self._selection = $0
                                         })
-
         TabView(selection: selection) {
             NavigableTabViewItem(tabSelection: TabSelection.Hottest, content: {
                 HottestView()
@@ -131,6 +130,9 @@ struct ContentView: View {
             }).environmentObject(settings).environment(\.managedObjectContext, viewContext)
         }.environment(\.didReselect, didReselect.eraseToAnyPublisher()).accentColor(settings.accentColor).font(Font(.body, sizeModifier: CGFloat(settings.textSizeModifier))).onOpenURL(perform: { url in
             let _ = print(url, self.observableSheet.sheet)
+            //UIApplication.shared.windows.first?.rootViewController?.presentedViewController?.dismiss(animated: true, completion: nil)
+            self.observableSheet.sheet = nil
+            self.urlToOpen.url = nil
             if url.host == "open", let comps = URLComponents(url: url, resolvingAgainstBaseURL: false), let items = comps.queryItems, let item = items.first, item.name == "url", let itemValue = item.value, let lobsters_url = URL(string: itemValue), lobsters_url.host == "lobste.rs" {
                 if lobsters_url.pathComponents.count > 2 {
                     if lobsters_url.pathComponents[1] == "s" {
@@ -180,23 +182,19 @@ struct ContentView: View {
             case .share(let url):
                 ShareSheet(activityItems: [url])
             default:
-                Text("Error: \(item.debugDescription)")
+                EZPanel {
+                    Text("Error: \(item.debugDescription)")
+                }
+                .environmentObject(urlToOpen)
+                .environmentObject(settings)
+                .environmentObject(self.observableSheet)
+                .environment(\.managedObjectContext, viewContext)
             }
         })
         .environmentObject(settings)
         .environment(\.managedObjectContext, viewContext)
         .environmentObject(self.observableSheet)
         .environmentObject(urlToOpen)
-
-        EmptyView().fullScreenCover(item: urlToOpen.bindingUrl, content: { url in
-            SafariView(
-                url: url,
-                configuration: SafariView.Configuration(
-                    entersReaderIfAvailable: settings.readerModeEnabled,
-                    barCollapsingEnabled: true
-                )
-            ).preferredControlAccentColor(settings.accentColor).dismissButtonStyle(.close)
-        })
     }
 }

diff --git a/claw/Settings/SettingsLinkView.swift b/claw/Settings/SettingsLinkView.swift
index 5a59050..e5c2e2a 100644
--- a/claw/Settings/SettingsLinkView.swift
+++ b/claw/Settings/SettingsLinkView.swift
@@ -1,5 +1,6 @@
 import Foundation
 import SwiftUI
+import BetterSafariView

 struct SettingsLinkView: View {
     var systemImage: String? = nil
@@ -21,6 +22,16 @@ struct SettingsLinkView: View {
             }, label: {
                 ZZLabel(iconBackgroundColor: iconColor, iconColor: .white, systemImage: systemImage, image: image, text: text)
         })
+            // this is necessary until multiple sheets can be displayed at one time. See #22
+            EmptyView().fullScreenCover(item: urlToOpen.bindingUrl, content: { url in
+                SafariView(
+                    url: url,
+                    configuration: SafariView.Configuration(
+                        entersReaderIfAvailable: settings.readerModeEnabled,
+                        barCollapsingEnabled: true
+                    )
+                ).preferredControlAccentColor(settings.accentColor).dismissButtonStyle(.close)
+            })
     }
 }

diff --git a/claw/Settings/SettingsView.swift b/claw/Settings/SettingsView.swift
index b5c7c1a..f9ea588 100644
--- a/claw/Settings/SettingsView.swift
+++ b/claw/Settings/SettingsView.swift
@@ -7,6 +7,7 @@

 import SwiftUI
 import MessageUI
+import BetterSafariView

 struct AppIcon: Codable {
     var alternateIconName: String?
diff --git a/claw/Stories/StoryView.swift b/claw/Stories/StoryView.swift
index a2084d1..5609b4e 100644
--- a/claw/Stories/StoryView.swift
+++ b/claw/Stories/StoryView.swift
@@ -1,4 +1,5 @@
 import SwiftUI
+import BetterSafariView

 struct StoryView: View {
     var short_id: String
@@ -116,5 +117,15 @@ struct StoryView: View {
                 }
             })
         }
+        // this is necessary until multiple sheets can be displayed at one time. See #22
+        EmptyView().fullScreenCover(item: urlToOpen.bindingUrl, content: { url in
+            SafariView(
+                url: url,
+                configuration: SafariView.Configuration(
+                    entersReaderIfAvailable: settings.readerModeEnabled,
+                    barCollapsingEnabled: true
+                )
+            ).preferredControlAccentColor(settings.accentColor).dismissButtonStyle(.close)
+        })
     }
 }
diff --git a/claw/URLView.swift b/claw/URLView.swift
index af352c7..fd28a61 100644
--- a/claw/URLView.swift
+++ b/claw/URLView.swift
@@ -6,6 +6,7 @@
 //

 import SwiftUI
+import BetterSafariView

 struct URLView: View {
     var link: HTMLLink
diff --git a/claw/User/UserView.swift b/claw/User/UserView.swift
index 8f39623..8f6051a 100644
--- a/claw/User/UserView.swift
+++ b/claw/User/UserView.swift
@@ -1,4 +1,5 @@
 import SwiftUI
+import BetterSafariView

 struct UserView: View {
     var user: NewestUser?
@@ -93,6 +94,16 @@ struct UserView: View {
                 self.presentationMode.wrappedValue.dismiss()
             }
         }
+        // this is necessary until multiple sheets can be displayed at one time. See #22
+        EmptyView().fullScreenCover(item: urlToOpen.bindingUrl, content: { url in
+            SafariView(
+                url: url,
+                configuration: SafariView.Configuration(
+                    entersReaderIfAvailable: settings.readerModeEnabled,
+                    barCollapsingEnabled: true
+                )
+            ).preferredControlAccentColor(settings.accentColor).dismissButtonStyle(.close)
+        })
     }
 }

Fixes the crash but if you have the SafariView up and try to open a link it claw, opening a link in claw will then never work again.

twodayslate commented 3 years ago
diff --git a/claw.xcodeproj/xcuserdata/twodayslate.xcuserdatad/xcschemes/xcschememanagement.plist b/claw.xcodeproj/xcuserdata/twodayslate.xcuserdatad/xcschemes/xcschememanagement.plist
index 7e7b82e..2ddc0c9 100644
--- a/claw.xcodeproj/xcuserdata/twodayslate.xcuserdatad/xcschemes/xcschememanagement.plist
+++ b/claw.xcodeproj/xcuserdata/twodayslate.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -7,7 +7,7 @@
        <key>claw.xcscheme_^#shared#^_</key>
        <dict>
            <key>orderHint</key>
-           <integer>2</integer>
+           <integer>1</integer>
        </dict>
        <key>deleteme.xcscheme_^#shared#^_</key>
        <dict>
@@ -17,7 +17,7 @@
        <key>hottest.widgetExtension.xcscheme_^#shared#^_</key>
        <dict>
            <key>orderHint</key>
-           <integer>3</integer>
+           <integer>2</integer>
        </dict>
        <key>open-action.xcscheme_^#shared#^_</key>
        <dict>
@@ -27,7 +27,7 @@
        <key>opener-action.xcscheme_^#shared#^_</key>
        <dict>
            <key>orderHint</key>
-           <integer>1</integer>
+           <integer>0</integer>
        </dict>
        <key>share-extension.xcscheme_^#shared#^_</key>
        <dict>
diff --git a/claw/ActiveSheet.swift b/claw/ActiveSheet.swift
index 19c95e1..4482ca8 100644
--- a/claw/ActiveSheet.swift
+++ b/claw/ActiveSheet.swift
@@ -11,8 +11,8 @@ enum ActiveSheet: Identifiable {
         switch self {
         case .share(let url): return "share:\(url.absoluteString)"
         case .safari(let url): return "safari:\(url.absoluteString)"
-        case .user(let id): return "user:\(id)"
-        case .story(let username): return "username:\(username)"
+        case .user(let username): return "user:\(username)"
+        case .story(let id): return "id:\(id)"
         case .url(let url): return "url\(url.absoluteString)"
         }
     }
diff --git a/claw/ContentView.swift b/claw/ContentView.swift
index da8a602..a474c30 100644
--- a/claw/ContentView.swift
+++ b/claw/ContentView.swift
@@ -100,7 +100,6 @@ struct ContentView: View {
                                             }
                                             self._selection = $0
                                         })
-
         TabView(selection: selection) {
             NavigableTabViewItem(tabSelection: TabSelection.Hottest, content: {
                 HottestView()
@@ -131,21 +130,28 @@ struct ContentView: View {
             }).environmentObject(settings).environment(\.managedObjectContext, viewContext)
         }.environment(\.didReselect, didReselect.eraseToAnyPublisher()).accentColor(settings.accentColor).font(Font(.body, sizeModifier: CGFloat(settings.textSizeModifier))).onOpenURL(perform: { url in
             let _ = print(url, self.observableSheet.sheet)
-            if url.host == "open", let comps = URLComponents(url: url, resolvingAgainstBaseURL: false), let items = comps.queryItems, let item = items.first, item.name == "url", let itemValue = item.value, let lobsters_url = URL(string: itemValue), lobsters_url.host == "lobste.rs" {
-                if lobsters_url.pathComponents.count > 2 {
-                    if lobsters_url.pathComponents[1] == "s" {
-                        self.observableSheet.sheet = ActiveSheet.story(id: lobsters_url.pathComponents[2])
-                    }
-                    else if lobsters_url.pathComponents[1] == "u" {
-                        self.observableSheet.sheet = ActiveSheet.user(username: lobsters_url.pathComponents[2])
+            let open = {
+                if url.host == "open", let comps = URLComponents(url: url, resolvingAgainstBaseURL: false), let items = comps.queryItems, let item = items.first, item.name == "url", let itemValue = item.value, let lobsters_url = URL(string: itemValue), lobsters_url.host == "lobste.rs" {
+                    if lobsters_url.pathComponents.count > 2 {
+                        if lobsters_url.pathComponents[1] == "s" {
+                            self.observableSheet.sheet = ActiveSheet.story(id: lobsters_url.pathComponents[2])
+                        }
+                        else if lobsters_url.pathComponents[1] == "u" {
+                            self.observableSheet.sheet = ActiveSheet.user(username: lobsters_url.pathComponents[2])
+                        } else {
+                            self.observableSheet.sheet = ActiveSheet.url(lobsters_url)
+                        }
                     } else {
                         self.observableSheet.sheet = ActiveSheet.url(lobsters_url)
                     }
                 } else {
-                    self.observableSheet.sheet = ActiveSheet.url(lobsters_url)
+                    self.observableSheet.sheet = ActiveSheet.url(url)
                 }
+            }
+            if url.host == "open" && (self.observableSheet.sheet != nil || self.urlToOpen.url != nil) {
+                UIApplication.shared.windows.first?.rootViewController?.presentedViewController?.dismiss(animated: true, completion: {open()})
             } else {
-                self.observableSheet.sheet = ActiveSheet.url(url)
+                open()
             }
         })
         .sheet(item: self.observableSheet.bindingSheet, content: { item in
@@ -180,23 +186,19 @@ struct ContentView: View {
             case .share(let url):
                 ShareSheet(activityItems: [url])
             default:
-                Text("Error: \(item.debugDescription)")
+                EZPanel {
+                    Text("Error: \(item.debugDescription)")
+                }
+                .environmentObject(urlToOpen)
+                .environmentObject(settings)
+                .environmentObject(self.observableSheet)
+                .environment(\.managedObjectContext, viewContext)
             }
         })
         .environmentObject(settings)
         .environment(\.managedObjectContext, viewContext)
         .environmentObject(self.observableSheet)
         .environmentObject(urlToOpen)
-
-        EmptyView().fullScreenCover(item: urlToOpen.bindingUrl, content: { url in
-            SafariView(
-                url: url,
-                configuration: SafariView.Configuration(
-                    entersReaderIfAvailable: settings.readerModeEnabled,
-                    barCollapsingEnabled: true
-                )
-            ).preferredControlAccentColor(settings.accentColor).dismissButtonStyle(.close)
-        })
     }
 }

diff --git a/claw/Settings/SettingsLinkView.swift b/claw/Settings/SettingsLinkView.swift
index 5a59050..e5c2e2a 100644
--- a/claw/Settings/SettingsLinkView.swift
+++ b/claw/Settings/SettingsLinkView.swift
@@ -1,5 +1,6 @@
 import Foundation
 import SwiftUI
+import BetterSafariView

 struct SettingsLinkView: View {
     var systemImage: String? = nil
@@ -21,6 +22,16 @@ struct SettingsLinkView: View {
             }, label: {
                 ZZLabel(iconBackgroundColor: iconColor, iconColor: .white, systemImage: systemImage, image: image, text: text)
         })
+            // this is necessary until multiple sheets can be displayed at one time. See #22
+            EmptyView().fullScreenCover(item: urlToOpen.bindingUrl, content: { url in
+                SafariView(
+                    url: url,
+                    configuration: SafariView.Configuration(
+                        entersReaderIfAvailable: settings.readerModeEnabled,
+                        barCollapsingEnabled: true
+                    )
+                ).preferredControlAccentColor(settings.accentColor).dismissButtonStyle(.close)
+            })
     }
 }

diff --git a/claw/Settings/SettingsView.swift b/claw/Settings/SettingsView.swift
index b5c7c1a..f9ea588 100644
--- a/claw/Settings/SettingsView.swift
+++ b/claw/Settings/SettingsView.swift
@@ -7,6 +7,7 @@

 import SwiftUI
 import MessageUI
+import BetterSafariView

 struct AppIcon: Codable {
     var alternateIconName: String?
diff --git a/claw/Stories/StoryView.swift b/claw/Stories/StoryView.swift
index a2084d1..5609b4e 100644
--- a/claw/Stories/StoryView.swift
+++ b/claw/Stories/StoryView.swift
@@ -1,4 +1,5 @@
 import SwiftUI
+import BetterSafariView

 struct StoryView: View {
     var short_id: String
@@ -116,5 +117,15 @@ struct StoryView: View {
                 }
             })
         }
+        // this is necessary until multiple sheets can be displayed at one time. See #22
+        EmptyView().fullScreenCover(item: urlToOpen.bindingUrl, content: { url in
+            SafariView(
+                url: url,
+                configuration: SafariView.Configuration(
+                    entersReaderIfAvailable: settings.readerModeEnabled,
+                    barCollapsingEnabled: true
+                )
+            ).preferredControlAccentColor(settings.accentColor).dismissButtonStyle(.close)
+        })
     }
 }
diff --git a/claw/URLView.swift b/claw/URLView.swift
index af352c7..fd28a61 100644
--- a/claw/URLView.swift
+++ b/claw/URLView.swift
@@ -6,6 +6,7 @@
 //

 import SwiftUI
+import BetterSafariView

 struct URLView: View {
     var link: HTMLLink
diff --git a/claw/User/UserView.swift b/claw/User/UserView.swift
index 8f39623..8f6051a 100644
--- a/claw/User/UserView.swift
+++ b/claw/User/UserView.swift
@@ -1,4 +1,5 @@
 import SwiftUI
+import BetterSafariView

 struct UserView: View {
     var user: NewestUser?
@@ -93,6 +94,16 @@ struct UserView: View {
                 self.presentationMode.wrappedValue.dismiss()
             }
         }
+        // this is necessary until multiple sheets can be displayed at one time. See #22
+        EmptyView().fullScreenCover(item: urlToOpen.bindingUrl, content: { url in
+            SafariView(
+                url: url,
+                configuration: SafariView.Configuration(
+                    entersReaderIfAvailable: settings.readerModeEnabled,
+                    barCollapsingEnabled: true
+                )
+            ).preferredControlAccentColor(settings.accentColor).dismissButtonStyle(.close)
+        })
     }
 }

Seems to work perfectly. Only downside is you can't have multiple sheets (story on top of story on top of story) but I guess that is okay as Octal doesn't either.

twodayslate commented 3 years ago

I'm now getting

2021-06-28 21:57:25.930602-0400 claw[21888:638657] [Presentation] Attempt to present <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x1454b8ab0> on <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x140817990> (from <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x140817990>) which is already presenting <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x145a3c7c0>.
2021-06-28 22:22:31.191029-0400 claw[22484:671564] [Presentation] Attempt to present <_UIRemoteViewController: 0x1301c7a00> on <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x12f763400> (from <UIActivityContentViewController: 0x13012a000>) whose view is not in the window hierarchy.

I am just trying to open a story comment in claw from claw