Skip to content

Commit

Permalink
Implement contributors count item in SwiftUI view for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
raseln committed Sep 6, 2024
1 parent 7dc182f commit d5513a1
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
49 changes: 49 additions & 0 deletions app-ios/Sources/ContributorFeature/ContributorsCountItem.swift
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ struct KmpPresenterContributorView: View {
if let contributors = currentState.map(\.contributors) {
ScrollView {
LazyVStack(spacing: 0) {

ContributorsCountItem(totalContributor: contributors.count)
.frame(maxWidth: .infinity)
.padding(.horizontal, 16)
.padding(.vertical, 10)

ForEach(contributors, id: \.id) { value in
let contributor = Model.Contributor(
id: Int(value.id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ struct SwiftUIContributorView: View {
if let contributors = store.contributors {
ScrollView {
LazyVStack(spacing: 0) {

ContributorsCountItem(totalContributor: contributors.count)
.frame(maxWidth: .infinity)
.padding(.horizontal, 16)
.padding(.vertical, 10)

ForEach(contributors, id: \.id) { contributor in
ContributorListItemView(contributor: contributor) { url in
store.send(.view(.contributorButtonTapped(url)))
Expand Down

0 comments on commit d5513a1

Please sign in to comment.