Skip to content

Commit

Permalink
Add NeumorphismDentView
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuzukihashi committed Mar 13, 2020
1 parent a921fa9 commit 13fdd0a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NeumorphismUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
DA954C782411D9740052B8FF /* NeumorphismManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA954C772411D9740052B8FF /* NeumorphismManager.swift */; };
DA98731B240BDE7D0083EB5E /* HighlightableButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA98731A240BDE7D0083EB5E /* HighlightableButton.swift */; };
DAD95493241B4E0200D3F56E /* NeumorphismLabelButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD95492241B4E0200D3F56E /* NeumorphismLabelButton.swift */; };
DAD95495241B740E00D3F56E /* NeumorphismDentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD95494241B740E00D3F56E /* NeumorphismDentView.swift */; };
OBJ_30 /* ColorTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_9 /* ColorTransformer.swift */; };
OBJ_31 /* ColorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_11 /* ColorExtension.swift */; };
OBJ_32 /* ViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_12 /* ViewExtension.swift */; };
Expand Down Expand Up @@ -65,6 +66,7 @@
DA954C772411D9740052B8FF /* NeumorphismManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismManager.swift; sourceTree = "<group>"; };
DA98731A240BDE7D0083EB5E /* HighlightableButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HighlightableButton.swift; sourceTree = "<group>"; };
DAD95492241B4E0200D3F56E /* NeumorphismLabelButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismLabelButton.swift; sourceTree = "<group>"; };
DAD95494241B740E00D3F56E /* NeumorphismDentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismDentView.swift; sourceTree = "<group>"; };
"NeumorphismUI::NeumorphismUI::Product" /* NeumorphismUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = NeumorphismUI.framework; sourceTree = BUILT_PRODUCTS_DIR; };
"NeumorphismUI::NeumorphismUITests::Product" /* NeumorphismUITests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; path = NeumorphismUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
OBJ_11 /* ColorExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorExtension.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -124,6 +126,7 @@
isa = PBXGroup;
children = (
DA98731A240BDE7D0083EB5E /* HighlightableButton.swift */,
DAD95494241B740E00D3F56E /* NeumorphismDentView.swift */,
DA5AFAC8241691210098E0BB /* NeumorphismButton.swift */,
DAD95492241B4E0200D3F56E /* NeumorphismLabelButton.swift */,
);
Expand Down Expand Up @@ -288,6 +291,7 @@
OBJ_32 /* ViewExtension.swift in Sources */,
OBJ_33 /* NeumorphismShadowModifier.swift in Sources */,
DA5AFACF241833430098E0BB /* AnyShape.swift in Sources */,
DAD95495241B740E00D3F56E /* NeumorphismDentView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
50 changes: 50 additions & 0 deletions Sources/CustomViews/NeumorphismDentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import SwiftUI

@available(iOS 13.0.0, *)
public struct NeumorphismDentView: View {
@EnvironmentObject var neumorphism: NeumorphismManager

private let width: CGFloat
private let height: CGFloat
private let cornerRadius: CGFloat

public init(
width: CGFloat = 100,
height: CGFloat = 100,
cornerRadius: CGFloat = 16
) {
self.width = width
self.height = height
self.cornerRadius = cornerRadius
}

public var body: some View {
ZStack{
RoundedRectangle(cornerRadius: self.cornerRadius)
.fill(self.neumorphism.color)
.frame(width: self.width, height: self.height)
.overlay(
RoundedRectangle(cornerRadius: self.cornerRadius)
.stroke(self.neumorphism.color, lineWidth: 4)
.shadow(color: self.neumorphism.color.darkerColor(), radius: 4, x: 4, y: 4)
.clipShape(RoundedRectangle(cornerRadius: self.cornerRadius))
.shadow(color: self.neumorphism.color.lighterColor(), radius: 2, x: -2, y: -2)
.clipShape(RoundedRectangle(cornerRadius: self.cornerRadius))
)
.cornerRadius(self.cornerRadius)
}
}
}

@available(iOS 13.0.0, *)
struct NeumorphismTextView_Previews: PreviewProvider {
static let neumorphism = NeumorphismManager(
lightColor: Color(hex: "C1D2EB"),
darkColor: Color(hex: "2C292C")
)
static var previews: some View {
NeumorphismDentView()
.environmentObject(neumorphism)
.previewLayout(.sizeThatFits)
}
}

0 comments on commit 13fdd0a

Please sign in to comment.