Skip to content

Commit

Permalink
fix EnvironmentLazyObject.Holder<Value> as @StateObject property
Browse files Browse the repository at this point in the history
  • Loading branch information
NikSativa committed Jul 19, 2024
1 parent 44cea87 commit 3ed0182
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 41 deletions.
8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import PackageDescription
let package = Package(
name: "DIKit",
platforms: [
.iOS(.v13),
.iOS(.v14),
.macOS(.v11),
.macCatalyst(.v13),
.macCatalyst(.v14),
.visionOS(.v1),
.tvOS(.v13),
.watchOS(.v6)
.tvOS(.v14),
.watchOS(.v7)
],
products: [
.library(name: "DIKit", targets: ["DIKit"]),
Expand Down
8 changes: 4 additions & 4 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import PackageDescription
let package = Package(
name: "DIKit",
platforms: [
.iOS(.v13),
.iOS(.v14),
.macOS(.v11),
.macCatalyst(.v13),
.tvOS(.v13),
.watchOS(.v6)
.macCatalyst(.v14),
.tvOS(.v14),
.watchOS(.v7)
],
products: [
.library(name: "DIKit", targets: ["DIKit"]),
Expand Down
8 changes: 4 additions & 4 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import PackageDescription
let package = Package(
name: "DIKit",
platforms: [
.iOS(.v13),
.iOS(.v14),
.macOS(.v11),
.macCatalyst(.v13),
.tvOS(.v13),
.watchOS(.v6)
.macCatalyst(.v14),
.tvOS(.v14),
.watchOS(.v7)
],
products: [
.library(name: "DIKit", targets: ["DIKit"]),
Expand Down
8 changes: 4 additions & 4 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import PackageDescription
let package = Package(
name: "DIKit",
platforms: [
.iOS(.v13),
.iOS(.v14),
.macOS(.v11),
.macCatalyst(.v13),
.tvOS(.v13),
.watchOS(.v6)
.macCatalyst(.v14),
.tvOS(.v14),
.watchOS(.v7)
],
products: [
.library(name: "DIKit", targets: ["DIKit"]),
Expand Down
8 changes: 4 additions & 4 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import PackageDescription
let package = Package(
name: "DIKit",
platforms: [
.iOS(.v13),
.iOS(.v14),
.macOS(.v11),
.macCatalyst(.v13),
.tvOS(.v13),
.watchOS(.v6)
.macCatalyst(.v14),
.tvOS(.v14),
.watchOS(.v7)
],
products: [
.library(name: "DIKit", targets: ["DIKit"]),
Expand Down
2 changes: 1 addition & 1 deletion Source/PropertyWrapper/EnvironmentLazyObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SwiftUI
@propertyWrapper
public struct EnvironmentLazyObject<Value: ObservableObject>: DynamicProperty {
@EnvironmentObject private var container: ObservableResolver
@ObservedObject private var holder: Holder<Value> = .init()
@StateObject private var holder: Holder<Value> = .init()

public var wrappedValue: Value {
return resolveInstance()
Expand Down
20 changes: 10 additions & 10 deletions Tests/EnvironmentLazyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SpryKit
import SwiftUI
import XCTest

@available(iOS 16.0, *)
@available(iOS 16.0, tvOS 16.0, watchOS 9.0, *)
final class EnvironmentLazyTests: XCTestCase {
private var resolvingCounter: Int = 0
private let container: Container = .init(assemblies: [])
Expand All @@ -29,18 +29,18 @@ final class EnvironmentLazyTests: XCTestCase {
var appView: (some View)? = makeAppView()
XCTAssertEqual(resolvingCounter, 0)

let capture = ImageRenderer(content: appView).uiImage
let capture = ImageRenderer(content: appView).actualImage
XCTAssertNotNil(capture)
XCTAssertEqual(resolvingCounter, 1)

let capture2 = ImageRenderer(content: appView).uiImage
let capture2 = ImageRenderer(content: appView).actualImage
XCTAssertNotNil(capture2)
XCTAssertEqual(resolvingCounter, 1)

appView = nil
let appView2 = makeAppView()

let capture3 = ImageRenderer(content: appView2).uiImage
let capture3 = ImageRenderer(content: appView2).actualImage
XCTAssertNotNil(capture3)
XCTAssertEqual(resolvingCounter, 2)
}
Expand All @@ -52,18 +52,18 @@ final class EnvironmentLazyTests: XCTestCase {
var appView: (some View)? = makeAppView()
XCTAssertEqual(resolvingCounter, 0)

let capture = ImageRenderer(content: appView).uiImage
let capture = ImageRenderer(content: appView).actualImage
XCTAssertNotNil(capture)
XCTAssertEqual(resolvingCounter, 1)

let capture2 = ImageRenderer(content: appView).uiImage
let capture2 = ImageRenderer(content: appView).actualImage
XCTAssertNotNil(capture2)
XCTAssertEqual(resolvingCounter, 1)

appView = nil
let appView2 = makeAppView()

let capture3 = ImageRenderer(content: appView2).uiImage
let capture3 = ImageRenderer(content: appView2).actualImage
XCTAssertNotNil(capture3)
XCTAssertEqual(resolvingCounter, 2)
}
Expand All @@ -75,18 +75,18 @@ final class EnvironmentLazyTests: XCTestCase {
var appView: (some View)? = makeAppView()
XCTAssertEqual(resolvingCounter, 0)

let capture = ImageRenderer(content: appView).uiImage
let capture = ImageRenderer(content: appView).actualImage
XCTAssertNotNil(capture)
XCTAssertEqual(resolvingCounter, 1)

let capture2 = ImageRenderer(content: appView).uiImage
let capture2 = ImageRenderer(content: appView).actualImage
XCTAssertNotNil(capture2)
XCTAssertEqual(resolvingCounter, 1)

appView = nil
let appView2 = makeAppView()

let capture3 = ImageRenderer(content: appView2).uiImage
let capture3 = ImageRenderer(content: appView2).actualImage
XCTAssertNotNil(capture3)
XCTAssertEqual(resolvingCounter, 1)
}
Expand Down
20 changes: 10 additions & 10 deletions Tests/EnvironmentProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SpryKit
import SwiftUI
import XCTest

@available(iOS 16.0, *)
@available(iOS 16.0, tvOS 16.0, watchOS 9.0, *)
final class EnvironmentProviderTests: XCTestCase {
private var resolvingCounter: Int = 0
private let container: Container = .init(assemblies: [])
Expand All @@ -29,18 +29,18 @@ final class EnvironmentProviderTests: XCTestCase {
var appView: (some View)? = makeAppView()
XCTAssertEqual(resolvingCounter, 0)

let capture = ImageRenderer(content: appView).uiImage
let capture = ImageRenderer(content: appView).actualImage
XCTAssertNotNil(capture)
XCTAssertEqual(resolvingCounter, 1)

let capture2 = ImageRenderer(content: appView).uiImage
let capture2 = ImageRenderer(content: appView).actualImage
XCTAssertNotNil(capture2)
XCTAssertEqual(resolvingCounter, 2)

appView = nil
let appView2 = makeAppView()

let capture3 = ImageRenderer(content: appView2).uiImage
let capture3 = ImageRenderer(content: appView2).actualImage
XCTAssertNotNil(capture3)
XCTAssertEqual(resolvingCounter, 3)
}
Expand All @@ -52,18 +52,18 @@ final class EnvironmentProviderTests: XCTestCase {
var appView: (some View)? = makeAppView()
XCTAssertEqual(resolvingCounter, 0)

let capture = ImageRenderer(content: appView).uiImage
let capture = ImageRenderer(content: appView).actualImage
XCTAssertNotNil(capture)
XCTAssertEqual(resolvingCounter, 1)

let capture2 = ImageRenderer(content: appView).uiImage
let capture2 = ImageRenderer(content: appView).actualImage
XCTAssertNotNil(capture2)
XCTAssertEqual(resolvingCounter, 2)

appView = nil
let appView2 = makeAppView()

let capture3 = ImageRenderer(content: appView2).uiImage
let capture3 = ImageRenderer(content: appView2).actualImage
XCTAssertNotNil(capture3)
XCTAssertEqual(resolvingCounter, 3)
}
Expand All @@ -75,18 +75,18 @@ final class EnvironmentProviderTests: XCTestCase {
var appView: (some View)? = makeAppView()
XCTAssertEqual(resolvingCounter, 0)

let capture = ImageRenderer(content: appView).uiImage
let capture = ImageRenderer(content: appView).actualImage
XCTAssertNotNil(capture)
XCTAssertEqual(resolvingCounter, 1)

let capture2 = ImageRenderer(content: appView).uiImage
let capture2 = ImageRenderer(content: appView).actualImage
XCTAssertNotNil(capture2)
XCTAssertEqual(resolvingCounter, 1)

appView = nil
let appView2 = makeAppView()

let capture3 = ImageRenderer(content: appView2).uiImage
let capture3 = ImageRenderer(content: appView2).actualImage
XCTAssertNotNil(capture3)
XCTAssertEqual(resolvingCounter, 1)
}
Expand Down
14 changes: 14 additions & 0 deletions Tests/ImageRenderer+TestHelper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation
import SpryKit
import SwiftUI

@available(iOS 16.0, tvOS 16.0, watchOS 9.0, *)
extension ImageRenderer {
@MainActor var actualImage: SpryKit.Image? {
#if os(macOS)
return nsImage
#elseif os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
return uiImage
#endif
}
}

0 comments on commit 3ed0182

Please sign in to comment.