Skip to content

Commit

Permalink
IOS-3632 Renamed NFCTag -> ScanTagImage. Moved it out of style into c…
Browse files Browse the repository at this point in the history
…onfig
  • Loading branch information
megakoko committed May 16, 2023
1 parent 4d94be8 commit 83385d6
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 26 deletions.
4 changes: 4 additions & 0 deletions TangemSdk/TangemSdk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
B0EC6500260110530088F03D /* WalletDeserializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0EC64FF260110530088F03D /* WalletDeserializer.swift */; };
B0EC6508260110CC0088F03D /* ReadWalletCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0EC6507260110CC0088F03D /* ReadWalletCommand.swift */; };
B0EC650E260131220088F03D /* ReadWalletsListCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0EC650D260131220088F03D /* ReadWalletsListCommand.swift */; };
DA11B1802A13876200C4604B /* ScanTagImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA11B17F2A13876200C4604B /* ScanTagImage.swift */; };
DA216CC0282E4D86003585B9 /* AccessCodeRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA216CBF282E4D86003585B9 /* AccessCodeRepository.swift */; };
DA6C752A292682650070EEFD /* LAContext+.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA6C7529292682650070EEFD /* LAContext+.swift */; };
DC1244B329B60B6F0037BC05 /* BIP39.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC1244B229B60B6F0037BC05 /* BIP39.swift */; };
Expand Down Expand Up @@ -634,6 +635,7 @@
B0EC64FF260110530088F03D /* WalletDeserializer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletDeserializer.swift; sourceTree = "<group>"; };
B0EC6507260110CC0088F03D /* ReadWalletCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReadWalletCommand.swift; sourceTree = "<group>"; };
B0EC650D260131220088F03D /* ReadWalletsListCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReadWalletsListCommand.swift; sourceTree = "<group>"; };
DA11B17F2A13876200C4604B /* ScanTagImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanTagImage.swift; sourceTree = "<group>"; };
DA216CBF282E4D86003585B9 /* AccessCodeRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessCodeRepository.swift; sourceTree = "<group>"; };
DA6C7529292682650070EEFD /* LAContext+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "LAContext+.swift"; sourceTree = "<group>"; };
DADB544F298BAFBC00491102 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.strings"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -979,6 +981,7 @@
5D7D5FB123449D4000058D69 /* SessionEnvironment.swift */,
5D705B5A23DAF2BB002CCD7A /* Config.swift */,
5D379C28268FA4AC00C7F473 /* CardSessionRunnable.swift */,
DA11B17F2A13876200C4604B /* ScanTagImage.swift */,
);
path = Core;
sourceTree = "<group>";
Expand Down Expand Up @@ -1810,6 +1813,7 @@
B006971825FFABA10040D203 /* InteractionMode.swift in Sources */,
DC1244E029BB6D460037BC05 /* Base58.swift in Sources */,
DCC0A21129D3146100C45B13 /* SetUserSettingsCommand.swift in Sources */,
DA11B1802A13876200C4604B /* ScanTagImage.swift in Sources */,
5DDD6C5625D2D14000E48D7B /* TlvLogging.swift in Sources */,
5D58202024221E060057EF40 /* CardSession.swift in Sources */,
B0390F92256590250061E5ED /* EllipticCurve.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions TangemSdk/TangemSdk/Common/Core/CardSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ public class CardSession {
break
case .sessionStarted:
self.viewDelegate.sessionStarted()
self.viewDelegate.setState(.scan)
self.viewDelegate.setState(.scan(scanTagImage: environment.config.scanTagImage))
case .sessionStopped:
self.viewDelegate.sessionStopped(completion: nil)
case .tagConnected:
self.viewDelegate.tagConnected()
self.viewDelegate.setState(.default)
case .tagLost:
self.viewDelegate.tagLost()
self.viewDelegate.setState(.scan)
self.viewDelegate.setState(.scan(scanTagImage: environment.config.scanTagImage))
}
})
.store(in: &nfcReaderSubscriptions)
Expand Down
3 changes: 3 additions & 0 deletions TangemSdk/TangemSdk/Common/Core/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public struct Config {

/// Localized reason for Touch ID. DO NOT leave it empty.
public var biometricsLocalizedReason: String = "touch_id_localized_reason".localized

/// Image to be displayed as a scan tag on the scanning screen
public var scanTagImage: ScanTagImage = .genericCard
}

public enum CardIdDisplayFormat {
Expand Down
21 changes: 21 additions & 0 deletions TangemSdk/TangemSdk/Common/Core/ScanTagImage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// ScanTagImage.swift
// TangemSdk
//
// Created by Andrey Chukavin on 16.05.2023.
// Copyright © 2023 Tangem AG. All rights reserved.
//

import UIKit

@available(iOS 13.0, *)
public enum ScanTagImage {
/// Generic card provided by the SDK
case genericCard

/// A custom tag made out of an UIImage instance.
/// The image can be shifted vertically from the standard position by specifying `verticalOffset`.
/// Note that the width of the image will be limited to a certain size, while the height will be determined by the aspect ratio of the image.
/// The value of the width can be found in ReadView.swift and is 210 points at the time of the writing.
case image(uiImage: UIImage, verticalOffset: Double)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class DefaultSessionViewDelegate: BaseViewDelegate {
private let engine: HapticsEngine
private var pinnedMessage: String?
private var style: TangemSdkStyle
private let viewModel: MainViewModel = .init(viewState: .scan)
private let viewModel: MainViewModel = .init(viewState: .empty)

init(reader: CardReader, style: TangemSdkStyle) {
self.reader = reader
Expand Down
6 changes: 3 additions & 3 deletions TangemSdk/TangemSdk/UI/Main/MainScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ struct MainScreen: View {
@ViewBuilder
private var mainView: some View {
switch viewModel.viewState {
case .scan:
ReadView()
case .scan(let scanTagImage):
ReadView(scanTagImage: scanTagImage)

case .requestCode(let type, cardId: let cardId, let showForgotButton, completion: let completion):
EnterUserCodeView(title: type.enterCodeTitle,
Expand Down Expand Up @@ -84,7 +84,7 @@ private extension MainScreen {
struct MainScreen_Preview: PreviewProvider {
static var previews: some View {
MainScreen()
.environmentObject(MainViewModel(viewState: .scan))
.environmentObject(MainViewModel(viewState: .scan(scanTagImage: .genericCard)))
.environmentObject(TangemSdkStyle())
}
}
Expand Down
2 changes: 1 addition & 1 deletion TangemSdk/TangemSdk/UI/Main/SessionViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public enum SessionViewState {
case progress(percent: Int)
case `default`
case empty
case scan
case scan(scanTagImage: ScanTagImage)
case requestCode(_ type: UserCodeType, cardId: String?, showForgotButton: Bool, completion: CompletionResult<String>)
case requestCodeChange(_ type: UserCodeType, cardId: String?, completion: CompletionResult<String>)

Expand Down
16 changes: 0 additions & 16 deletions TangemSdk/TangemSdk/UI/TangemSdkStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class TangemSdkStyle: ObservableObject {
public var colors: Colors = .default
public var textSizes: TextSizes = .default
public var indicatorWidth: Float = 12
public var nfcTag: NFCTag = .genericCard

public static var `default`: TangemSdkStyle = .init()
}
Expand Down Expand Up @@ -67,18 +66,3 @@ public extension TangemSdkStyle {
public static var `default`: TextSizes = .init()
}
}

@available(iOS 13.0, *)
public extension TangemSdkStyle {
/// Options for displaying different tags on the scanning screen
enum NFCTag {
/// Generic card provided by the SDK
case genericCard

/// A custom tag made out of an UIImage instance.
/// The image can be shifted vertically from the standard position by specifying `verticalOffset`.
/// Note that the width of the image will be limited to a certain size, while the height will be determined by the aspect ratio of the image.
/// The value of the width can be found in ReadView.swift and is 210 points at the time of the writing.
case image(uiImage: UIImage, verticalOffset: Double)
}
}
7 changes: 4 additions & 3 deletions TangemSdk/TangemSdk/UI/Views/Scan/ReadView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SwiftUI
struct ReadView: View {
@EnvironmentObject var style: TangemSdkStyle

@State var scanTagImage: ScanTagImage
@State private var cardOffset: CGSize = .init(width: -220, height: -160)

var body: some View {
Expand Down Expand Up @@ -42,7 +43,7 @@ struct ReadView: View {

@ViewBuilder
private var tagView: some View {
switch style.nfcTag {
switch scanTagImage {
case .genericCard:
CardView(cardColor: style.colors.cardColor, starsColor: style.colors.starsColor)
case .image(let uiImage, let verticalOffset):
Expand All @@ -58,8 +59,8 @@ struct ReadView: View {
struct ReadView_Previews: PreviewProvider {
static var previews: some View {
Group {
ReadView()
ReadView()
ReadView(scanTagImage: .genericCard)
ReadView(scanTagImage: .genericCard)
.preferredColorScheme(.dark)
}
.environmentObject(TangemSdkStyle())
Expand Down

0 comments on commit 83385d6

Please sign in to comment.