Move compound-ios package into the project.

This commit is contained in:
Doug
2025-09-28 15:19:46 +01:00
committed by Doug
parent 9874d6fd84
commit ed73853c9b
80 changed files with 3658 additions and 25 deletions
@@ -0,0 +1,56 @@
//
// Copyright 2023, 2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import SwiftUI
public extension View {
/// Positions this view within an invisible frame with a square size that scales relative to the user's selected font size.
func scaledFrame(size: CGFloat, alignment: Alignment = .center, relativeTo textStyle: Font.TextStyle = .body) -> some View {
scaledFrame(width: size, height: size, alignment: alignment, relativeTo: textStyle)
}
/// Positions this view within an invisible frame with a size that scales relative to the user's selected font size.
func scaledFrame(width: CGFloat, height: CGFloat, alignment: Alignment = .center, relativeTo textStyle: Font.TextStyle = .body) -> some View {
modifier(ScaledFrameModifier(width: width, height: height, alignment: alignment, relativeTo: textStyle))
}
}
private struct ScaledFrameModifier: ViewModifier {
@ScaledMetric var width: CGFloat
@ScaledMetric var height: CGFloat
let alignment: Alignment
init(width: CGFloat, height: CGFloat, alignment: Alignment, relativeTo textStyle: Font.TextStyle) {
_width = ScaledMetric(wrappedValue: width, relativeTo: textStyle)
_height = ScaledMetric(wrappedValue: height, relativeTo: textStyle)
self.alignment = alignment
}
func body(content: Content) -> some View {
content.frame(width: width, height: height, alignment: alignment)
}
}
// MARK: - Previews
struct ScaledFrameModifier_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
VStack {
ForEach(DynamicTypeSize.allCases, id: \.self) { size in
likeButtonLabel
.dynamicTypeSize(size)
}
}
}
static var likeButtonLabel: some View {
Image(systemSymbol: .heartCircleFill)
.resizable()
.foregroundStyle(.compound.iconAccentTertiary)
.scaledFrame(size: 24, relativeTo: .title)
}
}
@@ -0,0 +1,53 @@
//
// Copyright 2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import SwiftUI
public extension View {
/// Offset this view by the specified horizontal and vertical distances, scaled relative to the user's selected font size.
func scaledOffset(x: CGFloat = 0, y: CGFloat = 0, relativeTo textStyle: Font.TextStyle = .body) -> some View {
modifier(ScaledOffsetModifier(x: x, y: y, relativeTo: textStyle))
}
}
private struct ScaledOffsetModifier: ViewModifier {
@ScaledMetric var x: CGFloat
@ScaledMetric var y: CGFloat
init(x: CGFloat, y: CGFloat, relativeTo textStyle: Font.TextStyle) {
_x = ScaledMetric(wrappedValue: x, relativeTo: textStyle)
_y = ScaledMetric(wrappedValue: y, relativeTo: textStyle)
}
func body(content: Content) -> some View {
content.offset(x: x, y: y)
}
}
// MARK: - Previews
struct ScaledOffsetModifier_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
VStack {
ForEach(DynamicTypeSize.allCases, id: \.self) { size in
verifiedUserComposite
.dynamicTypeSize(size)
}
}
}
static var verifiedUserComposite: some View {
CompoundIcon(\.userSolid)
.foregroundStyle(.compound.iconAccentTertiary)
.overlay {
CompoundIcon(\.verified, size: .custom(10), relativeTo: .body)
.scaledOffset(x: 6, y: 6)
.foregroundStyle(.compound.gradientActionStop1)
}
}
}
@@ -0,0 +1,54 @@
//
// Copyright 2023, 2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import SwiftUI
public extension View {
/// Adds an equal padding amount to all edges of this view, scaled relative to the user's selected font size.
func scaledPadding(_ length: CGFloat, relativeTo textStyle: Font.TextStyle = .body) -> some View {
scaledPadding(.all, length, relativeTo: textStyle)
}
/// Adds an equal padding amount to specific edges of this view, scaled relative to the user's selected font size.
func scaledPadding(_ edges: Edge.Set, _ length: CGFloat, relativeTo textStyle: Font.TextStyle = .body) -> some View {
modifier(ScaledPaddingModifier(edges: edges, length: length, textStyle: textStyle))
}
}
private struct ScaledPaddingModifier: ViewModifier {
let edges: Edge.Set
@ScaledMetric var length: CGFloat
init(edges: Edge.Set, length: CGFloat, textStyle: Font.TextStyle) {
self.edges = edges
_length = ScaledMetric(wrappedValue: length, relativeTo: textStyle)
}
func body(content: Content) -> some View {
content.padding(edges, length)
}
}
// MARK: - Previews
struct ScaledPaddingModifier_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
VStack {
ForEach(DynamicTypeSize.allCases, id: \.self) { size in
userProfileButtonLabel
.dynamicTypeSize(size)
}
}
}
static var userProfileButtonLabel: some View {
CompoundIcon(\.userProfile, size: .medium, relativeTo: .title)
.foregroundStyle(.compound.iconOnSolidPrimary)
.scaledPadding(6, relativeTo: .title)
.background(.compound.bgAccentRest, in: Circle())
}
}