Skip to content

Commit b20abf1

Browse files
committed
Optional Binding
1 parent cef6301 commit b20abf1

File tree

6 files changed

+129
-42
lines changed

6 files changed

+129
-42
lines changed

Demo/What's New?.xcodeproj/project.pbxproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@
304304
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
305305
CODE_SIGN_ENTITLEMENTS = "What's New?/What_s_New_.entitlements";
306306
CODE_SIGN_STYLE = Automatic;
307-
CURRENT_PROJECT_VERSION = 10;
307+
CURRENT_PROJECT_VERSION = 11;
308308
DEVELOPMENT_ASSET_PATHS = "\"What's New?/Preview Content\"";
309309
DEVELOPMENT_TEAM = "";
310310
ENABLE_HARDENED_RUNTIME = YES;
@@ -318,7 +318,7 @@
318318
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
319319
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
320320
MACOSX_DEPLOYMENT_TARGET = 12.0;
321-
MARKETING_VERSION = 5.1;
321+
MARKETING_VERSION = 5.2;
322322
PRODUCT_BUNDLE_IDENTIFIER = io.startway.WhatsNew;
323323
PRODUCT_NAME = "$(TARGET_NAME)";
324324
SDKROOT = auto;
@@ -339,7 +339,7 @@
339339
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
340340
CODE_SIGN_ENTITLEMENTS = "What's New?/What_s_New_.entitlements";
341341
CODE_SIGN_STYLE = Automatic;
342-
CURRENT_PROJECT_VERSION = 10;
342+
CURRENT_PROJECT_VERSION = 11;
343343
DEVELOPMENT_ASSET_PATHS = "\"What's New?/Preview Content\"";
344344
DEVELOPMENT_TEAM = "";
345345
ENABLE_HARDENED_RUNTIME = YES;
@@ -353,7 +353,7 @@
353353
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
354354
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
355355
MACOSX_DEPLOYMENT_TARGET = 12.0;
356-
MARKETING_VERSION = 5.1;
356+
MARKETING_VERSION = 5.2;
357357
PRODUCT_BUNDLE_IDENTIFIER = io.startway.WhatsNew;
358358
PRODUCT_NAME = "$(TARGET_NAME)";
359359
SDKROOT = auto;

Demo/What's New?/ContentView.swift

+27-26
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,50 @@ import SwiftNEW
1010

