-
Notifications
You must be signed in to change notification settings - Fork 12
refactor: simplify home view #292
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
Merged
reez
merged 8 commits into
bitcoindevkit:main
from
r1b2ns:refactor/extract-activity-header-component
Apr 30, 2025
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
34e98a9
refactor: simplify HomeView by componentizing the header activity sec…
r1b2ns 512c037
chore: organize home files
r1b2ns 73a7a0c
refactor: removed ActivityHomeHeardeView.DataSource and create a Acti…
r1b2ns b98020b
Update BDKSwiftExampleWallet/View/Home/ActivityHomeHeaderView.swift
r1b2ns 1d74c68
feat: added code review suggestion
r1b2ns 4bfaba7
Update BDKSwiftExampleWallet/View/WalletView.swift
r1b2ns d185b24
Merge branch 'refactor/extract-activity-header-component' of https://…
r1b2ns 268d923
fix: added code review suggestions
r1b2ns File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
BDKSwiftExampleWallet/View/Home/ActivityHomeHeaderView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// | ||
// TransactionListHeaderView.swift | ||
// BDKSwiftExampleWallet | ||
// | ||
// Created by Rubens Machion on 24/04/25. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ActivityHomeHeaderView: View { | ||
|
||
enum State { | ||
case synced | ||
case fullSyncing(inspectedScripts: UInt64) | ||
case syncing(progress: Float, inspectedScripts: UInt64, totalScripts: UInt64) | ||
case notStarted | ||
case error(Error) | ||
} | ||
|
||
let state: State | ||
|
||
let showAllTransactions: () -> Void | ||
|
||
var body: some View { | ||
HStack { | ||
Text("Activity") | ||
Spacer() | ||
|
||
HStack { | ||
if case let .fullSyncing(inspectedScripts) = state { | ||
Text("\(inspectedScripts)") | ||
.padding(.trailing, -5.0) | ||
.fontWeight(.semibold) | ||
.contentTransition(.numericText()) | ||
.transition(.opacity) | ||
.fontDesign(.monospaced) | ||
.foregroundStyle(.secondary) | ||
.font(.caption2) | ||
.fontWeight(.thin) | ||
.animation(.easeInOut, value: inspectedScripts) | ||
} | ||
if case let .syncing(progress, inspectedScripts, totalScripts) = state { | ||
HStack { | ||
if progress < 1.0 { | ||
Text("\(inspectedScripts)") | ||
.padding(.trailing, -5.0) | ||
.fontWeight(.semibold) | ||
.contentTransition(.numericText()) | ||
.transition(.opacity) | ||
|
||
Text("/") | ||
.padding(.trailing, -5.0) | ||
.transition(.opacity) | ||
Text("\(totalScripts)") | ||
.contentTransition(.numericText()) | ||
.transition(.opacity) | ||
} | ||
|
||
Text( | ||
String( | ||
format: "%.0f%%", | ||
progress * 100 | ||
) | ||
) | ||
.contentTransition(.numericText()) | ||
.transition(.opacity) | ||
} | ||
.fontDesign(.monospaced) | ||
.foregroundStyle(.secondary) | ||
.font(.caption2) | ||
.fontWeight(.thin) | ||
.animation(.easeInOut, value: inspectedScripts) | ||
.animation(.easeInOut, value: totalScripts) | ||
.animation(.easeInOut, value: progress) | ||
} | ||
} | ||
HStack { | ||
HStack(spacing: 5) { | ||
state.syncImageIndicator | ||
} | ||
.contentTransition(.symbolEffect(.replace.offUp)) | ||
|
||
} | ||
.foregroundStyle(.secondary) | ||
.font(.caption) | ||
|
||
if case .synced = state { | ||
Button { | ||
self.showAllTransactions() | ||
} label: { | ||
HStack(spacing: 2) { | ||
Text("Show All") | ||
Image(systemName: "arrow.right") | ||
} | ||
.font(.caption) | ||
.foregroundStyle(.secondary) | ||
.fontWeight(.regular) | ||
} | ||
} | ||
} | ||
.fontWeight(.bold) | ||
} | ||
} | ||
|
||
|
||
fileprivate extension ActivityHomeHeaderView.State { | ||
|
||
var syncImageIndicator: some View { | ||
switch self { | ||
case .synced: | ||
return AnyView( | ||
Image(systemName: "checkmark.circle.fill") | ||
.foregroundStyle(.green) | ||
) | ||
|
||
case .syncing(_, _, _), .fullSyncing(_): | ||
return AnyView( | ||
Image(systemName: "slowmo") | ||
.symbolEffect( | ||
.variableColor.cumulative | ||
) | ||
) | ||
|
||
case .notStarted: | ||
return AnyView( | ||
Image(systemName: "arrow.clockwise") | ||
) | ||
default: | ||
return AnyView( | ||
Image( | ||
systemName: "person.crop.circle.badge.exclamationmark" | ||
) | ||
) | ||
} | ||
} | ||
} | ||
r1b2ns marked this conversation as resolved.
Show resolved
Hide resolved
|
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.