diff --git a/DemoApp/DemoApp.xcodeproj/project.pbxproj b/DemoApp/DemoApp.xcodeproj/project.pbxproj index c847fab..dd4a42b 100644 --- a/DemoApp/DemoApp.xcodeproj/project.pbxproj +++ b/DemoApp/DemoApp.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ DA5D60CF2422767E0021B0B7 /* DentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5D60CE2422767E0021B0B7 /* DentView.swift */; }; DA5D60D1242277C50021B0B7 /* NeumorphismButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5D60D0242277C50021B0B7 /* NeumorphismButtonView.swift */; }; DA5D60D324239E090021B0B7 /* BindingButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5D60D224239E090021B0B7 /* BindingButtonView.swift */; }; + DA6FEED324311E5800C1B554 /* NeumorphismSliderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA6FEED224311E5700C1B554 /* NeumorphismSliderView.swift */; }; DA74B267240B820400AD9A06 /* NeumorphismUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA74B266240B820400AD9A06 /* NeumorphismUI.framework */; }; DA74B268240B820400AD9A06 /* NeumorphismUI.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = DA74B266240B820400AD9A06 /* NeumorphismUI.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; /* End PBXBuildFile section */ @@ -50,6 +51,7 @@ DA5D60CE2422767E0021B0B7 /* DentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DentView.swift; sourceTree = ""; }; DA5D60D0242277C50021B0B7 /* NeumorphismButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismButtonView.swift; sourceTree = ""; }; DA5D60D224239E090021B0B7 /* BindingButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingButtonView.swift; sourceTree = ""; }; + DA6FEED224311E5700C1B554 /* NeumorphismSliderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismSliderView.swift; sourceTree = ""; }; DA74B266240B820400AD9A06 /* NeumorphismUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = NeumorphismUI.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -112,6 +114,7 @@ DA5AFAD22418367C0098E0BB /* SimpleView.swift */, DA5D60CE2422767E0021B0B7 /* DentView.swift */, DA5D60D224239E090021B0B7 /* BindingButtonView.swift */, + DA6FEED224311E5700C1B554 /* NeumorphismSliderView.swift */, DA5D60D0242277C50021B0B7 /* NeumorphismButtonView.swift */, ); path = Views; @@ -204,6 +207,7 @@ DA5D60D324239E090021B0B7 /* BindingButtonView.swift in Sources */, DA5D60CF2422767E0021B0B7 /* DentView.swift in Sources */, DA1A6B72240B81A4001EA5EB /* ContentView.swift in Sources */, + DA6FEED324311E5800C1B554 /* NeumorphismSliderView.swift in Sources */, DA5D60CC2422727E0021B0B7 /* BaseView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/DemoApp/DemoApp/ContentView.swift b/DemoApp/DemoApp/ContentView.swift index 94b4145..f07ec0e 100644 --- a/DemoApp/DemoApp/ContentView.swift +++ b/DemoApp/DemoApp/ContentView.swift @@ -38,6 +38,10 @@ struct ContentView: View { BaseView(name: "NeumorphismBindingButton", desc: "neumorphism binding button") }.padding() + NavigationLink(destination: NeumorphismSliderView()) { + BaseView(name: "NeumorphismSlider", desc: "custom slider") + }.padding() + Spacer() } }.background(self.neumorphism.color.edgesIgnoringSafeArea(.all)) diff --git a/DemoApp/DemoApp/Views/NeumorphismSliderView.swift b/DemoApp/DemoApp/Views/NeumorphismSliderView.swift new file mode 100644 index 0000000..27f2872 --- /dev/null +++ b/DemoApp/DemoApp/Views/NeumorphismSliderView.swift @@ -0,0 +1,29 @@ +import SwiftUI +import NeumorphismUI + +struct NeumorphismSliderView: View { + @EnvironmentObject var neumorphism: NeumorphismManager + @State private var value: Double = 0 + + var body: some View { + ZStack { + neumorphism.color.edgesIgnoringSafeArea(.all) + VStack { + Text("VALUE: \(value)") + .foregroundColor(self.neumorphism.fontColor()) + + NeumorphismSlider( + tipColor: neumorphism.color.darkerColor().darkerColor(), + barColor: nil, + value: $value + ) + } + } + } +} + +struct NeumorphismSliderView_Previews: PreviewProvider { + static var previews: some View { + NeumorphismSliderView() + } +} diff --git a/NeumorphismUI.xcodeproj/project.pbxproj b/NeumorphismUI.xcodeproj/project.pbxproj index 2fc2d7c..eb4c172 100644 --- a/NeumorphismUI.xcodeproj/project.pbxproj +++ b/NeumorphismUI.xcodeproj/project.pbxproj @@ -24,6 +24,7 @@ DA5AFAC9241691210098E0BB /* NeumorphismButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5AFAC8241691210098E0BB /* NeumorphismButton.swift */; }; DA5AFACD2418332A0098E0BB /* ShapeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5AFACC2418332A0098E0BB /* ShapeType.swift */; }; DA5AFACF241833430098E0BB /* AnyShape.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5AFACE241833430098E0BB /* AnyShape.swift */; }; + DA6FEED12430B26C00C1B554 /* NeumorphismSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA6FEED02430B26C00C1B554 /* NeumorphismSlider.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 */; }; @@ -64,6 +65,7 @@ DA5AFAC8241691210098E0BB /* NeumorphismButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismButton.swift; sourceTree = ""; }; DA5AFACC2418332A0098E0BB /* ShapeType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShapeType.swift; sourceTree = ""; }; DA5AFACE241833430098E0BB /* AnyShape.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyShape.swift; sourceTree = ""; }; + DA6FEED02430B26C00C1B554 /* NeumorphismSlider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismSlider.swift; sourceTree = ""; }; DA90AF642412D01900E759A9 /* NeumorphismManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismManagerTests.swift; sourceTree = ""; }; DA90AF672412D0EE00E759A9 /* NeumorphismManagerMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismManagerMock.swift; sourceTree = ""; }; DA954C772411D9740052B8FF /* NeumorphismManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismManager.swift; sourceTree = ""; }; @@ -137,6 +139,7 @@ DA5AFAC8241691210098E0BB /* NeumorphismButton.swift */, DAD9549A241BCFBE00D3F56E /* NeumorphismBindingButton.swift */, DAD95492241B4E0200D3F56E /* NeumorphismLabelButton.swift */, + DA6FEED02430B26C00C1B554 /* NeumorphismSlider.swift */, ); path = CustomViews; sourceTree = ""; @@ -301,6 +304,7 @@ OBJ_32 /* ViewExtension.swift in Sources */, DAD95499241BBD7500D3F56E /* NeumorphismCircleDentView.swift in Sources */, OBJ_33 /* NeumorphismShadowModifier.swift in Sources */, + DA6FEED12430B26C00C1B554 /* NeumorphismSlider.swift in Sources */, DA5AFACF241833430098E0BB /* AnyShape.swift in Sources */, DAD95495241B740E00D3F56E /* NeumorphismDentView.swift in Sources */, DAD95497241B855F00D3F56E /* UIColorExtensioin.swift in Sources */, diff --git a/Sources/CustomViews/NeumorphismSlider.swift b/Sources/CustomViews/NeumorphismSlider.swift new file mode 100644 index 0000000..f1b52b8 --- /dev/null +++ b/Sources/CustomViews/NeumorphismSlider.swift @@ -0,0 +1,106 @@ +import SwiftUI + +@available(iOS 13.0, *) +public struct NeumorphismSlider: View { + @EnvironmentObject var neumorphism: NeumorphismManager + @Binding var value: Double + private var tipColor: Color? + private let barColor: Color? + private let height: CGFloat + private let width: CGFloat + + public init( + width: CGFloat = 300, + height: CGFloat = 16, + tipColor: Color? = nil, + barColor: Color? = nil, + value: Binding + ) { + self.height = height + self.width = width + self.tipColor = tipColor + self.barColor = barColor + self._value = value + + validate() + } + + public var body: some View { + ZStack(alignment: .leading) { + NeumorphismDentView( + width: width, + height: height, + cornerRadius: self.height / 2 + ) + + ZStack (alignment: .trailing){ + RoundedRectangle(cornerRadius: self.height / 2) + .fill( + LinearGradient(gradient: + Gradient(colors: + [barColor ?? self.neumorphism.color.darkerColor(), + barColor?.darkerColor() ?? self.neumorphism.color.darkerColor().darkerColor()]), + startPoint: .leading, + endPoint: .trailing)) + .frame( + width: self.width * CGFloat(value), + height: height * 0.9, + alignment: .leading) + .padding(.leading, 4) + HStack { + ZStack { + Circle() + .fill(self.neumorphism.color) + .frame(width: height * 2, height: height * 2) + .neumorphismShadow() + + NeumorphismDentView( + width: height * 0.8, + height: height * 0.8, + color: tipColor ?? self.neumorphism.color.darkerColor(), + cornerRadius: height/2) + } + } + } + }.gesture( + DragGesture(minimumDistance: 0) + .onChanged({ (value) in + self.value = Double(value.location.x / self.width) + self.validate() + }) + .onEnded({ (value) in + self.value = Double(value.location.x / self.width) + self.validate() + }) + ) + } + + private func validate() { + if self.value > 1.0 { + DispatchQueue.main.async { + self.value = 1.0 + } + } + if self.value < 0 { + DispatchQueue.main.async { + self.value = 0 + } + } + } +} + +@available(iOS 13.0, *) +public struct NeumorphismSlider_Previews: PreviewProvider { + static let neumorphism = NeumorphismManager( + lightColor: Color(hex: "C1D2EB"), + darkColor: Color(hex: "2C292C") + ) + public static var previews: some View { + NeumorphismSlider( + width: 300, + height: 16, + value: .constant(0.4)) + .environmentObject(neumorphism) + .previewLayout(.sizeThatFits) + } +}