Skip to content

Instantly share code, notes, and snippets.

@ANSCoder
Created August 22, 2021 14:29
Show Gist options
  • Save ANSCoder/6841bf331127cb63d66cad4c0d7cfbe6 to your computer and use it in GitHub Desktop.
Save ANSCoder/6841bf331127cb63d66cad4c0d7cfbe6 to your computer and use it in GitHub Desktop.
Solution for Create Controller inside NavigationButton lazily in SwiftUI.
//
// LazyView.swift
// Grocers
//
// Created by Anand Nimje on 10/09/20.
// Copyright © 2020 Anscoder. All rights reserved.
//
import SwiftUI
/// Create destination View inside the NavigationButton lazily.
struct LazyView<Content: View>: View {
let build: () -> Content
init(_ build: @autoclosure @escaping () -> Content) {
self.build = build
}
var body: Content {
build()
}
}
@ANSCoder
Copy link
Author

Uses for this Lazy view inside the SwiftUI

NavigationLink(destination: LazyView( "Your SwiftUI view initialize here."){
    /// Handle code ..

}.buttonStyle(PlainButtonStyle())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment