-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
I'm implementing the a Rectangle
widget (#26).
Here is what a Rectangle view in SwiftUI can do:

The swift code for that looks like so:
import SwiftUI
struct RectanglePage: View {
var body: some View {
ScrollView {
VStack(spacing: 20) {
// Basic rectangle
Rectangle()
.fill(Color.blue)
.frame(width: 200, height: 100)
// Rectangle with stroke
Rectangle()
.stroke(Color.red, lineWidth: 4)
.frame(width: 200, height: 100)
// Rectangle with rounded corners
Rectangle()
.fill(Color.green)
.cornerRadius(20)
.frame(width: 200, height: 100)
// Rectangle with gradient fill
Rectangle()
.fill(LinearGradient(gradient: Gradient(colors: [.yellow, .orange]), startPoint: .leading, endPoint: .trailing))
.frame(width: 200, height: 100)
// Rectangle with shadow
Rectangle()
.fill(Color.purple)
.shadow(color: .gray, radius: 10, x: 0, y: 10)
.frame(width: 200, height: 100)
}
}
}
}
struct RectanglePage_Previews: PreviewProvider {
static var previews: some View {
RectanglePage()
}
}
In that code you can see a number of different modifier methods:
fill
frame
stroke
cornerRadius
shadow
One of the guiding principles is that swift_ui
doesn't use modifier methods.
How to avoid modifier methods gives a hypothetical alternative for Flutter:
Frame(
width: 200,
height: 100,
child: Fill(
Colors.purple,
child: Ellipse(),
),
);
Is this how we want to define the API, by creating widgets for all of the following?
Fill
Frame
Stroke
CornerRadius
Shadow
Not widget properties?
Metadata
Metadata
Assignees
Labels
No labels