Skip to content

Commit

Permalink
Asset transfer choose asset (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
GhenadieVP committed May 29, 2023
1 parent 435968f commit d4f4b90
Show file tree
Hide file tree
Showing 36 changed files with 938 additions and 640 deletions.
9 changes: 9 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package.addModules([
"AccountPreferencesFeature",
"AssetTransferFeature",
"AccountPortfoliosClient",
"AssetsFeature",
],
tests: .yes()
),
Expand Down Expand Up @@ -68,9 +69,17 @@ package.addModules([
dependencies: [
"ScanQRFeature",
"ChooseAccountsFeature",
"AssetsFeature",
],
tests: .yes()
),
.feature(
name: "AssetsFeature",
dependencies: [
"AccountPortfoliosClient",
],
tests: .no
),
.feature(
name: "AuthorizedDAppsFeature",
dependencies: [
Expand Down
22 changes: 19 additions & 3 deletions Sources/Core/DesignSystem/Components/Shapes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public struct VLine: Shape {
// MARK: - RoundedCorners
/// A more advanced rounded corners shape, allowing to round specific corners.
public struct RoundedCorners: Shape {
let radius: CGFloat
let corners: UIRectCorner
let radius: CGFloat

public init(radius: CGFloat, corners: UIRectCorner = .allCorners) {
self.radius = radius
public init(corners: UIRectCorner = .allCorners, radius: CGFloat) {
self.corners = corners
self.radius = radius
}

public func path(in rect: CGRect) -> SwiftUI.Path {
Expand All @@ -33,3 +33,19 @@ public struct RoundedCorners: Shape {
)
}
}

extension View {
public func roundedCorners(_ corners: UIRectCorner = .allCorners, radius: CGFloat) -> some View {
self.clipShape(RoundedCorners(corners: corners, radius: radius))
}
}

extension UIRectCorner {
public static var top: UIRectCorner {
[.topLeft, .topRight]
}

public static var bottom: UIRectCorner {
[.bottomLeft, .bottomRight]
}
}
68 changes: 68 additions & 0 deletions Sources/Core/DesignSystem/Layouts/StackedViewsLayout.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import Prelude

public struct StackedViewsLayout: Layout {
var isExpanded: Bool

/// Spacing between views in Expanded state
var spacing: CGFloat

/// Spacing between views in Collapsed state
var collapsedSpacing: CGFloat

/// Number of visible views in Collapsed state
var collapsedViewsCount: Int

public init(
isExpanded: Bool,
spacing: CGFloat = .small3,
collapsedSpacing: CGFloat = 10,
collapsedViewsCount: Int = 3
) {
self.isExpanded = isExpanded
self.spacing = spacing
self.collapsedSpacing = collapsedSpacing
self.collapsedViewsCount = collapsedViewsCount
}

public static var layoutProperties: LayoutProperties {
var properties = LayoutProperties()
properties.stackOrientation = .vertical
return properties
}

public func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
let container = proposal.replacingUnspecifiedDimensions()
guard !subviews.isEmpty else {
return container
}

let heights = subviews.map { $0.sizeThatFits(.init(width: container.width, height: nil)).height }
let height: CGFloat = {
if isExpanded {
return heights.reduce(0.0, +) + spacing * CGFloat(subviews.count - 1)
} else {
return heights[0] + CGFloat(collapsedViewsCount - 1) * collapsedSpacing
}
}()
return .init(width: container.width, height: height)
}

public func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
let container = proposal.replacingUnspecifiedDimensions()
var offset: CGFloat = 0
for (index, subview) in subviews.enumerated() {
let place = CGPoint(x: bounds.minX, y: bounds.minY + offset)
subview.place(at: place, proposal: .init(width: container.width, height: nil))

if isExpanded {
let subviewSize = subview.sizeThatFits(.init(width: container.width, height: nil))
offset += subviewSize.height + spacing
} else {
// The rest of the cards that go over `collapsedViewsCount` will go behind the last card.
if index < collapsedViewsCount - 1 {
offset += collapsedSpacing
}
}
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit d4f4b90

Please sign in to comment.