Skip to content

Commit e997ea7

Browse files
authored
Refactor the UI layout of ImagenScreen to solve the navigation flicker (#1719)
* change ImagenScreen UI from ZStack to ScrollView * change fix size of images to flexible * center the progressoverlay in firebase Imagen * remove unrelated comments in imagen
1 parent a72d3fe commit e997ea7

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

firebaseai/ImagenScreen/ImagenScreen.swift

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,26 @@ struct ImagenScreen: View {
3434

3535
var body: some View {
3636
ZStack {
37-
VStack {
38-
InputField("Enter a prompt to generate an image", text: $viewModel.userInput) {
39-
Image(
40-
systemName: viewModel.inProgress ? "stop.circle.fill" : "paperplane.circle.fill"
41-
)
42-
.font(.title)
43-
}
44-
.focused($focusedField, equals: .message)
45-
.onSubmit { sendOrStop() }
37+
ScrollView {
38+
VStack {
39+
InputField("Enter a prompt to generate an image", text: $viewModel.userInput) {
40+
Image(
41+
systemName: viewModel.inProgress ? "stop.circle.fill" : "paperplane.circle.fill"
42+
)
43+
.font(.title)
44+
}
45+
.focused($focusedField, equals: .message)
46+
.onSubmit { sendOrStop() }
4647

47-
ScrollView {
4848
let spacing: CGFloat = 10
4949
LazyVGrid(columns: [
50-
GridItem(.fixed(UIScreen.main.bounds.width / 2 - spacing), spacing: spacing),
51-
GridItem(.fixed(UIScreen.main.bounds.width / 2 - spacing), spacing: spacing),
50+
GridItem(.flexible(), spacing: spacing),
51+
GridItem(.flexible(), spacing: spacing),
5252
], spacing: spacing) {
5353
ForEach(viewModel.images, id: \.self) { image in
5454
Image(uiImage: image)
5555
.resizable()
56-
.aspectRatio(contentMode: .fill)
57-
.frame(width: UIScreen.main.bounds.width / 2 - spacing,
58-
height: UIScreen.main.bounds.width / 2 - spacing)
56+
.aspectRatio(1, contentMode: .fill)
5957
.cornerRadius(12)
6058
.clipped()
6159
}
@@ -95,18 +93,23 @@ struct ImagenScreen: View {
9593
struct ProgressOverlay: View {
9694
var body: some View {
9795
ZStack {
98-
RoundedRectangle(cornerRadius: 16)
99-
.fill(Material.ultraThinMaterial)
100-
.frame(width: 120, height: 100)
101-
.shadow(radius: 8)
96+
Color.black.opacity(0.3)
97+
.ignoresSafeArea()
98+
99+
ZStack {
100+
RoundedRectangle(cornerRadius: 16)
101+
.fill(Material.ultraThinMaterial)
102+
.frame(width: 120, height: 100)
103+
.shadow(radius: 8)
102104

103-
VStack(spacing: 12) {
104-
ProgressView()
105-
.scaleEffect(1.5)
105+
VStack(spacing: 12) {
106+
ProgressView()
107+
.scaleEffect(1.5)
106108

107-
Text("Loading...")
108-
.font(.subheadline)
109-
.foregroundColor(.secondary)
109+
Text("Loading...")
110+
.font(.subheadline)
111+
.foregroundColor(.secondary)
112+
}
110113
}
111114
}
112115
}

0 commit comments

Comments
 (0)