-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement contributors count item in SwiftUI view for iOS
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
app-ios/Sources/ContributorFeature/ContributorsCountItem.swift
This file contains 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,49 @@ | ||
import SwiftUI | ||
import Theme | ||
|
||
struct ContributorsCountItem: View { | ||
let totalContributor: Int | ||
let duration: Double = 1.0 | ||
@State private var tracker = 0 | ||
|
||
var body: some View { | ||
VStack(alignment: .leading) { | ||
|
||
Text(String(localized: "Total", bundle: .module)) | ||
.textStyle(.titleMedium) | ||
.foregroundStyle(AssetColors.Surface.onSurfaceVariant.swiftUIColor) | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
|
||
HStack { | ||
Text("\(tracker)") | ||
.textStyle(.headlineLarge) | ||
.foregroundStyle(AssetColors.Surface.onSurface.swiftUIColor) | ||
.onAppear() { | ||
animate() | ||
} | ||
|
||
Text(String(localized: "Person", bundle: .module)) | ||
.textStyle(.headlineSmall) | ||
.foregroundStyle(AssetColors.Surface.onSurface.swiftUIColor) | ||
} | ||
|
||
Spacer() | ||
.frame(height: 16) | ||
Divider() | ||
} | ||
} | ||
|
||
func animate() { | ||
let interval = duration / Double(totalContributor) | ||
Timer.scheduledTimer(withTimeInterval: interval, repeats: true) { time in | ||
tracker += 1 | ||
if tracker == totalContributor { | ||
time.invalidate() | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
ContributorsCountItem(totalContributor: 112) | ||
} |
This file contains 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
This file contains 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