-
-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
154 additions
and
8 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
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
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
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
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,18 @@ | ||
#if canImport(SwiftUI) && canImport(UIKit) && os(iOS) || os(tvOS) | ||
import Sentry | ||
|
||
public class PreviewRedactOptions: SentryRedactOptions { | ||
public let maskAllText: Bool | ||
public let maskAllImages: Bool | ||
public let maskedViewClasses: [AnyClass] | ||
public let unmaskedViewClasses: [AnyClass] | ||
|
||
public init(maskAllText: Bool = true, maskAllImages: Bool = true, maskedViewClasses: [AnyClass] = [], unmaskedViewClasses: [AnyClass] = []) { | ||
self.maskAllText = maskAllText | ||
self.maskAllImages = maskAllImages | ||
self.maskedViewClasses = maskedViewClasses | ||
self.unmaskedViewClasses = unmaskedViewClasses | ||
} | ||
} | ||
|
||
#endif |
41 changes: 41 additions & 0 deletions
41
Sources/SentrySwiftUI/Preview/SentryReplayMaskPreview.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,41 @@ | ||
#if canImport(SwiftUI) && canImport(UIKit) && os(iOS) || os(tvOS) | ||
import Sentry | ||
import SwiftUI | ||
import UIKit | ||
|
||
#if CARTHAGE || SWIFT_PACKAGE | ||
@_implementationOnly import SentryInternal | ||
#endif | ||
|
||
@available(iOS 13, macOS 10.15, tvOS 13, *) | ||
struct SentryReplayMaskPreview: ViewModifier { | ||
let redactOptions: SentryRedactOptions | ||
let opacity: Float | ||
func body(content: Content) -> some View { | ||
content.overlay(SentryReplayPreviewView(redactOptions: redactOptions, opacity: opacity).disabled(true)) | ||
} | ||
} | ||
|
||
@available(iOS 13, macOS 10.15, tvOS 13, *) | ||
public extension View { | ||
func sentryReplayPreviewMask(redactOptions: SentryRedactOptions? = nil, opacity: Float = 1) -> some View { | ||
let options = redactOptions ?? SentrySDK.options?.sessionReplay ?? PreviewRedactOptions() | ||
return modifier(SentryReplayMaskPreview(redactOptions: options, opacity: opacity)) | ||
} | ||
} | ||
|
||
@available(iOS 13, macOS 10.15, tvOS 13, *) | ||
struct SentryReplayPreviewView: UIViewRepresentable { | ||
let redactOptions: SentryRedactOptions | ||
let opacity: Float | ||
|
||
func makeUIView(context: Context) -> SentryReplayMaskPreviewUIView { | ||
return SentryReplayMaskPreviewUIView(redactOptions: redactOptions) | ||
} | ||
|
||
func updateUIView(_ uiView: SentryReplayMaskPreviewUIView, context: Context) { | ||
uiView.opacity = CGFloat(opacity) | ||
} | ||
} | ||
|
||
#endif |
36 changes: 36 additions & 0 deletions
36
Sources/SentrySwiftUI/Preview/SentryReplayMaskPreviewUIView.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,36 @@ | ||
#if canImport(SwiftUI) && canImport(UIKit) && os(iOS) || os(tvOS) | ||
import Sentry | ||
import UIKit | ||
|
||
#if CARTHAGE || SWIFT_PACKAGE | ||
import Sentry._Hybrid | ||
@_implementationOnly import SentryInternal | ||
#endif | ||
|
||
class SentryReplayMaskPreviewUIView: UIView { | ||
|
||
private let maskingOverlay: UIView | ||
|
||
var opacity: CGFloat { | ||
get { maskingOverlay.alpha } | ||
set { maskingOverlay.alpha = newValue } | ||
} | ||
|
||
init(redactOptions: SentryRedactOptions) { | ||
maskingOverlay = PrivateSentrySDKOnly.sessionReplayMaskingOverlay(redactOptions) | ||
super.init(frame: .zero) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func didMoveToWindow() { | ||
super.didMoveToWindow() | ||
guard let window = self.window else { return } | ||
maskingOverlay.frame = window.bounds | ||
window.addSubview(maskingOverlay) | ||
} | ||
} | ||
|
||
#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
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