Skip to content

Refactor the UI layout of ImagenScreen to solve the navigation flicker #1719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions firebaseai/ImagenScreen/ImagenScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,26 @@ struct ImagenScreen: View {

var body: some View {
ZStack {
VStack {
InputField("Enter a prompt to generate an image", text: $viewModel.userInput) {
Image(
systemName: viewModel.inProgress ? "stop.circle.fill" : "paperplane.circle.fill"
)
.font(.title)
}
.focused($focusedField, equals: .message)
.onSubmit { sendOrStop() }
ScrollView {
VStack {
InputField("Enter a prompt to generate an image", text: $viewModel.userInput) {
Image(
systemName: viewModel.inProgress ? "stop.circle.fill" : "paperplane.circle.fill"
)
.font(.title)
}
.focused($focusedField, equals: .message)
.onSubmit { sendOrStop() }

ScrollView {
let spacing: CGFloat = 10
LazyVGrid(columns: [
GridItem(.fixed(UIScreen.main.bounds.width / 2 - spacing), spacing: spacing),
GridItem(.fixed(UIScreen.main.bounds.width / 2 - spacing), spacing: spacing),
GridItem(.flexible(), spacing: spacing),
GridItem(.flexible(), spacing: spacing),
], spacing: spacing) {
ForEach(viewModel.images, id: \.self) { image in
Image(uiImage: image)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: UIScreen.main.bounds.width / 2 - spacing,
height: UIScreen.main.bounds.width / 2 - spacing)
.aspectRatio(1, contentMode: .fill)
.cornerRadius(12)
.clipped()
}
Expand Down Expand Up @@ -95,18 +93,23 @@ struct ImagenScreen: View {
struct ProgressOverlay: View {
var body: some View {
ZStack {
RoundedRectangle(cornerRadius: 16)
.fill(Material.ultraThinMaterial)
.frame(width: 120, height: 100)
.shadow(radius: 8)
Color.black.opacity(0.3)
.ignoresSafeArea()

ZStack {
RoundedRectangle(cornerRadius: 16)
.fill(Material.ultraThinMaterial)
.frame(width: 120, height: 100)
.shadow(radius: 8)

VStack(spacing: 12) {
ProgressView()
.scaleEffect(1.5)
VStack(spacing: 12) {
ProgressView()
.scaleEffect(1.5)

Text("Loading...")
.font(.subheadline)
.foregroundColor(.secondary)
Text("Loading...")
.font(.subheadline)
.foregroundColor(.secondary)
}
}
}
}
Expand Down
Loading