Skip to content

Commit

Permalink
Add NeurmophismButton
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuzukihashi committed Mar 9, 2020
1 parent 76788cc commit ae96bdf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
4 changes: 2 additions & 2 deletions DemoApp/DemoApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ struct ContentView: View {
.font(.title)
.foregroundColor(self.neumorphism.color.darkerColor())

NeumorphismCricleButton() {
NeumorphismButton() {
self.neumorphism.changeMode()
}

NeumorphismRoundedRectangleButton()
NeumorphismButton(normalImage: Image(systemName: "star"), selectedImage: Image(systemName: "star.fill"))

Circle()
.fill(self.neumorphism.color)
Expand Down
8 changes: 4 additions & 4 deletions NeumorphismUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/* End PBXAggregateTarget section */

/* Begin PBXBuildFile section */
DA5AFAC9241691210098E0BB /* NeumorphismCircleButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5AFAC8241691210098E0BB /* NeumorphismCircleButton.swift */; };
DA5AFAC9241691210098E0BB /* NeumorphismButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5AFAC8241691210098E0BB /* NeumorphismButton.swift */; };
DA90AF652412D01900E759A9 /* NeumorphismManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA90AF642412D01900E759A9 /* NeumorphismManagerTests.swift */; };
DA90AF682412D0EE00E759A9 /* NeumorphismManagerMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA90AF672412D0EE00E759A9 /* NeumorphismManagerMock.swift */; };
DA954C782411D9740052B8FF /* NeumorphismManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA954C772411D9740052B8FF /* NeumorphismManager.swift */; };
Expand Down Expand Up @@ -54,7 +54,7 @@

/* Begin PBXFileReference section */
DA1A6B5F240B76D9001EA5EB /* .gitignore */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitignore; sourceTree = "<group>"; };
DA5AFAC8241691210098E0BB /* NeumorphismCircleButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismCircleButton.swift; sourceTree = "<group>"; };
DA5AFAC8241691210098E0BB /* NeumorphismButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismButton.swift; sourceTree = "<group>"; };
DA90AF642412D01900E759A9 /* NeumorphismManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismManagerTests.swift; sourceTree = "<group>"; };
DA90AF672412D0EE00E759A9 /* NeumorphismManagerMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismManagerMock.swift; sourceTree = "<group>"; };
DA954C772411D9740052B8FF /* NeumorphismManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -102,7 +102,7 @@
isa = PBXGroup;
children = (
DA98731A240BDE7D0083EB5E /* HighlightableButton.swift */,
DA5AFAC8241691210098E0BB /* NeumorphismCircleButton.swift */,
DA5AFAC8241691210098E0BB /* NeumorphismButton.swift */,
);
path = CustomViews;
sourceTree = "<group>";
Expand Down Expand Up @@ -257,7 +257,7 @@
DA98731B240BDE7D0083EB5E /* HighlightableButton.swift in Sources */,
DA90AF682412D0EE00E759A9 /* NeumorphismManagerMock.swift in Sources */,
DA954C782411D9740052B8FF /* NeumorphismManager.swift in Sources */,
DA5AFAC9241691210098E0BB /* NeumorphismCircleButton.swift in Sources */,
DA5AFAC9241691210098E0BB /* NeumorphismButton.swift in Sources */,
OBJ_32 /* ViewExtension.swift in Sources */,
OBJ_33 /* NeumorphismShadowModifier.swift in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
import SwiftUI

@available(iOS 13.0.0, *)
public struct NeumorphismCricleButton: View {
public struct NeumorphismButton: View {
@EnvironmentObject var neumorphism: NeumorphismManager
@State var isSelected = false


private var normalImage: Image
private var selectedImage: Image
private var width: CGFloat
private var height: CGFloat
private var imageWidth: CGFloat
private var imageHeight: CGFloat
private var handler: (() -> Void)?

public init(width: CGFloat = 100, height: CGFloat = 100, handler: (() -> Void)? = nil) {
public init
(
normalImage: Image = Image(systemName: "heart"),
selectedImage: Image = Image(systemName: "heart.fill"),
width: CGFloat = 100,
height: CGFloat = 100,
imageWidth: CGFloat = 60,
imageHeight: CGFloat = 60,
handler: (() -> Void)? = nil
) {
self.normalImage = normalImage
self.selectedImage = selectedImage
self.width = width
self.height = height
self.imageWidth = imageWidth
self.imageHeight = imageHeight
self.handler = handler
}

Expand All @@ -20,17 +37,16 @@ public struct NeumorphismCricleButton: View {
self.isSelected.toggle()
self.handler?()
}) { isHeighlight in
Image(systemName: self.isSelected ? "heart.fill" : "heart")
(self.isSelected ? self.selectedImage : self.normalImage)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width:60, height: 60)
.frame(width:self.imageWidth, height: self.imageWidth)
.foregroundColor(self.neumorphism.color.darkerColor())
.background(
Circle()
.fill(self.neumorphism.color)
.frame(width: 100, height: 100)
.frame(width: self.width, height: self.height)
.modifier(NeumorphismShadowModifier(isAnimation: isHeighlight))

)
.padding()
.animation(Animation.spring(response: 0.3, dampingFraction: 0.7, blendDuration: 1))
Expand Down

0 comments on commit ae96bdf

Please sign in to comment.