How to display incoming call view as top on SwiftUI?

前端 未结 1 1174
青春惊慌失措
青春惊慌失措 2021-01-29 02:56

I have tried to simulate how displaying the call view on the top of all. But I have some unclear points:

  • Is there any way to make it more simple?
  • Will the
1条回答
  •  有刺的猬
    2021-01-29 03:19

    Something in just swiftUI would look like this

    struct AppView: View {
        
        @StateObject var callVM = CallViewModel()
        
        var body: some View {
            ZStack {
                TabView {
                    Text("TabOne")
                        .tabItem {
                            Image(systemName: "list.dash")
                            Text("Menu")
                        }
                    
                    Text("TabTwo")
                        .tabItem {
                            Image(systemName: "square.and.pencil")
                            Text("Order")
                        }
                }
                if callVM.isIncomingCallActive {
                    ZStack {
                        Color.green
                        VStack {
                            Text("Incoming call...")
                            Button(action: { callVM.isIncomingCallActive = false }) {
                                Text("Cancel")
                            }
                        }
                    }.edgesIgnoringSafeArea(.all) // <= here
                }
            }
            .onAppear {
                self.callVM.getCall()
            }
        }
    }
    
    class CallViewModel: ObservableObject {
        
        @Published public var isIncomingCallActive = false
        
        func getCall() {
            DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
                self.isIncomingCallActive = true
            }
        }
    }
    

    0 讨论(0)
提交回复
热议问题