1111
struct ContentView: View {
1212

13-
@State var preview: String = "Normal"
13+
@State var preview: String = "Simple"
1414

1515
// MARK: All States
1616
@State var showNew: Bool = false
17-
@State var align: HorizontalAlignment = .center
18-
@State var color: Color = .accentColor
19-
@State var size: String = "normal"
20-
#if os(iOS) || os(xrOS)
21-
@State var labelColor: Color = Color(UIColor.systemBackground)
22-
#elseif os(macOS)
23-
@State var labelColor: Color = Color(NSColor.windowBackgroundColor)
24-
#endif
25-
@State var label: String = "Show Release Note"
26-
@State var labelImage: String = "arrow.up.circle.fill"
27-
@State var history: Bool = true
28-
@State var data: String = "data"
29-
@State var showDrop: Bool = false
17+
// Optional
18+
// @State var align: HorizontalAlignment = .center
19+
// @State var color: Color = .accentColor
20+
// @State var size: String = "simple"
21+
// #if os(iOS) || os(visionOS)
22+
// @State var labelColor: Color = Color(UIColor.systemBackground)
23+
// #elseif os(macOS)
24+
// @State var labelColor: Color = Color(NSColor.windowBackgroundColor)
25+
// #endif
26+
// @State var label: String = "Show Release Note"
27+
// @State var labelImage: String = "arrow.up.circle.fill"
28+
// @State var history: Bool = true
29+
// @State var data: String = "data"
30+
// @State var showDrop: Bool = false
3031

31-
var normal: some View {
32-
SwiftNEW(show: $showNew, align: $align, color: $color, size: $size, labelColor: $labelColor, label: $label, labelImage: $labelImage, history: $history, data: $data, showDrop: $showDrop)
32+
var simple: some View {
33+
SwiftNEW(show: $showNew)
3334
}
3435

3536
var mini: some View {
3637
// MARK: Mini (Toolbar / List only)
3738
List {
3839
Section(header: Text("Compatible with Toolbar / List")) {
39-
SwiftNEW(show: $showNew, align: $align, color: $color, size: .constant("mini"), labelColor: $labelColor, label: $label, labelImage: $labelImage, history: $history, data: $data, showDrop: $showDrop)
40+
SwiftNEW(show: $showNew, size: .constant("mini"))
4041
}
4142
}
4243
}
4344

4445
var invisible: some View {
45-
SwiftNEW(show: $showNew, align: $align, color: $color, size: .constant("invisible"), labelColor: $labelColor, label: $label, labelImage: $labelImage, history: $history, data: $data, showDrop: $showDrop)
46+
SwiftNEW(show: $showNew, size: .constant("invisible"))
4647
}
4748

4849
var remote: some View {
4950
// MARK: Remote (>3.0.0) - Firebase Real Time Database Demo (Compatible with json format)
50-
SwiftNEW(show: $showNew, align: $align, color: $color, size: $size, labelColor: $labelColor, label: $label, labelImage: .constant("icloud"), history: $history, data: .constant("https://testground-a937f-default-rtdb.firebaseio.com/.json?print=pretty"), showDrop: $showDrop)
51+
SwiftNEW(show: $showNew, labelImage: .constant("icloud"), data: .constant("https://testground-a937f-default-rtdb.firebaseio.com/.json?print=pretty"))
5152
}
5253

5354
var drop: some View {
5455
// MARK: Drop (>3.4.0) - Recommended trigger with Remote Notification
55-
SwiftNEW(show: $showNew, align: $align, color: $color, size: $size, labelColor: $labelColor, label: .constant("Notification"), labelImage: .constant("bell.badge"), history: $history, data: .constant("https://testground-a937f-default-rtdb.firebaseio.com/.json?print=pretty"), showDrop: .constant(true))
56+
SwiftNEW(show: $showNew, label: .constant("Notification"), labelImage: .constant("bell.badge"), data: .constant("https://testground-a937f-default-rtdb.firebaseio.com/.json?print=pretty"), showDrop: .constant(true))
5657
}
5758

5859
var body: some View {
@@ -61,19 +62,19 @@ struct ContentView: View {
6162
tab
6263
}
6364
.navigationViewStyle(.stack)
64-
#elseif os(macOS) || os(xrOS)
65+
#elseif os(macOS) || os(visionOS)
6566
tab.padding()
6667
#endif
6768
}
6869

6970
var tab: some View {
70-
// MARK: Choose either one size (Normal, Mini or Invisible)
71+
// MARK: Choose either one size (Simple, Mini or Invisible)
7172
TabView(selection: $preview) {
72-
normal
73+
simple
7374
.tabItem {
74-
Label("Normal", systemImage: "textformat.size.larger")
75+
Label("Simple", systemImage: "textformat.size.larger")
7576
}
76-
.tag("Normal")
77+
.tag("Simple")
7778
mini
7879
.tabItem {
7980
Label("Mini", systemImage: "textformat.size.smaller")
@@ -99,7 +100,7 @@ struct ContentView: View {
99100
}
100101
.toolbar {
101102
if preview == "Mini" {
102-
SwiftNEW(show: $showNew, align: $align, color: $color, size: .constant("mini"), labelColor: $labelColor, label: $label, labelImage: $labelImage, history: $history, data: $data, showDrop: $showDrop)
103+
SwiftNEW(show: $showNew, size: .constant("mini"))
103104
}
104105
}
105106
}

Demo/What's New?/en.lproj/data.json

+24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
[
2+
{
3+
"version": "5.2",
4+
"subVersion": "5.2.0",
5+
"new": [
6+
{
7+
"icon": "hammer",
8+
"title": "Default",
9+
"subtitle": "Option",
10+
"body": "New optional binding for less code."
11+
},
12+
{
13+
"icon": "macpro.gen3.server",
14+
"title": "Serverless",
15+
"subtitle": "Design",
16+
"body": "Free and open source! ❤️‍🔥"
17+
},
18+
{
19+
"icon": "arrow.triangle.pull",
20+
"title": "Contribute",
21+
"subtitle": "Together",
22+
"body": "Pull requests and make it better for everyone! 🎉"
23+
}
24+
]
25+
},
226
{
327
"version": "5.1",
428
"subVersion": "5.1.0",

Demo/What's New?/zh-Hant.lproj/data.json

+24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
[
2+
{
3+
"version": "5.1",
4+
"subVersion": "5.1.0",
5+
"new": [
6+
{
7+
"icon": "hammer",
8+
"title": "預設",
9+
"subtitle": "選項",
10+
"body": "減少重複程式碼"
11+
},
12+
{
13+
"icon": "macpro.gen3.server",
14+
"title": "無服務器",
15+
"subtitle": "設計",
16+
"body": "免費開源! ❤️‍🔥"
17+
},
18+
{
19+
"icon": "arrow.triangle.pull",
20+
"title": "貢獻",
21+
"subtitle": "一起",
22+
"body": "提出請求,變得更好! 🎉"
23+
}
24+
]
25+
},
226
{
327
"version": "5.1",
428
"subVersion": "5.1.0",

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ var | Suggested | Options |
8888
showNew | false | false, true | Bool
8989
align | .center | .leading, .center, .trailing | HorizontalAlignment
9090
color | .accentColor | All Colors Supported | Color
91-
size | "normal" | "invisible", "mini", "normal" | String
91+
size | "simple" | "invisible", "mini", "simple" | String
9292
labelColor | Color(UIColor.systemBackground) or Color(NSColor.windowBackgroundColor) | All Colors Supported | Color
9393
label | "Show Release Note" | All Strings | String
9494
labelImage | "arrow.up.circle.fill" | All SF Symbols | String

Sources/SwiftNEW/SwiftNEW.swift

+49-11
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,57 @@ public struct SwiftNEW: View {
2929
@Binding var data: String
3030
@Binding var showDrop: Bool
3131

32-
public init( show: Binding<Bool>, align: Binding<HorizontalAlignment>, color: Binding<Color>, size: Binding<String>, labelColor: Binding<Color>, label: Binding<String>, labelImage: Binding<String>, history: Binding<Bool>, data: Binding<String>, showDrop: Binding<Bool>) {
32+
#if os(iOS) || os(visionOS)
33+
public init(
34+
show: Binding<Bool>,
35+
align: Binding<HorizontalAlignment>? = .constant(.center),
36+
color: Binding<Color>? = .constant(Color.accentColor),
37+
size: Binding<String>? = .constant("simple"),
38+
labelColor: Binding<Color>? = .constant(Color(UIColor.systemBackground)),
39+
label: Binding<String>? = .constant("Show Release Note"),
40+
labelImage: Binding<String>? = .constant("arrow.up.circle.fill"),
41+
history: Binding<Bool>? = .constant(true),
42+
data: Binding<String>? = .constant("data"),
43+
showDrop: Binding<Bool>? = .constant(false)
44+
) {
3345
_show = show
34-
_align = align
35-
_color = color
36-
_size = size
37-
_labelColor = labelColor
38-
_label = label
39-
_labelImage = labelImage
40-
_history = history
41-
_data = data
42-
_showDrop = showDrop
46+
_align = align ?? .constant(.center)
47+
_color = color ?? .constant(Color.accentColor)
48+
_size = size ?? .constant("simple")
49+
_labelColor = labelColor ?? .constant(Color(UIColor.systemBackground))
50+
_label = label ?? .constant("Show Release Note")
51+
_labelImage = labelImage ?? .constant("arrow.up.circle.fill")
52+
_history = history ?? .constant(true)
53+
_data = data ?? .constant("data")
54+
_showDrop = showDrop ?? .constant(false)
4355
compareVersion()
4456
}
57+
#elseif os(macOS)
58+
public init(
59+
show: Binding<Bool>,
60+
align: Binding<HorizontalAlignment>? = .constant(.center),
61+
color: Binding<Color>? = .constant(Color.accentColor),
62+
size: Binding<String>? = .constant("simple"),
63+
labelColor: Binding<Color>? = .constant(Color(NSColor.windowBackgroundColor)),
64+
label: Binding<String>? = .constant("Show Release Note"),
65+
labelImage: Binding<String>? = .constant("arrow.up.circle.fill"),
66+
history: Binding<Bool>? = .constant(true),
67+
data: Binding<String>? = .constant("data"),
68+
showDrop: Binding<Bool>? = .constant(false)
69+
) {
70+
_show = show
71+
_align = align ?? .constant(.center)
72+
_color = color ?? .constant(Color.accentColor)
73+
_size = size ?? .constant("simple")
74+
_labelColor = labelColor ?? .constant(Color(NSColor.windowBackgroundColor))
75+
_label = label ?? .constant("Show Release Note")
76+
_labelImage = labelImage ?? .constant("arrow.up.circle.fill")
77+
_history = history ?? .constant(true)
78+
_data = data ?? .constant("data")
79+
_showDrop = showDrop ?? .constant(false)
80+
compareVersion()
81+
}
82+
#endif
4583

4684
public var body: some View {
4785
Button(action: {
@@ -56,7 +94,7 @@ public struct SwiftNEW: View {
5694
if size == "mini" {
5795
Label(label, systemImage: labelImage)
5896
}
59-
else if size == "normal" {
97+
else if size == "normal" || size == "simple" {
6098
Label(label, systemImage: labelImage)
6199
.frame(width: 300, height: 50)
62100
#if os(iOS) && !os(xrOS)

0 commit comments

Comments
 (0)