Skip to content

Commit c166df3

Browse files
committed
Update the UI of the example project
1 parent 41a4e74 commit c166df3

1 file changed

Lines changed: 79 additions & 60 deletions

File tree

Example/Example (Shared)/ContentView.swift

Lines changed: 79 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// Created by Manabu Nakazawa on 27/8/2022.
66
//
77

8-
import SwiftUI
98
import ResizingTextView
9+
import SwiftUI
1010

1111
struct ContentView: View {
1212
@State var text1 = ""
@@ -15,68 +15,87 @@ struct ContentView: View {
1515
@State var text4 = ""
1616

1717
var body: some View {
18-
List {
19-
let textBackgroundColor = Color.black.opacity(0.1)
20-
21-
Section("Resizing automatically (Default)") {
22-
ResizingTextView(text: $text1)
23-
.background(textBackgroundColor)
24-
}
25-
26-
Section("Fixed height, scrollable, newline characters not allowed") {
27-
ResizingTextView(
28-
text: $text2,
29-
placeholder: "Placeholder",
30-
isScrollable: true,
31-
canHaveNewLineCharacters: false)
32-
.frame(height: 80)
33-
.background(textBackgroundColor)
34-
}
35-
36-
Section("Uneditable, selectable, color/font changed") {
37-
ResizingTextView(
38-
text: $text3,
39-
isEditable: false)
40-
.font(.boldSystemFont(ofSize: 16))
41-
.foregroundColor(.magenta)
42-
.background(textBackgroundColor)
43-
}
44-
45-
Section("Uneditable, selectable, max 2 lines") {
46-
ResizingTextView(
47-
text: .constant("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."),
48-
isEditable: false,
49-
lineLimit: 2)
50-
.background(textBackgroundColor)
51-
}
52-
53-
Section("Uneditable, unselectable, max 2 lines") {
54-
ResizingTextView(
55-
text: .constant("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."),
56-
isEditable: false,
57-
isSelectable: false,
58-
lineLimit: 2)
59-
.background(textBackgroundColor)
60-
}
61-
62-
Section("Selectable, uneditable, non-greedy short label") {
63-
ResizingTextView(
64-
text: .constant("Lorem ipsum"),
65-
isEditable: false,
66-
hasGreedyWidth: false)
67-
.background(textBackgroundColor)
68-
}
69-
18+
ScrollView {
19+
VStack {
20+
ExampleSection("Resizing automatically (Default)") {
21+
ResizingTextView(text: $text1)
22+
}
23+
24+
ExampleSection("Fixed height, scrollable, newline characters not allowed") {
25+
ResizingTextView(
26+
text: $text2,
27+
placeholder: "Placeholder",
28+
isScrollable: true,
29+
canHaveNewLineCharacters: false
30+
)
31+
.frame(height: 80)
32+
}
33+
34+
ExampleSection("Uneditable, selectable, color/font changed") {
35+
ResizingTextView(
36+
text: $text3,
37+
isEditable: false
38+
)
39+
.font(.boldSystemFont(ofSize: 16))
40+
.foregroundColor(.magenta)
41+
}
42+
43+
ExampleSection("Uneditable, selectable, max 2 lines") {
44+
ResizingTextView(
45+
text: .constant("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."),
46+
isEditable: false,
47+
lineLimit: 2
48+
)
49+
}
50+
51+
ExampleSection("Uneditable, unselectable, max 2 lines") {
52+
ResizingTextView(
53+
text: .constant("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."),
54+
isEditable: false,
55+
isSelectable: false,
56+
lineLimit: 2
57+
)
58+
}
59+
60+
ExampleSection("Selectable, uneditable, non-greedy short label") {
61+
ResizingTextView(
62+
text: .constant("Lorem ipsum"),
63+
isEditable: false,
64+
hasGreedyWidth: false
65+
)
66+
}
7067
#if os(iOS)
71-
Section("No autocapitalization") {
72-
ResizingTextView(
73-
text: $text4,
74-
placeholder: "Placeholder")
75-
.autocapitalizationType(.none)
76-
.background(textBackgroundColor)
77-
}
68+
ExampleSection("No autocapitalization") {
69+
ResizingTextView(
70+
text: $text4,
71+
placeholder: "Placeholder"
72+
)
73+
.autocapitalizationType(.none)
74+
}
7875
#endif
76+
}
77+
.scenePadding()
78+
}
79+
}
80+
}
81+
82+
private struct ExampleSection<Content: View>: View {
83+
var title: String
84+
@ViewBuilder var content: () -> Content
85+
86+
init(_ title: String, content: @escaping () -> Content) {
87+
self.title = title
88+
self.content = content
89+
}
90+
91+
var body: some View {
92+
VStack(alignment: .leading) {
93+
Text(title)
94+
.font(.headline.bold())
95+
content()
7996
}
97+
.padding(.bottom, 16)
98+
.frame(maxWidth: .infinity, alignment: .leading)
8099
}
81100
}
82101

0 commit comments

Comments
 (0)