Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
feature: add currency switch label
Browse files Browse the repository at this point in the history
  • Loading branch information
ottosuess committed Nov 15, 2019
1 parent e18d44e commit 27ee984
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 38 deletions.
6 changes: 6 additions & 0 deletions Library/Helper/Style.swift
Expand Up @@ -56,6 +56,12 @@ public enum Style {
$0.textColor = UIColor.Zap.white
$0.adjustsFontForContentSizeCategory = true
}

static let largeAmount = UIViewStyle<UILabel> {
$0.font = UIFontMetrics(forTextStyle: .title1).scaledFont(for: UIFont.Zap.regular.withSize(80))
$0.textColor = UIColor.Zap.white
$0.adjustsFontForContentSizeCategory = true
}

static let body = UIViewStyle<UILabel> {
$0.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: UIFont.Zap.light.withSize(17))
Expand Down
23 changes: 6 additions & 17 deletions Library/Scenes/Wallet/BalanceView/BalanceView.swift
Expand Up @@ -12,7 +12,6 @@ import SwiftBTC

final class BalanceView: UIView {
@IBOutlet private weak var totalBalanceLabel: UILabel!
@IBOutlet private weak var swapIconImageView: UIImageView!
@IBOutlet private weak var primaryBalanceLabel: UILabel!
@IBOutlet private weak var secondaryBalanceLabel: UILabel!

Expand All @@ -33,23 +32,16 @@ final class BalanceView: UIView {
totalBalanceLabel.text = L10n.Scene.Wallet.totalBalance
secondaryBalanceLabel.textColor = UIColor.Zap.gray
secondaryBalanceLabel.textAlignment = .center
Style.Label.boldTitle.apply(to: primaryBalanceLabel)
Style.Label.largeAmount.apply(to: primaryBalanceLabel)
primaryBalanceLabel.textAlignment = .center

swapIconImageView.tintColor = UIColor.Zap.lightningOrange
}

func setup(totalBalance: Observable<Satoshi>) {
combineLatest(totalBalance, Settings.shared.primaryCurrency) { satoshis, currency -> NSAttributedString? in
if let bitcoin = currency as? Bitcoin {
return bitcoin.attributedFormat(satoshis: satoshis)
} else {
guard let string = currency.format(satoshis: satoshis) else { return nil }
return NSAttributedString(string: string)
}
combineLatest(totalBalance, Settings.shared.primaryCurrency) { satoshis, currency -> String? in
currency.format(satoshis: satoshis, includeSymbol: false)
}
.distinctUntilChanged()
.bind(to: primaryBalanceLabel.reactive.attributedText)
.bind(to: primaryBalanceLabel.reactive.text)
.dispose(in: reactive.bag)

totalBalance
Expand Down Expand Up @@ -80,12 +72,9 @@ final class BalanceView: UIView {
}

private extension Bitcoin {
func attributedFormat(satoshis: Satoshi) -> NSAttributedString? {
func format(satoshis: Satoshi) -> String? {
let formatter = SatoshiFormatter(unit: self)
formatter.includeCurrencySymbol = false
let amountString = formatter.string(from: satoshis) ?? "0"
let attributedString = NSMutableAttributedString(string: amountString)
attributedString.append(NSAttributedString(string: " " + symbol, attributes: [.font: UIFont.Zap.light]))
return attributedString
return formatter.string(from: satoshis) ?? "0"
}
}
40 changes: 23 additions & 17 deletions Library/Scenes/Wallet/BalanceView/BalanceView.xib
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15400" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15404"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand All @@ -12,7 +10,6 @@
<connections>
<outlet property="primaryBalanceLabel" destination="rXu-f3-LsZ" id="COR-Ek-6Fw"/>
<outlet property="secondaryBalanceLabel" destination="g3o-jH-G1h" id="o3F-NW-ypB"/>
<outlet property="swapIconImageView" destination="Q1k-bc-5hS" id="6fd-77-sJM"/>
<outlet property="totalBalanceLabel" destination="P5E-fr-IFk" id="4Pl-mw-C2Y"/>
</connections>
</placeholder>
Expand All @@ -22,45 +19,57 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="LMV-Dp-83Y">
<rect key="frame" x="0.0" y="44" width="423" height="176"/>
<rect key="frame" x="0.0" y="0.0" width="423" height="254"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="rod-4p-XmL">
<rect key="frame" x="0.0" y="0.0" width="13" height="176"/>
<rect key="frame" x="0.0" y="0.0" width="24" height="254"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<stackView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="999" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="saP-Qu-cwl">
<rect key="frame" x="23" y="0.0" width="377" height="176"/>
<rect key="frame" x="34" y="0.0" width="355" height="254"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" text="_Total Balance" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="P5E-fr-IFk">
<rect key="frame" x="0.0" y="0.0" width="377" height="135"/>
<rect key="frame" x="0.0" y="0.0" width="355" height="213"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.10000000149011612" translatesAutoresizingMaskIntoConstraints="NO" id="rXu-f3-LsZ">
<rect key="frame" x="0.0" y="135" width="377" height="20.5"/>
<rect key="frame" x="0.0" y="213" width="355" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="g3o-jH-G1h">
<rect key="frame" x="0.0" y="155.5" width="377" height="20.5"/>
<rect key="frame" x="0.0" y="233.5" width="355" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="999" verticalHuggingPriority="251" horizontalCompressionResistancePriority="1000" image="icon_swap" translatesAutoresizingMaskIntoConstraints="NO" id="Q1k-bc-5hS">
<rect key="frame" x="410" y="0.0" width="13" height="176"/>
</imageView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="tS6-zk-C0B">
<rect key="frame" x="399" y="0.0" width="24" height="254"/>
<subviews>
<view contentMode="scaleToFill" horizontalHuggingPriority="1000" placeholderIntrinsicWidth="24" placeholderIntrinsicHeight="24" translatesAutoresizingMaskIntoConstraints="NO" id="DF1-Y7-iAE" customClass="CurrencySwitchLabel" customModule="Library" customModuleProvider="target">
<rect key="frame" x="0.0" y="205" width="24" height="24"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
</view>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="DF1-Y7-iAE" firstAttribute="leading" secondItem="tS6-zk-C0B" secondAttribute="leading" id="I39-Dk-73d"/>
<constraint firstAttribute="trailing" secondItem="DF1-Y7-iAE" secondAttribute="trailing" id="w9L-ja-hdN"/>
</constraints>
</view>
</subviews>
<constraints>
<constraint firstItem="Q1k-bc-5hS" firstAttribute="width" secondItem="rod-4p-XmL" secondAttribute="width" id="LGL-69-1cU"/>
<constraint firstItem="DF1-Y7-iAE" firstAttribute="baseline" secondItem="rXu-f3-LsZ" secondAttribute="firstBaseline" id="4A7-vV-SRH"/>
<constraint firstItem="tS6-zk-C0B" firstAttribute="width" secondItem="rod-4p-XmL" secondAttribute="width" id="GFj-ob-064"/>
</constraints>
</stackView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="AMg-TB-98y">
<rect key="frame" x="0.0" y="44" width="423" height="176"/>
<rect key="frame" x="0.0" y="0.0" width="423" height="254"/>
<connections>
<action selector="swapCurrencyButtonTapped:" destination="-1" eventType="touchUpInside" id="7si-aH-kVc"/>
</connections>
Expand All @@ -82,7 +91,4 @@
<point key="canvasLocation" x="-111" y="148"/>
</view>
</objects>
<resources>
<image name="icon_swap" width="13" height="13"/>
</resources>
</document>
2 changes: 1 addition & 1 deletion Library/Scenes/Wallet/Wallet.storyboard
Expand Up @@ -23,7 +23,7 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="421"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="VfT-Do-bRp">
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="VfT-Do-bRp" userLabel="Navigation Container">
<rect key="frame" x="0.0" y="421" width="414" height="60"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="260" verticalCompressionResistancePriority="742" translatesAutoresizingMaskIntoConstraints="NO" id="Tgv-5l-myg">
Expand Down
52 changes: 52 additions & 0 deletions Library/Views/CurrencySwitchLabel.swift
@@ -0,0 +1,52 @@
//
// Library
//
// Created by 0 on 14.11.19.
// Copyright © 2019 Zap. All rights reserved.
//

import Bond
import Foundation

final class CurrencySwitchLabel: PaddingLabel {
private let minSize: CGFloat = 24

override init(frame: CGRect) {
super.init(frame: frame)
edgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
}

required init?(coder: NSCoder) {
super.init(coder: coder)
edgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
}

override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
invalidateIntrinsicContentSize()
}

override func awakeFromNib() {
super.awakeFromNib()

backgroundColor = UIColor.Zap.seaBlue

textColor = UIColor.Zap.lightningOrange
font = .systemFont(ofSize: 17, weight: .medium)
textAlignment = .center
setContentCompressionResistancePriority(.required, for: .horizontal)

Settings.shared.primaryCurrency
.map { $0.symbol }
.bind(to: reactive.text)
.dispose(in: reactive.bag)

NSLayoutConstraint.activate([
heightAnchor.constraint(equalToConstant: minSize),
widthAnchor.constraint(greaterThanOrEqualToConstant: minSize)
])

layer.cornerRadius = 5
layer.masksToBounds = true
}
}
2 changes: 1 addition & 1 deletion Library/Views/PaddingLabel.swift
Expand Up @@ -7,7 +7,7 @@

import Foundation

final class PaddingLabel: UILabel {
class PaddingLabel: UILabel {
var edgeInsets = UIEdgeInsets.zero

override func drawText(in rect: CGRect) {
Expand Down
2 changes: 1 addition & 1 deletion SwiftBTC
6 changes: 5 additions & 1 deletion Zap.xcodeproj/project.pbxproj
Expand Up @@ -208,6 +208,7 @@
AD5AA2E72271B64500AEDDD7 /* rpc.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD5AA2E62271B64500AEDDD7 /* rpc.pb.swift */; };
AD60D0D6237DBAF4007D6420 /* BalanceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD60D0D5237DBAF4007D6420 /* BalanceView.swift */; };
AD60D0D8237DBB0A007D6420 /* BalanceView.xib in Resources */ = {isa = PBXBuildFile; fileRef = AD60D0D7237DBB0A007D6420 /* BalanceView.xib */; };
AD60D0DC237DC8EA007D6420 /* CurrencySwitchLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD60D0DB237DC8EA007D6420 /* CurrencySwitchLabel.swift */; };
AD615CF5211C82E600680790 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD615CF4211C82E600680790 /* LoadingView.swift */; };
AD615CF7211CAB0900680790 /* PaddingLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD615CF6211CAB0900680790 /* PaddingLabel.swift */; };
AD667E4721359D79007B9160 /* AuthenticationCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD667E4621359D79007B9160 /* AuthenticationCoordinator.swift */; };
Expand Down Expand Up @@ -750,6 +751,7 @@
AD5EA1E1213D827B00AB8031 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
AD60D0D5237DBAF4007D6420 /* BalanceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BalanceView.swift; sourceTree = "<group>"; };
AD60D0D7237DBB0A007D6420 /* BalanceView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = BalanceView.xib; sourceTree = "<group>"; };
AD60D0DB237DC8EA007D6420 /* CurrencySwitchLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencySwitchLabel.swift; sourceTree = "<group>"; };
AD615CF4211C82E600680790 /* LoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = "<group>"; };
AD615CF6211CAB0900680790 /* PaddingLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaddingLabel.swift; sourceTree = "<group>"; };
AD667E4621359D79007B9160 /* AuthenticationCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationCoordinator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1264,10 +1266,11 @@
isa = PBXGroup;
children = (
ADBA120720935871001F7700 /* AmountInput */,
AD21768820C3DFDB007779DE /* ChannelBalanceView.swift */,
A0BD44DE206FED1400BF27A3 /* BondCell.swift */,
AD21768820C3DFDB007779DE /* ChannelBalanceView.swift */,
AD8049B5224E896B00DA99F4 /* CircleView.swift */,
A0731FE52014AC0800C55E45 /* ContainerViewController.swift */,
AD60D0DB237DC8EA007D6420 /* CurrencySwitchLabel.swift */,
AD4B4BE022EAF0CE0029773A /* EmptyStateView.swift */,
A0F353CF20692570005B3639 /* GradientView.swift */,
ADBA12082093587B001F7700 /* KeyPad */,
Expand Down Expand Up @@ -3290,6 +3293,7 @@
ADFC816F20DA80EF00D26913 /* RecoverWalletViewModel.swift in Sources */,
AD391C5220D16F7A007EE22A /* ConfirmMnemonicViewController.swift in Sources */,
AD391C3D20D16F0B007EE22A /* BiometricAuthentication.swift in Sources */,
AD60D0DC237DC8EA007D6420 /* CurrencySwitchLabel.swift in Sources */,
ADBC29BE2375CE7C0097D0F6 /* CombinedQRCodeScannetStrategy.swift in Sources */,
ADCEAFD32255F2C2004F605B /* WarningSettingsItem.swift in Sources */,
AD391C3020D16EFA007EE22A /* UICollectionView.swift in Sources */,
Expand Down

0 comments on commit 27ee984

Please sign in to comment.