NavX

Version SwiftUI iOS Minimum iOS version

NavX 是一个直观的 SwiftUI 导航框架,旨在简化自定义导航模式的集成和管理。借助 PageXItem 和动态导航栏的强大功能,NavX 为开发者提供了流畅且可定制的导航体验,在现代 iOS 应用程序中无缝连接设计和功能。

目录

"Buy Me A Coffee"

安装

Swift Package Manager

在 Xcode 中,导航到你的项目设置 选择 “Swift Packages” 标签 点击 “+” 图标以添加新的包 粘贴仓库 URL (https://github.com/mkaulfers/NavX.git) 并点击 “Next” 对于版本规则,选择 “Up to Next Major” 并指定 1.0.0 作为最低版本,然后点击 “Next” 选择你想使用该包的目标,然后点击 “Finish”

或者,你可以直接通过 Xcode 添加包

你可以使用 Swift Package Manager 通过在你的 Package.swift 文件中添加正确的描述来安装 [NavX]

// swift-tools-version:5.2
import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    dependencies: [
        .package(url: "https://github.com/YOUR_GITHUB_USERNAME/YourPackageName.git", from: "1.0.0")
    ],
    targets: [
        .target(name: "YOUR_TARGET_NAME", dependencies: ["YourPackageName"])
    ]
)

将 YOUR_PROJECT_NAME、YOUR_GITHUB_USERNAME、YourPackageName 和 YOUR_TARGET_NAME 替换为你项目对应的实际值。

特性

NavX 视图

主要导航视图,用于管理和显示一系列 PageXItem 视图。主要特性包括

NavX(selecedIndex: $selectedIndex) {...}
    .barAlignment(.center)
    .barX { bar in ... }
    .respectedBarSafeAreas(.all)
    .ignoredPageSafeAreas(.all)
    .pageScrollIndicator(.always)

PageX 视图

PageXItem 协议的具体实现,代表 NavX 导航系统中的单个页面项。它提供了多种链式方法进行自定义。这应该包含你的 页面内容

NavX { ...
    PageX { ... }
    .iconX("house")
    .titleX("Home")
    .foregroundColorX(.black)
    .tabX {
        Circle()
            .fill(.gray)
            .frame(width: 40, height: 40)
    
}

PageXItem 协议

/// A protocol that represents an individual page item to be used within a `NavX` navigation system.
///
/// By conforming to `PageXItem`, a view becomes suitable for integration within the `NavX` tab-based navigation interface.
/// Each `PageXItem` can provide an icon, a title, a foreground color, and a custom tab view.
public protocol PageXItem: View {
    
    /// An optional system name of the icon to be displayed on the tab bar.
    var iconX: String? { get }
    
    /// An optional title to be displayed on the tab bar.
    /// This title typically represents the content or purpose of the associated view.
    var titleX: String? { get }
    
    /// An optional foreground color for the tab item.
    /// This color will be applied to the icon and title of the tab item.
    var foregroundColorX: Color? { get }
    
    /// An optional closure that returns a custom view for the tab.
    /// This allows for more advanced customization of the tab beyond just an icon and title.
    var tabX: (() -> any View)? { get }
}

用法

let navView = NavX(selectedIndex: .constant(0)) {
    PageX {
        Text("First Page")
    }
    .iconX("house")
    .titleX("Home")

    PageX {
        Text("Second Page")
    }
    .iconX("person")
    .titleX("Profile")
}

高级用法

通过结合使用 NavX(...)PageX(...) 及其各自的修饰符,你可以创建一个完全自定义的标签栏系统。

NavX(selectedIndex: $selectedIndex) {
    PageX {
        Color.red
            .frame(height: UIScreen.main.bounds.height)
    }
    .foregroundColorX(.black)
    .tabX {
        Circle()
            .fill(.gray)
            .frame(width: 40, height: 40)
    }
    
    PageX {
        Color.blue
            .frame(height: UIScreen.main.bounds.height)
    }
    .foregroundColorX(.black)
    .titleX("B")
    .iconX("person.circle")
    
    PageX {
        Color.green
            .frame(height: UIScreen.main.bounds.height)
    }
    .foregroundColorX(.yellow)
    .tabX {
        Rectangle()
            .fill(.red)
            .frame(width: 50, height: 50)
    }
}
.ignoredPageSafeAreas(.top)
.respectedBarSafeAreas(.bottom)
.barX { bar in
    bar.padding()
        .background {
            Color.white
        }
        .cornerRadius(5)
        .shadow(radius: 5)
}

贡献

欢迎贡献!请参阅 CONTRIBUTING 了解详情。

许可证

版权所有

保留所有权利。本作品的版权归原作者所有。

非商业用途许可

特此授权,免费授予任何获得本软件及相关文档文件(“软件”)副本的人员,在非商业应用中使用本软件,包括使用、复制和修改软件的权利,但须遵守以下条件

商业用途

如需获得在商业应用中使用本软件的许可,请联系原作者以获得书面同意

邮箱:matt@getnovara.com

免责声明

本软件按“原样”提供,不作任何明示或暗示的保证,包括但不限于适销性、特定用途的适用性和不侵权的保证。在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任负责,无论是在合同诉讼、侵权行为或其他方面,因本软件或本软件的使用或其他交易而产生、或与之相关。