Skip to content

Commit

Permalink
Ruller update
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Oct 8, 2022
1 parent f69a043 commit 857efd0
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 18 deletions.
22 changes: 22 additions & 0 deletions Sources/OversizeComponents/Buttons/ScaleButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Copyright © 2022 Alexander Romanov
// ScaleButton.swift
//

import SwiftUI

public struct ScaleButtonStyle: ButtonStyle {
public init() {}

public func makeBody(configuration: Self.Configuration) -> some View {
configuration.label
.scaleEffect(configuration.isPressed ? 0.96 : 1)
.animation(.easeIn(duration: 0.2), value: configuration.isPressed)
}
}

public extension ButtonStyle where Self == ScaleButtonStyle {
static var scale: ScaleButtonStyle {
ScaleButtonStyle()
}
}
49 changes: 41 additions & 8 deletions Sources/OversizeComponents/FloatingTabBar/FloatingTabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct FloatingTabBar<Content: View>: View {
.foregroundColor(Color.surfacePrimary)
}
.shadowElevaton(.z2)
.padding(.bottom, screenSize.safeAreaBottom)
.padding(.bottom, screenSize.safeAreaBottom + 24)
}
.ignoresSafeArea()
.onPreferenceChange(TabItemPreferenceKey.self) { value in
Expand All @@ -58,7 +58,16 @@ public struct FloatingTabBar<Content: View>: View {
Group {
if plusAction != nil, let number = tabs.count % 2, number == index {
Group {
tabItem.icon
Button {
withAnimation {
selection = index
}
} label: {
tabItem.icon
.renderingMode(.template)
.foregroundColor(index == selection ? Color.onSurfaceHighEmphasis : Color.onSurfaceMediumEmphasis)
}
.buttonStyle(ScaleRoundButtonStyle())

Button {
plusAction?()
Expand All @@ -71,15 +80,20 @@ public struct FloatingTabBar<Content: View>: View {
.frame(width: 32, height: 32, alignment: .center)
}
}
// .buttonStyle(.scale)
}

} else {
tabItem.icon
}
}
.onTapGesture {
withAnimation {
selection = index
Button {
withAnimation {
selection = index
}
} label: {
tabItem.icon
.renderingMode(.template)
.foregroundColor(index == selection ? Color.onSurfaceHighEmphasis : Color.onSurfaceMediumEmphasis)
}
.buttonStyle(ScaleRoundButtonStyle())
}
}
}
Expand Down Expand Up @@ -110,3 +124,22 @@ struct FloatingTabBar_Previews: PreviewProvider {
FloatingTabBarExample()
}
}

private struct ScaleRoundButtonStyle: ButtonStyle {
init() {}

fileprivate func makeBody(configuration: Self.Configuration) -> some View {
configuration.label
.scaleEffect(configuration.isPressed ? 0.92 : 1)
.background {
if configuration.isPressed {
Circle()
.fillSurfaceTertiary()
.padding(.all, -12)
} else {
EmptyView()
}
}
.animation(.easeIn(duration: 0.2), value: configuration.isPressed)
}
}
29 changes: 20 additions & 9 deletions Sources/OversizeHealthComponents/RulerPicker/RulerPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ public struct RulerPicker: View {

private let step: Double

private let witoutPoint: Bool

@Namespace private var animation

public init(selection: Binding<Double>, minValue: Double = 10, step: Double = 1, maxValue: Double = 150, mark: Mark = .fraction, tick: Mark = .fraction) {
public init(selection: Binding<Double>, minValue: Double = 10, step: Double = 1, maxValue: Double = 150, mark: Mark = .fraction, tick: Mark = .fraction, witoutPoint: Bool = false) {
_selection = selection
self.minValue = minValue
self.maxValue = maxValue
self.step = step
self.mark = mark
self.tick = tick
self.witoutPoint = witoutPoint
}

private var formatter: NumberFormatter {
Expand All @@ -49,15 +52,23 @@ public struct RulerPicker: View {
formatter: formatter)
.slidingRulerStyle(CenteredSlindingRulerStyle())
.overlay(alignment: .top) {
Text(step < 10 ? selection.toStringOnePoint : String(format: "%.1f", selection))
.foregroundColor(.white)
.font(.title2.monospacedDigit())
.bold()
.background {
Circle()
.foregroundColor(Color.black)
.frame(width: 72, height: 72, alignment: .center)
Group {
if witoutPoint {
Text(step < 10 ? selection.toStringWithoutPoint : String(format: "%.0f", selection))
.bold()
} else {
Text(step < 10 ? selection.toStringOnePoint : String(format: "%.1f", selection))
.bold()
}
}
.foregroundColor(.white)
.font(.title2.monospacedDigit())

.background {
Circle()
.foregroundColor(Color.black)
.frame(width: 72, height: 72, alignment: .center)
}
}
}
.background { Color.yellow.ignoresSafeArea() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public struct WeightPicker: View {
bottomContent
}
.background(Color.surfacePrimary)
// .alert("To add photos, you need to buy a Pro subscription", isPresented: <#T##Binding<Bool>#>, actions: <#T##() -> View#>)
}

var topContent: some View {
Expand Down

0 comments on commit 857efd0

Please sign in to comment.