Skip to content

Commit

Permalink
threading through more theme settings to widget
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight committed Oct 3, 2024
1 parent 201979c commit dfc9bc9
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,18 @@ import UIKit
*/
public var configureTheme: ((SentryUserFeedbackThemeConfiguration) -> Void)?

lazy var themeOverrides = SentryUserFeedbackThemeConfiguration()
lazy var theme = SentryUserFeedbackThemeConfiguration()

/**
* Builder for dark mode theme overrides. If your app does not deploy a different theme for dark
* mode, assign the same builder to this property as you do for `configureTheme`.
* mode, but you still want to override some theme settings, assign the same builder to this
* property as you do for `configureTheme`.
* - note: Default: `nil`
* - note: Only applies to iOS ≤12.
*/
public var configureDarkTheme: ((SentryUserFeedbackThemeConfiguration) -> Void)?

lazy var darkThemeOverrides = SentryUserFeedbackThemeConfiguration()
lazy var darkTheme = SentryUserFeedbackThemeConfiguration()
}

#endif // (os(iOS) || os(tvOS)) && !SENTRY_NO_UIKIT
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Foundation
import UIKit

/**
* Settings for overriding theming components for the User Feedback Widget.
* Settings for overriding theming components for the User Feedback Widget and Form.
*/
@objcMembers public class SentryUserFeedbackThemeConfiguration: NSObject {
/**
Expand All @@ -14,39 +14,39 @@ import UIKit
public var font: UIFont?

/**
* Foreground text color.
* Foreground text color of the widget and form.
* - 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(iOSApplicationExtension 12.0, *) {
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
}
}()

/**
* Background color of the widget (injected button and form).
* 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(iOSApplicationExtension 12.0, *) {
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
}
}()

/**
* Foreground color for the submit button.
* Foreground color for the form submit button.
* - note: Default: `rgb(255, 255, 255)` for both dark and light modes
*/
public var accentForeground: UIColor = UIColor.white

/**
* Background color for the submit button in light and dark modes.
* Background color for the form submit button in light and dark modes.
* - note: Default: `rgb(88, 74, 192)` for both light and dark modes
*/
public var accentBackground: UIColor = UIColor(red: 88 / 255, green: 74 / 255, blue: 192 / 255, alpha: 1)
Expand All @@ -57,7 +57,7 @@ import UIKit
*/
public var successColor: UIColor = {
let lightModeDefault = UIColor(red: 38 / 255, green: 141 / 255, blue: 117 / 255, alpha: 1)
if #available(iOSApplicationExtension 12.0, *) {
if #available(iOS 12.0, *) {
return UIScreen.main.traitCollection.userInterfaceStyle == .dark ? UIColor(red: 45 / 255, green: 169 / 255, blue: 140 / 255, alpha: 1) : lightModeDefault
} else {
return lightModeDefault
Expand All @@ -70,7 +70,7 @@ import UIKit
*/
public var errorColor: UIColor = {
let lightModeDefault = UIColor(red: 223 / 255, green: 51 / 255, blue: 56 / 255, alpha: 1)
if #available(iOSApplicationExtension 12.0, *) {
if #available(iOS 12.0, *) {
return UIScreen.main.traitCollection.userInterfaceStyle == .dark ? UIColor(red: 245 / 255, green: 84 / 255, blue: 89 / 255, alpha: 1) : lightModeDefault
} else {
return lightModeDefault
Expand All @@ -81,7 +81,13 @@ import UIKit
* Normal outline color for form inputs.
* - note: Default: `nil (system default)`
*/
public var outlineColor: UIColor?
public var outlineColor: UIColor = {
if #available(iOS 13.0, *) {
return UIColor.systemGray3
} else {
return UIColor.lightGray
}
}()

/**
* Outline color for form inputs when focused.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import UIKit
uiFormConfigBuilder(configuration.formConfig)
}
if let themeOverrideBuilder = configuration.configureTheme {
themeOverrideBuilder(configuration.themeOverrides)
themeOverrideBuilder(configuration.theme)
}
if let darkThemeOverrideBuilder = configuration.configureDarkTheme {
darkThemeOverrideBuilder(configuration.darkThemeOverrides)
darkThemeOverrideBuilder(configuration.darkTheme)
}

if configuration.widgetConfig.autoInject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ class SentryUserFeedbackWidgetButtonView: UIView {

lazy var tapGesture = UITapGestureRecognizer(target: self, action: #selector(buttonPressed))
let action: (SentryUserFeedbackWidgetButtonView) -> Void
let config: SentryUserFeedbackConfiguration

init(config: SentryUserFeedbackConfiguration, action: @escaping (SentryUserFeedbackWidgetButtonView) -> Void) {
self.action = action
self.config = config
super.init(frame: .zero)
translatesAutoresizingMaskIntoConstraints = false

Expand Down Expand Up @@ -57,8 +59,27 @@ class SentryUserFeedbackWidgetButtonView: UIView {
func label(text: String) -> UILabel {
let label = UILabel(frame: .zero)
label.text = text
label.textColor = .black
label.translatesAutoresizingMaskIntoConstraints = false

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

var font = UIFont.systemFont(ofSize: UIFont.systemFontSize)
if let fontOverride = config.theme.font {
font = fontOverride
}
label.font = font

return label
}

Expand All @@ -84,15 +105,42 @@ class SentryUserFeedbackWidgetButtonView: UIView {

let lozengeLayer = CAShapeLayer()
lozengeLayer.path = lozengeShape.cgPath
lozengeLayer.fillColor = UIColor.white.cgColor
lozengeLayer.strokeColor = UIColor.lightGray.cgColor

func configureLightTheme() {
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()
}

return lozengeLayer
}

lazy var megaphone: UIView = {
let svgLayer = CAShapeLayer()
svgLayer.path = megaphoneShape
svgLayer.fillColor = UIColor.black.cgColor

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()
}
} else {
configureLightTheme()
}

svgLayer.fillRule = .evenOdd

let svgView = UIView(frame: .zero)
Expand Down

0 comments on commit dfc9bc9

Please sign in to comment.