-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Public release 1.2.0.
- Loading branch information
Showing
22 changed files
with
1,193 additions
and
37 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 |
---|---|---|
|
@@ -124,3 +124,4 @@ workflows: | |
context: | ||
- security-tools | ||
- circleci | ||
|
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
92 changes: 92 additions & 0 deletions
92
...ShowSDK/UIElements/VGSImageView/VGSImageViewRepresentable/VGSImageViewRepresentable.swift
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,92 @@ | ||
// | ||
// VGSImageViewRepresentable.swift | ||
// VGSShowSDK | ||
// | ||
import SwiftUI | ||
|
||
@available(iOS 14.0, *) | ||
/// An object that displays revealed image data. | ||
public struct VGSImageViewRepresentable: VGSViewRepresentableProtocol, VGSViewRepresentableCallbacksProtocol { | ||
weak var vgsShow: VGSShow? | ||
/// Name that will be associated with `VGSImageViewRepresentable` and used as a decoding `contentPath` on request response with revealed data from your organization vault. | ||
var contentPath: String | ||
/// Image content mode, default is `.scaleToFill`. | ||
var imageContentMode: UIView.ContentMode = .scaleToFill | ||
|
||
// MARK: - VGSImageViewRepresentable interaction callbacks | ||
/// Tells when Image View content did changed. | ||
var onContentDidChange: (() -> Void)? | ||
/// Tells when reveal data operation was failed for the Image View. | ||
/// - Parameter error: `VGSShowError` object. | ||
var onRevealError: ((VGSShowError) -> Void)? | ||
|
||
// MARK: - Initialization | ||
/// Initialization | ||
/// | ||
/// - Parameters: | ||
/// - contentPath: `String` path in reveal request response with revealed data that should be displayed in VGSImageViewRepresentable . | ||
public init(vgsShow: VGSShow, contentPath: String) { | ||
self.vgsShow = vgsShow | ||
self.contentPath = contentPath | ||
} | ||
|
||
public func makeUIView(context: Context) -> VGSImageView { | ||
let vgsImageView = VGSImageView() | ||
vgsImageView.contentPath = contentPath | ||
vgsImageView.imageContentMode = imageContentMode | ||
vgsShow?.subscribe(vgsImageView) | ||
return vgsImageView | ||
} | ||
|
||
public func updateUIView(_ uiView: VGSImageView, context: Context) { | ||
uiView.imageContentMode = imageContentMode | ||
} | ||
/// Name that will be associated with `VGSImageViewRepresentable` and used as a decoding `contentPath` on request response with revealed data from your organization vault. | ||
public func contentPath(_ path: String) -> VGSImageViewRepresentable { | ||
var newRepresentable = self | ||
newRepresentable.contentPath = path | ||
return newRepresentable | ||
} | ||
/// Set mage content mode, default is `.scaleToFill`. | ||
public func imageContentMode(_ mode: UIView.ContentMode) -> VGSImageViewRepresentable { | ||
var newRepresentable = self | ||
newRepresentable.imageContentMode = mode | ||
return newRepresentable | ||
} | ||
|
||
// MARK: - Handle Image View events | ||
public func onContentDidChange(_ action: (() -> Void)?) -> VGSImageViewRepresentable { | ||
var newRepresentable = self | ||
newRepresentable.onContentDidChange = action | ||
return newRepresentable | ||
} | ||
|
||
/// Tells when reveal image operation was failed for the image view. | ||
/// - action: `VGSShowError` object. | ||
public func onRevealError(_ action: ((VGSShowError) -> Void)?) -> VGSImageViewRepresentable { | ||
var newRepresentable = self | ||
newRepresentable.onRevealError = action | ||
return newRepresentable | ||
} | ||
|
||
// MARK: - Coordinator | ||
public func makeCoordinator() -> Coordinator { | ||
return Coordinator(self) | ||
} | ||
|
||
public class Coordinator: NSObject, VGSImageViewDelegate { | ||
var parent: VGSImageViewRepresentable | ||
|
||
init(_ parent: VGSImageViewRepresentable) { | ||
self.parent = parent | ||
} | ||
|
||
public func imageDidChange(in imageView: VGSImageView) { | ||
parent.onContentDidChange?() | ||
} | ||
|
||
public func imageView(_ imageView: VGSImageView, didFailWithError error: VGSShowError) { | ||
parent.onRevealError?(error) | ||
} | ||
} | ||
} |
Oops, something went wrong.