View

@MainActor extension View

Plugin

  • 显示通用控制器插件,自动切换

    Declaration

    Swift

    @MainActor
    public func showPlugin(
        _ isShowing: Binding<Bool>,
        customize: @escaping @MainActor @Sendable (UIViewController) -> Void,
        viewContext: ViewContext? = nil
    ) -> some View
  • 显示控制器弹窗插件,自动切换

    Declaration

    Swift

    @MainActor
    public func showAlert(
        _ isShowing: Binding<Bool>,
        customize: @escaping @MainActor @Sendable (UIViewController) -> Void,
        viewContext: ViewContext? = nil
    ) -> some View
  • 显示控制器消息吐司插件,自动切换

    Declaration

    Swift

    @MainActor
    public func showToast(
        _ isShowing: Binding<Bool>,
        customize: @escaping @MainActor @Sendable (UIViewController) -> Void,
        viewContext: ViewContext? = nil
    ) -> some View
  • 显示控制器空界面插件,需手工切换

    Declaration

    Swift

    @MainActor
    public func showEmpty(
        _ isShowing: Bool,
        customize: (@MainActor @Sendable (UIViewController) -> Void)? = nil,
        viewContext: ViewContext? = nil
    ) -> some View
  • 显示控制器加载吐司插件,需手工切换

    Declaration

    Swift

    @MainActor
    public func showLoading(
        _ isShowing: Bool,
        customize: (@MainActor @Sendable (UIViewController) -> Void)? = nil,
        viewContext: ViewContext? = nil
    ) -> some View
  • 显示控制器进度吐司插件,需手工切换

    Declaration

    Swift

    @MainActor
    public func showProgress(
        _ isShowing: Bool,
        customize: @escaping @MainActor @Sendable (UIViewController) -> Void,
        viewContext: ViewContext? = nil
    ) -> some View

PluginView

  • 显示通用插件视图,需手工切换

    Declaration

    Swift

    @MainActor
    public func showPluginView<Plugin: View>(
        _ isShowing: Bool = true,
        @ViewBuilder content: () -> Plugin
    ) -> some View
  • 显示空界面插件视图,需手工切换。如果需要显示空界面时可滚动,放到滚动视图内部即可

    Declaration

    Swift

    @MainActor
    public func showEmptyView(
        _ isShowing: Bool = true,
        content: (() -> EmptyPluginView)? = nil
    ) -> some View
  • 显示加载插件视图,需手工切换

    Declaration

    Swift

    @MainActor
    public func showLoadingView(
        _ isShowing: Bool = true,
        content: (() -> LoadingPluginView)? = nil
    ) -> some View
  • 显示进度插件视图,需手工切换

    Declaration

    Swift

    @MainActor
    public func showProgressView(
        _ isShowing: Bool = true,
        content: @escaping () -> ProgressPluginView
    ) -> some View

View+Configure

  • 初始化当前顶部视图控制器,仅调用一次

    Declaration

    Swift

    @MainActor
    public func viewControllerInitialize(
        _ initialization: @escaping @MainActor @Sendable (UIViewController) -> Void,
        viewContext: ViewContext? = nil
    ) -> some View
  • 配置当前顶部视图控制器,可调用多次

    Declaration

    Swift

    @MainActor
    public func viewControllerConfigure(
        _ configuration: @escaping @MainActor @Sendable (UIViewController) -> Void,
        viewContext: ViewContext? = nil
    ) -> some View
  • 初始化当前SwiftUI视图对应UIView,仅调用一次。仅适用于有对应UIView的视图(如Text等),不支持Layer视图(如VStack等)

    Declaration

    Swift

    @MainActor
    public func hostingViewInitialize(
        _ initialization: @escaping @MainActor @Sendable (UIView) -> Void
    ) -> some View
  • 配置当前SwiftUI视图对应UIView,可调用多次。仅适用于有对应UIView的视图(如Text等),不支持Layer视图(如VStack等)

    Declaration

    Swift

    @MainActor
    public func hostingViewConfigure(
        _ configuration: @escaping @MainActor @Sendable (UIView) -> Void
    ) -> some View

