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..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/UIs/MobileAds/Sources/FixedAdsView.swift b/Surcharges/PresentationLayer/UIs/MobileAds/Sources/FixedAdsView.swift index 2241795..c649732 100644 --- a/Surcharges/PresentationLayer/UIs/MobileAds/Sources/FixedAdsView.swift +++ b/Surcharges/PresentationLayer/UIs/MobileAds/Sources/FixedAdsView.swift @@ -95,7 +95,6 @@ public struct FixedAdsView: View { } } - .background(R.color.gray100.color) .frame(minHeight: _adSize.size.width, maxHeight: _adSize.size.width) .cornerRadius(20) .readSize { size in diff --git a/Surcharges/PresentationLayer/UIs/MobileAds/Sources/ListAdsView.swift b/Surcharges/PresentationLayer/UIs/MobileAds/Sources/ListAdsView.swift index 59e03ae..915a4c7 100644 --- a/Surcharges/PresentationLayer/UIs/MobileAds/Sources/ListAdsView.swift +++ b/Surcharges/PresentationLayer/UIs/MobileAds/Sources/ListAdsView.swift @@ -30,7 +30,6 @@ public struct ListAdsView: View { .frame(height: _adSize.size.height) } .background(R.color.gray100.color) - .cornerRadius(20) .readSize { size in _adSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(size.width) } 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