From 6d7b0a18c1b06a282698f485ffccb245a06bf8b7 Mon Sep 17 00:00:00 2001 From: Bonsung Koo Date: Sat, 1 Feb 2025 16:07:18 +1300 Subject: [PATCH 1/2] Ads view supporting dark mode now. #58 (#60) --- .../Text+extension/blurBackground.swift | 6 ---- .../UIs/Main/Sources/MainView.swift | 31 ++++++++++++------- .../UIs/MobileAds/Sources/FixedAdsView.swift | 1 - .../UIs/MobileAds/Sources/ListAdsView.swift | 1 - 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Surcharges/PresentationLayer/UIs/CommonUI/Sources/Text+extension/blurBackground.swift b/Surcharges/PresentationLayer/UIs/CommonUI/Sources/Text+extension/blurBackground.swift index 25c60bb..32826ef 100644 --- a/Surcharges/PresentationLayer/UIs/CommonUI/Sources/Text+extension/blurBackground.swift +++ b/Surcharges/PresentationLayer/UIs/CommonUI/Sources/Text+extension/blurBackground.swift @@ -13,17 +13,11 @@ import Resources public extension View { func blurBackground() -> some View { self - .padding([.top, .bottom], 10) - .padding([.leading, .trailing], 20) - .frame(maxWidth: .infinity, alignment: .leading) .background(.ultraThinMaterial, in: Rectangle()) } func blurRoundedBackground(cornerRadius: CGFloat) -> some View { self - .padding([.top, .bottom], 10) - .padding([.leading, .trailing], 20) - .frame(maxWidth: .infinity, alignment: .leading) .background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: cornerRadius)) } } diff --git a/Surcharges/PresentationLayer/UIs/Main/Sources/MainView.swift b/Surcharges/PresentationLayer/UIs/Main/Sources/MainView.swift index 05df6ad..d383866 100644 --- a/Surcharges/PresentationLayer/UIs/Main/Sources/MainView.swift +++ b/Surcharges/PresentationLayer/UIs/Main/Sources/MainView.swift @@ -74,10 +74,6 @@ public struct MainView Date: Sat, 1 Feb 2025 16:57:14 +1300 Subject: [PATCH 2/2] Main UI is re-organised. #59 (#61) --- .../UIs/Main/Sources/MainView.swift | 206 ++++++------------ .../UIs/Main/Sources/Search/SearchView.swift | 120 ++++++++++ .../Sources/Main/MainViewModelProtocol.swift | 13 +- .../Sources/Main/MainViewModel.swift | 4 +- 4 files changed, 193 insertions(+), 150 deletions(-) create mode 100644 Surcharges/PresentationLayer/UIs/Main/Sources/Search/SearchView.swift diff --git a/Surcharges/PresentationLayer/UIs/Main/Sources/MainView.swift b/Surcharges/PresentationLayer/UIs/Main/Sources/MainView.swift index d383866..c144ca4 100644 --- a/Surcharges/PresentationLayer/UIs/Main/Sources/MainView.swift +++ b/Surcharges/PresentationLayer/UIs/Main/Sources/MainView.swift @@ -24,9 +24,6 @@ public struct MainView: View { + + private let _useLocationTip = UseLocationTip() + @State private var _showLocationDeniedAlert = false + @StateObject private var _viewModel: VM + + @FocusState private var _isSearchTextFeildFocused: Bool + + init(viewModel: StateObject) { + __viewModel = viewModel + } + + var body: some View { + HStack(spacing: 10) { + + Button { + + if _viewModel.isDeniedToUseUserLocation { + _showLocationDeniedAlert.toggle() + } else { + + withAnimation { + _viewModel.toggleUserLocation() + } + + _useLocationTip.invalidate(reason: .actionPerformed) + + } + + } label: { + + if _viewModel.isDeniedToUseUserLocation { + Image(systemName: "location.slash") + .foregroundStyle(R.color.blue600.color) + } else { + Image(systemName: _viewModel.isUserLocationOn ? "location.fill" : "location") + .foregroundStyle(R.color.blue600.color) + } + + } + .buttonStyle(.plain) + .contentTransition(.symbolEffect(.replace)) + .alert( + R.string.localizable.alertUseLocationDeniedTitle(), + isPresented: $_showLocationDeniedAlert + ) { + + Button { + + UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:], completionHandler: nil) + + } label: { + Text(R.string.localizable.goToSettings()) + } + + Button(role: .cancel) { + _showLocationDeniedAlert.toggle() + } label: { + Text(R.string.localizable.close()) + } + + } message: { + Text(R.string.localizable.alertUseLocationDeniedMessage()) + } + .popoverTip(_useLocationTip, arrowEdge: .leading) { action in + withAnimation { + _viewModel.toggleUserLocation() + } + _useLocationTip.invalidate(reason: .actionPerformed) + } + + TextField(R.string.localizable.searchBoxPlaceholder(), text: $_viewModel.searchText) + .textFieldStyle(.roundedBorder) + .font(.body) + .disabled(_viewModel.isLoading) + .onSubmit { + + if _viewModel.canSearch { + Task { + await _viewModel.search() + } + } + + } + .submitLabel(.search) + .focused($_isSearchTextFeildFocused) + .onChange(of: _isSearchTextFeildFocused, { _, newValue in + if newValue { + UseLocationTip.tryToSearch.toggle() + } + }) + + Button { + + Task { + await _viewModel.search() + } + + } label: { + Text(R.string.localizable.searchButtonTitle()) + .font(.body) + .disabled(!_viewModel.canSearch) + } + + } + } +} diff --git a/Surcharges/PresentationLayer/ViewModelProtocols/Sources/Main/MainViewModelProtocol.swift b/Surcharges/PresentationLayer/ViewModelProtocols/Sources/Main/MainViewModelProtocol.swift index 51867e3..baf1f45 100644 --- a/Surcharges/PresentationLayer/ViewModelProtocols/Sources/Main/MainViewModelProtocol.swift +++ b/Surcharges/PresentationLayer/ViewModelProtocols/Sources/Main/MainViewModelProtocol.swift @@ -13,12 +13,13 @@ import Models public protocol MainViewModelProtocol: ViewModelProtocol { var mainModel: MainModel { get set } var searchText: String { get set } - var searchedText: String { get set } - var isLoading: Bool { get set } - var noResults: Bool { get set } - var canSearch: Bool { get set } - var isDeniedToUseUserLocation: Bool { get set } - var isUserLocationOn: Bool { get set } + var searchedText: String { get } + var showWelcome: Bool { get } + var isLoading: Bool { get } + var noResults: Bool { get } + var canSearch: Bool { get } + var isDeniedToUseUserLocation: Bool { get } + var isUserLocationOn: Bool { get } func search() async func next() async diff --git a/Surcharges/PresentationLayer/ViewModels/Sources/Main/MainViewModel.swift b/Surcharges/PresentationLayer/ViewModels/Sources/Main/MainViewModel.swift index 8a2de3f..173b126 100644 --- a/Surcharges/PresentationLayer/ViewModels/Sources/Main/MainViewModel.swift +++ b/Surcharges/PresentationLayer/ViewModels/Sources/Main/MainViewModel.swift @@ -25,6 +25,7 @@ public final class MainViewModel< @Published public var mainModel: MainModel = .init(places: [], isExistNextPage: false) @Published public var searchText: String = "" @Published public var searchedText: String = "" + @Published public var showWelcome: Bool = true @Published public var isLoading: Bool = false @Published public var noResults: Bool = false @Published public var canSearch: Bool = false @@ -62,6 +63,8 @@ public final class MainViewModel< _nextPageToken = nil isLoading = true + showWelcome = false + searchedText = searchText var userLocation: Location? @@ -81,7 +84,6 @@ public final class MainViewModel< ) ) - searchedText = searchText noResults = false let places = getPlacesResult.items.map { item -> Place in