Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
devMinseok committed Aug 7, 2024
1 parent 2b9cfe3 commit 6200153
Show file tree
Hide file tree
Showing 15 changed files with 324 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,29 @@ struct ButtonDetailView: View {
.disabled(false)
}
}

// VStack {
// Text("Secondary")
// .frame(maxWidth: .infinity)
// .foregroundStyle(Global.Color.white)
// .background(Global.Color.black)
// HStack(spacing: 10) {
// Button(
// icon: Image(systemName: "center"),
// action: { /*action*/ }
// )
// .buttonStyle(.round(color: .secondary))
//
// Button(
// icon: Image(systemName: "center"),
// action: { /*action*/ }
// )
// .buttonStyle(.round(color: .primary))
// }
// }



}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ struct ContentView: View {
Text("Button")
}

NavigationLink {
NavigationDetailView()
} label: {
Text("Navigation")
}

NavigationLink {

} label: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// NavigationDetailView.swift
// DesignSystemExample
//
// Created by devMinseok on 8/7/24.
// Copyright © 2024 PomoNyang. All rights reserved.
//

import SwiftUI

import DesignSystem

struct NavigationDetailView: View {
var body: some View {
NavigationContainer(
title: Text("Title"),
style: .navigation,
navBackground: .clear
) {
ScrollView {

Check warning on line 21 in Projects/Shared/DesignSystem/Example/Sources/NavigationDetailView.swift

View workflow job for this annotation

GitHub Actions / Run Swiftlint

Don't include vertical whitespace (empty line) before closing braces (vertical_whitespace_closing_braces)
}
}
.background(Global.Color.gray50)
}
}

#Preview {
NavigationDetailView()
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "24_arrow_left_primary.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "24_cancel_primary.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Helper.swift
// BarButtonDetail.swift
// DesignSystem
//
// Created by devMinseok on 8/7/24.
Expand All @@ -8,15 +8,15 @@

import SwiftUI

