Skip to content

Commit 8134fa7

Browse files
committed
update readme and implement datepicker
1 parent 71ba6a0 commit 8134fa7

File tree

9 files changed

+127
-144
lines changed

9 files changed

+127
-144
lines changed

Example/Example/Page/Alert/ActionSheetPage.swift

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,11 @@ struct ActionSheetPage : View {
2020
.bold()
2121
.font(.system(.largeTitle,
2222
design: .rounded))
23-
}//.sheet(isPresented: $showSheet, onDismiss: nil, content: <#T##() -> View#>)
24-
//.presentation(sheet)
23+
}
2524
.actionSheet(isPresented: $showSheet, content: {sheet})
2625
}
2726

28-
// NavigationView {
29-
//
30-
// Button(action: {
31-
// self.showSheet = true
32-
// }) {
33-
// Text("ActionSheet")
34-
// .bold()
35-
// .font(.system(.largeTitle,
36-
// design: .rounded))
37-
// }
38-
// }.sheet(isPresented: $showSheet, content: sheet)
39-
40-
// ActionSheet.Button.default(<#T##label: Text##Text#>, action: <#T##(() -> Void)?##(() -> Void)?##() -> Void#>)
27+
4128
}
4229

4330
private var sheet: ActionSheet {
@@ -56,7 +43,6 @@ struct ActionSheetPage : View {
5643
self.showSheet = false
5744
})])
5845

59-
// return self.showSheet ? action:nil
6046
return action
6147
}
6248
}

