Skip to content

Consider introspecting UIWindowScene #122

@gongzhang

Description

@gongzhang

UIWindowScene contains a lot of contextual information about the current window, and SwiftUI currently has no corresponding API to get this environment information. Therefore, I propose to support getting the parent UIWindowScene from a View.

Code snippets that may be useful:

struct SomeIntrospectionHelperView: UIViewRepresentable {
    
    func makeUIView(context: Context) -> UnderlyingView {
        UnderlyingView()
    }
    
    func updateUIView(_ view: UnderlyingView, context: Context) {
        
    }
    
    class UnderlyingView: UIView {
        
        init() {
            super.init(frame: .zero)
        }
        
        required init?(coder: NSCoder) {
            super.init(frame: .zero)
        }
        
        override func willMove(toWindow newWindow: UIWindow?) {
            super.willMove(toWindow: newWindow)
            if let scene = newWindow?.windowScene {
                // we got window scene here, 👀 callback introspect delegate...
            }
        }
    }
    
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions