Skip to content

Commit

Permalink
Add Platform and minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Sep 26, 2024
1 parent 8d673c9 commit 0e2a4ac
Show file tree
Hide file tree
Showing 20 changed files with 308 additions and 103 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OversizeUI

[![Build Example](https://github.com/oversizedev/OversizeUI/actions/workflows/build-example.yml/badge.svg)](https://github.com/oversizedev/OversizeUI/actions/workflows/build-example.yml) [![Deploy DocC](https://github.com/oversizedev/OversizeUI/actions/workflows/publish-docc.yml/badge.svg)](https://github.com/oversizedev/OversizeUI/actions/workflows/publish-docc.yml)
[![Build Example](https://github.com/oversizedev/OversizeUI/actions/workflows/build-example.yml/badge.svg)](https://github.com/oversizedev/OversizeUI/actions/workflows/ci-release.yml)

Yet another component library on SwiftUI

Expand Down
2 changes: 0 additions & 2 deletions Sources/OversizeUI/Controls/ContentView/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ extension ContentView {
#if os(macOS)
.controlSize(.large)
#endif

case .back:

Button(action: { dismiss() }) {
Expand Down Expand Up @@ -247,7 +246,6 @@ extension ContentView {
.buttonStyle(.tertiary)
#endif
.disabled(true)

case .none:
EmptyView()
}
Expand Down
36 changes: 26 additions & 10 deletions Sources/OversizeUI/Controls/Divider/Separator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,40 @@ public struct Separator: View {

return Rectangle()
.fill(Color.border)
.frame(width: isHorizontal ? nil : 0.5,
height: isHorizontal ? 0.5 : nil)
.frame(
width: isHorizontal ? nil : lineWidth,
height: isHorizontal ? lineWidth : nil
)
#if !os(macOS)
.padding(insets(isHorizontal))
#endif
}

private func insets(_ isHorizontal: Bool) -> EdgeInsets {
if isHorizontal {
EdgeInsets(top: 0.5,
leading: padding.rawValue,
bottom: 0,
trailing: padding.rawValue)
EdgeInsets(
top: 0.5,
leading: padding.rawValue,
bottom: 0,
trailing: padding.rawValue
)
} else {
EdgeInsets(top: padding.rawValue,
leading: 0.5,
bottom: padding.rawValue,
trailing: 0)
EdgeInsets(
top: padding.rawValue,
leading: 0.5,
bottom: padding.rawValue,
trailing: 0
)
}
}

var lineWidth: CGFloat {
#if os(macOS)
return 1
#else
return 0.5
#endif
}
}

struct Separator_Preview: PreviewProvider {
Expand Down
6 changes: 3 additions & 3 deletions Sources/OversizeUI/Controls/PageControl/PageIndexView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import SwiftUI

public struct PageIndexView: View {
@Binding private var index: Int
private var index: Int
private let maxIndex: Int

public init(_ index: Binding<Int>, maxIndex: Int) {
_index = index
public init(_ index: Int, maxIndex: Int) {
self.index = index
self.maxIndex = maxIndex
}

Expand Down
10 changes: 4 additions & 6 deletions Sources/OversizeUI/Controls/PriceField/PriceField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@ public struct PriceField: View {
return formatter
}

private var strValue2: String { value.components(separatedBy: CharacterSet(charactersIn: "0123456789").inverted).joined() } // value.filter { !$0.isWhitespace } }
private var doubleValue2: Double { .init((Double(strValue2) ?? 0) / 100.0) ?? 0 }
private var stringValue2: String { value.components(separatedBy: CharacterSet(charactersIn: "0123456789").inverted).joined() }
private var doubleValue2: Double { .init((Double(stringValue2) ?? 0) / 100.0) ?? 0 }

private var strValue3: String { value.components(separatedBy: CharacterSet(charactersIn: "0123456789").inverted).joined() } // value.filter { !$0.isWhitespace } }
private var doubleValue3: Double { .init((Double(strValue3) ?? 0) * 100) ?? 0 }
private var stringValue3: String { value.components(separatedBy: CharacterSet(charactersIn: "0123456789").inverted).joined() }
private var doubleValue3: Double { .init((Double(stringValue3) ?? 0) * 100) ?? 0 }

private var strValue: String { value.filter { !$0.isWhitespace } }
private var doubleValue: Double { .init(strValue) ?? 0 }
private var formattedValue: String {
let value = doubleValue

return formatter.string(for: value) ?? ""
}

Expand Down Expand Up @@ -80,7 +79,6 @@ public struct PriceField: View {
.padding(.leading, .xSmall)

Text(dispalySymbol)

.onChange(of: currency) { _ in
validate()
}
Expand Down
13 changes: 7 additions & 6 deletions Sources/OversizeUI/Controls/Row/Row.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ public struct Row<LeadingLabel, TrailingLabel>: View where LeadingLabel: View, T
(subtitle?.isEmpty) != nil
}

public init(_ title: String,
subtitle: String? = nil,
action: (() -> Void)? = nil,
@ViewBuilder leading: () -> LeadingLabel,
@ViewBuilder trailing: () -> TrailingLabel)
{
public init(
_ title: String,
subtitle: String? = nil,
action: (() -> Void)? = nil,
@ViewBuilder leading: () -> LeadingLabel,
@ViewBuilder trailing: () -> TrailingLabel
) {
self.title = title
self.subtitle = subtitle
self.action = action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
import SwiftUI

public struct ScrollViewWithOffsetTracking<Content: View>: View {
public typealias ScrollAction = (_ offset: CGPoint) -> Void

private let axes: Axis.Set
private let showsIndicators: Bool
private let cordinateSpaceName: String
private let onScroll: ScrollAction
private let content: () -> Content

public init(
_ axes: Axis.Set = .vertical,
showsIndicators: Bool = true,
Expand All @@ -20,14 +28,6 @@ public struct ScrollViewWithOffsetTracking<Content: View>: View {
self.content = content
}

public typealias ScrollAction = (_ offset: CGPoint) -> Void

private let axes: Axis.Set
private let showsIndicators: Bool
private let cordinateSpaceName: String
private let onScroll: ScrollAction
private let content: () -> Content

public var body: some View {
ScrollView(axes, showsIndicators: showsIndicators) {
ScrollViewOffsetTracker {
Expand Down
28 changes: 20 additions & 8 deletions Sources/OversizeUI/Controls/Surface/Surface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,29 @@ public struct Surface<Label: View>: View {
.padding(.leading, forceContentInsets?.leading ?? contentInsets.leading)
.padding(.trailing, forceContentInsets?.trailing ?? contentInsets.trailing)
.background(
RoundedRectangle(cornerRadius: surfaceRadius, style: .continuous)
.fill(surfaceBackgroundColor)
.overlay(
RoundedRectangle(cornerRadius: surfaceRadius, style: .continuous)
.strokeBorder(strokeBorderColor, lineWidth: strokeBorderLineWidth)
)
.shadowElevaton(elevation)
RoundedRectangle(
cornerRadius: surfaceRadius,
style: .continuous
)
.fill(surfaceBackgroundColor)
.shadowElevaton(elevation)
)
.overlay(
RoundedRectangle(
cornerRadius: surfaceRadius,
style: .continuous
)
.strokeBorder(
strokeBorderColor,
lineWidth: strokeBorderLineWidth
)
)
.if(isSurfaceClipped) { view in
view.clipShape(
RoundedRectangle(cornerRadius: surfaceRadius, style: .continuous)
RoundedRectangle(
cornerRadius: surfaceRadius,
style: .continuous
)
)
}
}
Expand Down
36 changes: 21 additions & 15 deletions Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum FieldHelperStyle {

public struct FieldHelperViewModifier: ViewModifier {
@Environment(\.theme) private var theme: ThemeSettings
@Environment(\.platform) private var platform: Platform
@Binding public var helperText: String
@Binding public var helperStyle: FieldHelperStyle
public init(helperText: Binding<String>, helperStyle: Binding<FieldHelperStyle>) {
Expand All @@ -22,24 +23,29 @@ public struct FieldHelperViewModifier: ViewModifier {
}

public func body(content: Content) -> some View {
VStack(alignment: .leading) {
VStack(alignment: .leading, spacing: platform == .mac ? .xxxSmall : .xSmall) {
content
if helperText != "" {
if helperStyle == .helperText {
Text(helperText)
.subheadline(.semibold)
.foregroundColor(.onSurfaceMediumEmphasis)
} else if helperStyle == .errorText {
Text(helperText)
.subheadline(.semibold)
.foregroundColor(.error)
} else if helperStyle == .sussesText {
Text(helperText)
.subheadline(.semibold)
.foregroundColor(.success)
}
if helperText.isEmpty == false, helperStyle != .none {
Text(helperText)
.subheadline(.medium)
.foregroundColor(helperForegroundColor)
.offset(x: platform == .mac ? 4 : 0)
}
}
.animation(.easeIn(duration: 0.15), value: helperStyle)
}

private var helperForegroundColor: Color {
switch helperStyle {
case .helperText:
Color.onSurfaceMediumEmphasis
case .errorText:
Color.error
case .sussesText:
Color.success
case .none:
Color.clear
}
}
}

Expand Down
Loading

0 comments on commit 0e2a4ac

Please sign in to comment.