Skip to content

Commit

Permalink
only support ios 13+ for now
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight committed Oct 18, 2024
1 parent be4eb19 commit 0f7ba54
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 51 deletions.
7 changes: 5 additions & 2 deletions Sources/Sentry/SentrySDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,11 @@ + (void)installIntegrations
[SentrySDK.currentHub getClient].options.integrations.mutableCopy;

#if TARGET_OS_IOS && SENTRY_HAS_UIKIT
if (options.userFeedbackConfiguration != nil) {
[integrationNames addObject:NSStringFromClass([SentryUserFeedbackIntegrationShell class])];
if (@available(iOS 13.0, *)) {
if (options.userFeedbackConfiguration != nil) {
[integrationNames
addObject:NSStringFromClass([SentryUserFeedbackIntegrationShell class])];
}
}
#endif // TARGET_OS_IOS && SENTRY_HAS_UIKIT

Expand Down
7 changes: 5 additions & 2 deletions Sources/Sentry/include/SentryOptions+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Block used to configure the user feedback widget, form, behaviors and submission data.
*/
API_AVAILABLE(ios(13.0))
typedef void (^SentryUserFeedbackConfigurationBlock)(
SentryUserFeedbackConfiguration *_Nonnull configuration);

Expand All @@ -28,9 +29,11 @@ FOUNDATION_EXPORT NSString *const kSentryDefaultEnvironment;
* https://docs.sentry.io/platforms/apple/user-feedback/#user-feedback-api and (TODO: add link to
* new docs) for more information on each approach.
*/
@property (nonatomic, copy, nullable) SentryUserFeedbackConfigurationBlock configureUserFeedback;
@property (nonatomic, copy, nullable)
SentryUserFeedbackConfigurationBlock configureUserFeedback API_AVAILABLE(ios(13.0));

@property (nonatomic, strong, nullable) SentryUserFeedbackConfiguration *userFeedbackConfiguration;
@property (nonatomic, strong, nullable)
SentryUserFeedbackConfiguration *userFeedbackConfiguration API_AVAILABLE(ios(13.0));