extension Button where Label == Detail<Text, Image?, Image?> {
extension Button where Label == BarButtonDetail<Text, Image?, Image?> {
public init(
title: LocalizedStringKey,
leftIcon: Image? = nil,
rightIcon: Image? = nil,
action: @escaping () -> Void
) {
self.init(action: action) {
Detail {
BarButtonDetail {
Text(title)
} leftIcon: {
leftIcon
Expand All @@ -27,8 +27,8 @@ extension Button where Label == Detail<Text, Image?, Image?> {
}
}

public struct Detail<Title: View, LeftIcon: View, RightIcon: View>: View {
@Environment(\.detailStyle) private var style
public struct BarButtonDetail<Title: View, LeftIcon: View, RightIcon: View>: View {
@Environment(\.barButtonDetailStyle) private var style
private let title: Title
private let leftIcon: LeftIcon
private let rightIcon: RightIcon
Expand All @@ -44,7 +44,7 @@ public struct Detail<Title: View, LeftIcon: View, RightIcon: View>: View {
}

public var body: some View {
let configuration = DetailStyleConfiguration(
let configuration = BarButtonDetailConfiguration(
title: title,
leftIcon: leftIcon,
rightIcon: rightIcon
Expand All @@ -53,7 +53,7 @@ public struct Detail<Title: View, LeftIcon: View, RightIcon: View>: View {
}
}

struct DetailStyleConfiguration {
struct BarButtonDetailConfiguration {
struct Title: View {
let body: AnyView
}
Expand All @@ -77,20 +77,20 @@ struct DetailStyleConfiguration {
}
}

protocol DetailStyle: DynamicProperty {
typealias Configuration = DetailStyleConfiguration
associatedtype Body : View
protocol BarButtonDetailStyle: DynamicProperty {
typealias Configuration = BarButtonDetailConfiguration
associatedtype Body: View

@ViewBuilder func makeBody(configuration: Configuration) -> Body
}

extension DetailStyle {
extension BarButtonDetailStyle {
fileprivate func resolve(configuration: Configuration) -> some View {
ResolvedDetailStyle(style: self, configuration: configuration)
}
}

private struct ResolvedDetailStyle<Style: DetailStyle>: View {
private struct ResolvedDetailStyle<Style: BarButtonDetailStyle>: View {
let style: Style
let configuration: Style.Configuration

Expand All @@ -99,19 +99,19 @@ private struct ResolvedDetailStyle<Style: DetailStyle>: View {
}
}

struct DetailStyleKey: EnvironmentKey {
static var defaultValue: any DetailStyle = BoxButtonDetailStyle()
struct BarButtonDetailStyleKey: EnvironmentKey {
static var defaultValue: any BarButtonDetailStyle = BoxButtonDetailStyle()
}

extension EnvironmentValues {
fileprivate var detailStyle : any DetailStyle {
get { self[DetailStyleKey.self] }
set { self[DetailStyleKey.self] = newValue }
fileprivate var barButtonDetailStyle: any BarButtonDetailStyle {
get { self[BarButtonDetailStyleKey.self] }
set { self[BarButtonDetailStyleKey.self] = newValue }
}
}

extension View {
func detailStyle(_ style: some DetailStyle) -> some View {
environment(\.detailStyle, style)
func barButtonDetailStyle(_ style: some BarButtonDetailStyle) -> some View {
environment(\.barButtonDetailStyle, style)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public struct BoxButtonStyle: ButtonStyle {
getForegroundColor(isPressed: configuration.isPressed)
)
.labelStyle(BoxButtonLabelStyle())
.detailStyle(BoxButtonDetailStyle())
.barButtonDetailStyle(BoxButtonDetailStyle())
}

private func getBackgroundColor(isPressed: Bool) -> Color {
Expand Down Expand Up @@ -71,7 +71,7 @@ extension ButtonStyle where Self == BoxButtonStyle {
}
}

struct BoxButtonDetailStyle: DetailStyle {
struct BoxButtonDetailStyle: BarButtonDetailStyle {
func makeBody(configuration: Configuration) -> some View {
HStack(spacing: Alias.Spacing.small) {
configuration.leftIcon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public struct TextButtonStyle: ButtonStyle {
getForegroundColor(isPressed: configuration.isPressed)
)
.labelStyle(TextButtonLabelStyle())
.detailStyle(TextButtonDetailStyle())
.barButtonDetailStyle(TextButtonDetailStyle())
}

private func getBackgroundColor(isPressed: Bool) -> Color {
Expand Down Expand Up @@ -71,7 +71,7 @@ extension ButtonStyle where Self == TextButtonStyle {
}
}

struct TextButtonDetailStyle: DetailStyle {
struct TextButtonDetailStyle: BarButtonDetailStyle {
func makeBody(configuration: Configuration) -> some View {
HStack(spacing: Alias.Spacing.small) {
configuration.leftIcon
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// NavigationBar.swift
// DesignSystem
//
// Created by devMinseok on 8/7/24.
// Copyright © 2024 PomoNyang. All rights reserved.
//

import SwiftUI

struct NavigationBar<Title: View, Trailing: View, Background: ShapeStyle>: View {
let title: Title
let trailing: Trailing
let style: NavigationBarStyle
let background: Background
let foregroundColor: Color
let onDismiss: () -> Void

init(
title: Title,
trailing: Trailing,
style: NavigationBarStyle,
background: Background,
foregroundColor: Color,
onDismiss: @escaping () -> Void
) {
self.title = title
self.trailing = trailing
self.style = style
self.background = background
self.foregroundColor = foregroundColor
self.onDismiss = onDismiss
}

var body: some View {
ZStack(alignment: style == .bottomSheet ? .leading : .center) {
self.title
.font(Typography.bodySB)
.lineLimit(1)
.frame(maxWidth: .infinity, alignment: .center)
HStack {
switch style {
case .modal:
Button {
self.onDismiss()
} label: {
DesignSystemAsset.Image._24CancelPrimary.swiftUIImage
.renderingMode(.template)
.foregroundStyle(foregroundColor)
}
Spacer()
self.trailing

case .navigation:
Button {
self.onDismiss()
} label: {
DesignSystemAsset.Image._24ArrowLeftPrimary.swiftUIImage
.renderingMode(.template)
.foregroundStyle(foregroundColor)
}
Spacer()
self.trailing

case .bottomSheet:
Spacer()
Button {
self.onDismiss()
} label: {
DesignSystemAsset.Image._24CancelPrimary.swiftUIImage
.renderingMode(.template)
.foregroundStyle(foregroundColor)
}
}
}
}
.padding(.horizontal, 10)
.frame(maxWidth: .infinity)
.frame(height: 56)
.background(background)
.foregroundStyle(foregroundColor)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// NavigationBarStyle.swift
// DesignSystem
//
// Created by devMinseok on 8/7/24.
// Copyright © 2024 PomoNyang. All rights reserved.
//

import Foundation

public enum NavigationBarStyle {
case modal
case navigation
case bottomSheet
}
Loading

0 comments on commit 6200153

Please sign in to comment.