|
| 1 | +# SwiftNEW |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +## 功能 |
| 6 | +| 描述 | 版本 | |
| 7 | +|---------------------------------------------------|-----------| |
| 8 | +| 網格漸變同線性漸變背景 | 5.3.0 | |
| 9 | +| Apple visionOS 同 Vision Pro 支援 | 4.1.0 | |
| 10 | +| 版本/構建變更時自動觸發/彈出 .sheet | 4.0.0 | |
| 11 | +| 版本號格式 x.y.z 同/或 x.y | 4.0.0 | |
| 12 | +| 遠程下拉通知 | 3.5.0 | |
| 13 | +| Firebase 實時數據庫 | 3.0.0 | |
| 14 | +| 遠程 JSON 文件 | 3.0.0 | |
| 15 | +| 版本控制 + 睇歷史 | 2.0.0 | |
| 16 | +| 支持所有用例(包括商業/非營利) | - | |
| 17 | +| 簡單模型,易於修改同重用 | - | |
| 18 | +| 簡單綁定同數據傳遞 | - | |
| 19 | +| 從本地存儲即時加載 | - | |
| 20 | + |
| 21 | +## 預覽 |
| 22 | + |
| 23 | + |
| 24 | +## 展示 |
| 25 | + |  |
| 26 | +------------- | ------------ |
| 27 | +淺色主題 | 深色主題 |
| 28 | + |
| 29 | + |   |
| 30 | +------------- | ------------ |
| 31 | +歷史視圖 (2.0.0) | 應用圖標 (3.9.6) [垂直 / 水平] |
| 32 | + |
| 33 | + | <img alt="Screenshot 2024-07-01 at 10 18 33 PM" src="https://github.com/1998code/SwiftNEWKit/assets/54872601/a845c460-65d7-47a0-ae15-23897efd0508"> | |
| 34 | +------------- | ------------ |
| 35 | +支援 VisionOS (4.1.0 或更高版本) | 網格漸變背景 (5.3.0 或更高版本) |
| 36 | + |
| 37 | +## 示例 |
| 38 | +路徑: `./Demo` (Xcode 項目) |
| 39 | + |
| 40 | +## 版本 |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +## 測試平台同環境 |
| 47 | +### 本地 |
| 48 | +測試平台 | 最新版本 | 兼容版本 |
| 49 | +-------- | ------ | ---------- |
| 50 | +iOS | 18.4 | > 14 |
| 51 | +iPadOS | 18.2 | > 14 |
| 52 | +macOS | 15.2 | > 11 |
| 53 | +visionOS | 2 | > 1 |
| 54 | +### 雲端 |
| 55 | +測試平台 | 兼容版本 |
| 56 | +-------- | ---------- |
| 57 | +Xcode | > 13.4 (13F17a) |
| 58 | +macOS | > 12.3.1 (21E258) |
| 59 | + |
| 60 | +### 設置 |
| 61 | +步驟 | 描述 | 截圖 |
| 62 | +------| ----------- | ---------- |
| 63 | +1 | 導航到根項目 | <img width="274" alt="CleanShot 2022-06-11 at 17 39 39@2x" src="https://user-images.githubusercontent.com/54872601/173182521-27481cf2-c9bf-4f87-95cc-76f5d1c05094.png"> |
| 64 | +2 | 選擇項目 | <img width="174" alt="CleanShot 2022-06-11 at 17 39 48@2x" src="https://user-images.githubusercontent.com/54872601/173182523-6a24c67a-8f27-4ef7-a3f4-ea63cfd8436f.png"> |
| 65 | +3 | 選擇包依賴項 | <img width="309" alt="CleanShot 2022-06-11 at 17 39 53@2x" src="https://user-images.githubusercontent.com/54872601/173182526-e5660b7f-c50c-4173-81f5-83c10c514659.png"> |
| 66 | +4 | 點擊 + 同貼上 <code>https://github.com/1998code/SwiftNEWKit</code> 到搜索框 | <img width="614" alt="CleanShot 2022-06-11 at 17 39 32@2x" src="https://user-images.githubusercontent.com/54872601/173182527-2a151198-7ac0-4735-8257-11580ada3d5e.png"> |
| 67 | +5L | 創建一個名為 `data.json` 嘅新本地文件 | 你可以複製呢個 [JSON 示例](https://github.com/1998code/SwiftNEWKit#sample)。 |
| 68 | +5R | 你都可以使用遠程 JSON / firebase 實時數據庫。 | 示例: https://testground-a937f-default-rtdb.firebaseio.com/0.json?print=pretty |
| 69 | + |
| 70 | +### 主要用法 |
| 71 | +1. 導入包。 |
| 72 | +```swift |
| 73 | +import SwiftNEW |
| 74 | +``` |
| 75 | + |
| 76 | +2. 喺 `body` 或任何 `some View` 之前添加狀態。 |
| 77 | +### 狀態 |
| 78 | +變量 | 建議值 | 選項 | 類型 |
| 79 | +----------- | ------------------------------ | ----------------------------- | ---- |
| 80 | +showNew * | false | false, true | Bool |
| 81 | +align | .center | .leading, .center, .trailing | HorizontalAlignment |
| 82 | +color | .accentColor | 支持所有顏色 | Color |
| 83 | +size | "simple" | "invisible", "mini", "simple" | String |
| 84 | +labelColor | UIColor.systemBackground 或 NSColor.windowBackgroundColor | 支持所有顏色 | Color |
| 85 | +label | "顯示發布說明" | 所有字符串 | String |
| 86 | +labelImage | "arrow.up.circle.fill" | 所有 SF 符號 | String |
| 87 | +history | true | true, false | Bool |
| 88 | +data | "data" 或 "https://.../{}.json"| "{本地JSON文件}" 或 遠程 | String |
| 89 | +showDrop | false | false, true | Bool |
| 90 | +mesh | true | false, true | Bool |
| 91 | + |
| 92 | +##### 示例: |
| 93 | +```swift |
| 94 | +// 必需 |
| 95 | +@State var showNew: Bool = false |
| 96 | + |
| 97 | +// 可選 (5.2.0 或更高版本) |
| 98 | +@State var align: HorizontalAlignment = .center |
| 99 | +@State var color: Color = .accentColor |
| 100 | +@State var size: String = "normal" |
| 101 | +#if os(iOS) |
| 102 | +@State var labelColor: Color = Color(UIColor.systemBackground) |
| 103 | +#elseif os(macOS) |
| 104 | +@State var labelColor: Color = Color(NSColor.windowBackgroundColor) |
| 105 | +#endif |
| 106 | +@State var label: String = "顯示發布說明" |
| 107 | +@State var labelImage: String = "arrow.up.circle.fill" |
| 108 | +@State var history: Bool = true |
| 109 | +@State var data: String = "data" |
| 110 | +@State var showDrop: Bool = false |
| 111 | +@State var mesh: Bool = false |
| 112 | +``` |
| 113 | + |
| 114 | +3. 然後,將此代碼粘貼到 `body` 或任何 `some View` 內部。 |
| 115 | +```swift |
| 116 | +// 5.2.0 或更高版本中使用默認選項嘅簡化版本 |
| 117 | +SwiftNEW(show: $showNew) |
| 118 | + |
| 119 | +// 5.1.0 或更低版本 |
| 120 | +SwiftNEW(show: $showNew, align: $align, color: $color, size: $size, labelColor: $labelColor, label: $label, labelImage: $labelImage, history: $history, data: $data, showDrop: $showDrop) |
| 121 | +``` |
| 122 | +除咗使用單獨嘅狀態外,內聯狀態都可以工作。(5.2.0 後唔再需要) |
| 123 | + |
| 124 | +*`Show Bool` 唔可以內聯。 |
| 125 | +```swift |
| 126 | +SwiftNEW(show: $showNew, align: .constant(.center), color: .constant(.accentColor), size: .constant("normal"), labelColor: .constant(Color(UIColor.systemBackground)), label: .constant("顯示發布說明"), labelImage: .constant("arrow.up.circle.fill"), history: .constant(true), data: .constant("data"), showDrop: .constant(false)) |
| 127 | +``` |
| 128 | + |
| 129 | +4. 你嘅代碼應該類似於以下內容,包含最小功能同默認樣式。 |
| 130 | +```swift |
| 131 | +struct ContentView: View { |
| 132 | + @State var showNew: Bool = false |
| 133 | + var body: some View { |
| 134 | + SwiftNEW(show: $showNew) |
| 135 | + } |
| 136 | +} |
| 137 | +``` |
| 138 | + |
| 139 | +### JSON |
| 140 | +#### 結構 / 模型 (參考) |
| 141 | +* 以下代碼僅供參考。你唔需要複製結構或模型。 |
| 142 | +```swift |
| 143 | +public struct Vmodel: Codable, Hashable { |
| 144 | + var version: String |
| 145 | + var new: [Model] |
| 146 | +} |
| 147 | +public struct Model: Codable, Hashable { |
| 148 | + var icon: String |
| 149 | + var title: String |
| 150 | + var subtitle: String |
| 151 | + var body: String |
| 152 | +} |
| 153 | +``` |
| 154 | + |
| 155 | +#### 示例 |
| 156 | +將 JSON 示例複製到 `data.json` 文件中(如果你冇該文件,請創建一個新文件。) |
| 157 | + |
| 158 | + |
| 159 | +```json |
| 160 | +[ |
| 161 | + { |
| 162 | + "version": "1.2", |
| 163 | + "new": [ |
| 164 | + { |
| 165 | + "body": "適用於 iOS 16, iPadOS 16, macOS 13", |
| 166 | + "icon": "hammer.fill", |
| 167 | + "subtitle": "修復UI問題", |
| 168 | + "title": "錯誤修復" |
| 169 | + }, |
| 170 | + { |
| 171 | + "body": "通過遠程存儲直接加載。好簡單!", |
| 172 | + "icon": "square.and.arrow.down.fill", |
| 173 | + "subtitle": "已支持", |
| 174 | + "title": "Firebase 遠程" |
| 175 | + }, |
| 176 | + { |
| 177 | + "body": "免費開源!由 Ming 用 ❤️🔥 創建", |
| 178 | + "icon": "macpro.gen3.server", |
| 179 | + "subtitle": "設計", |
| 180 | + "title": "無服務器" |
| 181 | + }, |
| 182 | + { |
| 183 | + "body": "提交拉取請求,令佢對每個人都更好!", |
| 184 | + "icon": "arrow.triangle.pull", |
| 185 | + "subtitle": "一齊", |
| 186 | + "title": "貢獻" |
| 187 | + } |
| 188 | + ] |
| 189 | + }, |
| 190 | + { |
| 191 | + "version": "1.1", |
| 192 | + "new": [ |
| 193 | + { |
| 194 | + "body": "適用於 iOS 16, iPadOS 16, macOS 13", |
| 195 | + "icon": "hammer.fill", |
| 196 | + "subtitle": "修復UI問題", |
| 197 | + "title": "錯誤修復" |
| 198 | + }, |
| 199 | + { |
| 200 | + "body": "通過本地存儲直接加載。超快速!", |
| 201 | + "icon": "square.and.arrow.down.fill", |
| 202 | + "subtitle": "已支持", |
| 203 | + "title": "本地文件" |
| 204 | + }, |
| 205 | + { |
| 206 | + "body": "免費開源!由 Ming 用 ❤️🔥 創建", |
| 207 | + "icon": "macpro.gen3.server", |
| 208 | + "subtitle": "設計", |
| 209 | + "title": "無服務器" |
| 210 | + }, |
| 211 | + { |
| 212 | + "body": "提交拉取請求,令佢對每個人都更好!", |
| 213 | + "icon": "arrow.triangle.pull", |
| 214 | + "subtitle": "一齊", |
| 215 | + "title": "貢獻" |
| 216 | + } |
| 217 | + ] |
| 218 | + } |
| 219 | +] |
| 220 | +``` |
| 221 | + |
| 222 | +## 貢獻 |
| 223 | + |
| 224 | +歡迎對 SwiftNEW 做出貢獻! |
| 225 | + |
| 226 | +- 要報告錯誤或請求功能,請喺 GitHub 上提出問題 |
| 227 | +- 提交拉取請求時,請遵循項目嘅編碼風格 |
| 228 | + |
| 229 | +## 許可證 |
| 230 | + |
| 231 | +MIT。 詳情請閱讀 LICENSE 文件。 |
| 232 | + |
| 233 | +## 翻譯 |
| 234 | + |
| 235 | +呢個文檔仲有其他語言版本: |
| 236 | + |
| 237 | +[English](../README.md) | [简中](README_zh.md) / [繁中](README_tc.md) / 粵語 | [日本語](README_ja.md) | [한국어](README_ko.md) |
| 238 | + |
| 239 | +請隨時提交拉取請求,添加新語言或修復任何錯別字/錯誤。 |
| 240 | + |
| 241 | +## 支持 |
| 242 | +<a href="https://m.do.co/c/ce873177d9ab"> |
| 243 | + <img src="https://opensource.nyc3.cdn.digitaloceanspaces.com/attribution/assets/SVG/DO_Logo_horizontal_blue.svg" width="201px"> |
| 244 | +</a> |
0 commit comments