Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize backgroundEffect blur styles for BackgroundEffectStyle.systemDefault #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions DrawerView/DrawerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ private struct ChildScrollViewInfo {
updateVisuals()
}
}

/// The background blur effect style for dark mode.
public var darkBlurEffectStyle: UIBlurEffect.Style = .dark {
didSet {
updateVisuals()
}
}

/// The background blur effect style for light mode.
public var lightBlurEffectStyle: UIBlurEffect.Style = .light {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, for some reason developers may set a dark style for light mode, but, seems like we shouldn't make a limitation on it, because for some kind of Themes, developers may want to set .light for dark mode and .extraLight for light mode. You know what I mean? :)

didSet {
updateVisuals()
}
}

public var borderColor: UIColor = kDefaultBorderColor {
didSet {
Expand Down Expand Up @@ -1106,7 +1120,7 @@ private struct ChildScrollViewInfo {

private func updateBackgroundVisuals(_ backgroundView: UIVisualEffectView) {
backgroundView.effect = self.backgroundEffect
.effect(inTraitCollection: self.traitCollection)
.effect(inTraitCollection: self.traitCollection, darkBlurEffectStyle: darkBlurEffectStyle, lightBlurEffectStyle: lightBlurEffectStyle)
if #available(iOS 11.0, *) {
backgroundView.layer.cornerRadius = self.cornerRadius
backgroundView.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMinXMinYCorner]
Expand Down Expand Up @@ -1438,7 +1452,7 @@ public extension DrawerView {

extension DrawerView.BackgroundEffectStyle {

func effect(inTraitCollection traitCollection: UITraitCollection) -> UIVisualEffect? {
func effect(inTraitCollection traitCollection: UITraitCollection, darkBlurEffectStyle: UIBlurEffect.Style, lightBlurEffectStyle: UIBlurEffect.Style) -> UIVisualEffect? {
switch self {
case .none: return nil
case let .visualEffect(effect): return effect
Expand All @@ -1450,8 +1464,8 @@ extension DrawerView.BackgroundEffectStyle {
darkMode = false
}
return darkMode
? UIBlurEffect(style: .dark)
: UIBlurEffect(style: .light)
? UIBlurEffect(style: darkBlurEffectStyle)
: UIBlurEffect(style: lightBlurEffectStyle)
}
}
}
Expand Down