Skip to content

Commit 583a27f

Browse files
Revert "fix(feedback): user feedback widget in SwiftUI (getsentry#5223)"
This reverts commit d170e0d.
1 parent 5c1ce6f commit 583a27f

File tree

3 files changed

+4
-43
lines changed

3 files changed

+4
-43
lines changed

Samples/iOS-SwiftUI/iOS-SwiftUI/SwiftUIApp.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Foundation
2-
import Sentry
32
import SentrySampleShared
43
import SwiftUI
54

@@ -39,7 +38,6 @@ class MySceneDelegate: NSObject, UIWindowSceneDelegate, ObservableObject {
3938
}
4039

4140
SampleAppDebugMenu.shared.display()
42-
SentrySDK.feedback.showWidget()
4341
initializedSentry = true
4442
}
4543
}

Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackIntegrationDriver.swift

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,6 @@ import UIKit
4343
} else if let widgetConfigBuilder = configuration.configureWidget {
4444
widgetConfigBuilder(configuration.widgetConfig)
4545
validate(configuration.widgetConfig)
46-
47-
/*
48-
* We cannot currently automatically inject a widget into a SwiftUI application, because at the recommended time to start the Sentry SDK (SwiftUIApp.init) there is nowhere to put a UIWindow overlay. SwiftUI apps must currently declare a UIApplicationDelegateAdaptor that returns a UISceneConfiguration, which we can then extract a connected UIScene from into which we can inject a UIWindow.
49-
*
50-
* At the time this integration is being installed, if there is no UIApplicationDelegate and no connected UIScene, it is very likely we are in a SwiftUI app, but it's possible we could instead be in a UIKit app that has some nonstandard launch procedure or doesn't call SentrySDK.start in a place we expect/recommend, in which case they will need to manually display the widget when they're ready by calling SentrySDK.feedback.showWidget.
51-
*/
52-
if UIApplication.shared.connectedScenes.isEmpty && UIApplication.shared.delegate == nil {
53-
return
54-
}
55-
5646
if configuration.widgetConfig.autoInject {
5747
widget = SentryUserFeedbackWidget(config: configuration, delegate: self)
5848
}
@@ -68,9 +58,9 @@ import UIKit
6858
@objc public func showWidget() {
6959
if widget == nil {
7060
widget = SentryUserFeedbackWidget(config: configuration, delegate: self)
61+
} else {
62+
widget?.rootVC.setWidget(visible: true, animated: configuration.animations)
7163
}
72-
73-
widget?.rootVC.setWidget(visible: true, animated: configuration.animations)
7464
}
7565

7666
@objc public func hideWidget() {

Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidget.swift

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,53 +17,26 @@ final class SentryUserFeedbackWidget {
1717
let button = SentryUserFeedbackWidgetButtonView(config: config, target: self, selector: #selector(showForm))
1818
return button
1919
}()
20-
2120
lazy var rootVC = RootViewController(config: config, button: button)
22-
23-
private var window: Window?
24-
21+
private lazy var window = SentryUserFeedbackWidget.Window(config: config)
2522
let config: SentryUserFeedbackConfiguration
2623
weak var delegate: (any SentryUserFeedbackWidgetDelegate)?
2724

2825
init(config: SentryUserFeedbackConfiguration, delegate: any SentryUserFeedbackWidgetDelegate) {
2926
self.config = config
3027
self.delegate = delegate
31-
32-
/*
33-
* We must have a UIScene in order to display an overlaying UIWindow in a SwiftUI app, which is currently how we display the widget. SentryUserFeedbackIntegrationDriver won't try to initialize this class if there are no connected UIScenes _and_ there is no UIApplicationDelegate at the time the integration is being installed.
34-
*
35-
* Both UIKit and SwiftUI apps can have connected UIScenes. Here's how we then try to tell the difference:
36-
* - If there is no connected UIScene but there is already a UIApplicationDelegate by the time this integration is being installed, then we are either in a UIKit app, or inside a SwiftUI app that for whatever reason delays the call to SentrySDK.start until there is a connected scene. In either case, we'll just grab the first connected UIScene and proceed.
37-
* - Otherwise, we're either in a SwiftUI app that _does_ call SentrySDK.start at the recommended time (SwiftUIApp.init), or there is a more complicated initialization procedure in a UIKit app that we can't automatically detect, and the app will need to call SentrySDK.feedback.showWidget() at the appropriate time, the same as how SwiftUI apps must currently do once they've connected a UIScene to their UIApplicationDelegateAdaptor.
38-
*/
39-
let window: Window
40-
if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
41-
window = SentryUserFeedbackWidget.Window(config: config, windowScene: scene)
42-
} else {
43-
window = SentryUserFeedbackWidget.Window(config: config)
44-
}
4528
window.rootViewController = rootVC
4629
window.isHidden = false
47-
self.window = window
4830
}
4931

5032
@objc func showForm() {
5133
self.delegate?.showForm()
5234
}
5335

5436
final class Window: UIWindow {
55-
private func _init(config: SentryUserFeedbackConfiguration) {
56-
windowLevel = config.widgetConfig.windowLevel
57-
}
58-
59-
init(config: SentryUserFeedbackConfiguration, windowScene: UIWindowScene) {
60-
super.init(windowScene: windowScene)
61-
_init(config: config)
62-
}
63-
6437
init(config: SentryUserFeedbackConfiguration) {
6538
super.init(frame: UIScreen.main.bounds)
66-
_init(config: config)
39+
windowLevel = config.widgetConfig.windowLevel
6740
}
6841

6942
required init?(coder: NSCoder) {

0 commit comments

Comments
 (0)