Skip to content

Commit

Permalink
Added the blur effect to the SheetStyle options
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaMiotto committed Apr 30, 2020
1 parent 5067898 commit 51b4b47
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Example/PartialSheetExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
01294541244ED5E5006190B0 /* PartialSheetStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01294540244ED5E5006190B0 /* PartialSheetStyle.swift */; };
01477D8B2458E928007AE720 /* PartialSheetManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01477D8A2458E928007AE720 /* PartialSheetManager.swift */; };
0174F417245962B80053C454 /* PushNavigationExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0174F416245962B80053C454 /* PushNavigationExample.swift */; };
0174F419245A569C0053C454 /* BlurEffectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0174F418245A569C0053C454 /* BlurEffectView.swift */; };
01A013942458E4A900D0F5DD /* NormalExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01A013932458E4A900D0F5DD /* NormalExample.swift */; };
01A013962458E4C000D0F5DD /* TextfieldExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01A013952458E4C000D0F5DD /* TextfieldExample.swift */; };
01A013992458E4D800D0F5DD /* ListExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01A013982458E4D800D0F5DD /* ListExample.swift */; };
Expand All @@ -28,6 +29,7 @@
01294540244ED5E5006190B0 /* PartialSheetStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PartialSheetStyle.swift; sourceTree = "<group>"; };
01477D8A2458E928007AE720 /* PartialSheetManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PartialSheetManager.swift; sourceTree = "<group>"; };
0174F416245962B80053C454 /* PushNavigationExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushNavigationExample.swift; sourceTree = "<group>"; };
0174F418245A569C0053C454 /* BlurEffectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurEffectView.swift; sourceTree = "<group>"; };
01A013932458E4A900D0F5DD /* NormalExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NormalExample.swift; sourceTree = "<group>"; };
01A013952458E4C000D0F5DD /* TextfieldExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextfieldExample.swift; sourceTree = "<group>"; };
01A013982458E4D800D0F5DD /* ListExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListExample.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -116,6 +118,7 @@
1F177AA423E1F0E0006F59D0 /* DragState.swift */,
1F177AA523E1F0E0006F59D0 /* View+PartialSheetModifier.swift */,
01CCB63B244AEE3900F7F67F /* View+IfDeviceType.swift */,
0174F418245A569C0053C454 /* BlurEffectView.swift */,
);
name = PartialSheet;
path = ../../Sources/PartialSheet;
Expand Down Expand Up @@ -200,6 +203,7 @@
01477D8B2458E928007AE720 /* PartialSheetManager.swift in Sources */,
1F177AA823E1F0E0006F59D0 /* View+PartialSheetModifier.swift in Sources */,
1DDC0E5923E3E6DB0033EC03 /* ContentView.swift in Sources */,
0174F419245A569C0053C454 /* BlurEffectView.swift in Sources */,
1F177AA723E1F0E0006F59D0 /* DragState.swift in Sources */,
1F177AA623E1F0E0006F59D0 /* PartialSheetViewModifier.swift in Sources */,
01A013992458E4D800D0F5DD /* ListExample.swift in Sources */,
Expand Down
24 changes: 24 additions & 0 deletions Sources/PartialSheet/BlurEffectView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// BlurEffectView.swift
// PartialSheetExample
//
// Created by Andrea Miotto on 30/4/20.
// Copyright © 2020 Swift. All rights reserved.
//

import SwiftUI

/// An UIViewRepresentable for the UIBlurEffectView
struct BlurEffectView: UIViewRepresentable {

/// The style of the Blut Effect View
var style: UIBlurEffect.Style = .systemMaterial

func makeUIView(context: Context) -> UIVisualEffectView {
return UIVisualEffectView(effect: UIBlurEffect(style: style))
}

func updateUIView(_ uiView: UIVisualEffectView, context: Context) {
uiView.effect = UIBlurEffect(style: style)
}
}
26 changes: 24 additions & 2 deletions Sources/PartialSheet/PartialSheetStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,31 @@ public struct PartialSheetStyle {
/// The color of the cover
var coverColor: Color

public init(backgroundColor: Color, handlerBarColor: Color, enableCover: Bool, coverColor: Color) {
/// The blur effect style to applied between the partialSheet and the Presenter Conter
var blurEffectStyle: UIBlurEffect.Style?

/**
The **Style** for the PartialSheet
- parameter backgroundColor: The background color of the partial sheet
- parameter handlerBarColor: The color of the handler bar to close the partial sheet
- parameter enableCover: True if you want a cover enabled between the sheet and the presenter view.
- parameter coverColor: The color of the cover, use the .opacity modifier if you want a transparent effect
- parameter blurEffectStyle: If you want a blur effect on the cover, set the effect style, otherwise put it to nil.

Use `PartialSheetStyle.defaultStyle` if you want a quicker init for the style with default values.
*/
public init(
backgroundColor: Color,
handlerBarColor: Color,
enableCover: Bool,
coverColor: Color,
blurEffectStyle: UIBlurEffect.Style?
) {
self.backgroundColor = backgroundColor
self.handlerBarColor = handlerBarColor
self.enableCover = enableCover
self.coverColor = coverColor
self.blurEffectStyle = blurEffectStyle
}
}

Expand All @@ -38,12 +58,14 @@ extension PartialSheetStyle {
- handlerBarColor: Color(UIColor.systemGray2)
- enableCover: true
- coverColor: Color.black.opacity(0.4)
- blurEffectStyle: nil
*/
public static func defaultStyle() -> PartialSheetStyle {
return PartialSheetStyle(backgroundColor: Color(UIColor.tertiarySystemBackground),
handlerBarColor: Color(UIColor.systemGray2),
enableCover: true,
coverColor: Color.black.opacity(0.4)
coverColor: Color.black.opacity(0.4),
blurEffectStyle: nil
)
}
}
16 changes: 12 additions & 4 deletions Sources/PartialSheet/PartialSheetViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,18 @@ extension PartialSheet {

return ZStack {

// Attach the COVER VIEW
if manager.isPresented && style.enableCover {
Rectangle()
.foregroundColor(style.coverColor)
//MARK: - iPhone Cover View

if manager.isPresented {
Group {
if style.enableCover {
Rectangle()
.foregroundColor(style.coverColor)
}
if style.blurEffectStyle != nil {
BlurEffectView(style: style.blurEffectStyle ?? UIBlurEffect.Style.systemChromeMaterial)
}
}
.edgesIgnoringSafeArea(.vertical)
.onTapGesture {
withAnimation {
Expand Down

0 comments on commit 51b4b47

Please sign in to comment.