Skip to content
Merged
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
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
37 changes: 37 additions & 0 deletions Modules/Sources/WooFoundation/Utilities/SharedImageAsset.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Foundation
import SwiftUI

public enum SharedImageAsset: CaseIterable {
case cardReaderUpdateProgressArrow
case cardReaderUpdateProgressCheckmark
case coupons
case location
case shoppingBags

public var image: Image {
Image(imageName, bundle: .module)
}

public var decorativeImage: Image {
Image(decorative: imageName, bundle: .module)
}

public var uiImage: UIImage? {
UIImage(named: imageName, in: .module, compatibleWith: nil)
}

private var imageName: String {
switch self {
case .cardReaderUpdateProgressArrow:
"card-reader-update-progress-arrow"
case .cardReaderUpdateProgressCheckmark:
"card-reader-update-progress-checkmark"
case .coupons:
"coupons"
case .location:
"location"
case .shoppingBags:
"shopping-bags"
}
}
}
11 changes: 6 additions & 5 deletions WooCommerce/Classes/Extensions/UIImage+Woo.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import UIKit
import Gridicons
import WooFoundation


/// WooCommerce UIImage Assets
Expand Down Expand Up @@ -327,7 +328,7 @@ extension UIImage {
/// Coupons Image
///
static var couponsImage: UIImage {
return UIImage(named: "coupons")!
SharedImageAsset.coupons.uiImage!
}

/// Empty Inbox Notes Icon
Expand Down Expand Up @@ -355,7 +356,7 @@ extension UIImage {
}

static var shoppingBagsImage: UIImage {
UIImage(named: "shopping-bags")!
SharedImageAsset.shoppingBags.uiImage!
}

/// Image showing boxes
Expand Down Expand Up @@ -675,13 +676,13 @@ extension UIImage {
/// Card Reader Update arrow
///
static var cardReaderUpdateProgressArrow: UIImage {
return UIImage(named: "card-reader-update-progress-arrow")!
SharedImageAsset.cardReaderUpdateProgressArrow.uiImage!
}

/// Card Reader Update checkmark
///
static var cardReaderUpdateProgressCheckmark: UIImage {
return UIImage(named: "card-reader-update-progress-checkmark")!
SharedImageAsset.cardReaderUpdateProgressCheckmark.uiImage!
}

/// Card Reader Low Battery
Expand Down Expand Up @@ -1369,7 +1370,7 @@ extension UIImage {
}

static var cardReaderLocationImage: UIImage {
UIImage(named: "location")!
SharedImageAsset.location.uiImage!
}
}

Expand Down
18 changes: 0 additions & 18 deletions WooCommerce/Classes/POS/Extensions/UIImage+POS.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import SwiftUI
struct PointOfSaleCardPresentPaymentConnectingFailedLocationRequiredAlertViewModel: Hashable {
let title = Localization.title
let subtitle = Localization.subtitle
let imageName = PointOfSaleAssets.readerLocation.imageName

let primaryButtonViewModel: CardPresentPaymentsModalButtonViewModel
let cancelButtonViewModel: CardPresentPaymentsModalButtonViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ struct PointOfSaleCardPresentPaymentConnectingLocationPreAlertViewModel: Hashabl
let title = Localization.title
let subtitle = Localization.subtitle
let detail = Localization.settings
let imageName = PointOfSaleAssets.readerLocation.imageName

let primaryButtonViewModel: CardPresentPaymentsModalButtonViewModel

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftUI
import WooFoundation

struct PointOfSaleCardPresentPaymentReaderUpdateProgressView: View {
let progress: CGFloat
Expand All @@ -19,7 +20,9 @@ struct PointOfSaleCardPresentPaymentReaderUpdateProgressView: View {
)
.animation(.easeOut(duration: 0.2), value: progress)

Image(uiImage: isComplete ? .posCardReaderUpdateProgressCheckmark : .posCardReaderUpdateProgressArrow)
(
isComplete ? SharedImageAsset.cardReaderUpdateProgressCheckmark.decorativeImage : SharedImageAsset.cardReaderUpdateProgressArrow.decorativeImage
)
.renderingMode(.template)
.foregroundColor(Color(.posOnPrimary))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftUI
import WooFoundation

struct PointOfSaleCardPresentPaymentConnectingFailedLocationRequiredAlertView: View {
let viewModel: PointOfSaleCardPresentPaymentConnectingFailedLocationRequiredAlertViewModel
Expand All @@ -7,7 +8,7 @@ struct PointOfSaleCardPresentPaymentConnectingFailedLocationRequiredAlertView: V
var body: some View {
VStack(spacing: PointOfSaleReaderConnectionModalLayout.contentButtonSpacing) {
VStack(spacing: PointOfSaleReaderConnectionModalLayout.imageTextSpacing) {
Image(decorative: viewModel.imageName)
SharedImageAsset.location.image
.matchedGeometryEffect(id: animation.iconTransitionId, in: animation.namespace, properties: .position)

VStack(spacing: PointOfSaleReaderConnectionModalLayout.textSpacing) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftUI
import WooFoundation

struct PointOfSaleCardPresentPaymentConnectingLocationPreAlertView: View {
let viewModel: PointOfSaleCardPresentPaymentConnectingLocationPreAlertViewModel
Expand All @@ -7,7 +8,7 @@ struct PointOfSaleCardPresentPaymentConnectingLocationPreAlertView: View {
var body: some View {
VStack(spacing: PointOfSaleReaderConnectionModalLayout.contentButtonSpacing) {
VStack(spacing: PointOfSaleReaderConnectionModalLayout.imageTextSpacing) {
Image(decorative: viewModel.imageName)
SharedImageAsset.location.decorativeImage
.matchedGeometryEffect(id: animation.iconTransitionId, in: animation.namespace, properties: .position)

VStack(spacing: PointOfSaleReaderConnectionModalLayout.textSpacing) {
Expand Down
2 changes: 1 addition & 1 deletion WooCommerce/Classes/POS/Presentation/CartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private extension CartView {
.foregroundColor(Color.posOnSurfaceVariantLowest)
.multilineTextAlignment(.center)
.overlay(alignment: .top) {
Image(decorative: PointOfSaleAssets.shoppingBags.imageName)
SharedImageAsset.shoppingBags.decorativeImage
.resizable()
.frame(width: Constants.shoppingBagImageSize, height: Constants.shoppingBagImageSize, alignment: .bottom)
.offset(y: -(Constants.shoppingBagImageSize + Constants.emptyViewImageTextSpacing))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import SwiftUI

struct POSOrderListEmptyViewModel: POSListEmptyViewModelProtocol {
let isSearching: Bool
Expand All @@ -19,8 +20,8 @@ struct POSOrderListEmptyViewModel: POSListEmptyViewModelProtocol {
isSearching ? nil : Localization.emptyOrdersButtonTitle
}

var iconName: String {
PointOfSaleAssets.magnifierNotFound.imageName
var icon: Image {
PointOfSaleAssets.magnifierNotFound.decorativeImage
}
}

Expand Down
14 changes: 5 additions & 9 deletions WooCommerce/Classes/POS/Presentation/PointOfSaleAssets.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import SwiftUI

enum PointOfSaleAssets: CaseIterable {
case error
Expand All @@ -10,10 +11,7 @@ enum PointOfSaleAssets: CaseIterable {
case readerConnectionLowBattery
case readerConnectionSuccess
case readerDisconnected
case readerLocation
case shoppingBags
case successCheck
case coupons
case gears
case barcodeFieldScreenshot
case starBsh20SetupBarcode
Expand All @@ -23,6 +21,10 @@ enum PointOfSaleAssets: CaseIterable {
case netum1228BCPairBarcode
case testEan13Barcode

var decorativeImage: Image {
Image(decorative: imageName)
}

var imageName: String {
switch self {
case .error:
Expand All @@ -43,14 +45,8 @@ enum PointOfSaleAssets: CaseIterable {
"pos-reader-connection-complete"
case .readerDisconnected:
"pos-reader-disconnected"
case .readerLocation:
"location"
case .shoppingBags:
"shopping-bags"
case .successCheck:
"pos-success-check"
case .coupons:
"coupons"
case .gears:
"pos-gears"
case .barcodeFieldScreenshot:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import SwiftUI
import struct WooFoundation.ScrollableVStack
import WooFoundation

protocol POSListEmptyViewModelProtocol {
var title: String { get }
var subtitle: String { get }
var hint: String? { get }
var buttonTitle: String? { get }
var iconName: String { get }
var icon: Image { get }
}

struct POSListEmptyView: View {
Expand Down Expand Up @@ -85,7 +85,7 @@ struct POSListEmptyView: View {

@ViewBuilder
private var icon: some View {
Image(decorative: viewModel.iconName)
viewModel.icon
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: Constants.iconSize, height: Constants.iconSize)
Expand Down Expand Up @@ -166,12 +166,12 @@ struct POSListEmptyViewModel: POSListEmptyViewModelProtocol {
}
}

var iconName: String {
var icon: Image {
switch itemListType {
case .coupons(search: false):
PointOfSaleAssets.coupons.imageName
SharedImageAsset.coupons.decorativeImage
default:
PointOfSaleAssets.magnifierNotFound.imageName
PointOfSaleAssets.magnifierNotFound.decorativeImage
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import SwiftUI
import struct WooFoundation.ScrollableVStack
import WooFoundation

/// A view that displays an error message with a retry CTA when the list of POS items fails to load.
struct POSListErrorView: View {
@Environment(\.floatingControlAreaSize) private var floatingControlAreaSize: CGSize
private let viewModel: POSListErrorViewModell
private let viewModel: POSListErrorViewModel
private let onAction: (() -> Void)?

@State private var viewWidth: CGFloat = 0

@Environment(\.keyboardObserver) private var keyboard

init(error: PointOfSaleErrorState, onAction: (() -> Void)? = nil) {
self.viewModel = POSListErrorViewModell(error: error)
self.viewModel = POSListErrorViewModel(error: error)
self.onAction = onAction
}

Expand All @@ -21,8 +21,8 @@ struct POSListErrorView: View {
Spacer()
VStack(alignment: .center, spacing: POSSpacing.none) {
if !keyboard.isFullSizeKeyboardVisible {
if let imageName = viewModel.imageAsset?.imageName {
Image(decorative: imageName)
if let image = viewModel.imageAsset {
image
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 88, height: 88)
Expand Down Expand Up @@ -68,19 +68,19 @@ struct POSListErrorView: View {
}
}

struct POSListErrorViewModell {
struct POSListErrorViewModel {
let title: String
let subtitle: String
let buttonText: String
let imageAsset: PointOfSaleAssets?
let imageAsset: Image?

init(error: PointOfSaleErrorState) {
self.title = error.title
self.subtitle = error.subtitle
self.buttonText = error.buttonText
switch error.errorType {
case .couponsDisabled:
self.imageAsset = PointOfSaleAssets.coupons
self.imageAsset = SharedImageAsset.coupons.decorativeImage
default:
self.imageAsset = nil
}
Expand Down
4 changes: 0 additions & 4 deletions WooCommerce/WooCommerce.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
01620C4E2C5394B200D3EA2F /* POSProgressViewStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01620C4D2C5394B200D3EA2F /* POSProgressViewStyle.swift */; };
01654EB12E786223001DBB6F /* POSServiceLocatorAdaptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01654EAF2E786223001DBB6F /* POSServiceLocatorAdaptor.swift */; };
01654EB62E78641B001DBB6F /* WooAnalyticsEvent+WooApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01654EB52E78641B001DBB6F /* WooAnalyticsEvent+WooApp.swift */; };
016582C92E786840001DBB6F /* UIImage+POS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016582C72E786840001DBB6F /* UIImage+POS.swift */; };
016582D62E78715B001DBB6F /* CardPresentPaymentBluetoothReaderConnectionAlertsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016582CA2E78715B001DBB6F /* CardPresentPaymentBluetoothReaderConnectionAlertsProvider.swift */; };
016582D72E78715B001DBB6F /* CardPresentPaymentsTransactionAlertsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016582D22E78715B001DBB6F /* CardPresentPaymentsTransactionAlertsProvider.swift */; };
016582D82E78715B001DBB6F /* POSCollectOrderPaymentAnalyticsAdaptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016582D52E78715B001DBB6F /* POSCollectOrderPaymentAnalyticsAdaptor.swift */; };
Expand Down Expand Up @@ -3283,7 +3282,6 @@
01620C4D2C5394B200D3EA2F /* POSProgressViewStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSProgressViewStyle.swift; sourceTree = "<group>"; };
01654EAF2E786223001DBB6F /* POSServiceLocatorAdaptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSServiceLocatorAdaptor.swift; sourceTree = "<group>"; };
01654EB52E78641B001DBB6F /* WooAnalyticsEvent+WooApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WooAnalyticsEvent+WooApp.swift"; sourceTree = "<group>"; };
016582C72E786840001DBB6F /* UIImage+POS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+POS.swift"; sourceTree = "<group>"; };
016582CA2E78715B001DBB6F /* CardPresentPaymentBluetoothReaderConnectionAlertsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardPresentPaymentBluetoothReaderConnectionAlertsProvider.swift; sourceTree = "<group>"; };
016582CB2E78715B001DBB6F /* CardPresentPaymentCollectOrderPaymentUseCaseAdaptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardPresentPaymentCollectOrderPaymentUseCaseAdaptor.swift; sourceTree = "<group>"; };
016582CC2E78715B001DBB6F /* CardPresentPaymentInvalidatablePaymentOrchestrator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardPresentPaymentInvalidatablePaymentOrchestrator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6577,7 +6575,6 @@
016582C82E786840001DBB6F /* Extensions */ = {
isa = PBXGroup;
children = (
016582C72E786840001DBB6F /* UIImage+POS.swift */,
01BE93FF2DDCB1110063541C /* Error+Connectivity.swift */,
);
path = Extensions;
Expand Down Expand Up @@ -15683,7 +15680,6 @@
024DF32123744798006658FE /* AztecFormatBarCommandCoordinator.swift in Sources */,
689F291A2DE4557E004DF52B /* POSStockFormatter.swift in Sources */,
B5AA7B3F20ED81C2004DA14F /* UserDefaults+Woo.swift in Sources */,
016582C92E786840001DBB6F /* UIImage+POS.swift in Sources */,
DED0392B2BC7A076005D0571 /* StorePerformanceViewModel.swift in Sources */,
318477E527A33C650058C7E9 /* CardPresentModalConnectingFailedChargeReader.swift in Sources */,
CEEF742A2B9A02EB00B03948 /* OrdersReportCardViewModel.swift in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions WooCommerce/WooCommerceTests/Extensions/IconsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -824,4 +824,8 @@ final class IconsTests: XCTestCase {
func test_wooShippingRatesPlaceholder_is_not_nil() {
XCTAssertNotNil(UIImage.wooShippingRatesPlaceholder)
}

func test_shoppingBagsImage_is_not_nil() {
XCTAssertNotNil(UIImage.shoppingBagsImage)
}
}