ScrollView+Configure

  • 初始化ScrollView视图,仅调用一次,一般用于绑定下拉刷新、上拉追加等

    Declaration

    Swift

    @MainActor
    public func scrollViewInitialize(
        _ initialization: @escaping @MainActor @Sendable (UIScrollView) -> Void
    ) -> some View
  • 配置ScrollView视图,可调用多次

    Declaration

    Swift

    @MainActor
    public func scrollViewConfigure(
        _ configuration: @escaping @MainActor @Sendable (UIScrollView) -> Void
    ) -> some View
  • 绑定ScrollView下拉刷新插件,action必须调用completionHandler,可指定是否已加载完成不能继续追加

    Declaration

    Swift

    @MainActor
    public func scrollViewRefreshing(
        shouldBegin: Binding<Bool>? = nil,
        loadingFinished: Binding<Bool?>? = nil,
        action: @escaping @MainActor @Sendable (@escaping @MainActor @Sendable (_ finished: Bool?) -> Void) -> Void,
        customize: (@MainActor @Sendable (UIScrollView) -> Void)? = nil
    ) -> some View
  • 绑定ScrollView上拉追加插件,action必须调用completionHandler,可指定是否已加载完成不能继续追加

    Declaration

    Swift

    @MainActor
    public func scrollViewLoading(
        shouldBegin: Binding<Bool>? = nil,
        loadingFinished: Binding<Bool?>? = nil,
        action: @escaping @MainActor @Sendable (@escaping @MainActor @Sendable (_ finished: Bool?) -> Void) -> Void,
        customize: (@MainActor @Sendable (UIScrollView) -> Void)? = nil
    ) -> some View
  • 显示ScrollView空界面插件,需手工切换,空界面显示时也可滚动

    Declaration

    Swift

    @MainActor
    public func showScrollEmpty(_ isShowing: Bool, customize: (@MainActor @Sendable (UIScrollView) -> Void)? = nil) -> some View

List+Configure

  • 重置List样式,去除多余间距等,可指定背景色

    Declaration

    Swift

    @MainActor
    public func resetListStyle(background: Color? = nil, isPlainStyle: Bool = false) -> some View

    Parameters

    background

    自定义背景色,默认nil时不处理

    isPlainStyle

    是否是plain样式,默认false,如果是则会自动清除iOS16+多余的Header顶部间距

    Return Value

    View

  • 重置Header|Footer样式,左对齐并去除多余间距,可指定背景色

    Declaration

    Swift

    @MainActor
    public func resetHeaderStyle(background: Color? = nil) -> some View
  • 重置Cell样式,左对齐并隐藏分割线、去除多余间距,可指定背景色

    Declaration

    Swift

    @MainActor
    public func resetCellStyle(background: Color? = nil) -> some View
  • 初始化List视图,仅调用一次,一般用于绑定下拉刷新、上拉追加等

    注意:iOS16以上scrollView为UICollectionView,iOS16以下为UITableView

    Declaration

    Swift

    @MainActor
    public func listViewInitialize(
        _ initialization: @escaping @MainActor @Sendable (UIScrollView) -> Void
    ) -> some View
  • 配置List视图,可调用多次

    注意:iOS16以上scrollView为UICollectionView,iOS16以下为UITableView

    Declaration

    Swift

    @MainActor
    public func listViewConfigure(
        _ configuration: @escaping @MainActor @Sendable (UIScrollView) -> Void
    ) -> some View
  • 绑定List下拉刷新插件,action必须调用completionHandler,可指定是否已加载完成不能继续追加

    Declaration

    Swift

    @MainActor
    public func listViewRefreshing(
        shouldBegin: Binding<Bool>? = nil,
        loadingFinished: Binding<Bool?>? = nil,
        action: @escaping @MainActor @Sendable (@escaping @MainActor @Sendable (_ finished: Bool?) -> Void) -> Void,
        customize: (@MainActor @Sendable (UIScrollView) -> Void)? = nil
    ) -> some View
  • 绑定List上拉追加插件,action必须调用completionHandler,可指定是否已加载完成不能继续追加

    Declaration

    Swift

    @MainActor
    public func listViewLoading(
        shouldBegin: Binding<Bool>? = nil,
        loadingFinished: Binding<Bool?>? = nil,
        action: @escaping @MainActor @Sendable (@escaping @MainActor @Sendable (_ finished: Bool?) -> Void) -> Void,
        customize: (@MainActor @Sendable (UIScrollView) -> Void)? = nil
    ) -> some View
  • 显示List空界面插件,需手工切换,空界面显示时也可滚动

    Declaration

    Swift

    @MainActor
    public func showListEmpty(_ isShowing: Bool, customize: (@MainActor @Sendable (UIScrollView) -> Void)? = nil) -> some View

