Skip to content

Commit

Permalink
update: build FeedbackView inspired by github ui
Browse files Browse the repository at this point in the history
  • Loading branch information
devahmedshendy committed Apr 30, 2024
1 parent 863e152 commit 0d00f63
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 12 deletions.
41 changes: 40 additions & 1 deletion Sources/FeedbackKit/Feedback.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
struct Feedback {
struct Feedback: Identifiable, Hashable {
var id: String { title }

let type: FeedbackType
let title: String
let description: String
let state: FeedbackState
}

extension Feedback {
static var samples: [Feedback] {
[
.init(
type: .bug,
title: "We need an alternative when failed to create SQLite database using GRDB",
description: "",
state: .open
),
.init(
type: .feature,
title: "[FEATURE]: Hook up search screen and favoriting functionality",
description: "",
state: .closed
),
.init(
type: .feature,
title: "[FEATURE]: Sort search locations by distance from a location",
description: "",
state: .open
),
.init(
type: .feature,
title: "[FEATURE]: Enhance weather information for detail view of a location",
description: "",
state: .open
),
]
}
}

enum FeedbackState {
case open
case closed
}
7 changes: 0 additions & 7 deletions Sources/FeedbackKit/FeedbackView.swift

This file was deleted.

49 changes: 49 additions & 0 deletions Sources/FeedbackKit/View/FeedbackItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// File.swift
//
//
// Created by Ahmed Shendy on 30/04/2024.
//

import SwiftUI

public struct FeedbackItem: View {
let feedback: Feedback

init(_ feedback: Feedback) {
self.feedback = feedback
}

public var body: some View {
HStack(alignment: .top) {

FeedbackStateIcon(state: feedback.state)
Spacer().frame(width: 5)

VStack(spacing: 0) {
HStack(spacing: 0) {
FeedbackTitle(text: feedback.title)
Spacer()
HStack(spacing: 0) {
Image(systemName: "message")
Text("2")
}
.font(.subheadline)
.foregroundColor(.init(red: 0.518, green: 0.553, blue: 0.592))
}

Spacer().frame(height: 8)

HStack(spacing: 0) {
Text("opened on May 18, 2023")
.font(.caption)
.foregroundColor(Color.gray)
Spacer()
FeedbackLabel(text: feedback.type.rawValue)
}
}
}
.padding(.horizontal, 15)
.padding(.vertical, 10)
}
}
23 changes: 23 additions & 0 deletions Sources/FeedbackKit/View/FeedbackLabel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// File.swift
//
//
// Created by Ahmed Shendy on 30/04/2024.
//

import SwiftUI

public struct FeedbackLabel: View {
let text: String

public var body: some View {
Text(text)
.font(.caption2)
.fontWeight(.light)
.foregroundColor(.white)
.padding(.horizontal, 6)
.background(Color.gray.opacity(0.5))
.clipShape(Capsule(style: .continuous))
}
}

27 changes: 27 additions & 0 deletions Sources/FeedbackKit/View/FeedbackStateIcon.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// File.swift
//
//
// Created by Ahmed Shendy on 30/04/2024.
//

import SwiftUI

public struct FeedbackStateIcon: View {
let state: FeedbackState

public var body: some View {
Group {
switch state {
case .open:
Image(systemName: "smallcircle.filled.circle")
.foregroundColor(.green)
case .closed:
Image(systemName: "checkmark.circle")
.foregroundColor(.blue)
}
}
.font(.body.weight(.bold))
}
}

17 changes: 17 additions & 0 deletions Sources/FeedbackKit/View/FeedbackTitle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// File.swift
//
//
// Created by Ahmed Shendy on 30/04/2024.
//

import SwiftUI

public struct FeedbackTitle: View {
let text: String

public var body: some View {
Text(text)
.font(.headline)
}
}
29 changes: 29 additions & 0 deletions Sources/FeedbackKit/View/FeedbackView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import SwiftUI

public struct FeedbackView: View {
public init() { }
public var body: some View {
ScrollView {
LazyVStack(spacing: 0) {
ForEach(Feedback.samples) { item in
FeedbackItem(item)

if item != Feedback.samples.last {
Divider()
}
}
}
}
.fixedSize(horizontal: false, vertical: true)
.clipShape(RoundedRectangle(cornerRadius: 5))
.overlay(
RoundedRectangle(cornerRadius: 5)
.inset(by: 1)
.strokeBorder(
Color(red: 0.255, green: 0.255, blue: 0.255),
lineWidth: 1,
antialiased: true
)
)
}
}
8 changes: 4 additions & 4 deletions playground/FeedbackKitPlayground/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
//

import SwiftUI
import FeedbackKit

struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
FeedbackView()
Spacer()
.background(Color.yellow)
}
.padding()
}
Expand Down

0 comments on commit 0d00f63

Please sign in to comment.