Skip to content

Commit

Permalink
feat: 馃幐 [JIRA: HCPSDKFIORIUIKIT-2459] Tab Bar (#621)
Browse files Browse the repository at this point in the history
* feat: 馃幐 [JIRA: HCPSDKFIORIUIKIT-2459] Tab Bar

* feat: 馃幐 add tap audio
  • Loading branch information
xiaoyu0722 committed Dec 7, 2023
1 parent 26ae03e commit ba03a23
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Apps/Examples/Examples.xcodeproj/project.pbxproj
Expand Up @@ -74,6 +74,9 @@
B13408922B01FA0700600331 /* NavigationBarExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = B13408912B01FA0700600331 /* NavigationBarExample.swift */; };
B141D6BB29261F9E008A8BD6 /* SearchableListViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = B141D6BA29261F9E008A8BD6 /* SearchableListViewExample.swift */; };
B18D2E9F2988B07B000A1821 /* KPIHeaderExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = B18D2E9E2988B07B000A1821 /* KPIHeaderExample.swift */; };
B18D593C2B0C52C700ABB1AD /* TabViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = B18D593B2B0C52C700ABB1AD /* TabViewExample.swift */; };
B1BA1F922B19AAEE00E6C052 /* TabViewDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1BA1F912B19AAEE00E6C052 /* TabViewDetailView.swift */; };
B1BA1F942B1EC36100E6C052 /* 08 Tap.wav in Resources */ = {isa = PBXBuildFile; fileRef = B1BA1F932B1EC36100E6C052 /* 08 Tap.wav */; };
B1C7DC8129FBB13F00DC5EEB /* SPIModelExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1C7DC8029FBB13F00DC5EEB /* SPIModelExample.swift */; };
B1D41B20291A2D97004E64A5 /* DurationPickerExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1D41B1F291A2D97004E64A5 /* DurationPickerExample.swift */; };
B1D9D22A2991E056008FF5BC /* ObjectItemAvatarsExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1D9D2292991E056008FF5BC /* ObjectItemAvatarsExample.swift */; };
Expand Down Expand Up @@ -221,6 +224,9 @@
B13408912B01FA0700600331 /* NavigationBarExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationBarExample.swift; sourceTree = "<group>"; };
B141D6BA29261F9E008A8BD6 /* SearchableListViewExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchableListViewExample.swift; sourceTree = "<group>"; };
B18D2E9E2988B07B000A1821 /* KPIHeaderExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KPIHeaderExample.swift; sourceTree = "<group>"; };
B18D593B2B0C52C700ABB1AD /* TabViewExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabViewExample.swift; sourceTree = "<group>"; };
B1BA1F912B19AAEE00E6C052 /* TabViewDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabViewDetailView.swift; sourceTree = "<group>"; };
B1BA1F932B1EC36100E6C052 /* 08 Tap.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = "08 Tap.wav"; sourceTree = "<group>"; };
B1C7DC8029FBB13F00DC5EEB /* SPIModelExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPIModelExample.swift; sourceTree = "<group>"; };
B1D41B1F291A2D97004E64A5 /* DurationPickerExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DurationPickerExample.swift; sourceTree = "<group>"; };
B1D9D2292991E056008FF5BC /* ObjectItemAvatarsExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectItemAvatarsExample.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -437,6 +443,7 @@
8A5579C824C1293C0098003A /* FioriSwiftUICore */ = {
isa = PBXGroup;
children = (
B1BA1F902B19A8B500E6C052 /* TabViewExample */,
B1CC61C52AFA0856002078C1 /* NavigationBar */,
C1C764862A818BD600BCB0F7 /* SortFilter */,
B100639129C0623300AF0CA2 /* StepProgressIndicator */,
Expand Down Expand Up @@ -523,6 +530,16 @@
path = StepProgressIndicator;
sourceTree = "<group>";
};
B1BA1F902B19A8B500E6C052 /* TabViewExample */ = {
isa = PBXGroup;
children = (
B1BA1F932B1EC36100E6C052 /* 08 Tap.wav */,
B18D593B2B0C52C700ABB1AD /* TabViewExample.swift */,
B1BA1F912B19AAEE00E6C052 /* TabViewDetailView.swift */,
);
path = TabViewExample;
sourceTree = "<group>";
};
B1CC61C52AFA0856002078C1 /* NavigationBar */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -717,6 +734,7 @@
8A55796324C1286F0098003A /* LaunchScreen.storyboard in Resources */,
993A122E26A726AC0018028B /* PrivacyText.html in Resources */,
8A55796024C1286F0098003A /* Preview Assets.xcassets in Resources */,
B1BA1F942B1EC36100E6C052 /* 08 Tap.wav in Resources */,
B8D4376825EEC5E80024EE7D /* Assets.xcassets in Resources */,
9996CD03262FFEBE001B99AE /* EULA2.html in Resources */,
993A122F26A726AC0018028B /* PrivacyText.rtf in Resources */,
Expand Down Expand Up @@ -781,6 +799,7 @@
8A5579D124C1293C0098003A /* Settings.swift in Sources */,
8AD9DFB025D49967007448EC /* ContactItemActionItemsExample.swift in Sources */,
8A6D64B125AE658300D2D76C /* ExpHeaderView.swift in Sources */,
B1BA1F922B19AAEE00E6C052 /* TabViewDetailView.swift in Sources */,
B1DD864F2B07441C00D7EDFD /* UIFont+Fiori.swift in Sources */,
B8D4376F25F980340024EE7D /* ObjectCell_Spec_Jan2018.swift in Sources */,
8A5579CF24C1293C0098003A /* SettingsAxis.swift in Sources */,
Expand Down Expand Up @@ -814,6 +833,7 @@
692F338B26556A6A009B98DA /* SideBarExample.swift in Sources */,
8A5579D324C1293C0098003A /* SettingsPoint.swift in Sources */,
B80DA9BA260BBF8600C0B2E9 /* SingleActionProfiles.swift in Sources */,
B18D593C2B0C52C700ABB1AD /* TabViewExample.swift in Sources */,
8A5579D424C1293C0098003A /* SettingsBaseline.swift in Sources */,
1F90888C261A59820015A84D /* FioriButtonExample.swift in Sources */,
B8D4377125F983730024EE7D /* ObjectCell_Rules_Alignment.swift in Sources */,
Expand Down
5 changes: 5 additions & 0 deletions Apps/Examples/Examples/FioriSwiftUICore/CoreContentView.swift
Expand Up @@ -43,6 +43,11 @@ struct CoreContentView: View {
destination: NavigationBarExample()) {
Text("Customized NavigationBar")
}

NavigationLink(
destination: TabViewExample()) {
Text("Customized TabView")
}
}

