-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix SwiftUI bug, when object realloceted after invalidate view
- Loading branch information
1 parent
043c612
commit f4d152c
Showing
25 changed files
with
244 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
/.build | ||
/Packages | ||
/*.xcodeproj | ||
/xcuserdata | ||
/.swiftpm | ||
/Pods |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// | ||
// DIComponentContext.swift | ||
// | ||
// SwiftDI | ||
// | ||
// Created by v.a.prusakov on 01/07/2019. | ||
// | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// | ||
// DIComponentManager.swift | ||
// | ||
// SwiftDI | ||
// | ||
// Created by v.a.prusakov on 01/07/2019. | ||
// | ||
|
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// | ||
// DIPart.swift | ||
// | ||
// SwiftDI | ||
// | ||
// Created by v.a.prusakov on 01/07/2019. | ||
// | ||
|
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 was deleted.
Oops, something went wrong.
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,27 @@ | ||
// | ||
// EnvironmentInject.swift | ||
// SwiftDI | ||
// | ||
// Created by Vladislav Prusakov on 17.11.2019. | ||
// | ||
|
||
#if canImport(SwiftUI) | ||
import SwiftUI | ||
import Combine | ||
|
||
/// A property wrapper that inject object from environment container | ||
/// Read only object | ||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *) | ||
@propertyWrapper | ||
public struct EnvironmentInject<Value: AnyObject>: DynamicProperty { | ||
|
||
public let wrappedValue: Value | ||
|
||
public init() { | ||
let bundle = Bundle(for: Value.self) | ||
let resolvedValue = Environment(\.container).wrappedValue.resolve(bundle: bundle) as Value | ||
self.wrappedValue = resolvedValue | ||
} | ||
} | ||
|
||
#endif |
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,36 @@ | ||
// | ||
// EnvironmentObservedInject.swift | ||
// SwiftDI | ||
// | ||
// Created by v.a.prusakov on 27/06/2019. | ||
// | ||
|
||
#if canImport(SwiftUI) | ||
import SwiftUI | ||
import Combine | ||
|
||
/// A dynamic view property that subscribes to a `ObservableObject` automatically invalidating the view | ||
/// when it changes. | ||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *) | ||
@propertyWrapper | ||
public struct EnvironmentObservedInject<Value: ObservableObject>: DynamicProperty { | ||
|
||
@ObservedObject private var _wrappedValue: Value | ||
public var wrappedValue: Value { | ||
_wrappedValue | ||
} | ||
|
||
public init() { | ||
let bundle = Bundle(for: Value.self) | ||
let resolvedValue = Environment(\.container).wrappedValue.resolve(bundle: bundle) as Value | ||
self.__wrappedValue = ObservedObject<Value>(initialValue: resolvedValue) | ||
} | ||
|
||
/// The binding value, as "unwrapped" by accessing `$foo` on a `@Binding` property. | ||
public var projectedValue: ObservedObject<Value>.Wrapper { | ||
return __wrappedValue.projectedValue | ||
} | ||
} | ||
|
||
#endif | ||
|
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,37 @@ | ||
// | ||
// View+SwiftDI.swift | ||
// SwiftDI | ||
// | ||
// Created by Vladislav Prusakov on 17.11.2019. | ||
// | ||
|
||
#if canImport(SwiftUI) | ||
import SwiftUI | ||
|
||
public extension View { | ||
|
||
/// Set dependency container to view | ||
func inject(container: DIContainer) -> some View { | ||
self.environment(\.container, container) | ||
} | ||
|
||
// Inject property into container | ||
func environmentInject<Value>(_ value: Value) -> some View { | ||
return self.transformEnvironment(\.container) { con in | ||
con.register({ value }) | ||
} | ||
} | ||
} | ||
|
||
struct DIContainerEnvironmentKey: EnvironmentKey { | ||
static var defaultValue: DIContainer = SwiftDI.sharedContainer | ||
} | ||
|
||
extension EnvironmentValues { | ||
var container: DIContainer { | ||
get { self[DIContainerEnvironmentKey.self] } | ||
set { self[DIContainerEnvironmentKey.self] = newValue } | ||
} | ||
} | ||
|
||
#endif |
File renamed without changes.
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
File renamed without changes.
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,6 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
/.swiftpm | ||
/Pods |
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
Oops, something went wrong.