diff --git a/.swiftformat b/.swiftformat index c1ab489f7..526a11c0b 100644 --- a/.swiftformat +++ b/.swiftformat @@ -8,5 +8,7 @@ --maxwidth 100 --wraparguments before-first --funcattributes prev-line +--typeattributes prev-line +--varattributes prev-line --disable andOperator ---swiftversion 5.4 +--swiftversion 5.6 diff --git a/Sources/TokamakCore/Animation/Animatable.swift b/Sources/TokamakCore/Animation/Animatable.swift index c93ebd887..ca75dcac2 100644 --- a/Sources/TokamakCore/Animation/Animatable.swift +++ b/Sources/TokamakCore/Animation/Animatable.swift @@ -40,14 +40,20 @@ public extension Animatable where Self.AnimatableData == EmptyAnimatableData { } } -@frozen public struct EmptyAnimatableData: VectorArithmetic { +@frozen +public struct EmptyAnimatableData: VectorArithmetic { @inlinable public init() {} - @inlinable public static var zero: Self { .init() } + + @inlinable + public static var zero: Self { .init() } + @inlinable public static func += (lhs: inout Self, rhs: Self) {} + @inlinable public static func -= (lhs: inout Self, rhs: Self) {} + @inlinable public static func + (lhs: Self, rhs: Self) -> Self { .zero @@ -60,11 +66,15 @@ public extension Animatable where Self.AnimatableData == EmptyAnimatableData { @inlinable public mutating func scale(by rhs: Double) {} - @inlinable public var magnitudeSquared: Double { .zero } + + @inlinable + public var magnitudeSquared: Double { .zero } + public static func == (a: Self, b: Self) -> Bool { true } } -@frozen public struct AnimatablePair: VectorArithmetic +@frozen +public struct AnimatablePair: VectorArithmetic where First: VectorArithmetic, Second: VectorArithmetic { public var first: First @@ -81,7 +91,8 @@ public extension Animatable where Self.AnimatableData == EmptyAnimatableData { set { (first, second) = newValue } } - @_transparent public static var zero: Self { + @_transparent + public static var zero: Self { @_transparent get { .init(First.zero, Second.zero) } @@ -115,7 +126,8 @@ public extension Animatable where Self.AnimatableData == EmptyAnimatableData { second.scale(by: rhs) } - @_transparent public var magnitudeSquared: Double { + @_transparent + public var magnitudeSquared: Double { @_transparent get { first.magnitudeSquared + second.magnitudeSquared } diff --git a/Sources/TokamakCore/Animation/Animation.swift b/Sources/TokamakCore/Animation/Animation.swift index 2213f3f02..65a9b70da 100644 --- a/Sources/TokamakCore/Animation/Animation.swift +++ b/Sources/TokamakCore/Animation/Animation.swift @@ -139,7 +139,8 @@ public struct _AnimationProxy { public func resolve() -> _AnimationBoxBase._Resolved { subject.box.resolve() } } -@frozen public struct _AnimationModifier: ViewModifier, Equatable +@frozen +public struct _AnimationModifier: ViewModifier, Equatable where Value: Equatable { public var animation: Animation? @@ -155,7 +156,9 @@ public struct _AnimationProxy { let content: Content let animation: Animation? let value: Value - @State private var lastValue: Value? + + @State + private var lastValue: Value? var body: some View { content.transaction { @@ -180,7 +183,8 @@ public struct _AnimationProxy { } } -@frozen public struct _AnimationView: View +@frozen +public struct _AnimationView: View where Content: Equatable, Content: View { public var content: Content diff --git a/Sources/TokamakCore/Animation/Transaction.swift b/Sources/TokamakCore/Animation/Transaction.swift index 2e5a696be..187f8c851 100644 --- a/Sources/TokamakCore/Animation/Transaction.swift +++ b/Sources/TokamakCore/Animation/Transaction.swift @@ -50,7 +50,8 @@ protocol _TransactionModifierProtocol { func modifyTransaction(_ transaction: inout Transaction) } -@frozen public struct _TransactionModifier: ViewModifier { +@frozen +public struct _TransactionModifier: ViewModifier { public var transform: (inout Transaction) -> () @inlinable @@ -77,7 +78,8 @@ extension ModifiedContent: _TransactionModifierProtocol } } -@frozen public struct _PushPopTransactionModifier: ViewModifier where V: ViewModifier { +@frozen +public struct _PushPopTransactionModifier: ViewModifier where V: ViewModifier { public var content: V public var base: _TransactionModifier diff --git a/Sources/TokamakCore/Animation/VectorArithmetic.swift b/Sources/TokamakCore/Animation/VectorArithmetic.swift index a8c06d9d3..5a04d7a03 100644 --- a/Sources/TokamakCore/Animation/VectorArithmetic.swift +++ b/Sources/TokamakCore/Animation/VectorArithmetic.swift @@ -25,7 +25,9 @@ public protocol VectorArithmetic: AdditiveArithmetic { extension Float: VectorArithmetic { @_transparent public mutating func scale(by rhs: Double) { self *= Float(rhs) } - @_transparent public var magnitudeSquared: Double { + + @_transparent + public var magnitudeSquared: Double { @_transparent get { Double(self * self) } } } @@ -33,7 +35,9 @@ extension Float: VectorArithmetic { extension Double: VectorArithmetic { @_transparent public mutating func scale(by rhs: Double) { self *= rhs } - @_transparent public var magnitudeSquared: Double { + + @_transparent + public var magnitudeSquared: Double { @_transparent get { self * self } } } @@ -41,7 +45,9 @@ extension Double: VectorArithmetic { extension CGFloat: VectorArithmetic { @_transparent public mutating func scale(by rhs: Double) { self *= CGFloat(rhs) } - @_transparent public var magnitudeSquared: Double { + + @_transparent + public var magnitudeSquared: Double { @_transparent get { Double(self * self) } } } diff --git a/Sources/TokamakCore/Animation/_VectorMath.swift b/Sources/TokamakCore/Animation/_VectorMath.swift index 27e08b7c6..3f4470a83 100644 --- a/Sources/TokamakCore/Animation/_VectorMath.swift +++ b/Sources/TokamakCore/Animation/_VectorMath.swift @@ -20,7 +20,8 @@ import Foundation public protocol _VectorMath: Animatable {} public extension _VectorMath { - @inlinable var magnitude: Double { + @inlinable + var magnitude: Double { animatableData.magnitudeSquared.squareRoot() } diff --git a/Sources/TokamakCore/App/AppStorage.swift b/Sources/TokamakCore/App/AppStorage.swift index a9afa3190..388e67d5d 100644 --- a/Sources/TokamakCore/App/AppStorage.swift +++ b/Sources/TokamakCore/App/AppStorage.swift @@ -17,9 +17,13 @@ import OpenCombineShim -@propertyWrapper public struct AppStorage: DynamicProperty { +@propertyWrapper +public struct AppStorage: DynamicProperty { let provider: _StorageProvider? - @Environment(\._defaultAppStorage) var defaultProvider: _StorageProvider? + + @Environment(\._defaultAppStorage) + var defaultProvider: _StorageProvider? + var unwrappedProvider: _StorageProvider { provider ?? defaultProvider! } diff --git a/Sources/TokamakCore/App/Scenes/SceneStorage.swift b/Sources/TokamakCore/App/Scenes/SceneStorage.swift index 960308905..51208961f 100644 --- a/Sources/TokamakCore/App/Scenes/SceneStorage.swift +++ b/Sources/TokamakCore/App/Scenes/SceneStorage.swift @@ -23,7 +23,8 @@ public enum _DefaultSceneStorageProvider { public static var `default`: _StorageProvider! } -@propertyWrapper public struct SceneStorage: DynamicProperty { +@propertyWrapper +public struct SceneStorage: DynamicProperty { let key: String let defaultValue: Value let store: (_StorageProvider, String, Value) -> () diff --git a/Sources/TokamakCore/Environment/Environment.swift b/Sources/TokamakCore/Environment/Environment.swift index 7e79f8d52..08caef0c9 100644 --- a/Sources/TokamakCore/Environment/Environment.swift +++ b/Sources/TokamakCore/Environment/Environment.swift @@ -23,7 +23,8 @@ protocol EnvironmentReader { mutating func setContent(from values: EnvironmentValues) } -@propertyWrapper public struct Environment: DynamicProperty { +@propertyWrapper +public struct Environment: DynamicProperty { enum Content { case keyPath(KeyPath) case value(Value) diff --git a/Sources/TokamakCore/Environment/EnvironmentObject.swift b/Sources/TokamakCore/Environment/EnvironmentObject.swift index 7c4986cd3..59956a31f 100644 --- a/Sources/TokamakCore/Environment/EnvironmentObject.swift +++ b/Sources/TokamakCore/Environment/EnvironmentObject.swift @@ -17,10 +17,12 @@ import OpenCombineShim -@propertyWrapper public struct EnvironmentObject: DynamicProperty +@propertyWrapper +public struct EnvironmentObject: DynamicProperty where ObjectType: ObservableObject { - @dynamicMemberLookup public struct Wrapper { + @dynamicMemberLookup + public struct Wrapper { internal let root: ObjectType public subscript( dynamicMember keyPath: ReferenceWritableKeyPath diff --git a/Sources/TokamakCore/Fiber/AlignmentID.swift b/Sources/TokamakCore/Fiber/AlignmentID.swift index 1f19467cd..063396294 100644 --- a/Sources/TokamakCore/Fiber/AlignmentID.swift +++ b/Sources/TokamakCore/Fiber/AlignmentID.swift @@ -49,7 +49,8 @@ public protocol AlignmentID { } /// An alignment position along the horizontal axis. -@frozen public struct HorizontalAlignment: Equatable { +@frozen +public struct HorizontalAlignment: Equatable { public static func == (lhs: Self, rhs: Self) -> Bool { lhs.id == rhs.id } @@ -87,7 +88,8 @@ extension HorizontalAlignment { } } -@frozen public struct VerticalAlignment: Equatable { +@frozen +public struct VerticalAlignment: Equatable { public static func == (lhs: Self, rhs: Self) -> Bool { lhs.id == rhs.id } diff --git a/Sources/TokamakCore/Fiber/Fiber.swift b/Sources/TokamakCore/Fiber/Fiber.swift index 2212ccc01..15e49e7a6 100644 --- a/Sources/TokamakCore/Fiber/Fiber.swift +++ b/Sources/TokamakCore/Fiber/Fiber.swift @@ -1,4 +1,4 @@ -// Copyright 2021 Tokamak contributors +// Copyright 2022 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -45,7 +45,8 @@ public extension FiberReconciler { /// Stored as an IUO because we must use the `bindProperties` method /// to create the `View` with its dependencies setup, /// which requires all stored properties be set before using. - @_spi(TokamakCore) public var view: Any! + @_spi(TokamakCore) + public var view: Any! /// Outputs from evaluating `View._makeView` /// /// Stored as an IUO because creating `ViewOutputs` depends on @@ -64,9 +65,11 @@ public extension FiberReconciler { /// The index of this element in its elementParent var elementIndex: Int? /// The first child node. - @_spi(TokamakCore) public var child: Fiber? + @_spi(TokamakCore) + public var child: Fiber? /// This node's right sibling. - @_spi(TokamakCore) public var sibling: Fiber? + @_spi(TokamakCore) + public var sibling: Fiber? /// An unowned reference to the parent node. /// /// Parent references are `unowned` (as opposed to `weak`) diff --git a/Sources/TokamakCore/Fiber/FiberReconciler.swift b/Sources/TokamakCore/Fiber/FiberReconciler.swift index 904b4c20c..86c626420 100644 --- a/Sources/TokamakCore/Fiber/FiberReconciler.swift +++ b/Sources/TokamakCore/Fiber/FiberReconciler.swift @@ -21,7 +21,8 @@ import Foundation /// [Fiber reconciler](https://reactjs.org/docs/faq-internals.html#what-is-react-fiber) public final class FiberReconciler { /// The root node in the `Fiber` tree that represents the `View`s currently rendered on screen. - @_spi(TokamakCore) public var current: Fiber! + @_spi(TokamakCore) + public var current: Fiber! /// The alternate of `current`, or the work in progress tree root. /// /// We must keep a strong reference to both the current and alternate tree roots, diff --git a/Sources/TokamakCore/Modifiers/AspectRatioLayout.swift b/Sources/TokamakCore/Modifiers/AspectRatioLayout.swift index 2a40a25eb..b7792c547 100644 --- a/Sources/TokamakCore/Modifiers/AspectRatioLayout.swift +++ b/Sources/TokamakCore/Modifiers/AspectRatioLayout.swift @@ -14,7 +14,8 @@ import Foundation -@frozen public enum ContentMode: Hashable, CaseIterable { +@frozen +public enum ContentMode: Hashable, CaseIterable { case fit case fill } diff --git a/Sources/TokamakCore/Modifiers/Effects/OffsetEffect.swift b/Sources/TokamakCore/Modifiers/Effects/OffsetEffect.swift index 5bd13e814..1b6327854 100644 --- a/Sources/TokamakCore/Modifiers/Effects/OffsetEffect.swift +++ b/Sources/TokamakCore/Modifiers/Effects/OffsetEffect.swift @@ -17,7 +17,8 @@ import Foundation -@frozen public struct _OffsetEffect: GeometryEffect, Equatable { +@frozen +public struct _OffsetEffect: GeometryEffect, Equatable { public var offset: CGSize @inlinable diff --git a/Sources/TokamakCore/Modifiers/Effects/ScaleEffect.swift b/Sources/TokamakCore/Modifiers/Effects/ScaleEffect.swift index 9e03cc416..e880643da 100644 --- a/Sources/TokamakCore/Modifiers/Effects/ScaleEffect.swift +++ b/Sources/TokamakCore/Modifiers/Effects/ScaleEffect.swift @@ -17,7 +17,8 @@ import Foundation -@frozen public struct _ScaleEffect: GeometryEffect, Equatable { +@frozen +public struct _ScaleEffect: GeometryEffect, Equatable { public var scale: CGSize public var anchor: UnitPoint diff --git a/Sources/TokamakCore/Modifiers/ModifiedContent.swift b/Sources/TokamakCore/Modifiers/ModifiedContent.swift index dc592da57..45156beda 100644 --- a/Sources/TokamakCore/Modifiers/ModifiedContent.swift +++ b/Sources/TokamakCore/Modifiers/ModifiedContent.swift @@ -20,7 +20,9 @@ protocol ModifiedContentProtocol {} /// A value with a modifier applied to it. public struct ModifiedContent: ModifiedContentProtocol { - @Environment(\.self) public var environment + @Environment(\.self) + public var environment + public typealias Body = Never public private(set) var content: Content public private(set) var modifier: Modifier diff --git a/Sources/TokamakCore/Modifiers/StyleModifiers.swift b/Sources/TokamakCore/Modifiers/StyleModifiers.swift index 50ebbc4d9..5a016a999 100644 --- a/Sources/TokamakCore/Modifiers/StyleModifiers.swift +++ b/Sources/TokamakCore/Modifiers/StyleModifiers.swift @@ -77,7 +77,8 @@ public extension View { } } -@frozen public struct _BackgroundShapeModifier: ViewModifier, EnvironmentReader +@frozen +public struct _BackgroundShapeModifier: ViewModifier, EnvironmentReader where Style: ShapeStyle, Bounds: Shape { public var environment: EnvironmentValues! diff --git a/Sources/TokamakCore/Preferences/_PreferenceReadingView.swift b/Sources/TokamakCore/Preferences/_PreferenceReadingView.swift index 7ff7b5836..fdda25528 100644 --- a/Sources/TokamakCore/Preferences/_PreferenceReadingView.swift +++ b/Sources/TokamakCore/Preferences/_PreferenceReadingView.swift @@ -20,7 +20,8 @@ public struct _DelayedPreferenceView: View, _PreferenceReadingViewProtocol where Key: PreferenceKey, Content: View { - @State private var resolvedValue: _PreferenceValue = _PreferenceValue( + @State + private var resolvedValue: _PreferenceValue = _PreferenceValue( valueList: [Key.defaultValue] ) public let transform: (_PreferenceValue) -> Content diff --git a/Sources/TokamakCore/PreviewProvider.swift b/Sources/TokamakCore/PreviewProvider.swift index 171b4bb41..b665b377f 100644 --- a/Sources/TokamakCore/PreviewProvider.swift +++ b/Sources/TokamakCore/PreviewProvider.swift @@ -18,7 +18,8 @@ import Foundation public protocol PreviewProvider { associatedtype Previews: View - @ViewBuilder static var previews: Previews { get } + @ViewBuilder + static var previews: Previews { get } } public struct PreviewDevice: RawRepresentable, ExpressibleByStringLiteral { diff --git a/Sources/TokamakCore/Reflection/Layouts/StructTypeDescriptor.swift b/Sources/TokamakCore/Reflection/Layouts/StructTypeDescriptor.swift index cdb8e86a3..018f38660 100644 --- a/Sources/TokamakCore/Reflection/Layouts/StructTypeDescriptor.swift +++ b/Sources/TokamakCore/Reflection/Layouts/StructTypeDescriptor.swift @@ -20,7 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -typealias FieldTypeAccessor = @convention(c) (UnsafePointer) -> UnsafePointer +typealias FieldTypeAccessor = @convention(c) + (UnsafePointer) -> UnsafePointer struct StructTypeDescriptor { let flags: Int32 diff --git a/Sources/TokamakCore/Shapes/ContainerRelativeShape.swift b/Sources/TokamakCore/Shapes/ContainerRelativeShape.swift index ecfdaa56f..8d851b0ae 100644 --- a/Sources/TokamakCore/Shapes/ContainerRelativeShape.swift +++ b/Sources/TokamakCore/Shapes/ContainerRelativeShape.swift @@ -38,7 +38,8 @@ extension ContainerRelativeShape: InsettableShape { } @usableFromInline - @frozen internal struct _Inset: InsettableShape, DynamicProperty { + @frozen + internal struct _Inset: InsettableShape, DynamicProperty { @usableFromInline internal var amount: CGFloat @inlinable @@ -76,7 +77,8 @@ private extension EnvironmentValues { } } -@frozen public struct _ContainerShapeModifier: ViewModifier where Shape: InsettableShape { +@frozen +public struct _ContainerShapeModifier: ViewModifier where Shape: InsettableShape { public var shape: Shape @inlinable public init(shape: Shape) { self.shape = shape } diff --git a/Sources/TokamakCore/Shapes/ModifiedShapes.swift b/Sources/TokamakCore/Shapes/ModifiedShapes.swift index 67b681d8b..41b131920 100644 --- a/Sources/TokamakCore/Shapes/ModifiedShapes.swift +++ b/Sources/TokamakCore/Shapes/ModifiedShapes.swift @@ -18,7 +18,9 @@ import Foundation public struct _StrokedShape: Shape, DynamicProperty where S: Shape { - @Environment(\.self) public var environment + @Environment(\.self) + public var environment + public var shape: S public var style: StrokeStyle diff --git a/Sources/TokamakCore/Shapes/Rectangle.swift b/Sources/TokamakCore/Shapes/Rectangle.swift index f148bf545..320d643f8 100644 --- a/Sources/TokamakCore/Shapes/Rectangle.swift +++ b/Sources/TokamakCore/Shapes/Rectangle.swift @@ -89,8 +89,11 @@ extension RoundedRectangle: InsettableShape { @usableFromInline struct _Inset: InsettableShape { - @usableFromInline var base: RoundedRectangle - @usableFromInline var amount: CGFloat + @usableFromInline + var base: RoundedRectangle + + @usableFromInline + var amount: CGFloat @inlinable init(base: RoundedRectangle, amount: CGFloat) { diff --git a/Sources/TokamakCore/Shapes/Shape.swift b/Sources/TokamakCore/Shapes/Shape.swift index 14c83b52b..1eeecf596 100644 --- a/Sources/TokamakCore/Shapes/Shape.swift +++ b/Sources/TokamakCore/Shapes/Shape.swift @@ -55,8 +55,12 @@ public struct FillStyle: Equatable { } public struct _ShapeView: _PrimitiveView where Content: Shape, Style: ShapeStyle { - @Environment(\.self) public var environment - @Environment(\.foregroundColor) public var foregroundColor + @Environment(\.self) + public var environment + + @Environment(\.foregroundColor) + public var foregroundColor + public var shape: Content public var style: Style public var fillStyle: FillStyle diff --git a/Sources/TokamakCore/Shapes/ShapeStyles/BackgroundStyle.swift b/Sources/TokamakCore/Shapes/ShapeStyles/BackgroundStyle.swift index 364225c64..0374054af 100644 --- a/Sources/TokamakCore/Shapes/ShapeStyles/BackgroundStyle.swift +++ b/Sources/TokamakCore/Shapes/ShapeStyles/BackgroundStyle.swift @@ -56,7 +56,8 @@ public extension View { } } -@frozen public struct _BackgroundStyleModifier