NavigationLink(
Expand Down
Binary file not shown.
@@ -0,0 +1,132 @@
import AVFAudio
import FioriThemeManager
import SwiftUI

struct TabBarModel: Identifiable {
var id = UUID()
var name: String
var badge: String? = nil
var imageName: String
}

struct TabViewDetailView: View {
@Binding var numberOfTabs: Int
@Binding var isCustomColor: Bool
@Binding var isCustomSelectionIndicatorImage: Bool
@Binding var isCustomBackgroundImage: Bool
@State private var selection = 0
@State private var accendColor = Color.random
@State private var selectionAudioPlayer: AVAudioPlayer!

var tabs: [TabBarModel] = [TabBarModel(name: "bicycle", badge: "2", imageName: "bicycle"),
TabBarModel(name: "list", imageName: "list.dash"),
TabBarModel(name: "cart", badge: "NEW", imageName: "cart"),
TabBarModel(name: "person", imageName: "person.crop.circle"),
TabBarModel(name: "1", imageName: "1.square"),
TabBarModel(name: "2", imageName: "2.circle"),
TabBarModel(name: "3", imageName: "3.circle.fill")]

var handler: Binding<Int> { Binding(
get: { self.selection },
set: {
if selection != $0 {
self.selection = $0
accendColor = Color.random
}

selectionAudioPlayer?.play()
}
) }

var body: some View {
TabView(selection: handler) {
ForEach(0 ..< numberOfTabs, id: \.self) { index in
let t = tabs[index]
Group {
if index.isMultiple(of: 2) {
Color.random
} else {
List(0 ..< 20) { index in
Text("index: \(index)")
}
}
}
.badge(t.badge)
.tag(index)
.tabItem {
Label(
title: { Text(t.name) },
icon: { Image(systemName: t.imageName) }
)
}
}
}
.navigationTitle("Customized TabView")
.accentColor(accendColor)
.onAppear {
if let path = Bundle.main.path(forResource: "08 Tap", ofType: "wav") {
let url = URL(fileURLWithPath: path)
do {
selectionAudioPlayer = try AVAudioPlayer(contentsOf: url)
selectionAudioPlayer.prepareToPlay()
} catch let error as NSError {
print("Error creating AVAudioPlayer \(error)")
}
}

if isCustomColor {
customTabColor()
} else {
resetTabColor()
}
if isCustomSelectionIndicatorImage {
UITabBar.appearance().selectionIndicatorImage = UIImage(systemName: "car")
} else {
UITabBar.appearance().selectionIndicatorImage = nil
}

if isCustomBackgroundImage {
UITabBar.appearance().backgroundImage = UIImage(named: "SAPLogo")?.stretchableImage(withLeftCapWidth: 0, topCapHeight: 0)
} else {
UITabBar.appearance().backgroundImage = nil
}
}
.onDisappear {
resetTabColor()
UITabBar.appearance().selectionIndicatorImage = nil
UITabBar.appearance().backgroundImage = nil
}
}

func customTabColor() {
UITabBarItem.appearance().setTitleTextAttributes([.font: UIFont.preferredFioriFont(forTextStyle: .title3),
.foregroundColor: UIColor(Color.preferredColor(.primaryLabel))], for: .normal)
UITabBarItem.appearance().setTitleTextAttributes([.font: UIFont.preferredFioriFont(forTextStyle: .title3),
.foregroundColor: UIColor(Color.random)], for: .selected)
UITabBarItem.appearance().setBadgeTextAttributes([.font: UIFont.preferredFioriFont(forTextStyle: .callout),
.foregroundColor: UIColor(Color.random)], for: .normal)
UITabBarItem.appearance().setBadgeTextAttributes([.font: UIFont.preferredFioriFont(forTextStyle: .callout),
.foregroundColor: UIColor(Color.random)], for: .selected)
UITabBar.appearance().unselectedItemTintColor = UIColor(Color.preferredColor(.red11))
UITabBar.appearance().backgroundColor = UIColor(Color.preferredColor(.green11))
UITabBarItem.appearance().badgeColor = UIColor(Color.preferredColor(.base1))
}

func resetTabColor() {
UITabBar.appearance().unselectedItemTintColor = nil
UITabBar.appearance().backgroundColor = nil
UITabBarItem.appearance().badgeColor = UIColor.systemRed

UITabBarItem.appearance().setTitleTextAttributes([:], for: .normal)
UITabBarItem.appearance().setTitleTextAttributes([:], for: .selected)
UITabBarItem.appearance().setBadgeTextAttributes([:], for: .normal)
UITabBarItem.appearance().setBadgeTextAttributes([:], for: .selected)
}
}

#Preview {
TabViewDetailView(numberOfTabs: .constant(6),
isCustomColor: .constant(false),
isCustomSelectionIndicatorImage: .constant(false),
isCustomBackgroundImage: .constant(true))
}
@@ -0,0 +1,61 @@
import FioriSwiftUICore
import SwiftUI

