SwiftUI Components
VGS Show iOS SDK provide support for integration with apps that are buid with SwiftUI toolkit by providing SwiftUI wrappers for all VGS UI elements. VGS Show SwiftUI wrappers are designed to make integration easier and more straight forward by taking care of all needed state and editing events.
VGSLabelRepresentable
A user interface element that displays any revealed text to the user.
Declaration
struct VGSLabelRepresentable: UIViewRepresentable
Creating VGSLabelRepresentable
/// Initialization
///
/// - Parameters:
/// - vgsShow: `VGSShow` instance that will manage label states.
/// - contentPath: `String` path in reveal request response with revealed data that should be displayed in VGSLabelRepresentable .
public init(vgsShow: VGSShow, contentPath: String)
Instance Methods
VGSLabelRepresentable
is a SwiftUI wrapper around VGSLabel
and have similar attributes and functionality represented in SwiftUI way.
VGSLabelRepresentable Text modifiers
/// VGSLabelRepresentable text font.
public func font(_ font: UIFont)
/// Placeholder text.
public func placeholder(_ text: String)
/// Add transformation regex to format raw revealed text.
public func addTransformationRegex(_ regex: NSRegularExpression, template: String)
/// `Bool` flag. Apply secure mask if `true`. If secure range is not defined mask all text. Default is `false`.
public func isSecureText(_ isSecure: Bool)
/// Text Symbol that will replace visible label text character when securing String. Should be one charcter only.
public func secureTextSymbol(_ symbol: String)
// Set text range to be replaced with `VGSLabel.secureTextSymbol`.
public func setSecureText(start: Int? = nil, end: Int? = nil)
/// Set array of text ranges to be replaced with `VGSLabel.secureTextSymbol`.
public func setSecureText(ranges: [VGSTextRange])
/// Indicates whether `VGSLabelRepresentable ` should automatically update its font
/// when the device’s `UIContentSizeCategory` is changed. It only works
/// automatically with dynamic fonts
public func vgsAdjustsFontForContentSizeCategory(_ adjusts: Bool)
VGSLabelRepresentable View and Layout modifiers
/// Placeholder text styles.
public func placeholderStyle(_ style: VGSPlaceholderLabelStyle)
/// `UIEdgeInsets` for text.
public func labelPaddings(_ paddings: UIEdgeInsets)
/// `UIEdgeInsets` for placeholder. Default is `nil`. If placeholder paddings not set, `paddings` property will be used to control placeholder insets.
public func placeholderLabelPaddings(_ paddings: UIEdgeInsets)
/// Set `borderColor` and `lineWidth`.
public func border(color: UIColor, lineWidth: CGFloat)
/// Label text color.
public func textColor(_ color: UIColor?)
/// Label text alignment.
public func textAlignment(_ alignment: NSTextAlignment)
/// Number of lines. Default is 1.
public func numberOfLines(_ lines: Int)
/// Label line break mode.
public func lineBreakMode(_ mode: NSLineBreakMode)
/// Label minimum text line height.
public func textMinLineHeight(_ height: CGFloat)
VGSLabelRepresentable Accessibility modifiers
/// A succinct label in a localized string that identifies the accessibility element.
public func vgsAccessibilityLabel(_ label: String)
/// A localized string that contains a brief description of the result of performing an action on the accessibility element.
public func vgsAccessibilityHint(_ hint: String?)
VGSLabelRepresentable Event modifiers
/// Tells when label text did changed.
public func onContentDidChange(_ action: (() -> Void)?)
/// Tells when reveal data operation was failed for the label.
/// - action: `VGSShowError` object.
public func onRevealError(_ action: ((VGSShowError) -> Void)?)
Code example
/// Change raw card number format
let cardNumberPattern = "(\\d{4})(\\d{4})(\\d{4})(\\d{4})"
let template = "$1 $2 $3 $4"
let regex = try! NSRegularExpression(pattern: cardNumberPattern, options: [])
VGSLabelRepresentable(vgsShow: vgsShow, contentPath: "payment_card_number")
.placeholder("XXXX XXXX XXXX XXXX")
.placeholderStyle(VGSPlaceholderLabelStyle())
.setSecureText(ranges: [VGSTextRange(start: 5, end: 8),
VGSTextRange(start: 10, end: 13)])
.addTransformationRegex(regex, template: template)
.labelPaddings(UIEdgeInsets(top: 2, left: 8, bottom: 2, right: 8))
.onContentDidChange({
print("-card number label updated")
})
.onRevealError({ error in
print("-card number label error: \(error)")
})
.border(color: .gray, lineWidth: 1)
.frame(height: 54)
You can reade more about Data formatting, Secure text, Styling and other feature that work similar in VGSLabel
at VGSLabel page.
VGSPDFViewRepresentable
A user interface element that displays revealed pdf document to the user.
Declaration
struct VGSPDFViewRepresentable: UIViewRepresentable
Creating VGSPDFViewRepresentable
/// Initialization
///
/// - Parameters:
/// - vgsShow: `VGSShow` instance that will manage view represantable states.
/// - contentPath: `String` path in reveal request response with revealed data that should be displayed in VGSPDFViewRepresentable.
public init(vgsShow: VGSShow, contentPath: String)
Instance Methods
VGSPDFViewRepresentable
is a SwiftUI wrapper around VGSPDFView
and have similar attributes and functionality represented in SwiftUI way.
VGSPDFViewRepresentable UI modifiers
/// Set PDF display mode, default is `.singlePageContinuous`.
public func pdfDisplayMode(_ mode: PDFDisplayMode)
/// Set PDF layout direction, either vertical or horizontal for the given display mode, default is `.vertical`.
public func pdfDisplayDirection(_ direction: PDFDisplayDirection)
/// Set whether pdf is autoscaling, default is `true`.
public func pdfAutoScales(_ scale: Bool)
/// Set whether the view will display the first page as a book cover (meaningful only when the document is in two-up or two-up continuous display mode).
public func displayAsBook(_ bookDisplay: Bool)
/// Set background color of PDF viewer.
public func pdfBackgroundColor(_ color: UIColor)
/// Set if shadows should be drawn around page borders in a PDF View, default is `true`.
public func pageShadowsEnabled(_ enabled: Bool)
VGSPDFViewRepresentable Event modifiers
/// Tells when PDF View content did changed.
public func onContentDidChange(_ action: (() -> Void)?)
/// Tells when reveal operation was failed for the PDF View.
/// - action: `VGSShowError` object.
public func onRevealError(_ action: ((VGSShowError) -> Void)?)
Code example
VGSPDFViewvgsShow: vgsShow, contentPath: "pdf_view")
.pdfAutoScales(false)
.pageShadowsEnabled(true)
.pdfDisplayDirection(.horizontal)
.onContentDidChange {
print("-PDF view updated")
}.onRevealError { error in
print("-PDF view error: \(error)")
}
Reveal PDF with VGSShowSDK
Revealing PDF files might take more time than for text data. Consider your pdf file size and specify additional request timeout with VGSShowRequestOptions
if needed. Max file size that can be sent to VGS is 24Mb.
func revealPdf() {
let payload: [String: Any] = ["customKey" : "customData"]
var options = VGSShowRequestOptions()
options.requestTimeoutInterval = 360
vgsShow.request(path: "/post", method: .post, payload: payload, requestOptions: options) {[weak self] result in
switch result {
case .success(let code):
print("success")
case .failure(let code, let error):
print("vgsshow failed, code: \(code), error: \(error)")
}
}
}
Revealing invalid base64 data or invalid pdf data will produce an error.
>
You can reade more about other PDF View feature that work similar in VGSPDFView
at VGSPDFView page.
VGSImageViewRepresentable
A user interface element that displays revealed pdf document to the user.
Declaration
struct VGSImageViewRepresentable: UIViewRepresentable
Creating VGSImageViewRepresentable
/// Initialization
///
/// - Parameters:
/// - vgsShow: `VGSShow` instance that will manage view represantable states.
/// - contentPath: `String` path in reveal request response with revealed data that should be displayed in VGSImageViewRepresentable .
public init(vgsShow: VGSShow, contentPath: String)
Instance Methods
VGSImageViewRepresentable
is a SwiftUI wrapper around VGSImageView
and have similar attributes and functionality represented in SwiftUI way.
VGSImageViewRepresentable UI modifiers
/// Set mage content mode, default is `.scaleToFill`.
public func imageContentMode(_ mode: UIView.ContentMode)
VGSImageViewRepresentable Event modifiers
/// Tells when Image View content did changed.
public func onContentDidChange(_ action: (() -> Void)?)
/// Tells when reveal operation was failed for the Image View.
/// - action: `VGSShowError` object.
public func onRevealError(_ action: ((VGSShowError) -> Void)?)
Code example
VGSImageViewRepresentable(vgsShow: vgsShow, contentPath: "pdf_view")
.imageContentMode(.scaleAspectFit)
.onContentDidChange {
print("-Image view updated")
}.onRevealError { error in
print("-Image view error: \(error)")
}
Reveal image with VGSShowSDK
Revealing image files might take more time than for text data. Consider your image file size and specify additional request timeout with VGSShowRequestOptions
if needed. Max file size that can be sent to VGS is 24Mb.
@func revealImage() {
let payload: [String: Any] = ["customKey" : "customData"]
var options = VGSShowRequestOptions()
options.requestTimeoutInterval = 360
vgsShow.request(path: "/post", method: .post, payload: payload, requestOptions: options) {[weak self] result in
switch result {
case .success(let code):
print("success")
case .failure(let code, let error):
print("vgsshow failed, code: \(code), error: \(error)")
}
}
}
Revealing invalid base64 data or invalid image data will produce an error.
You can reade more about other Image View feature that work similar in VGSImageView
at VGSImageView page.
Last updated