SENTRY_EXTERN BOOL sentry_isValidSampleRate(NSNumber *sampleRate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import UIKit
* The settings to use for how the user feedback form is presented, what data is required and how
* it's submitted, and some auxiliary hooks to customize the workflow.
*/
@objcMembers public class SentryUserFeedbackConfiguration: NSObject {
@available(iOS 13.0, *)
@objcMembers
public class SentryUserFeedbackConfiguration: NSObject {
/**
* Configuration settings specific to the managed widget that displays the UI form.
* - note: Default: `nil` to use the default widget settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import UIKit
/**
* Settings to control the behavior and appearance of the UI form.
*/
@objcMembers public class SentryUserFeedbackFormConfiguration: NSObject {
@available(iOS 13.0, *)
@objcMembers
public class SentryUserFeedbackFormConfiguration: NSObject {
// MARK: General settings

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import UIKit
/**
* Settings for overriding theming components for the User Feedback Widget and Form.
*/
@objcMembers public class SentryUserFeedbackThemeConfiguration: NSObject {
@available(iOS 13.0, *)
@objcMembers
public class SentryUserFeedbackThemeConfiguration: NSObject {
/**
* The default font to use.
* - note: Defaults to the current system default.
Expand All @@ -18,25 +20,15 @@ import UIKit
* - note: Default light mode: `rgb(43, 34, 51)`; dark mode: `rgb(235, 230, 239)`
*/
public var foreground: UIColor = {
let lightModeDefault = UIColor(red: 43 / 255, green: 34 / 255, blue: 51 / 255, alpha: 1)
if #available(iOS 12.0, *) {
return UIScreen.main.traitCollection.userInterfaceStyle == .dark ? UIColor(red: 235 / 255, green: 230 / 255, blue: 239 / 255, alpha: 1) : lightModeDefault
} else {
return lightModeDefault
}
UIScreen.main.traitCollection.userInterfaceStyle == .dark ? UIColor(red: 235 / 255, green: 230 / 255, blue: 239 / 255, alpha: 1) : UIColor(red: 43 / 255, green: 34 / 255, blue: 51 / 255, alpha: 1)
}()

/**
* Background color of the widget and form.
* - note: Default light mode: `rgb(255, 255, 255)`; dark mode: `rgb(41, 35, 47)`
*/
public var background: UIColor = {
let lightModeDefault = UIColor.white
if #available(iOS 12.0, *) {
return UIScreen.main.traitCollection.userInterfaceStyle == .dark ? UIColor(red: 41 / 255, green: 35 / 255, blue: 47 / 255, alpha: 1) : lightModeDefault
} else {
return lightModeDefault
}
UIScreen.main.traitCollection.userInterfaceStyle == .dark ? UIColor(red: 41 / 255, green: 35 / 255, blue: 47 / 255, alpha: 1) : UIColor.white
}()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import UIKit
/**
* Settings for whether to show the widget and how it should appear.
*/
@objcMembers public class SentryUserFeedbackWidgetConfiguration: NSObject {
@available(iOS 13.0, *)
@objcMembers
public class SentryUserFeedbackWidgetConfiguration: NSObject {
/**
* Injects the Feedback widget into the application UI when the integration is added. Set to `false`
* if you want to call `attachToButton()` or `createWidget()` directly, or only want to show the
Expand Down Expand Up @@ -49,7 +51,7 @@ import UIKit
* The location for positioning the widget.
* - note: Default: `[.bottom, .right]`
*/
public var location: UIRectEdge = [.bottom, .right]
public var location: UIDirectionalRectEdge = [.bottom, .trailing]

/**
* The distance to use from the widget button to the `safeAreaLayoutGuide` of the root view in the widget's container window.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import UIKit
* An integration managing a workflow for end users to report feedback via Sentry.
* - note: The default method to show the feedback form is via a floating widget placed in the bottom trailing corner of the screen. See the configuration classes for alternative options.
*/
@objcMembers class SentryUserFeedbackIntegration: NSObject {
@available(iOS 13.0, *)
@objcMembers
class SentryUserFeedbackIntegration: NSObject {
let configuration: SentryUserFeedbackConfiguration
private var window: SentryUserFeedbackWidget.Window?

Expand Down Expand Up @@ -71,12 +73,12 @@ import UIKit
}

private func validate(_ config: SentryUserFeedbackWidgetConfiguration) {
let noOpposingHorizontals = config.location.contains(.right) && !config.location.contains(.left)
|| !config.location.contains(.right) && config.location.contains(.left)
let noOpposingHorizontals = config.location.contains(.trailing) && !config.location.contains(.leading)
|| !config.location.contains(.trailing) && config.location.contains(.leading)
let noOpposingVerticals = config.location.contains(.top) && !config.location.contains(.bottom)
|| !config.location.contains(.top) && config.location.contains(.bottom)
let atLeastOneLocation = config.location.contains(.right)
|| config.location.contains(.left)
let atLeastOneLocation = config.location.contains(.trailing)
|| config.location.contains(.leading)
|| config.location.contains(.top)
|| config.location.contains(.bottom)
let notAll = !config.location.contains(.all)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

NS_ASSUME_NONNULL_BEGIN

API_AVAILABLE(ios(13.0))
@interface SentryUserFeedbackIntegrationShell : SentryBaseIntegration

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Foundation
@_implementationOnly import _SentryPrivate
import UIKit

@available(iOS 13.0, *)
struct SentryUserFeedbackWidget {
class Window: UIWindow {
class RootViewController: UIViewController {
Expand Down Expand Up @@ -47,11 +48,11 @@ struct SentryUserFeedbackWidget {
if config.widgetConfig.location.contains(.top) {
constraints.append(button.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: config.widgetConfig.layoutUIOffset.vertical))
}
if config.widgetConfig.location.contains(.right) {
constraints.append(button.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor, constant: -config.widgetConfig.layoutUIOffset.horizontal))
if config.widgetConfig.location.contains(.trailing) {
constraints.append(button.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -config.widgetConfig.layoutUIOffset.horizontal))
}
if config.widgetConfig.location.contains(.left) {
constraints.append(button.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: config.widgetConfig.layoutUIOffset.horizontal))
if config.widgetConfig.location.contains(.leading) {
constraints.append(button.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: config.widgetConfig.layoutUIOffset.horizontal))
}
NSLayoutConstraint.activate(constraints)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@ import Foundation
@_implementationOnly import _SentryPrivate
import UIKit

@available(iOS 13.0, *)
class SentryUserFeedbackWidgetButtonMegaphoneIconView: UIView {
init(config: SentryUserFeedbackConfiguration) {
super.init(frame: .zero)

let svgLayer = CAShapeLayer()
svgLayer.path = megaphoneShape

func configureLightTheme() {
svgLayer.fillColor = config.theme.foreground.cgColor
}
if #available(iOS 12.0, *) {
if UIScreen.main.traitCollection.userInterfaceStyle == .dark {
svgLayer.fillColor = config.darkTheme.foreground.cgColor
} else {
configureLightTheme()
}
if UIScreen.main.traitCollection.userInterfaceStyle == .dark {
svgLayer.fillColor = config.darkTheme.foreground.cgColor
} else {
configureLightTheme()
svgLayer.fillColor = config.theme.foreground.cgColor
}

svgLayer.fillRule = .evenOdd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Foundation
@_implementationOnly import _SentryPrivate
import UIKit

@available(iOS 13.0, *)
class SentryUserFeedbackWidgetButtonView: UIView {
// MARK: Measurements

Expand Down Expand Up @@ -159,20 +160,13 @@ class SentryUserFeedbackWidgetButtonView: UIView {
let lozengeLayer = CAShapeLayer()
lozengeLayer.path = lozengeShape.cgPath

func configureLightTheme() {
if UIScreen.main.traitCollection.userInterfaceStyle == .dark {
lozengeLayer.fillColor = config.darkTheme.background.cgColor
lozengeLayer.strokeColor = config.darkTheme.outlineColor.cgColor
} else {
lozengeLayer.fillColor = config.theme.background.cgColor
lozengeLayer.strokeColor = config.theme.outlineColor.cgColor
}
if #available(iOS 12.0, *) {
if UIScreen.main.traitCollection.userInterfaceStyle == .dark {
lozengeLayer.fillColor = config.darkTheme.background.cgColor
lozengeLayer.strokeColor = config.darkTheme.outlineColor.cgColor
} else {
configureLightTheme()
}
} else {
configureLightTheme()
}

let iconSizeDifference = (scaledIconSize - svgSize) / 2
if hasText {
Expand Down

0 comments on commit 0f7ba54

Please sign in to comment.