Skip to content

Commit

Permalink
Add styles for bar button and fix small bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Nov 12, 2022
1 parent af08e6c commit 5c882e1
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 39 deletions.
16 changes: 16 additions & 0 deletions Sources/OversizeUI/Controls/Button/BarButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public enum BarButtonType {
case primary(_ text: String, action: () -> Void)
case secondary(_ text: String, action: () -> Void)
case disabled(_ text: String)
case image(_ image: Image, action: () -> Void)
case icon(_ icon: IconsNames, action: () -> Void)
}

public struct BarButton: View {
Expand Down Expand Up @@ -91,6 +93,20 @@ extension BarButton {
}
.style(.gray, size: .medium, rounded: .full, shadow: false)
.disabled(true)
case let .image(image, action):
Button {
action()
} label: {
image
.renderingMode(.template)
.foregroundOnSurfaceHighEmphasis()
}
.style(.secondary, size: .medium, rounded: .full, width: .round, shadow: true)
case let .icon(icon, action):
Button(action: action) {
Icon(icon)
}
.style(.secondary, size: .medium, rounded: .full, width: .round, shadow: true)
}
}
}
6 changes: 3 additions & 3 deletions Sources/OversizeUI/Controls/ContentView/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public struct ContentView: View {
private let primaryButton: ContenButtonType?
private let secondaryButton: ContenButtonType?

public init(image: Image?,
public init(image: Image? = nil,
title: String,
subtitle: String?,
subtitle: String? = nil,
primaryButton: ContenButtonType? = nil,
secondaryButton: ContenButtonType? = nil)
{
Expand All @@ -45,7 +45,7 @@ public struct ContentView: View {
VStack(alignment: vStackAlignment, spacing: .medium) {
if let image {
image
.frame(width: 218, height: 218, alignment: .center)
.frame(width: 218, height: 218, alignment: .bottom)
}

TextBox(title: title, subtitle: subtitle)
Expand Down
54 changes: 32 additions & 22 deletions Sources/OversizeUI/Controls/PageView/PageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@

import SwiftUI


public struct PageView<Content, LeadingBar, TrailingBar, TopToolbar, TitleLabel>: View where Content: View, LeadingBar: View, TrailingBar: View, TopToolbar: View, TitleLabel: View {
@Environment(\.screenSize) var screenSize

private let title: String?
private let content: Content
private var isModalable = false
private var isLargeTitle = false
private var isAlwaysSlideSmallTile = false
@State private var offset: CGPoint = .init(x: 0, y: 0)

private var leadingBar: LeadingBar?
private var trailingBar: TrailingBar?
private var topToolbar: TopToolbar?
private var titleLabel: TitleLabel?

private var backgroundColor: Color = .backgroundPrimary
private var backgroundLinerGradient: LinearGradient?

private let onOffsetChanged: (CGFloat) -> Void

public init(_ title: String? = nil,
onOffsetChanged: @escaping (CGFloat) -> Void = { _ in },
@ViewBuilder content: () -> Content)
Expand All @@ -34,7 +33,7 @@ public struct PageView<Content, LeadingBar, TrailingBar, TopToolbar, TitleLabel>
self.onOffsetChanged = onOffsetChanged
self.content = content()
}

public var body: some View {
VStack(spacing: .zero) {
if title != nil || leadingBar != nil || trailingBar != nil || topToolbar != nil || titleLabel != nil {
Expand All @@ -47,7 +46,7 @@ public struct PageView<Content, LeadingBar, TrailingBar, TopToolbar, TitleLabel>
trailingBar: { trailingBar },
bottomBar: { topToolbar },
titleLabel: { titleLabel })
.zIndex(999_999_999)
.zIndex(999_999_999)
}
ScrollViewOffset(offset: $offset) {
content
Expand All @@ -59,7 +58,7 @@ public struct PageView<Content, LeadingBar, TrailingBar, TopToolbar, TitleLabel>
onOffsetChanged(offset.y)
}
}

var background: some View {
Group {
if let backgroundLinerGradient {
Expand All @@ -69,73 +68,73 @@ public struct PageView<Content, LeadingBar, TrailingBar, TopToolbar, TitleLabel>
}
}
}

public func modalable(_ isModalable: Bool = true) -> PageView {
var control = self
control.isModalable = isModalable
return control
}

public func slideSmallTile(_ isSlise: Bool = true) -> PageView {
var control = self
control.isAlwaysSlideSmallTile = isSlise
return control
}

public func navigationBarHidden(_ isModalable: Bool = true) -> PageView {
var control = self
control.isModalable = isModalable
return control
}

public func largeTitle(_ isLargeTitle: Bool = true) -> PageView {
var control = self
control.isLargeTitle = isLargeTitle
return control
}

public func backgroundColor(_ backgroundColor: Color = .backgroundSecondary) -> PageView {
var control = self
control.backgroundColor = backgroundColor
return control
}

public func backgroundSecondary() -> PageView {
var control = self
control.backgroundColor = .backgroundSecondary
return control
}

public func backgroundLinerGradient(_ gradient: LinearGradient) -> PageView {
var control = self
control.backgroundLinerGradient = gradient
return control
}

public func leadingBar(@ViewBuilder leadingBar: @escaping () -> LeadingBar) -> PageView {
var control = self
control.leadingBar = leadingBar()
return control
}

public func trailingBar(@ViewBuilder trailingBar: @escaping () -> TrailingBar) -> PageView {
var control = self
control.trailingBar = trailingBar()
return control
}

public func topToolbar(@ViewBuilder topToolbar: @escaping () -> TopToolbar) -> PageView {
var control = self
control.topToolbar = topToolbar()
return control
}

public func titleLabel(@ViewBuilder titleLabel: @escaping () -> TitleLabel) -> PageView {
var control = self
control.titleLabel = titleLabel()
return control
}

public func bottomToolbar(style: PageViewBottomType = .shadow, ignoreSafeArea: Bool = true, @ViewBuilder bottomToolbar: @escaping () -> some View) -> some View {
VStack(spacing: .zero) {
self
Expand All @@ -147,7 +146,7 @@ public struct PageView<Content, LeadingBar, TrailingBar, TopToolbar, TitleLabel>
LinearGradient(colors: [backgroundColor.opacity(0), Color.surfacePrimary.opacity(1)],
startPoint: .top,
endPoint: .bottom)
.frame(height: 60)
.frame(height: 60)
}
}
if style == .none {
Expand Down Expand Up @@ -348,3 +347,14 @@ public extension PageView where TopToolbar == EmptyView {
}
}

public extension PageView where TitleLabel == EmptyView {
init(_ title: String? = nil,
onOffsetChanged: @escaping (CGFloat) -> Void = { _ in },
@ViewBuilder content: () -> Content)
{
self.title = title
self.onOffsetChanged = onOffsetChanged
self.content = content()
titleLabel = nil
}
}
12 changes: 7 additions & 5 deletions Sources/OversizeUI/Controls/Row/Row.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public enum RowTrailingType {
public enum RowLeadingType {
case icon(_ name: IconsNames)
case iconOnSurface(_ name: IconsNames)
case image(_ image: Image)
case image(_ image: Image, color: Color? = .onSurfaceHighEmphasis)
case imageOnSurface(_ image: Image, color: Color? = nil)
case systemImage(_ imageName: String)
case avatar(_ avatar: AvatarView)
Expand Down Expand Up @@ -130,12 +130,14 @@ public struct Row: View {
Icon(icon)
.padding(.trailing, Constants.spacingIconAndText)

case let .image(image):
case let .image(image, color):
image
.renderingMode(.template)
.renderingMode(color != nil ? .template : .original)
.resizable()
.foregroundColor(.onSurfaceHighEmphasis)
.frame(width: 24, height: 24)
.scaledToFill()
.foregroundColor(color)
.frame(width: subtitle != nil ? 48 : 24, height: subtitle != nil ? 48 : 24)
.cornerRadius(subtitle != nil ? 4 : 2)

case let .avatar(avatar):
avatar
Expand Down
41 changes: 33 additions & 8 deletions Sources/OversizeUI/Controls/Row/RowButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public enum RowButtonStyle {
}

public struct RowButton: View {
@Environment(\.multilineTextAlignment) var multilineTextAlignment
@Environment(\.controlPadding) var controlPadding: ControlPadding
public var text: String
public var style: RowButtonStyle
public var icon: IconsNames
Expand All @@ -30,8 +32,12 @@ public struct RowButton: View {

public var body: some View {
VStack(alignment: .leading) {
Button(action: self.tapAction) {
Button(action: tapAction) {
HStack {
if multilineTextAlignment == .center || multilineTextAlignment == .trailing {
Spacer()
}

if icon != .none {
Surface {
Icon(icon)
Expand All @@ -42,16 +48,35 @@ public struct RowButton: View {

Text(text)
.fontStyle(.headline)
.foregroundColor(style == .link
? Color.link
: style == .delete
? Color.error
: Color.onSurfaceHighEmphasis)
.foregroundColor(foregroundColor)

Spacer()
if multilineTextAlignment == .leading || multilineTextAlignment == .center {
Spacer()
}
}
.padding(.vertical, verticalPadding)
.padding(.horizontal, controlPadding.horizontal)
}
.buttonStyle(.row)
}
}

private var verticalPadding: CGFloat {
switch controlPadding.vertical {
case .zero:
return .zero
case .xxSmall:
return .zero
default:
return controlPadding.vertical.rawValue - Space.xxSmall.rawValue
}
}

}.frame(minHeight: 70)
private var foregroundColor: Color {
style == .link
? Color.link
: style == .delete
? Color.error
: Color.onSurfaceHighEmphasis
}
}
2 changes: 1 addition & 1 deletion Sources/OversizeUI/Core/Appearance/ThemeSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public enum ThemeSettingsNames {
public class ThemeSettings: ObservableObject {
public init() {}

@AppStorage(ThemeSettingsNames.appearance) public var appearance: Appearance = .light
@AppStorage(ThemeSettingsNames.appearance) public var appearance: Appearance = .system

#if os(iOS)
@AppStorage(ThemeSettingsNames.accentColor) public var accentColor: Color = .blue
Expand Down
5 changes: 5 additions & 0 deletions Sources/OversizeUI/Extensions/HalfSheet/HalfSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ import SwiftUI
}
}
}

@_disfavoredOverload
func presentationDragIndicator(_ visibility: Visibility) -> some View {
self
}
}

public struct SheetView<Content: View>: UIViewControllerRepresentable {
Expand Down

0 comments on commit 5c882e1

Please sign in to comment.