Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Banners V2 #1428

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "Vector.svg",
"filename" : "iconBannerClose.pdf",
"idiom" : "universal"
}
],
Expand Down

This file was deleted.

Binary file not shown.
2 changes: 1 addition & 1 deletion novawallet/Common/Configs/ApplicationConfigs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ extension ApplicationConfig: ApplicationConfigProtocol {
}

var bannersContentPath: String {
"https://raw.githubusercontent.com/novasamatech/nova-utils/refs/heads/master/banners/content/"
"https://raw.githubusercontent.com/novasamatech/nova-utils/refs/heads/master/banners/v2/content/"
}

// swiftlint:enable line_length
Expand Down
52 changes: 41 additions & 11 deletions novawallet/Modules/Banners/BannersInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ final class BannersInteractor {
// MARK: Private

private extension BannersInteractor {
func fetchBanners(for locale: Locale) {
let fullFetchWrapper = createFullFetchWrapper(for: locale)
func fetchBanners(
for locale: Locale,
availableTextWidth: CGFloat
) {
let fullFetchWrapper = createFullFetchWrapper(
for: locale,
availableTextWidth: availableTextWidth
)

execute(
wrapper: fullFetchWrapper,
Expand All @@ -48,20 +54,26 @@ private extension BannersInteractor {
}
}

func createFullFetchWrapper(for locale: Locale) -> CompoundOperationWrapper<BannersFetchResult> {
func createFullFetchWrapper(
for locale: Locale,
availableTextWidth: CGFloat
) -> CompoundOperationWrapper<BannersFetchResult> {
let backgroundImageInfo = CommonImageInfo(
size: CGSize(width: 343, height: 110),
scale: UIScreen.main.scale
)
let contentImageInfo = CommonImageInfo(
size: CGSize(width: 202, height: 126),
size: CGSize(width: 126, height: 96),
scale: UIScreen.main.scale
)
let bannersFetchWrapper = bannersFactory.createWrapper(
backgroundImageInfo: backgroundImageInfo,
contentImageInfo: contentImageInfo
)
let localizationFetchWrapper = localizationFactory.createWrapper(for: locale)
let localizationFetchWrapper = localizationFactory.createWrapper(
for: locale,
availableWidth: availableTextWidth
)

let mergeOperation: ClosureOperation<BannersFetchResult> = ClosureOperation { [weak self] in
guard let self else {
Expand Down Expand Up @@ -93,8 +105,14 @@ private extension BannersInteractor {
// MARK: BannersInteractorInputProtocol

extension BannersInteractor: BannersInteractorInputProtocol {
func updateResources(for locale: Locale) {
let localizationFetchWrapper = localizationFactory.createWrapper(for: locale)
func updateResources(
for locale: Locale,
availableTextWidth: CGFloat
) {
let localizationFetchWrapper = localizationFactory.createWrapper(
for: locale,
availableWidth: availableTextWidth
)

execute(
wrapper: localizationFetchWrapper,
Expand All @@ -111,12 +129,24 @@ extension BannersInteractor: BannersInteractorInputProtocol {
}
}

func setup(with locale: Locale) {
fetchBanners(for: locale)
func setup(
with locale: Locale,
availableTextWidth: CGFloat
) {
fetchBanners(
for: locale,
availableTextWidth: availableTextWidth
)
}

func refresh(for locale: Locale) {
fetchBanners(for: locale)
func refresh(
for locale: Locale,
availableTextWidth: CGFloat
) {
fetchBanners(
for: locale,
availableTextWidth: availableTextWidth
)
}

func closeBanner(with id: String) {
Expand Down
26 changes: 22 additions & 4 deletions novawallet/Modules/Banners/BannersPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class BannersPresenter {
private var banners: [Banner]?
private var closedBanners: ClosedBanners?
private var localizedResources: BannersLocalizedResources?
private var setUp: Bool = false

init(
interactor: BannersInteractorInputProtocol,
Expand Down Expand Up @@ -45,9 +46,16 @@ final class BannersPresenter {
// MARK: BannersPresenterProtocol

extension BannersPresenter: BannersPresenterProtocol {
func setup() {
func setup(with availableTextWidth: CGFloat) {
guard !setUp else { return }

provideBanners()
interactor.setup(with: locale)

interactor.setup(
with: locale,
availableTextWidth: availableTextWidth
)
setUp = true
}

func action(for bannerId: String) {
Expand Down Expand Up @@ -127,12 +135,22 @@ extension BannersPresenter: BannersModuleInputProtocol {
}

func refresh() {
interactor.refresh(for: locale)
guard let availableTextWidth = view?.getAvailableTextWidth() else { return }

interactor.refresh(
for: locale,
availableTextWidth: availableTextWidth
)
}

func updateLocale(_ newLocale: Locale) {
guard let availableTextWidth = view?.getAvailableTextWidth() else { return }

locale = newLocale

interactor.updateResources(for: newLocale)
interactor.updateResources(
for: newLocale,
availableTextWidth: availableTextWidth
)
}
}
20 changes: 15 additions & 5 deletions novawallet/Modules/Banners/BannersProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protocol BannersModuleInputProtocol: AnyObject {
var bannersState: BannersState { get }
var locale: Locale { get }

func setup()
func setup(with availableTextWidth: CGFloat)
func refresh()
func updateLocale(_ newLocale: Locale)
}
Expand Down Expand Up @@ -58,18 +58,28 @@ extension BannersViewProviderProtocol {
protocol BannersViewProtocol: ControllerBackedProtocol, BannersViewProviderProtocol {
func update(with viewModel: LoadableViewModelState<BannersWidgetViewModel>?)
func didCloseBanner(updatedViewModel: BannersWidgetViewModel)
func getAvailableTextWidth() -> CGFloat
}

protocol BannersPresenterProtocol: AnyObject {
func setup()
func setup(with availableTextWidth: CGFloat)
func action(for bannerId: String)
func closeBanner(with id: String)
}

protocol BannersInteractorInputProtocol: AnyObject {
func setup(with locale: Locale)
func refresh(for locale: Locale)
func updateResources(for locale: Locale)
func setup(
with locale: Locale,
availableTextWidth: CGFloat
)
func refresh(
for locale: Locale,
availableTextWidth: CGFloat
)
func updateResources(
for locale: Locale,
availableTextWidth: CGFloat
)
func closeBanner(with id: String)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ extension BannersViewController: UICollectionViewDelegateFlowLayout {
layout _: UICollectionViewLayout,
sizeForItemAt _: IndexPath
) -> CGSize {
CGSize(
let height = maxContentHeight > BannersViewLayout.Constants.contentMinHeight
? maxContentHeight
: BannersViewLayout.Constants.contentMinHeight

return CGSize(
width: rootView.backgroundView.bounds.width,
height: maxWidgetHeight - BannersViewLayout.Constants.containerVerticalInset * 2
height: height
)
}

Expand Down
28 changes: 21 additions & 7 deletions novawallet/Modules/Banners/BannersViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ final class BannersViewController: UIViewController, ViewHolder {
private var staticState: StaticState?
private var dynamicState: DynamicState?

var maxWidgetHeight = BannersViewLayout.Constants.skeletonViewHeight
var maxContentHeight = BannersViewLayout.Constants.contentMinHeight

var maxWidgetHeight: CGFloat {
maxContentHeight + BannersViewLayout.Constants.pageControlHeight
}

init(presenter: BannersPresenterProtocol) {
self.presenter = presenter
Expand All @@ -36,12 +40,18 @@ final class BannersViewController: UIViewController, ViewHolder {

setupCollectionView()
setupActions()
presenter.setup()
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

presenter.setup(with: rootView.availableTextWidth)
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

rootView.restartLoadingIfNeeded()
setupAutoScroll()
}

Expand Down Expand Up @@ -71,13 +81,12 @@ private extension BannersViewController {
}

func updateMaxWidgetHeight(for widgetViewModel: BannersWidgetViewModel) {
let oldHeight = maxWidgetHeight
let oldHeight = maxContentHeight
let height = widgetViewModel.maxTextHeight
+ BannerView.Constants.textContainerTopInset
+ BannerView.Constants.textContainerBottomInset
+ BannerView.Constants.textContainerVerticalInset * 2
+ BannerView.Constants.contentImageViewVerticalInset * 2

maxWidgetHeight = height
maxContentHeight = height

if height != oldHeight {
rootView.collectionView.collectionViewLayout.invalidateLayout()
Expand Down Expand Up @@ -228,7 +237,8 @@ private extension BannersViewController {
if CGFloat(staticState.itemByActualOffset) == rawItemIndex {
targetItemIndex = staticState.itemByActualOffset
} else {
let newIndex = staticState.itemByActualOffset + (rawItemIndex > CGFloat(staticState.itemByActualOffset) ? 1 : -1)
let newIndex = staticState.itemByActualOffset
+ (rawItemIndex > CGFloat(staticState.itemByActualOffset) ? 1 : -1)
targetItemIndex = abs(Int(rawItemIndex) - staticState.itemByActualOffset) > 1 ? Int(rawItemIndex) : newIndex
}

Expand Down Expand Up @@ -342,6 +352,10 @@ extension BannersViewController: BannersViewProtocol {
func getMaxBannerHeight() -> CGFloat {
maxWidgetHeight
}

func getAvailableTextWidth() -> CGFloat {
rootView.availableTextWidth
}
}

// MARK: UIScrollViewDelegate
Expand Down
Loading