Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

접근성 #18

Open
minsOne opened this issue Sep 30, 2022 · 1 comment
Open

접근성 #18

minsOne opened this issue Sep 30, 2022 · 1 comment

Comments

@minsOne
Copy link
Owner Author

minsOne commented Sep 30, 2022

import SwiftUI
import UIKit

// from https://github.com/cashapp/AccessibilitySnapshot
import AccessibilitySnapshotCore

struct AccessibilityPreview<Content: View>: View {
    let content: Content
    
    var body: some View {
        AccessibilityPreviewRepresentable(content: content)
            .previewLayout(.fixed(
                width: UIScreen.main.bounds.width * 2,
                height: UIScreen.main.bounds.height
            ))
            .previewDisplayName("VoiceOver Representation")
    }
}

private struct AccessibilityPreviewRepresentable<Content: View>: UIViewRepresentable {
    let content: Content
    
    func makeUIView(context: Context) -> some UIView {
        let view = UIHostingController(rootView: content)
        view.view.frame = UIScreen.main.bounds
        
        let snapshotView = AccessibilitySnapshotView(
            containedView: view.view,
            viewRenderingMode: .drawHierarchyInRect,
            activationPointDisplayMode: .whenOverridden
        )
        
        // who needs error management 'eh?
        try! snapshotView.parseAccessibility(useMonochromeSnapshot: false)
        
        return snapshotView
    }
    
    func updateUIView(_ uiView: UIViewType, context: Context) {}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant