fullScreenCover 在滑动 tabView 后关闭 |SwiftUI界面 |iOS系统

fullScreenCover dissmissed after swipe of tabView | SwiftUI | iOS

提问人:Hitesh Patil 提问时间:8/16/2023 最后编辑:Hitesh Patil 更新时间:8/17/2023 访问量:123

问:

我的应用程序有一个初始屏幕,其中包含以下代码: 它重定向到 ApplicationSwitcher()

HStack {
Spacer()
VStack(alignment: .center) {
    Spacer()
    // Text("Value: \(vm.isNavigating == true ? "True" : "False")")
    Image(systemName: "apple.logo")
        .resizable()
        .scaledToFit()
        .foregroundColor(.LabelRev)
        .frame(maxHeight: .infinity, alignment: .center)
        .aspectRatio(contentMode: .fit)
        .clipped()
    
    Spacer()
    
    if appUpdateChecker.isLoading {
        ProgressView("Checking for Updates...")
            .progressViewStyle(CircularProgressViewStyle())
    } else {
        Text(appUpdateChecker.needsUpdate ? "New Version is Available. Please Update to Proceed" : "You are Using the Latest Version")
            .font(.system(size: showingUpdateAlert ? Sizes.MESSAGE : Sizes.LABEL))
            .multilineTextAlignment(.center)
            .foregroundColor(Color.Dim)
            .underline(!showingUpdateAlert && appUpdateChecker.needsUpdate)
            .onTapGesture {
                if appUpdateChecker.needsUpdate {
                    appUpdateChecker.initiateAppUpdate()
                }
            }
    }
}
.onReceive(appUpdateChecker.$goodToGo) { value in
    if value {
        DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
            vm.isNavigating = true
        }
    }
}
.fullScreenCover(isPresented: $vm.isNavigating, content: {
    NavigationStack {
        ApplicationSwitcher()
    }
    .frame(maxWidth: .infinity, maxHeight: .infinity)
    .environmentObject(vm)
    .environmentObject(sbVM)
    .environmentObject(orderBookViewModel)
})
Spacer()
}

在ApplicationSwitcher()中,我有一个代码:

VStack(spacing: 0) {
        TabView(selection: $orderBookViewModel.activeTab) {
            WatchlistView()
                .applyBackground()
                .tag(MainTab.Watchlist)
                .id(MainTab.Watchlist)
            
            Orders()
                .applyBackground()
                .tag(MainTab.Orders)
                .id(MainTab.Orders)
            
            Positions()
                .applyBackground()
                .tag(MainTab.Positions)
                .id(MainTab.Positions)
            
            OverviewView()
                .applyBackground()
                .tag(MainTab.Overview)
                .id(MainTab.Overview)

            AdvisoryView()
                .applyBackground()
                .tag(MainTab.Advisory)
                .id(MainTab.Advisory)
        }
     }

监视列表中,我有代码:

TabView (selection: $activeTab) {
    ForEach(watchlist.indices, id: \.self) { index in
        if activeTab == index {
            ScrollView{
                getList(index: index)
                
            }
        }                                
    }
}
.tabViewStyle(.page(indexDisplayMode: .never))

将 getList 函数作为 -

func getList(index: Int) -> some View {
    
    return LazyVStack (spacing: 0) {
        
        ForEach(watchlist[index].scrips, id: \.self) { scrip in
            if scrip.pInstType != nil {
                    
                    watchListItem(scrip: scrip, advisoryFlag: true)
                        .environmentObject(commonViewModel)
                    Divider().background(Color.gray)
            }
        }
    }
    .environmentObject(accountViewModel)
}

编辑我正在使用底板的扩展

extension View {
@ViewBuilder
func bottomSheet<Content: View>(
    presentationDetents: Set<PresentationDetent>,
    isPresented: Binding<Bool>,
    selectedDetent: Binding<PresentationDetent>,
    dragIndicator: Visibility = .visible,
    sheetCornerRadius: CGFloat? = CGFloat(Sizes.CORNER_RADIUS),
    largestUndimmedIdentifier: UISheetPresentationController.Detent.Identifier = .large,
    isTransparent: Bool = false,
    interactiveDisabled: Bool = false,
    @ViewBuilder content: @escaping () -> Content,
    onDismiss: @escaping () -> ()
) -> some View {
    self
        .sheet(isPresented: isPresented) {
            onDismiss()
        } content: {
            content()
                .presentationDetents(presentationDetents, selection: selectedDetent)
                .presentationDragIndicator(dragIndicator)
                .interactiveDismissDisabled(interactiveDisabled)
                .onAppear {
                    guard let windows = UIApplication.shared.connectedScenes.first as? UIWindowScene else {
                        return
                    }
                    
                    if let controller = windows.windows.first?.rootViewController?.presentedViewController,
                       let sheet = controller.presentationController as? UISheetPresentationController {
                        if isTransparent {
                            controller.view.backgroundColor = .clear
                        }
                        controller.presentingViewController?.view.tintAdjustmentMode = .normal
                        sheet.largestUndimmedDetentIdentifier = largestUndimmedIdentifier
                        sheet.preferredCornerRadius = sheetCornerRadius
                    } else {
                        print("NO CONTROLLER FOUND")
                    }
                }
        }
}

}

在我单击监视列表项目并关闭弹出窗口并尝试切换监视列表选项卡后

它被重定向到初始屏幕。

只有当我在执行 onDismiss 函数的内容之前更改点击时,才会发生这种情况

在此处查看问题

iOS版 swiftUI swift3

评论

0赞 Prashant Tukadiya 8/16/2023
这可能有助于防止在滑动时关闭interactiveDismissDisabled
0赞 Hitesh Patil 8/17/2023
@PrashantTukadiya仍然不起作用,请查看有问题的编辑。我忘了添加那部分。

答: 暂无答案