Skip to content

Commit 820869b

Browse files
authored
Merge pull request #1118 from kiwix/1116-ios-library-scroll-no-viewmodifier-fix-p2
Replace viewModifiers with inline, use system colours
2 parents c5c76cb + 3da4a34 commit 820869b

File tree

6 files changed

+70
-60
lines changed

6 files changed

+70
-60
lines changed

Views/BuildingBlocks/ArticleCell.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@ struct ArticleCell: View {
5757
}
5858
.foregroundColor(.primary)
5959
.padding(12)
60-
.modifier(CellBackground(isHovering: isHovering))
60+
.background(CellBackground.colorFor(isHovering: isHovering))
61+
.clipShape(CellBackground.clipShapeRectangle)
6162
.onHover { self.isHovering = $0 }
6263
}
6364
}
6465

6566
struct ArticleCell_Previews: PreviewProvider {
67+
6668
static let result: SearchResult = {
6769
let result = SearchResult(zimFileID: UUID(), path: "", title: "Article Title")!
6870
result.snippet = NSAttributedString(string: """

Views/BuildingBlocks/DownloadTaskCell.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ struct DownloadTaskCell: View {
6363
}.font(.caption).foregroundColor(.secondary)
6464
}
6565
.padding()
66-
.modifier(CellBackground(isHovering: isHovering))
66+
.background(CellBackground.colorFor(isHovering: isHovering))
67+
.clipShape(CellBackground.clipShapeRectangle)
6768
.onHover { self.isHovering = $0 }
6869
.onReceive(DownloadService.shared.progress.publisher) { states in
6970
if let state = states[downloadZimFile.fileID] {

Views/BuildingBlocks/ZimFileCell.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ struct ZimFileCell: View {
8181
}
8282
}
8383
.padding()
84-
.modifier(CellBackground(isHovering: isHovering || isLoading))
84+
.background(CellBackground.colorFor(isHovering: isHovering))
85+
.clipShape(CellBackground.clipShapeRectangle)
8586
.modifier(LoadingOverlay(isLoading: isLoading))
8687
.onHover { self.isHovering = $0 }
8788
}

Views/Library/ZimFileDetail.swift

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ struct ZimFileDetail: View {
123123
#endif
124124
}
125125
#if os(macOS)
126+
.buttonStyle(.borderedProminent)
127+
#endif
128+
#if os(macOS)
126129
Action(title: LocalString.zim_file_action_reveal_in_finder_title) {
127130
guard let url = await ZimFileService.shared.getFileURL(zimFileID: zimFile.id) else { return }
128131
NSWorkspace.shared.activateFileViewerSelecting([url])
@@ -209,6 +212,9 @@ struct ZimFileDetail: View {
209212
secondaryButton: .cancel()
210213
)
211214
}
215+
#if os(macOS)
216+
.buttonStyle(.borderedProminent)
217+
#endif
212218
}
213219

214220
@ViewBuilder
@@ -371,30 +377,3 @@ private struct ServiceWorkerWarning: View {
371377
}
372378
}
373379
}
374-
375-
struct ZimFileDetail_Previews: PreviewProvider {
376-
static let context = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
377-
static let zimFile: ZimFile = {
378-
let zimFile = ZimFile(context: context)
379-
zimFile.articleCount = 1000000
380-
zimFile.category = "wikipedia"
381-
zimFile.created = Date()
382-
zimFile.downloadURL = URL(string: "https://www.example.com")
383-
zimFile.fileID = UUID()
384-
zimFile.fileDescription = "A very long description"
385-
zimFile.flavor = "max"
386-
zimFile.hasDetails = true
387-
zimFile.hasPictures = false
388-
zimFile.hasVideos = true
389-
zimFile.languageCode = "en"
390-
zimFile.mediaCount = 100
391-
zimFile.name = "Wikipedia Zim File Name"
392-
zimFile.persistentID = ""
393-
zimFile.size = 1000000000
394-
return zimFile
395-
}()
396-
397-
static var previews: some View {
398-
ZimFileDetail(zimFile: zimFile, dismissParent: nil).frame(width: 300).previewLayout(.sizeThatFits)
399-
}
400-
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// This file is part of Kiwix for iOS & macOS.
2+
//
3+
// Kiwix is free software; you can redistribute it and/or modify it
4+
// under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation; either version 3 of the License, or
6+
// any later version.
7+
//
8+
// Kiwix is distributed in the hope that it will be useful, but
9+
// WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
// General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with Kiwix; If not, see https://www.gnu.org/licenses/.
15+
16+
import SwiftUI
17+
import CoreData
18+
19+
struct ZimFileDetail_Previews: PreviewProvider {
20+
static let context = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
21+
static let zimFile: ZimFile = {
22+
let zimFile = ZimFile(context: context)
23+
zimFile.articleCount = 1000000
24+
zimFile.category = "wikipedia"
25+
zimFile.created = Date()
26+
zimFile.downloadURL = URL(string: "https://www.example.com")
27+
zimFile.fileID = UUID()
28+
zimFile.fileDescription = "A very long description"
29+
zimFile.flavor = "max"
30+
zimFile.hasDetails = true
31+
zimFile.hasPictures = false
32+
zimFile.hasVideos = true
33+
zimFile.languageCode = "en"
34+
zimFile.mediaCount = 100
35+
zimFile.name = "Wikipedia Zim File Name"
36+
zimFile.persistentID = ""
37+
zimFile.size = 1000000000
38+
return zimFile
39+
}()
40+
41+
static var previews: some View {
42+
ZimFileDetail(zimFile: zimFile, dismissParent: nil).frame(width: 300).previewLayout(.sizeThatFits)
43+
}
44+
}

Views/ViewModifiers/CellBackground.swift

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,18 @@
1515

1616
import SwiftUI
1717

18-
struct CellBackground: ViewModifier {
19-
@Environment(\.colorScheme) var colorScheme: ColorScheme
20-
21-
let isHovering: Bool
22-
23-
func body(content: Content) -> some View {
24-
content
25-
.background(backgroundColor)
26-
.clipShape(RoundedRectangle(cornerRadius: 12, style: .continuous))
27-
}
28-
29-
private var backgroundColor: Color {
30-
switch (colorScheme, isHovering) {
31-
case (.dark, true):
32-
#if os(macOS)
33-
return Color.background
34-
#elseif os(iOS)
35-
return Color.secondaryBackground
36-
#endif
37-
case (.dark, false):
38-
return Color.tertiaryBackground
39-
case (.light, true):
40-
return Color(white: 0.9)
41-
case (.light, false), (_, _):
42-
#if os(macOS)
43-
return Color.white
44-
#elseif os(iOS)
45-
return Color(white: 0.96)
46-
#endif
47-
}
18+
enum CellBackground {
19+
#if os(macOS)
20+
private static let normal: Color = Color(nsColor: NSColor.controlBackgroundColor)
21+
private static let hover: Color = Color(nsColor: NSColor.selectedControlColor)
22+
#else
23+
private static let normal: Color = .secondaryBackground
24+
private static let hover: Color = .tertiaryBackground
25+
#endif
26+
27+
static func colorFor(isHovering: Bool) -> Color {
28+
isHovering ? hover : normal
4829
}
30+
31+
static let clipShapeRectangle = RoundedRectangle(cornerRadius: 12, style: .continuous)
4932
}

0 commit comments

Comments
 (0)