From 0fa7b69f2cf3649a2cdb43e43dbe038740b96d3e Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 16 Dec 2023 22:16:00 +0800 Subject: [PATCH] Fix build warnings --- Package.swift | 7 ++- .../Views/Controls/Slider/Slider.swift | 60 +++++++++++++++++++ .../Views/View/internal/ViewAlias.swift | 10 +++- 3 files changed, 73 insertions(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index ddcf154d..61b6186e 100644 --- a/Package.swift +++ b/Package.swift @@ -20,6 +20,7 @@ let openSwiftUITarget = Target.target( ], swiftSettings: [ .enableExperimentalFeature("AccessLevelOnImport"), + .define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS") ], linkerSettings: [ .unsafeFlags( @@ -36,13 +37,15 @@ let openSwiftUITestTarget = Target.testTarget( name: "OpenSwiftUITests", dependencies: [ "OpenSwiftUI", - ] + ], + exclude: ["README.md"] ) let openSwiftUICompatibilityTestTarget = Target.testTarget( name: "OpenSwiftUICompatibilityTests", dependencies: [ "OpenSwiftUI", - ] + ], + exclude: ["README.md"] ) let package = Package( diff --git a/Sources/OpenSwiftUI/Views/Controls/Slider/Slider.swift b/Sources/OpenSwiftUI/Views/Controls/Slider/Slider.swift index f18bfd3d..0f2e1ba3 100644 --- a/Sources/OpenSwiftUI/Views/Controls/Slider/Slider.swift +++ b/Sources/OpenSwiftUI/Views/Controls/Slider/Slider.swift @@ -129,7 +129,9 @@ extension Slider { /// The slider calls `onEditingChanged` when editing begins and ends. For /// example, on iOS, editing begins when the user starts to drag the thumb /// along the slider's track. + #if !OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS @_alwaysEmitIntoClient + #endif public init( value: Binding, in bounds: ClosedRange = 0 ... 1, @@ -138,6 +140,18 @@ extension Slider { @ViewBuilder maximumValueLabel: () -> ValueLabel, onEditingChanged: @escaping (Bool) -> Void = { _ in } ) where V: BinaryFloatingPoint, V.Stride: BinaryFloatingPoint { + #if OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS + self.init( + value: value, + in: bounds, + step: nil, + onEditingChanged: onEditingChanged, + minimumValueLabel: minimumValueLabel(), + maximumValueLabel: maximumValueLabel(), + customMinMaxValueLabels: true, + label: label() + ) + #else self.init( value: value, in: bounds, @@ -146,6 +160,7 @@ extension Slider { maximumValueLabel: maximumValueLabel(), label: label ) + #endif } /// Creates a slider to select a value from a given range, subject to a @@ -169,7 +184,9 @@ extension Slider { /// The slider calls `onEditingChanged` when editing begins and ends. For /// example, on iOS, editing begins when the user starts to drag the thumb /// along the slider's track. + #if !OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS @_alwaysEmitIntoClient + #endif public init( value: Binding, in bounds: ClosedRange, @@ -179,6 +196,18 @@ extension Slider { @ViewBuilder maximumValueLabel: () -> ValueLabel, onEditingChanged: @escaping (Bool) -> Void = { _ in } ) where V: BinaryFloatingPoint, V.Stride: BinaryFloatingPoint { + #if OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS + self.init( + value: value, + in: bounds, + step: step, + onEditingChanged: onEditingChanged, + minimumValueLabel: minimumValueLabel(), + maximumValueLabel: maximumValueLabel(), + customMinMaxValueLabels: true, + label: label() + ) + #else self.init( value: value, in: bounds, @@ -188,6 +217,7 @@ extension Slider { maximumValueLabel: maximumValueLabel(), label: label ) + #endif } } @@ -211,19 +241,34 @@ extension Slider where ValueLabel == EmptyView { /// The slider calls `onEditingChanged` when editing begins and ends. For /// example, on iOS, editing begins when the user starts to drag the thumb /// along the slider's track. + #if !OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS @_alwaysEmitIntoClient + #endif public init( value: Binding, in bounds: ClosedRange = 0 ... 1, @ViewBuilder label: () -> Label, onEditingChanged: @escaping (Bool) -> Void = { _ in } ) where V: BinaryFloatingPoint, V.Stride: BinaryFloatingPoint { + #if OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS + self.init( + value: value, + in: bounds, + step: nil, + onEditingChanged: onEditingChanged, + minimumValueLabel: EmptyView(), + maximumValueLabel: EmptyView(), + customMinMaxValueLabels: false, + label: label() + ) + #else self.init( value: value, in: bounds, onEditingChanged: onEditingChanged, label: label ) + #endif } /// Creates a slider to select a value from a given range, subject to a @@ -245,7 +290,9 @@ extension Slider where ValueLabel == EmptyView { /// The slider calls `onEditingChanged` when editing begins and ends. For /// example, on iOS, editing begins when the user starts to drag the thumb /// along the slider's track. + #if !OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS @_alwaysEmitIntoClient + #endif public init( value: Binding, in bounds: ClosedRange, @@ -253,6 +300,18 @@ extension Slider where ValueLabel == EmptyView { @ViewBuilder label: () -> Label, onEditingChanged: @escaping (Bool) -> Void = { _ in } ) where V: BinaryFloatingPoint, V.Stride: BinaryFloatingPoint { + #if OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS + self.init( + value: value, + in: bounds, + step: step, + onEditingChanged: onEditingChanged, + minimumValueLabel: EmptyView(), + maximumValueLabel: EmptyView(), + customMinMaxValueLabels: false, + label: label() + ) + #else self.init( value: value, in: bounds, @@ -260,6 +319,7 @@ extension Slider where ValueLabel == EmptyView { onEditingChanged: onEditingChanged, label: label ) + #endif } } diff --git a/Sources/OpenSwiftUI/Views/View/internal/ViewAlias.swift b/Sources/OpenSwiftUI/Views/View/internal/ViewAlias.swift index 4009af2d..2d0d10e4 100644 --- a/Sources/OpenSwiftUI/Views/View/internal/ViewAlias.swift +++ b/Sources/OpenSwiftUI/Views/View/internal/ViewAlias.swift @@ -12,11 +12,17 @@ protocol ViewAlias: PrimitiveView { } extension View { - func viewAlias(_ alias: Alias.Type, _ source: () -> Source) -> some View { + func viewAlias( + _ alias: Alias.Type, + _ source: () -> Source + ) -> some View { modifier(StaticSourceWriter(source: source())) } - func viewAlias(_ alias: Alias.Type, _ source: () -> Source?) -> some View { + func viewAlias( + _ alias: Alias.Type, + _ source: () -> Source? + ) -> some View { modifier(OptionalSourceWriter(source: source())) } }