Skip to content
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

Reader: Fix navigation button animation issues #22808

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,29 @@ struct ReaderNavigationButton: View {
}

private func menuLabel(for item: ReaderTabItem) -> some View {
HStack(spacing: 4.0) {
item.image
.frame(width: 24.0, height: 24.0)
.foregroundColor(Colors.primary)
Text(item.title)
.foregroundStyle(Colors.primary)
.font(.subheadline.weight(.semibold))
.minimumScaleFactor(0.1) // prevents the text from truncating while in transition.
.frame(minHeight: 24.0)
Image("reader-menu-chevron-down")
.frame(width: 16.0, height: 16.0)
.foregroundColor(Colors.primary)
/// There's a bug/unexpected behavior with how `SwiftUI.Menu`'s label "twitches" when it's animated.
/// Using `ZStack` is a hack to prevent the "container" view from twitching during animation.
ZStack {
// This is used for the background component.
Capsule().fill(Colors.background)

HStack(spacing: 4.0) {
item.image
.frame(width: 24.0, height: 24.0)
.foregroundColor(Colors.primary)
Text(item.title)
.foregroundStyle(Colors.primary)
.font(.subheadline.weight(.semibold))
.minimumScaleFactor(0.1) // prevents the text from truncating while in transition.
.frame(minHeight: 24.0)
Image("reader-menu-chevron-down")
.frame(width: 16.0, height: 16.0)
.foregroundColor(Colors.primary)
}
.padding(.vertical, 6.0)
.padding(.leading, item.image == nil ? 16.0 : 8.0)
.padding(.trailing, 12.0)
}
.padding(.vertical, 6.0)
.padding(.leading, item.image == nil ? 16.0 : 8.0)
.padding(.trailing, 12.0)
.background(Colors.background)
.clipShape(Capsule())
}

private func menuButton(for item: ReaderTabItem) -> some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct ReaderNavigationMenu: View {
HStack {
ReaderNavigationButton(viewModel: viewModel)
.frame(maxHeight: .infinity)
.zIndex(1)
.animation(.easeInOut, value: viewModel.selectedItem)
streamFilterView
// add some empty space so that the last filter chip doesn't get covered by the gradient mask.
Expand Down
Loading