-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
T17120620: CC-6770 When OS text size is 135% the segment control comp…
…onent between All videos and Playlists is gone.
- Loading branch information
Showing
3 changed files
with
163 additions
and
133 deletions.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
Modules/Presentation/Features/Video/Sources/Video/Views/TabBarView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import SwiftUI | ||
|
||
struct TabBarView: View { | ||
@Binding var currentTab: VideosTab | ||
@Namespace var namespace | ||
let videoConfig: VideoConfig | ||
|
||
static let defaultHeight: CGFloat = 44 | ||
|
||
@State private var orientation = UIDeviceOrientation.unknown | ||
|
||
var body: some View { | ||
HStack { | ||
if interfaceOrientation.isLandscape { | ||
Spacer() | ||
} | ||
ForEach(VideosTab.allCases, id: \.self) { tab in | ||
TabBarItem( | ||
currentTab: self.$currentTab, | ||
namespace: namespace.self, | ||
tabBarItemName: tab.title, | ||
tab: tab, | ||
videoConfig: videoConfig | ||
) | ||
.frame(maxWidth: orientation.isPortrait ? .infinity : 195) | ||
} | ||
if interfaceOrientation.isLandscape { | ||
Spacer() | ||
} | ||
} | ||
.frame(maxWidth: interfaceOrientation.isPortrait ? .infinity : nil) | ||
.edgesIgnoringSafeArea(.all) | ||
.background(videoConfig.colorAssets.navigationBgColor) | ||
.onRotate { newOrientation in | ||
orientation = newOrientation | ||
} | ||
} | ||
|
||
private var interfaceOrientation: UIInterfaceOrientation { | ||
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene else { | ||
return .unknown | ||
} | ||
return windowScene.interfaceOrientation | ||
} | ||
} | ||
|
||
struct TabBarItem: View { | ||
@Binding var currentTab: VideosTab | ||
let namespace: Namespace.ID | ||
|
||
var tabBarItemName: String | ||
var tab: VideosTab | ||
|
||
let videoConfig: VideoConfig | ||
|
||
var body: some View { | ||
Button( | ||
action: { currentTab = tab }, | ||
label: buttonContent | ||
) | ||
} | ||
|
||
private func buttonContent() -> some View { | ||
ZStack(alignment: .bottom) { | ||
Text(tabBarItemName) | ||
.multilineTextAlignment(.center) | ||
.font(isTabActive ? .system(.subheadline).bold() : .subheadline) | ||
.foregroundStyle( | ||
isTabActive | ||
? videoConfig.colorAssets.tabActiveIndicatorColor | ||
: videoConfig.colorAssets.tabInactiveTextColor | ||
) | ||
.frame(maxHeight: .infinity, alignment: .center) | ||
|
||
Group { | ||
if isTabActive { | ||
videoConfig.colorAssets.tabActiveIndicatorColor | ||
.frame(height: 1) | ||
.matchedGeometryEffect(id: "underline", in: namespace, properties: .frame) | ||
} else { | ||
videoConfig.colorAssets.tabInactiveIndicatorColor | ||
.frame(height: 1) | ||
} | ||
} | ||
} | ||
.animation(.spring(), value: self.currentTab) | ||
.frame(height: TabBarView.defaultHeight) | ||
} | ||
|
||
private var isTabActive: Bool { | ||
currentTab == tab | ||
} | ||
} | ||
|
||
struct Preview_TabBarView: View { | ||
@State private var currentTab: VideosTab = .all | ||
|
||
var body: some View { | ||
TabBarView( | ||
currentTab: $currentTab, | ||
videoConfig: .preview | ||
) | ||
} | ||
} | ||
|
||
#Preview { | ||
Preview_TabBarView() | ||
} | ||
|
||
#Preview { | ||
Preview_TabBarView() | ||
.preferredColorScheme(.dark) | ||
} | ||
|
||
#Preview { | ||
Preview_TabBarView() | ||
.dynamicTypeSize(.xxxLarge) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters