Skip to content

Commit

Permalink
Fix build warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Dec 16, 2023
1 parent a9b128b commit 0fa7b69
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
7 changes: 5 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let openSwiftUITarget = Target.target(
],
swiftSettings: [
.enableExperimentalFeature("AccessLevelOnImport"),
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS")
],
linkerSettings: [
.unsafeFlags(
Expand All @@ -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(
Expand Down
60 changes: 60 additions & 0 deletions Sources/OpenSwiftUI/Views/Controls/Slider/Slider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<V>(
value: Binding<V>,
in bounds: ClosedRange<V> = 0 ... 1,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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<V>(
value: Binding<V>,
in bounds: ClosedRange<V>,
Expand All @@ -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,
Expand All @@ -188,6 +217,7 @@ extension Slider {
maximumValueLabel: maximumValueLabel(),
label: label
)
#endif
}
}

Expand All @@ -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<V>(
value: Binding<V>,
in bounds: ClosedRange<V> = 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
Expand All @@ -245,21 +290,36 @@ 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<V>(
value: Binding<V>,
in bounds: ClosedRange<V>,
step: V.Stride = 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: step,
onEditingChanged: onEditingChanged,
minimumValueLabel: EmptyView(),
maximumValueLabel: EmptyView(),
customMinMaxValueLabels: false,
label: label()
)
#else
self.init(
value: value,
in: bounds,
step: step,
onEditingChanged: onEditingChanged,
label: label
)
#endif
}
}

Expand Down
10 changes: 8 additions & 2 deletions Sources/OpenSwiftUI/Views/View/internal/ViewAlias.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ protocol ViewAlias: PrimitiveView {
}

extension View {
func viewAlias<Alias: ViewAlias, Source: View>(_ alias: Alias.Type, _ source: () -> Source) -> some View {
func viewAlias<Alias: ViewAlias, Source: View>(
_ alias: Alias.Type,
_ source: () -> Source
) -> some View {
modifier(StaticSourceWriter<Alias, Source>(source: source()))
}

func viewAlias<Alias: ViewAlias, Source: View>(_ alias: Alias.Type, _ source: () -> Source?) -> some View {
func viewAlias<Alias: ViewAlias, Source: View>(
_ alias: Alias.Type,
_ source: () -> Source?
) -> some View {
modifier(OptionalSourceWriter<Alias, Source>(source: source()))
}
}
Expand Down

0 comments on commit 0fa7b69

Please sign in to comment.