-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c28fb24
commit 8f6092b
Showing
14 changed files
with
407 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// Checkerboard.swift | ||
// | ||
// | ||
// Created by Noah Martin on 7/4/23. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct Checkerboard: Shape { | ||
func path(in rect: CGRect) -> Path { | ||
var path = Path() | ||
|
||
let rowSize: Double = 10 | ||
let columnSize: Double = 10 | ||
|
||
let rows = Int(rect.height / CGFloat(rowSize)) | ||
let columns = Int(rect.width / CGFloat(columnSize)) | ||
let columnRemainder = rect.width - Double(columns) * columnSize | ||
let rowRemainder = rect.height - Double(rows) * rowSize | ||
|
||
for row in 0 ..< rows { | ||
for column in 0 ..< columns { | ||
if (row + column).isMultiple(of: 2) { | ||
let startX = Double(columnSize) * Double(column) | ||
let startY = Double(rowSize) * Double(row) | ||
|
||
let rect = CGRect(x: startX, y: startY, width: columnSize, height: rowSize) | ||
path.addRect(rect) | ||
} | ||
} | ||
if (row + columns).isMultiple(of: 2) { | ||
if columnRemainder > 0 { | ||
let startX = Double(columnSize) * Double(columns) | ||
let startY = Double(rowSize) * Double(row) | ||
|
||
let rect = CGRect(x: startX, y: startY, width: columnRemainder, height: rowSize) | ||
path.addRect(rect) | ||
} | ||
} | ||
} | ||
if rowRemainder > 0 { | ||
for column in 0..<columns { | ||
if (rows + column).isMultiple(of: 2) { | ||
let startX = Double(columnSize) * Double(column) | ||
let startY = Double(rowSize) * Double(rows) | ||
|
||
let rect = CGRect(x: startX, y: startY, width: columnSize, height: rowRemainder) | ||
path.addRect(rect) | ||
} | ||
} | ||
if (rows + columns).isMultiple(of: 2) { | ||
let startX = Double(columnSize) * Double(columns) | ||
let startY = Double(rowSize) * Double(rows) | ||
|
||
let rect = CGRect(x: startX, y: startY, width: columnRemainder, height: rowRemainder) | ||
path.addRect(rect) | ||
} | ||
} | ||
|
||
return path | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// ModuleFeatures.swift | ||
// | ||
// | ||
// Created by Noah Martin on 8/31/23. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
struct ModuleFeatures: View { | ||
|
||
let module: String | ||
let data: PreviewData | ||
|
||
var body: some View { | ||
let featureProviders = data.previews(in: module).filter { provider in | ||
return provider.previews.contains { preview in | ||
return preview.requiresFullScreen | ||
} | ||
} | ||
return List { | ||
ForEach(featureProviders) { provider in | ||
let featurePreviews = provider.previews.filter { $0.requiresFullScreen } | ||
NavigationLink { | ||
if featurePreviews.count == 1 { | ||
try! featurePreviews[0].view() | ||
} else { | ||
List { | ||
ForEach(featurePreviews) { preview in | ||
NavigationLink(preview.displayName ?? provider.displayName) { | ||
try! preview.view() | ||
} | ||
} | ||
}.navigationTitle(provider.displayName) | ||
} | ||
} label: { | ||
VStack(alignment: .leading) { | ||
Text(provider.displayName) | ||
.font(.headline) | ||
.foregroundStyle(Color(UIColor.label)) | ||
.padding(.leading, 8) | ||
|
||
Text("\(featurePreviews.count) Preview\(featurePreviews.count != 1 ? "s" : "")") | ||
.font(.subheadline) | ||
.foregroundStyle(Color(UIColor.secondaryLabel)) | ||
.padding(.leading, 8) | ||
} | ||
} | ||
} | ||
}.navigationTitle("Features") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// ModulePreviews.swift | ||
// | ||
// | ||
// Created by Noah Martin on 7/3/23. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
struct ModulePreviews: View { | ||
let module: String | ||
let data: PreviewData | ||
|
||
var body: some View { | ||
let componentProviders = data.previews(in: module).filter { provider in | ||
return provider.previews.contains { preview in | ||
return !preview.requiresFullScreen | ||
} | ||
} | ||
let featureProviders = data.previews(in: module).filter { provider in | ||
return provider.previews.contains { preview in | ||
return preview.requiresFullScreen | ||
} | ||
} | ||
return NavigationLink(module) { | ||
ScrollView { | ||
LazyVStack(alignment: .leading) { | ||
if !featureProviders.isEmpty { | ||
NavigationLink { | ||
ModuleFeatures(module: module, data: data) | ||
} label: { | ||
VStack { | ||
TitleSubtitleRow( | ||
title: "Features", | ||
subtitle: "\(featureProviders.count) Preview\(featureProviders.count != 1 ? "s" : "")") | ||
Divider() | ||
} | ||
} | ||
} | ||
ForEach(componentProviders) { preview in | ||
PreviewCellView(preview: preview) | ||
} | ||
} | ||
} | ||
.navigationTitle(module) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Preview+FullScreen.swift | ||
// | ||
// | ||
// Created by Noah Martin on 8/31/23. | ||
// | ||
|
||
import Foundation | ||
import SnapshotPreviewsCore | ||
|
||
extension Preview { | ||
|
||
var requiresFullScreen: Bool { | ||
switch layout { | ||
case .device: | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// PreviewCell.swift | ||
// | ||
// | ||
// Created by Noah Martin on 8/18/23. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
import SnapshotPreviewsCore | ||
|
||
struct PreviewCell: View { | ||
|
||
let preview: SnapshotPreviewsCore.Preview | ||
|
||
@Environment(\.colorScheme) var colorScheme | ||
|
||
var body: some View { | ||
VStack { | ||
try! preview.view() | ||
.border(Color(UIColor.separator)) | ||
.background { | ||
Checkerboard() | ||
.foregroundStyle(Color(UIColor.label)) | ||
.opacity(0.1) | ||
.background(Color(UIColor.systemBackground)) | ||
} | ||
.preferredColorScheme(nil) | ||
.colorScheme(try! preview.colorScheme() ?? colorScheme) | ||
} | ||
.background(Color(UIColor.systemBackground)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// PreviewData.swift | ||
// | ||
// | ||
// Created by Noah Martin on 7/3/23. | ||
// | ||
|
||
import Foundation | ||
import SnapshotPreviewsCore | ||
|
||
public struct PreviewData { | ||
let previews: [PreviewType] | ||
|
||
func previews(in module: String) -> [PreviewType] { | ||
previews.filter { $0.module == module }.sorted { $0.typeName < $1.typeName } | ||
} | ||
|
||
var modules: Set<String> { | ||
Set(previews.map { $0.module }) | ||
} | ||
|
||
public static var `default`: PreviewData { | ||
self.init(previews: findPreviews()) | ||
} | ||
} |
Oops, something went wrong.