Skip to content

Commit

Permalink
[FIX][Fixed BottomTabBar], [DEV][Added dark-light theme support]
Browse files Browse the repository at this point in the history
  • Loading branch information
developersancho committed Mar 5, 2022
1 parent d0cef3a commit 0e2d4c9
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 35 deletions.
16 changes: 16 additions & 0 deletions SwiftRorty.iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
E26BD3A327D01629006CA548 /* DetailHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E26BD3A227D01629006CA548 /* DetailHeaderView.swift */; };
E26BD3A527D01769006CA548 /* DetailContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E26BD3A427D01769006CA548 /* DetailContentView.swift */; };
E28A38BF27C94730005DD497 /* DtoExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = E28A38BE27C94730005DD497 /* DtoExtension.swift */; };
E2900B9627D3F6080055AD96 /* CheckboxToggleStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2900B9527D3F6080055AD96 /* CheckboxToggleStyle.swift */; };
E2900B9827D3F6290055AD96 /* VerticalToggleStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2900B9727D3F6290055AD96 /* VerticalToggleStyle.swift */; };
E2900B9A27D3F74A0055AD96 /* ColoredToggleStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2900B9927D3F74A0055AD96 /* ColoredToggleStyle.swift */; };
E2900B9C27D3FF720055AD96 /* UITabBarControllerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2900B9B27D3FF720055AD96 /* UITabBarControllerExtension.swift */; };
E2991AA927AC72ED00BF4B9A /* Status.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2991AA827AC72ED00BF4B9A /* Status.swift */; };
E2991AAF27AC740800BF4B9A /* LocationInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2991AAE27AC740800BF4B9A /* LocationInfo.swift */; };
E2991AB127AC760E00BF4B9A /* LocationResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2991AB027AC760E00BF4B9A /* LocationResponse.swift */; };
Expand Down Expand Up @@ -147,6 +151,10 @@
E26BD3A227D01629006CA548 /* DetailHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailHeaderView.swift; sourceTree = "<group>"; };
E26BD3A427D01769006CA548 /* DetailContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailContentView.swift; sourceTree = "<group>"; };
E28A38BE27C94730005DD497 /* DtoExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DtoExtension.swift; sourceTree = "<group>"; };
E2900B9527D3F6080055AD96 /* CheckboxToggleStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxToggleStyle.swift; sourceTree = "<group>"; };
E2900B9727D3F6290055AD96 /* VerticalToggleStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerticalToggleStyle.swift; sourceTree = "<group>"; };
E2900B9927D3F74A0055AD96 /* ColoredToggleStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColoredToggleStyle.swift; sourceTree = "<group>"; };
E2900B9B27D3FF720055AD96 /* UITabBarControllerExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITabBarControllerExtension.swift; sourceTree = "<group>"; };
E2991AA827AC72ED00BF4B9A /* Status.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Status.swift; sourceTree = "<group>"; };
E2991AAE27AC740800BF4B9A /* LocationInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationInfo.swift; sourceTree = "<group>"; };
E2991AB027AC760E00BF4B9A /* LocationResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationResponse.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -454,6 +462,9 @@
isa = PBXGroup;
children = (
E267D17627C9189700254746 /* LottieView.swift */,
E2900B9527D3F6080055AD96 /* CheckboxToggleStyle.swift */,
E2900B9727D3F6290055AD96 /* VerticalToggleStyle.swift */,
E2900B9927D3F74A0055AD96 /* ColoredToggleStyle.swift */,
);
path = component;
sourceTree = "<group>";
Expand Down Expand Up @@ -566,6 +577,7 @@
E2AF0A4027CD88FD0012EE85 /* UINavigationControllerExtension.swift */,
E2B5A95A27D0223700C14287 /* UIApplicationExtension.swift */,
E2B5A95E27D0258200C14287 /* BundleExtension.swift */,
E2900B9B27D3FF720055AD96 /* UITabBarControllerExtension.swift */,
);
path = extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -838,12 +850,14 @@
E232FA0627CD4D570073FCC8 /* Endpoint.swift in Sources */,
E2D5A98327C96E3E0017DA32 /* APIMethod.swift in Sources */,
E232FA1B27CD6DC10073FCC8 /* FontTemplateModifier.swift in Sources */,
E2900B9827D3F6290055AD96 /* VerticalToggleStyle.swift in Sources */,
E2D5A99127C9986C0017DA32 /* CharacterRow.swift in Sources */,
E26BD39F27CFFE51006CA548 /* DetailViewModel.swift in Sources */,
E232FA1727CD6C9D0073FCC8 /* AppFont.swift in Sources */,
E2991AAF27AC740800BF4B9A /* LocationInfo.swift in Sources */,
E2291D6E27A5F362006D3FD8 /* CharactersViewModel.swift in Sources */,
E232FA0927CD4DBF0073FCC8 /* Color.swift in Sources */,
E2900B9627D3F6080055AD96 /* CheckboxToggleStyle.swift in Sources */,
E2555C0B27A872A2007E5266 /* FavoritesViewModel.swift in Sources */,
E232FA1927CD6D9B0073FCC8 /* FontTemplate.swift in Sources */,
E2512DB227C830FF00FC6129 /* StringExtension.swift in Sources */,
Expand All @@ -865,6 +879,7 @@
E2991ABD27AC777300BF4B9A /* CharacterResponse.swift in Sources */,
E2512DAC27C82A5E00FC6129 /* LocationDto.swift in Sources */,
E26BD3A327D01629006CA548 /* DetailHeaderView.swift in Sources */,
E2900B9A27D3F74A0055AD96 /* ColoredToggleStyle.swift in Sources */,
E2AD779C27CAC242006565C2 /* RestClientErrors.swift in Sources */,
E2B5A95D27D0237600C14287 /* DetailStatusView.swift in Sources */,
E2555C0327A87220007E5266 /* FavoriteDao.swift in Sources */,
Expand All @@ -879,6 +894,7 @@
E2991ABB27AC771E00BF4B9A /* CharacterInfo.swift in Sources */,
E28A38BF27C94730005DD497 /* DtoExtension.swift in Sources */,
E2291D3327A5E908006D3FD8 /* SwiftRorty_iOSApp.swift in Sources */,
E2900B9C27D3FF720055AD96 /* UITabBarControllerExtension.swift in Sources */,
E2991AB727AC76D400BF4B9A /* Origin.swift in Sources */,
E2AD779E27CACD8D006565C2 /* CharacterListDto.swift in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.961",
"green" : "0.949",
"red" : "0.961"
"blue" : "0xF5",
"green" : "0xF1",
"red" : "0xF5"
}
},
"idiom" : "universal"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x2E",
"green" : "0x29",
"red" : "0x24"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xEE",
"green" : "0xEE",
"red" : "0xEE"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
5 changes: 4 additions & 1 deletion SwiftRorty.iOS/SwiftRorty_iOSApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import SwiftUI

@main
struct SwiftRorty_iOSApp: App {

@AppStorage("isDarkMode") private var isDarkMode = false

var body: some Scene {
WindowGroup {
SplashScreen()
SplashScreen().preferredColorScheme(isDarkMode ? .dark : .light)
}
}
}
21 changes: 21 additions & 0 deletions SwiftRorty.iOS/component/CheckboxToggleStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// CheckboxToggleStyle.swift
// SwiftRorty.iOS
//
// Created by developersancho on 5.03.2022.
//

import SwiftUI

struct CheckboxToggleStyle: ToggleStyle {
func makeBody(configuration: Configuration) -> some View {
return HStack {
configuration.label
Spacer()
Image(systemName: configuration.isOn ? "checkmark.square" : "square")
.resizable()
.frame(width: 22, height: 22)
.onTapGesture { configuration.isOn.toggle() }
}
}
}
34 changes: 34 additions & 0 deletions SwiftRorty.iOS/component/ColoredToggleStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// ColoredToggleStyle.swift
// SwiftRorty.iOS
//
// Created by developersancho on 5.03.2022.
//

import SwiftUI

struct ColoredToggleStyle: ToggleStyle {
var onColor = Color(UIColor.systemGray5)
var offColor = Color(UIColor.systemGray5)
var thumbColor = Color.ToggleRed

func makeBody(configuration: Self.Configuration) -> some View {
HStack {
configuration.label // The text (or view) portion of the Toggle
Spacer()
RoundedRectangle(cornerRadius: 16, style: .circular)
.fill(configuration.isOn ? onColor : offColor)
.frame(width: 50, height: 29)
.overlay(
Circle()
.fill(thumbColor)
.shadow(radius: 1, x: 0, y: 1)
.padding(1.5)
.offset(x: configuration.isOn ? 10 : -10))
.animation(Animation.easeInOut(duration: 0.2))
.onTapGesture { configuration.isOn.toggle() }
}
.font(.title)
//.padding(.horizontal)
}
}
22 changes: 22 additions & 0 deletions SwiftRorty.iOS/component/VerticalToggleStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// VerticalToggleStyle.swift
// SwiftRorty.iOS
//
// Created by developersancho on 5.03.2022.
//

import SwiftUI

struct VerticalToggleStyle: ToggleStyle {
func makeBody(configuration: Configuration) -> some View {
return VStack(alignment: .leading) {
Toggle(configuration).labelsHidden()
}
.frame(width: .infinity)
.padding()
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(configuration.isOn ? Color.green: Color.gray, lineWidth: 2) // <4>
)
}
}
26 changes: 26 additions & 0 deletions SwiftRorty.iOS/extensions/UITabBarControllerExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// UITabBarControllerExtension.swift
// SwiftRorty.iOS
//
// Created by developersancho on 5.03.2022.
//

import Foundation
import SwiftUI

//extension UITabBarController {
// override open func viewDidAppear(_ animated: Bool) {
// super.viewDidAppear(animated)
// let appeareance = UITabBarAppearance()
// appeareance.backgroundColor = UIColor(Color.Primary)
//
// // Use this appearance when scrolling behind the TabView:
// UITabBar.appearance().standardAppearance = appeareance
// // Use this appearance when scrolled all the way up:
// UITabBar.appearance().scrollEdgeAppearance = appeareance
//
// //UITabBar.appearance().backgroundColor = UIColor(Color.Primary)
// UITabBar.appearance().barTintColor = UIColor(Color.Primary)
// UITabBar.appearance().unselectedItemTintColor = UIColor(Color.UnSelectedBottomItem)
// }
//}
13 changes: 5 additions & 8 deletions SwiftRorty.iOS/presentation/features/detail/DetailScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@ struct DetailScreen: View {

init(id: Int) {
_characterId = State(initialValue: id)
UITabBar.appearance().barTintColor = UIColor(Color.Primary)
}

var body: some View {
ZStack {
Color.Background.edgesIgnoringSafeArea(.all)
LazyVStack {
ScrollView {
LazyVStack {
DetailHeaderView(dto: viewModel.dto)
DetailContentView(contents: viewModel.details, dto: viewModel.dto)
}.padding(12)
}
ScrollView {
LazyVStack {
DetailHeaderView(dto: viewModel.dto)
DetailContentView(contents: viewModel.details, dto: viewModel.dto)
}.padding(12)
}
}
.navigationBarTitleDisplayMode(.inline)
Expand Down
38 changes: 18 additions & 20 deletions SwiftRorty.iOS/presentation/features/home/HomeScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,34 @@ import SwiftUI

struct HomeScreen: View {

// init () {
// let coloredAppearance = UINavigationBarAppearance()
//
// // this overrides everything you have set up earlier.
// coloredAppearance.configureWithTransparentBackground()
// coloredAppearance.backgroundColor = UIColor(Color.Primary)
//
// // to make everything work normally
// UINavigationBar.appearance().standardAppearance = coloredAppearance
// UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance
// }
init() {
let appeareance = UITabBarAppearance()
appeareance.backgroundColor = UIColor(Color.Primary)

// Use this appearance when scrolling behind the TabView:
UITabBar.appearance().standardAppearance = appeareance
// Use this appearance when scrolled all the way up:
UITabBar.appearance().scrollEdgeAppearance = appeareance

//UITabBar.appearance().backgroundColor = UIColor(Color.Primary)
UITabBar.appearance().barTintColor = UIColor(Color.Primary)
UITabBar.appearance().unselectedItemTintColor = UIColor(Color.UnSelectedBottomItem)
//UITabBar.appearance().isTranslucent = false

}

@State var uiTabarController: UITabBarController?

var body: some View {
TabView {
CharactersScreen().tabItem {
Label("Characters", systemImage: "magazine")
Label("Characters", systemImage: "magazine").fontTemplate(AppFontTemplate.body5)
}
FavoritesScreen().tabItem {
Label("Favorites", systemImage: "heart")
Label("Favorites", systemImage: "heart").fontTemplate(AppFontTemplate.body5)
}
SettingsScreen().tabItem {
Label("Settings", systemImage: "gearshape")
Label("Settings", systemImage: "gearshape").fontTemplate(AppFontTemplate.body5)
}
}
.onAppear() {
UITabBar.appearance().barTintColor = UIColor(Color.Primary)
UITabBar.appearance().unselectedItemTintColor = UIColor(Color.UnSelectedBottomItem)
}
.accentColor(Color.SelectedBottomItem)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

struct SettingsScreen: View {
@State private var nightMode = false
@AppStorage("isDarkMode") private var isDarkMode = false

fileprivate func SettingsContentView() -> some View {
return ZStack(alignment: .topLeading) {
Expand All @@ -20,8 +20,12 @@ struct SettingsScreen: View {
Text("Theme Mode")
.fontTemplate(AppFontTemplate.body4)
Spacer()
Toggle("", isOn: $nightMode)
.toggleStyle(SwitchToggleStyle(tint: .ToggleRed))
Toggle("", isOn: $isDarkMode)
.toggleStyle(ColoredToggleStyle())
//.toggleStyle(SwitchToggleStyle(tint: .ToggleRed))
.onChange(of: isDarkMode, perform: { value in

})
}
Divider()
HStack(alignment: .center) {
Expand Down
4 changes: 4 additions & 0 deletions SwiftRorty.iOS/theme/Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ extension Color {
static let Card = Color(Color.Key.card.rawValue)
static let Text = Color(Color.Key.text.rawValue)
static let ToggleRed = Color(Color.Key.toggleRed.rawValue)
static let BackgroundDark = Color(Color.Key.backgroundDark.rawValue)
static let BackgroundLight = Color(Color.Key.backgroundLight.rawValue)

enum Key: String {
case primary = "Primary"
Expand All @@ -31,5 +33,7 @@ extension Color {
case card = "Card"
case text = "Text"
case toggleRed = "ToggleRed"
case backgroundDark = "BackgroundDark"
case backgroundLight = "BackgroundLight"
}
}
4 changes: 4 additions & 0 deletions SwiftRorty.iOS/theme/fonts/AppFontTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ struct AppFontTemplate {
weight: .bold,
foregroundColor: .Text)

static let body5 = FontTemplate(font: Font.custom(AppFont.bold.rawValue, size: 12.0),
weight: .medium,
foregroundColor: .Text)

}

0 comments on commit 0e2d4c9

Please sign in to comment.