-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0d8781
commit efffec6
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import SwiftUI | ||
|
||
@available(iOS 13.0.0, *) | ||
struct NeumorphismLabelButton: View { | ||
@EnvironmentObject var neumorphism: NeumorphismManager | ||
@State var isSelected = false | ||
private var text: String | ||
private var font: Font? | ||
private var color: Color? | ||
private var width: CGFloat | ||
private var height: CGFloat | ||
private var cornerRadius: CGFloat | ||
private var handler: (() -> Void)? | ||
|
||
public init | ||
( | ||
text: String = "Button", | ||
font: Font? = nil, | ||
color: Color? = nil, | ||
width: CGFloat = 100, | ||
height: CGFloat = 100, | ||
cornerRadius: CGFloat = 10, | ||
handler: (() -> Void)? = nil | ||
) { | ||
self.text = text | ||
self.font = font | ||
self.color = color | ||
self.width = width | ||
self.height = height | ||
self.cornerRadius = cornerRadius | ||
self.handler = handler | ||
} | ||
|
||
public var body: some View { | ||
HighlightableButton(action: { | ||
self.isSelected.toggle() | ||
self.handler?() | ||
}) { isHeighlight in | ||
ZStack { | ||
RoundedRectangle(cornerRadius: self.cornerRadius) | ||
.fill(self.neumorphism.color) | ||
.frame(width: self.width, height: self.height) | ||
.modifier(NeumorphismShadowModifier(isAnimation: isHeighlight)) | ||
.padding() | ||
|
||
|
||
Text(self.text) | ||
.font(self.font ?? .title) | ||
.foregroundColor( | ||
isHeighlight ? self.color?.darkerColor() ?? self.neumorphism.color.darkerColor().darkerColor() : self.color ?? self.neumorphism.color.darkerColor()) | ||
} | ||
.animation(Animation.spring(response: 0.3, dampingFraction: 0.7, blendDuration: 1)) | ||
} | ||
.padding() | ||
} | ||
} | ||
|
||
@available(iOS 13.0.0, *) | ||
struct NeumorphismLabelButton_Previews: PreviewProvider { | ||
static let neumorphism = NeumorphismManager( | ||
lightColor: Color(hex: "C1D2EB"), | ||
darkColor: Color(hex: "2C292C") | ||
) | ||
|
||
static var previews: some View { | ||
NeumorphismLabelButton() | ||
.environmentObject(neumorphism) | ||
.previewLayout(.sizeThatFits) | ||
} | ||
} |