Activity indicator in SwiftUI

As of Xcode 12 beta (iOS 14), a new view called ProgressView is available to developers, and that can display both determinate and indeterminate progress. Its style defaults to CircularProgressViewStyle, which is exactly what we’re looking for. var body: some View { VStack { ProgressView() // and if you want to be explicit / future-proof… … Read more

SwiftUI: Switch .sheet on enum, does not work

With some very small alterations to your code, you can use sheet(item:) for this, which prevents this problem: //MARK: main view: struct ContentView: View { //construct enum to decide which sheet to present: enum ActiveSheet : String, Identifiable { // <— note that it’s now Identifiable case sheetA, sheetB var id: String { return self.rawValue … Read more

Not Receiving scenePhase Changes

Use inside scene root view (usually ContentView) Tested with Xcode 12 / iOS 14 as worked. struct ContentView: View { @Environment(\.scenePhase) private var scenePhase var body: some View { TestView() .onChange(of: scenePhase) { phase in switch phase { case .active: print(“>> your code is here on scene become active”) case .inactive: print(“>> your code is … Read more

SwiftUI – Get size of child?

Updated and generalized @arsenius code. Now you can easily bind a parent view’s state variable. struct ChildSizeReader<Content: View>: View { @Binding var size: CGSize let content: () -> Content var body: some View { ZStack { content() .background( GeometryReader { proxy in Color.clear .preference(key: SizePreferenceKey.self, value: proxy.size) } ) } .onPreferenceChange(SizePreferenceKey.self) { preferences in self.size … Read more

Are there maximum limits to VStack?

SwiftUI uses ViewBuilder to construct the views that make up many SwiftUI views, like VStack, HStack, List, etc. If you take a look at the ViewBuilder documentation, you’ll see that the buildBlock function has many copies, each with a different amount of views as arguments. The function with the most amount of views only takes … Read more

SwiftUI WKWebView content height issue

It is confusing of ScrollView in SwiftUI, which expects known content size in advance, and UIWebView internal UIScrollView, which tries to get size from parent view… cycling. So here is possible approach.. to pass determined size from web view into SwiftUI world, so no hardcoding is used and ScrollView behaves like having flat content. At … Read more

Hosting Controller When Using iOS 14 @main

Here is a possible approach (tested with Xcode 12 / iOS 14)… but if you intend to use UIKit features heavily it is better to use UIKit Life-Cycle, as it gives more flexibility to configure UIKit part. struct ContentView: View { var body: some View { Text(“Demo Root Controller access”) .withHostingWindow { window in if … Read more