TextField+Configure

  • 初始化TextField视图,仅调用一次,一般用于配置键盘管理,自动聚焦等

    Declaration

    Swift

    @MainActor
    public func textFieldInitialize(
        _ initialization: @escaping @MainActor @Sendable (UITextField) -> Void,
        autoFocus viewContext: ViewContext? = nil
    ) -> some View
  • 配置TextField视图,可调用多次

    Declaration

    Swift

    @MainActor
    public func textFieldConfigure(
        _ configuration: @escaping @MainActor @Sendable (UITextField) -> Void
    ) -> some View
  • 初始化TextView视图,仅调用一次,一般用于配置键盘管理,自动聚焦等

    Declaration

    Swift

    @MainActor
    public func textViewInitialize(
        _ initialization: @escaping @MainActor @Sendable (UITextView) -> Void,
        autoFocus viewContext: ViewContext? = nil
    ) -> some View
  • 配置TextView视图,可调用多次

    Declaration

    Swift

    @MainActor
    public func textViewConfigure(
        _ configuration: @escaping @MainActor @Sendable (UITextView) -> Void
    ) -> some View
  • 设置视图上下文,可指定自定义对象

    Declaration

    Swift

    @MainActor
    public func viewContext(_ viewController: UIViewController?, object: Any? = nil) -> some View
  • 设置视图上下文,可指定自定义对象和用户信息

    Declaration

    Swift

    @MainActor
    public func viewContext(_ viewController: UIViewController?, object: Any? = nil, userInfo: [AnyHashable : Any]?) -> some View
  • 转换视图上下文,内部可使用DispatchQueue.main.async执行异步方法

    如果要监听上下文变化,可使用如下方式:

    1. onReceive(viewContext.subject)
    2. onReceive(viewContext.$object)
    3. viewContext.$object.receive(on: RunLoop.main)

    Declaration

    Swift

    @MainActor
    public func transformViewContext(transform: @escaping (ViewContext) -> Void) -> some View
  • 快速包装视图到上下文控制器

    Declaration

    Swift

    @MainActor
    public func wrappedContextController() -> UIHostingController<AnyView>

Introspect

  • Introspects a SwiftUI view to find its underlying UIKit/AppKit instance.

    Here’s an example usage:

    struct ContentView: View {
        @State var date = Date()
    
        var body: some View {
            DatePicker("Pick a date", selection: $date)
                .introspect(.datePicker, on: .iOS(.all)) {
                    print(type(of: $0)) // UIDatePicker
                }
        }
    }
    

    Declaration

    Swift

    @MainActor
    public func introspect<SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity>(
        _ viewType: SwiftUIViewType,
        on platforms: PlatformViewVersionPredicate<SwiftUIViewType, PlatformSpecificEntity>...,
        scope: IntrospectionScope? = nil,
        customize: @escaping (PlatformSpecificEntity) -> Void
    ) -> some View

    Parameters

    viewType

    The type of view to be introspected.

    platforms

    A list of PlatformViewVersions that specify platform-specific entities associated with the view, with one or more corresponding version numbers.

    scope

    An optional IntrospectionScope that specifies the scope of introspection.

    customize

    A closure that hands over the underlying UIKit/AppKit instance ready for customization.

ViewSizePreferenceKey

  • 捕获当前视图大小

    Declaration

    Swift

    @MainActor
    public func captureSize(in binding: Binding<CGSize>) -> some View

