Skip to content

Commit

Permalink
chore: refactor previews and utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
reez authored Jun 24, 2024
1 parent 0093a96 commit 2f4f1a4
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 111 deletions.
22 changes: 6 additions & 16 deletions Sources/BitcoinUI/AddressFormattedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public struct AddressFormattedView: View {
),
spacing: spacing
) {
let chunks = chunkedAddress()
let chunks = address.chunked(into: 4)
ForEach(chunks.indices, id: \.self) { index in
Text(chunks[index])
.font(.system(size: 20, weight: .medium, design: .monospaced))
Expand All @@ -46,27 +46,17 @@ public struct AddressFormattedView: View {
}
}

extension AddressFormattedView {
private func chunkedAddress() -> [String] {
let chunkSize = 4
return stride(from: 0, to: address.count, by: chunkSize).map {
let start = address.index(address.startIndex, offsetBy: $0)
let end =
address.index(start, offsetBy: chunkSize, limitedBy: address.endIndex)
?? address.endIndex
return String(address[start..<end])
}
}
}

struct AddressFormattedView_Previews: PreviewProvider {
static var previews: some View {
AddressFormattedView(
address: "tb1pw6y0vtmsn46epvz0j8ddc46ketmp28t82p22hcrrkch3a0jhu40qe267dl"
address:
"tb1pw6y0vtmsn46epvz0j8ddc46ketmp28t82p22hcrrkch3a0jhu40qe267dl"
)
}
}

#Preview {
AddressFormattedView(address: "tb1pw6y0vtmsn46epvz0j8ddc46ketmp28t82p22hcrrkch3a0jhu40qe267dl")
AddressFormattedView(
address: "tb1pw6y0vtmsn46epvz0j8ddc46ketmp28t82p22hcrrkch3a0jhu40qe267dl"
)
}
11 changes: 5 additions & 6 deletions Sources/BitcoinUI/ButtonStyles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,10 @@ struct ButtonStylesView: View {

struct ButtonStylesView_Previews: PreviewProvider {
static var previews: some View {
Group {
ButtonStylesView()
.environment(\.colorScheme, .light)
ButtonStylesView()
.environment(\.colorScheme, .dark)
}
ButtonStylesView()
}
}

#Preview {
ButtonStylesView()
}
12 changes: 5 additions & 7 deletions Sources/BitcoinUI/Colors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,10 @@ struct ColorsView: View {

struct ColorsView_Previews: PreviewProvider {
static var previews: some View {
Group {
ColorsView()
.environment(\.colorScheme, .light)
ColorsView()
.environment(\.colorScheme, .dark)

}
ColorsView()
}
}

#Preview {
ColorsView()
}
11 changes: 5 additions & 6 deletions Sources/BitcoinUI/Images.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,10 @@ struct IconsView: View {

struct IconsView_Previews: PreviewProvider {
static var previews: some View {
Group {
IconsView()
.environment(\.colorScheme, .light)
IconsView()
.environment(\.colorScheme, .dark)
}
IconsView()
}
}

#Preview {
IconsView()
}
83 changes: 13 additions & 70 deletions Sources/BitcoinUI/SeedPhraseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,19 @@ struct WordCapsule: View {
}
}

extension Array {
func chunked(into size: Int) -> [[Element]] {
stride(from: 0, to: count, by: size).map {
Array(self[$0..<Swift.min($0 + size, count)])
}
struct SeedPhraseView_Previews: PreviewProvider {
static var previews: some View {
SeedPhraseView(
words: [
"paddle", "train", "boil", "catch", "trim", "plastic",
"wolf", "hazard", "govern", "oval", "drama", "gun",
"swim", "accuse", "degree", "teach", "game", "penalty",
"social", "hard", "crush", "media", "radar", "click",
],
preferredWordsPerRow: 2,
usePaging: true,
wordsPerPage: 4
)
}
}

Expand All @@ -149,68 +157,3 @@ extension Array {
wordsPerPage: 4
)
}

#Preview {
SeedPhraseView(
words: [
"apple", "banana", "cherry", "date", "elderberry", "fig", "grape", "honeydew", "kiwi",
"lemon", "mango", "nectarine",
],
preferredWordsPerRow: 3
)
}

#Preview {
SeedPhraseView(
words: [
"apple", "banana", "cherry", "date", "elderberry", "fig", "grape", "honeydew", "kiwi",
"lemon", "mango", "nectarine",
],
preferredWordsPerRow: 3
)
}

#Preview {
SeedPhraseView(
words: [
"apple", "banana", "cherry", "date", "elderberry", "fig", "grape", "honeydew", "kiwi",
"lemon", "mango", "nectarine",
],
preferredWordsPerRow: 3,
usePaging: true
)
}

#Preview {
SeedPhraseView(
words: [
"apple", "banana", "cherry", "date", "elderberry", "fig", "grape", "honeydew", "kiwi",
"lemon", "mango", "nectarine",
],
preferredWordsPerRow: 2
)
}

#Preview {
SeedPhraseView(
words: [
"apple", "banana", "cherry", "date", "elderberry", "fig", "grape", "honeydew", "kiwi",
"lemon", "mango", "nectarine",
],
preferredWordsPerRow: 4
)
}

struct SeedPhraseView_Previews: PreviewProvider {
static var previews: some View {
Group {
SeedPhraseView(
words: [
"apple", "banana", "cherry", "date", "elderberry", "fig", "grape", "honeydew",
"kiwi", "lemon", "mango", "nectarine",
],
preferredWordsPerRow: 3
)
}
}
}
11 changes: 5 additions & 6 deletions Sources/BitcoinUI/TextStyles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,10 @@ struct TextStylesView: View {

struct TextStylesView_Previews: PreviewProvider {
static var previews: some View {
Group {
TextStylesView()
.environment(\.colorScheme, .light)
TextStylesView()
.environment(\.colorScheme, .dark)
}
TextStylesView()
}
}

#Preview {
TextStylesView()
}
18 changes: 18 additions & 0 deletions Sources/BitcoinUI/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
import Foundation
import SwiftUI

extension Array {
func chunked(into size: Int) -> [[Element]] {
stride(from: 0, to: count, by: size).map {
Array(self[$0..<Swift.min($0 + size, count)])
}
}
}

extension CGFloat {

// Choose horizontal spacing per Figma
Expand All @@ -22,6 +30,16 @@ extension CGFloat {

}

extension String {
func chunked(into size: Int) -> [String] {
return stride(from: 0, to: self.count, by: size).map {
let start = self.index(self.startIndex, offsetBy: $0)
let end = self.index(start, offsetBy: size, limitedBy: self.endIndex) ?? self.endIndex
return String(self[start..<end])
}
}
}

extension View {
func applyFidgetEffect(viewState: Binding<CGSize>) -> some View {
self
Expand Down

0 comments on commit 2f4f1a4

Please sign in to comment.