struct TabViewExample: View {
@State var isPresented: Bool = false
@State var numberOfTabs: Int = 4
@State var isModalPresentation: Bool = false
@State var isCustomColor: Bool = false
@State var isCustomSelectionIndicatorImage: Bool = false
@State var isCustomBackgroundImage: Bool = false

var body: some View {
Form {
if isModalPresentation {
HStack {
Text("Selecte to Test")
Spacer()
}
.contentShape(Rectangle())
.onTapGesture {
isPresented.toggle()
}
.sheet(isPresented: $isPresented) {
TabViewDetailView(numberOfTabs: $numberOfTabs,
isCustomColor: $isCustomColor,
isCustomSelectionIndicatorImage: $isCustomSelectionIndicatorImage,
isCustomBackgroundImage: $isCustomBackgroundImage)
}
} else {
NavigationLink {
TabViewDetailView(numberOfTabs: $numberOfTabs,
isCustomColor: $isCustomColor,
isCustomSelectionIndicatorImage: $isCustomSelectionIndicatorImage,
isCustomBackgroundImage: $isCustomBackgroundImage)
} label: {
Text("Selecte to Test")
}
}

Picker("Number of Tabs", selection: $numberOfTabs) {
Text("2").tag(2)
Text("3").tag(3)
Text("4").tag(4)
Text("5").tag(5)
Text("6").tag(6)
}

Toggle("Modal Presentation", isOn: $isModalPresentation)
Toggle("Custom Colors", isOn: $isCustomColor)
Toggle("Custom Selection Indicator Image", isOn: $isCustomSelectionIndicatorImage)
Toggle("Custom Background Image", isOn: $isCustomBackgroundImage)
}
.navigationTitle("TabView Example")
}
}

#Preview {
NavigationStack {
TabViewExample()
}
}

0 comments on commit ba03a23

Please sign in to comment.