ViewContentOffsetPreferenceKey

  • 捕获当前滚动视图内容偏移,需滚动视图调用,且用GeometryReader包裹滚动视图

    使用示例: GeometryReader { proxy in List { … } .captureContentOffset(in: $contentOffsets) }

    Declaration

    Swift

    @MainActor
    public func captureContentOffset(in binding: Binding<CGPoint>) -> some View
  • 捕获当前滚动视图内容偏移,需滚动视图第一个子视图调用

    使用示例: GeometryReader { proxy in List { Cell .captureContentOffset(proxy: proxy)

      ...
    }
    .captureContentOffset(in: $contentOffsets)
    

    }

    Declaration

    Swift

    @MainActor
    public func captureContentOffset(proxy outsideProxy: GeometryProxy) -> some View
  • 监听当前滚动视图内容偏移实现悬停效果,需GeometryReader调用

    使用示例: GeometryReader { proxy in List { Cell .captureContentOffset(proxy: proxy)

      ...
    }
    .captureContentOffset(in: $contentOffsets)
    

    } .hoverContentOffset(visible: contentOffset.y >= offset) { … }

    Declaration

    Swift

    @MainActor
    public func hoverContentOffset<Content: View>(
        alignment: Alignment = .top,
        visible: Bool = true,
        @ViewBuilder content: () -> Content
    ) -> some View

View+Toolkit

  • 设置不规则圆角效果

    Declaration

    Swift

    @MainActor
    public func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View
  • 同时设置边框和圆角

    Declaration

    Swift

    @MainActor
    public func border<S>(_ content: S, width lineWidth: CGFloat, cornerRadius: CGFloat) -> some View where S : ShapeStyle
  • 切换视图移除性

    Declaration

    Swift

    @MainActor
    public func removable(_ removable: Bool) -> some View
  • 切换视图隐藏性

    Declaration

    Swift

    @MainActor
    public func hidden(_ isHidden: Bool) -> some View
  • 切换视图可见性

    Declaration

    Swift

    @MainActor
    public func visible(_ isVisible: Bool = true) -> some View
  • 动态切换裁剪性

    Declaration

    Swift

    @MainActor
    public func clipped(_ value: Bool) -> some View
  • 执行闭包并返回新的视图

    Declaration

    Swift

    @MainActor
    public func then(_ body: (Self) -> AnyView) -> some View
  • 条件成立时执行闭包并返回新的视图

    Declaration

    Swift

    @MainActor
    public func then<T>(_ condition: Bool, body: (Self) -> T) -> some View where T : View
  • 值不为空时执行闭包并返回新的视图

    Declaration

    Swift

    @MainActor
    public func then<T, Value>(_ value: Value?, body: (Self, Value) -> T) -> some View where T : View
  • 配置当前对象

    Declaration

    Swift

    @MainActor
    public func configure(_ body: (inout Self) -> Void) -> Self
  • 转换为AnyView

    Declaration

    Swift

    @MainActor
    public func eraseToAnyView() -> AnyView

Button+Toolkit

  • 设置按钮高亮和禁用时的透明度,nil时使用默认

    Declaration

    Swift

    @MainActor
    public func opacityButtonStyle(
        disabled: Bool = false,
        highlightedAlpha: CGFloat? = nil,
        disabledAlpha: CGFloat? = nil
    ) -> some View
  • 包装到Button并指定点击事件

    Declaration

    Swift

    @MainActor
    public func wrappedButton(
        action: @escaping @MainActor () -> Void
    ) -> some View
  • 包装到VStack,可指定内容(如Spacer)

    Declaration

    Swift

    @MainActor
    public func wrappedVStack<Content: View>(
        alignment: HorizontalAlignment = .center,
        spacing: CGFloat? = nil,
        content: (() -> Content)? = nil
    ) -> some View
  • 包装到HStack,可指定内容(如Spacer)

    Declaration

    Swift

    @MainActor
    public func wrappedHStack<Content: View>(
        alignment: VerticalAlignment = .center,
        spacing: CGFloat? = nil,
        content: (() -> Content)? = nil
    ) -> some View