How to pass one SwiftUI View as a variable to another View struct

后端 未结 6 1047
孤城傲影
孤城傲影 2020-12-30 19:24

I\'m implementing a very custom NavigationLink called MenuItem and would like to reuse it across the project. It\'s a struct that conforms to Vie

6条回答
  •  旧巷少年郎
    2020-12-30 20:04

    You should make the generic parameter part of MenuItem:

    struct MenuItem: View {
        private var destinationView: Content
    
        init(destinationView: Content) {
            self.destinationView = destinationView
        }
    
        var body : some View {
            // ...
        }
    }
    

提交回复
热议问题