Skip to content

Commit

Permalink
feat: Show unread markers in the grid view (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbmorley authored Jun 6, 2023
1 parent 1e23bbb commit 0b58d2f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 7 deletions.
23 changes: 16 additions & 7 deletions core/Sources/BookmarksCore/Views/BookmarkCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public struct BookmarkCell: View {

private struct LayoutMetrics {
static let cornerRadius = 10.0
static let horizontalSpacing = 8.0
}

var bookmark: Bookmark
Expand Down Expand Up @@ -72,14 +73,22 @@ public struct BookmarkCell: View {
public var body: some View {
VStack(alignment: .leading, spacing: 0) {
thumbnail
VStack(alignment: .leading) {
Text(title)
.lineLimit(1)
Text(bookmark.url.host ?? "Unknown")
.lineLimit(1)
.foregroundColor(.secondary)
Grid(horizontalSpacing: LayoutMetrics.horizontalSpacing, verticalSpacing: 0) {
GridRow {
UnreadMark(isOn: bookmark.toRead)
Text(title)
.lineLimit(1)
.frame(maxWidth: .infinity, alignment: .leading)
}
GridRow {
UnreadMark(isOn: false) // ~ Spacer
Text(bookmark.url.host ?? "Unknown")
.lineLimit(1)
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundColor(.secondary)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.trailing, UnreadMark.LayoutMetrics.size)
.padding()
.background(Color.controlSecondaryBackground)
}
Expand Down
48 changes: 48 additions & 0 deletions core/Sources/BookmarksCore/Views/UnreadMark.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2020-2023 InSeven Limited
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import SwiftUI

public struct UnreadMark: View {

public struct LayoutMetrics {
static let size = 10.0
}

private let isOn: Bool

public init(isOn: Bool) {
self.isOn = isOn
}

public var body: some View {
if isOn {
Image(systemName: "circle.fill")
.resizable()
.frame(width: LayoutMetrics.size, height: LayoutMetrics.size)
.foregroundColor(.accentColor)
} else {
Color.clear
.frame(width: LayoutMetrics.size, height: LayoutMetrics.size)
}

}

}

0 comments on commit 0b58d2f

Please sign in to comment.