Skip to content

Commit

Permalink
Rewrite the library using Swift concurrency (#30)
Browse files Browse the repository at this point in the history
* Rewrite using Swift concurrency.

* Update workflows

* Run swift-format

* Fix Xcode version in workflows

* Update sample code

* Update README

* Run swift-format

* Update README

* Better approach for visionOS compatibility

* Run swift-format

* Update documentation

* Add SwiftPackageIndex manifest

* Replace PlatformImage with CGImage
  • Loading branch information
gonzalezreal authored Sep 9, 2023
1 parent 87a1980 commit 7aff8d1
Show file tree
Hide file tree
Showing 56 changed files with 1,063 additions and 1,502 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ on:
- '*'
jobs:
tests:
runs-on: macos-11
runs-on: macos-12
steps:
- uses: actions/checkout@v2
- name: Select Xcode 13.1
run: sudo xcode-select -s /Applications/Xcode_13.1.app
- name: Select Xcode 14.2
run: sudo xcode-select -s /Applications/Xcode_14.2.app
- name: Run tests
run: make test
6 changes: 4 additions & 2 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ on:
jobs:
format:
name: swift-format
runs-on: macos-10.15
runs-on: macos-12
steps:
- uses: actions/checkout@v2
- name: Select Xcode 14.2
run: sudo xcode-select -s /Applications/Xcode_14.2.app
- name: Tap
run: brew tap pointfreeco/formulae
- name: Install
run: brew install Formulae/swift-format@5.3
run: brew install Formulae/swift-format@5.7
- name: Format
run: make format
- uses: stefanzweifel/git-auto-commit-action@v4
Expand Down
4 changes: 4 additions & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: 1
builder:
configs:
- documentation_targets: [NetworkImage]
105 changes: 59 additions & 46 deletions Demo/NetworkImageDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

This file was deleted.

52 changes: 52 additions & 0 deletions Demo/Shared/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import SwiftUI

struct ContentView: View {
var body: some View {
NavigationView {
List {
NavigationLink {
ImagesView()
.navigationTitle("Displaying Images")
.inlineNavigationBarTitleDisplayMode()
} label: {
Label("Displaying Images", systemImage: "photo")
}
NavigationLink {
StyledImagesView()
.navigationTitle("Styling Images")
.inlineNavigationBarTitleDisplayMode()
} label: {
Label("Styling Images", systemImage: "photo.artframe")
}
NavigationLink {
PlaceholdersView()
.navigationTitle("Placeholders and fallbacks")
.inlineNavigationBarTitleDisplayMode()
} label: {
Label("Placeholders and fallbacks", systemImage: "square.dashed")
}
NavigationLink {
RandomImageView()
.navigationTitle("Random Image")
.inlineNavigationBarTitleDisplayMode()
} label: {
Label("Random Image", systemImage: "questionmark.square")
}
NavigationLink {
ImageListView()
.navigationTitle("Image List")
.inlineNavigationBarTitleDisplayMode()
} label: {
Label("Image List", systemImage: "scroll")
}
}
.navigationTitle("NetworkImage")
}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
29 changes: 0 additions & 29 deletions Demo/Shared/ExampleList.swift

This file was deleted.

51 changes: 0 additions & 51 deletions Demo/Shared/ImageListExampleView.swift

This file was deleted.

40 changes: 40 additions & 0 deletions Demo/Shared/ImageListView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import NetworkImage
import SwiftUI

struct ImageListView: View {
private struct Item: Identifiable {
let id = UUID()
let imageURL = URL.randomImageURL(size: .init(width: 400, height: 300))
}

private let items = Array(repeating: (), count: 100).map(Item.init)

var body: some View {
ScrollView {
LazyVStack {
ForEach(self.items) { item in
NetworkImage(url: item.imageURL, transaction: .init(animation: .default)) { image in
image.resizable().scaledToFill()
}
.aspectRatio(1.333, contentMode: .fill)
.clipShape(RoundedRectangle(cornerRadius: 4))
.overlay {
RoundedRectangle(cornerRadius: 4)
// This crashes in Xcode 15 beta 8 when running on visionOS simulator
// .strokeBorder(Color.primary.opacity(0.25), lineWidth: 0.5)
.strokeBorder(style: .init(lineWidth: 0.5))
.foregroundColor(Color.primary.opacity(0.25))

}
}
}
.padding()
}
}
}

struct ImageListView_Previews: PreviewProvider {
static var previews: some View {
ImageListView()
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import NetworkImage
import SwiftUI

struct SimpleExampleView: View {
private var content: some View {
VStack {
struct ImagesView: View {
var body: some View {
Form {
NetworkImage(url: URL(string: "https://picsum.photos/id/1025/300/200"))
.frame(width: 200, height: 200)
.clipShape(RoundedRectangle(cornerRadius: 8))
NetworkImage(url: URL(string: "https://picsum.photos/id/237/300/200"))
.frame(width: 200, height: 200)
.clipShape(RoundedRectangle(cornerRadius: 8))
}
.navigationTitle("Displaying Network Images")
}
}

var body: some View {
#if os(iOS)
content.navigationBarTitleDisplayMode(.inline)
#else
content
#endif
struct ImagesView_Previews: PreviewProvider {
static var previews: some View {
ImagesView()
}
}
17 changes: 17 additions & 0 deletions Demo/Shared/InlineNavigationBarTitleDisplayModeModifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import SwiftUI

extension View {
func inlineNavigationBarTitleDisplayMode() -> some View {
self.modifier(InlineNavigationBarTitleDisplayModeModifier())
}
}

struct InlineNavigationBarTitleDisplayModeModifier: ViewModifier {
func body(content: Content) -> some View {
#if os(iOS) || os(watchOS)
content.navigationBarTitleDisplayMode(.inline)
#else
content
#endif
}
}
4 changes: 1 addition & 3 deletions Demo/Shared/NetworkImageDemoApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import SwiftUI
struct NetworkImageDemoApp: App {
var body: some Scene {
WindowGroup {
NavigationView {
ExampleList()
}
ContentView()
}
}
}
41 changes: 0 additions & 41 deletions Demo/Shared/PlaceholderExampleView.swift

This file was deleted.

Loading

0 comments on commit 7aff8d1

Please sign in to comment.