Example/Example/Page/Alert/AlertPage.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ struct AlertPage : View {
1313
@State var showAlert = false
1414

1515
var body: some View {
16+
17+
1618
Button(action: {
1719
self.showAlert = true
1820
print("Tap")

Example/Example/Page/Alert/PopoverPage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct PopoverPage : View {
1919
print(self.showPop)
2020
}) {
2121
Text("Popover").bold().font(.system(.largeTitle, design: .monospaced))
22-
}//.presentation(popView)
22+
}
2323
.popover(isPresented: $showPop, content: {
2424
ImagePage()
2525
})

Example/Example/Page/List/ForEachPage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import SwiftUI
1010

1111
struct ForEachPage : View {
1212

13-
let data = (0..<5)//.map { $0 }
13+
let data = (0..<5)
1414

1515
var body: some View {
1616

Example/Example/Page/Picker/DatePickerPage.swift

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,19 @@ struct DatePickerPage : View {
2828
var body: some View {
2929

3030

31-
VStack(spacing: 10) {
32-
Text("日期选择").bold()
33-
// TODO: DatePicker implement
34-
// DatePicker(selection: $server.date, in: speaceDate, displayedComponents: .date, label: {})
35-
// DatePicker(selection: $server.date, in: speaceDate, displayedComponents: .date) {
36-
// Text("Select a date")
37-
// }
38-
}
39-
.padding(10)
40-
.navigationBarTitle(Text("DatePicker"))
41-
/*
42-
VStack(alignment: .center, spacing: 10) {
43-
Text("日期选择").bold()
44-
DatePicker(
45-
$server.date,
46-
minimumDate: Calendar.current.date(byAdding: .year,
47-
value: -1,
48-
to: server.date),
49-
maximumDate: Calendar.current.date(byAdding: .year,
50-
value: 1,
51-
to: server.date),
52-
displayedComponents: .date
53-
)
31+
VStack {
32+
VStack(spacing: 10) {
33+
Text("日期选择").bold()
34+
35+
DatePicker(selection: $server.date, in: server.spaceDate, displayedComponents: .date, label: {
36+
Text("")
37+
})
5438
}
5539
.padding(.top)
5640
.navigationBarTitle(Text("DatePicker"))
57-
*/
41+
42+
}
43+
5844

5945
}
6046
}
@@ -69,6 +55,18 @@ class DateServer: ObservableObject {
6955
print("Date Changed: \(date)")
7056
}
7157
}
58+
59+
var spaceDate: ClosedRange<Date> {
60+
let soon = Calendar.current.date(byAdding: .year,
61+
value: -1,
62+
to: date) ?? Date()
63+
64+
let later = Calendar.current.date(byAdding: .year,
65+
value: 1,
66+
to: date) ?? Date()
67+
let speaceDate = soon...later
68+
return speaceDate
69+
}
7270
}
7371

7472

README.md

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Example:
143143

144144
```swift
145145
Text("SwiftUI")
146-
.color(.orange)
146+
.foregroundColor(.orange)
147147
.bold()
148148
.font(.system(.largeTitle))
149149
.fontWeight(.medium)
@@ -177,7 +177,7 @@ TextField(self.$name, placeholder: self.nameText, onEditingChanged: { changed in
177177
}}
178178
.padding(10)
179179
.frame(height: 50)
180-
.textFieldStyle(.roundedBorder)
180+
.textFieldStyle(RoundedBorderTextFieldStyle())
181181
.padding(EdgeInsets(top: 0, leading: 20, bottom: 0, trailing: 20))
182182

183183
```
@@ -201,8 +201,8 @@ The `Image` control is used to display images, example:
201201
```swift
202202
Image("icon")
203203
.resizable()
204-
.frame(width: Length(100),
205-
height: Length(100),
204+
.frame(width: 100,
205+
height: 100,
206206
alignment: .center)
207207
```
208208

@@ -224,10 +224,10 @@ var body: some View {
224224
Image(uiImage: self.uiImage ?? placeholderImage)
225225
.resizable()
226226
.onAppear(perform: downloadWebImage)
227-
.frame(width: Length(80),
228-
height: Length(80),
227+
.frame(width: 80,
228+
height: 80,
229229
alignment: .center)
230-
.tapAction {
230+
.onTapGesture {
231231
print("Tap ")
232232
}
233233
}
@@ -276,9 +276,12 @@ Waiting for release.
276276
Example:
277277

278278
```swift
279-
NavigationButton(destination: NavigationButtonPage()) {
280-
Text("NavigationButton").bold().color(.orange).font(.largeTitle)
281-
}.navigationBarItem(title: Text("Page"))
279+
NavigationLink(destination: NavigationButtonPage()) {
280+
Text("NavigationButton").bold()
281+
.foregroundColor(.orange)
282+
.font(.largeTitle)
283+
}
284+
.navigationBarTitle(Text("Page"))
282285
```
283286

284287
<details close>
@@ -288,23 +291,10 @@ NavigationButton(destination: NavigationButtonPage()) {
288291

289292
[🔝](#Button_D)
290293

291-
<h4 id="PresentationButton"> PresentationButton </h4>
294+
<h4 id="PresentationButton" style='color:red'> PresentationButton is deprecated</h4>
292295

293-
`PresentationButton` is used to pop up a page.
296+
`PresentationButton` ~~is used to pop up a page.~~ has deprecated, please use `NavigationLink`
294297

295-
Example:
296-
297-
```swift
298-
PresentationButton(PageRow(title: "PresentationButton", subTitle: "pop up a page"),
299-
destination: Text("I'm Text")) {
300-
print("Present 🦄")
301-
}
302-
```
303-
304-
<details close>
305-
<summary>View running results</summary>
306-
<img width="40%" src="images/example/PresentationButton.png"/>
307-
</details>
308298

309299
[🔝](#Button_D)
310300

@@ -358,16 +348,12 @@ Picker(selection: $leftIndex, label: Text("Picker")) {
358348
Example:
359349

360350
```swift
361-
DatePicker(
362-
$server.date,
363-
minimumDate: Calendar.current.date(byAdding: .year,
364-
value: -1,
365-
to: server.date),
366-
maximumDate: Calendar.current.date(byAdding: .year,
367-
value: 1,
368-
to: server.date),
369-
displayedComponents: .date
370-
)
351+
352+
DatePicker(selection: $server.date,
353+
in: server.spaceDate,
354+
displayedComponents: .date, label: {
355+
Text("")
356+
})
371357
```
372358

373359
<details close>
@@ -428,7 +414,7 @@ Stepper(value: $value, step: 2, onEditingChanged: { c in
428414

429415
[🔝](#Picker_D)
430416

431-
<h4 id="SegmentedControl"> SegmentedControl </h4>
417+
<h4 id="SegmentedControl" style="color:red">SegmentedControl is deprecated</h4>
432418

433419
`SegmentedControl ` is used for segmentation condition selection, example:
434420

@@ -615,9 +601,10 @@ ScrollView {
615601
Divider()
616602
Text("Views and ... user interface.")
617603
}
618-
.border(style, width: 1,cornerRadius: 10)
619-
.padding(10)
620-
.navigationBarTitle(Text("ScrollView"))
604+
.border(Color.gray.gradient, width: 1)
605+
.cornerRadius(10)
606+
.padding(10)
607+
.navigationBarTitle(Text("ScrollView"))
621608
```
622609

623610
<details close>
@@ -634,7 +621,7 @@ ScrollView {
634621
Example:
635622

636623
```swift
637-
let data = (0..<5).map { $0 }
624+
let data = (0..<5)
638625
var body: some View {
639626
ForEach(data) { e in
640627
Text("Hello \(e)")
@@ -705,9 +692,13 @@ Example:
705692

706693
```swift
707694
NavigationView {
708-
Text("🧚‍♂️🧚‍♀️🧜‍♂️🧜‍♀️🧞‍♂️🧞‍♀️").blur(radius: 5)
709-
Text("Swifter Swifter").bold().color(.orange).font(.largeTitle)
710-
}.navigationBarTitle(Text("NavigationView"))
695+
Text("🧚‍♂️🧚‍♀️🧜‍♂️🧜‍♀️🧞‍♂️🧞‍♀️").blur(radius: 5)
696+
Text("Swifter Swifter")
697+
.bold()
698+
.foregroundColor(.orange)
699+
.font(.largeTitle)
700+
}
701+
.navigationBarTitle(Text("NavigationView"))
711702
```
712703

713704
<details close>
@@ -757,14 +748,17 @@ Waiting for release.
757748
Example:
758749

759750
```swift
760-
presentation($showsAlert, alert: {
761-
Alert(title: Text("Hello"))
762-
})
751+
alert(isPresented: $showAlert, content: {
752+
Alert(title: Text("确定要支付这100000000美元吗?"),
753+
message: Text("请谨慎操作\n一旦确认,钱款将立即转入对方账户"),
754+
primaryButton: .destructive(Text("确认")) { print("转出中...") },
755+
secondaryButton: .cancel())
756+
}).navigationBarTitle(Text("Alert"))
763757
```
764758

765759
<details close>
766760
<summary>View running results</summary>
767-
<img width="80%" src="images/example/Alert.png"/>
761+
<img width="80%" src="images/example/AlertPage.jpg"/>
768762
</details>
769763

770764
[🔝](#Alert_D)
@@ -792,6 +786,10 @@ ActionSheet(title: Text("Title"),
792786
})])
793787
```
794788

789+
usage:
790+
```swift
791+
.actionSheet(isPresented: $showSheet, content: {sheet})
792+
```
795793
<details close>
796794
<summary>View running results</summary>
797795
<img width="80%" src="images/example/ActionSheet.png"/>
@@ -827,9 +825,9 @@ Modal(Text("Modal View"),onDismiss: {
827825
Example:
828826

829827
```swift
830-
Popover(content: Text("Popover View")) {
831-
print("Popover Dismiss !")
832-
}
828+
.popover(isPresented: $showPop, content: {
829+
ImagePage()
830+
})
833831
```
834832

835833
<details close>

0 commit comments

Comments
 (0)