Skip to content

Commit 9462fb0

Browse files
committed
Deprecate View any modifier
1 parent 7c4c7bc commit 9462fb0

File tree

6 files changed

+23
-25
lines changed

6 files changed

+23
-25
lines changed

RELEASE_NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Thanks to [pnewell](https://github.com/pnewell), SwiftUIKit now supports Catalys
1313
* The `DateFormatter` init extensions have been deprecated.
1414
* The `DispatchQueue` `asyncAfter` extension has been deprecated.
1515
* The `JsonEncoder/Decoder` date extensions have been deprecated.
16+
* The `View` `any()` extension should NOT be used and has been deprecated.
1617

1718

1819

Sources/SwiftUIKit/Presentation/FullScreenCoverContext.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class FullScreenCoverContext: PresentationContext<AnyView> {
3636
public func present<Cover: View>(
3737
_ cover: @autoclosure @escaping () -> Cover
3838
) {
39-
presentContent(cover().any())
39+
presentContent(AnyView(cover()))
4040
}
4141
}
4242

@@ -53,7 +53,7 @@ public extension View {
5353
) -> some View {
5454
fullScreenCover(
5555
isPresented: context.isActiveBinding,
56-
content: context.content ?? EmptyView().any
56+
content: context.content ?? { AnyView(EmptyView()) }
5757
)
5858
.environmentObject(context)
5959
}

Sources/SwiftUIKit/Presentation/SheetContext.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class SheetContext: PresentationContext<AnyView> {
3636

3737
@MainActor
3838
public func present<Sheet: View>(_ sheet: @autoclosure @escaping () -> Sheet) {
39-
presentContent(sheet().any())
39+
presentContent(AnyView(sheet()))
4040
}
4141
}
4242

@@ -48,7 +48,7 @@ public extension View {
4848
func sheet(_ context: SheetContext) -> some View {
4949
sheet(
5050
isPresented: context.isActiveBinding,
51-
content: context.content ?? EmptyView().any
51+
content: context.content ?? { AnyView(EmptyView()) }
5252
)
5353
.environmentObject(context)
5454
}

Sources/SwiftUIKit/Progress/CircularProgressBar.swift

+16-16
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,27 @@ private extension CircularProgressBar {
5454

5555
var progressCircle: some View {
5656
style.progressModifier(
57-
Circle()
57+
AnyView(
58+
Circle()
5859
.trim(from: 0.0, to: CGFloat(progress))
5960
.rotation(.degrees(style.startAngle - 90))
6061
.stroke(style: StrokeStyle(lineWidth: style.progressWidth, lineCap: .round, lineJoin: .round))
6162
.foregroundColor(style.progressColor)
6263
.animation(style.animation, value: progress)
63-
.any()
64+
)
6465
)
6566
}
6667

6768
@ViewBuilder
6869
var progressText: some View {
6970
if style.showTitle {
7071
style.titleModifier(
71-
Text("\(progressValue, specifier: "%.\(style.decimals)f")%")
72-
.lineLimit(1)
73-
.font(style.titleFont)
74-
.foregroundColor(style.titleColor)
75-
.any()
72+
AnyView(
73+
Text("\(progressValue, specifier: "%.\(style.decimals)f")%")
74+
.lineLimit(1)
75+
.font(style.titleFont)
76+
.foregroundColor(style.titleColor)
77+
)
7678
)
7779
}
7880
}
@@ -94,14 +96,12 @@ private extension CircularProgressBar {
9496
CircularProgressBar(progress: progress)
9597

9698
CircularProgressBar(progress: progress)
97-
.shadow(.elevated)
98-
.circularProgressBarStyle(.swedish)
99+
.shadow(.elevated)
100+
.circularProgressBarStyle(.swedish)
99101

100-
CircularProgressBar(
101-
progress: progress
102-
)
103-
.shadow(.sticker)
104-
.circularProgressBarStyle(.noText)
102+
CircularProgressBar(progress: progress)
103+
.shadow(.sticker)
104+
.circularProgressBarStyle(.noText)
105105

106106
Button("Preview.Progress") {
107107
progress += 0.1
@@ -128,10 +128,10 @@ fileprivate extension CircularProgressBar.Style {
128128
style.startAngle = 45
129129
style.progressColor = .yellow
130130
style.progressWidth = 15
131-
style.progressModifier = { $0.shadow(.elevated).any() }
131+
style.progressModifier = { AnyView($0.shadow(.elevated)) }
132132
style.titleColor = .yellow
133133
style.titleFont = .title.bold()
134-
style.titleModifier = { $0.shadow(.elevated).any() }
134+
style.titleModifier = { AnyView($0.shadow(.elevated)) }
135135
return style
136136
}
137137

Sources/SwiftUIKit/Views/FetchedDataView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public struct FetchedDataView<Model, Content: View, LoadingView: View, NoDataVie
6262
struct Preview: View {
6363

6464
let nilData: String? = nil
65-
let content: (String) -> AnyView = { Text($0).any() }
65+
let content: (String) -> Text = { .init($0) }
6666
let loadingView = Text("Preview.Loading")
6767
let noDataView = Text("Preview.NoData")
6868

Sources/SwiftUIKit/Extensions/View+AnyView.swift renamed to Sources/SwiftUIKit/_Deprecated/View+AnyView.swift

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import SwiftUI
1010

1111
public extension View {
1212

13-
/// Wrap the view in an `AnyView`.
14-
///
15-
/// > Important: Do not misuse AnyView. It esmess up the
16-
/// view identity, which messes up animations, state etc.
13+
@available(*, deprecated, message: "This should not be used and will be removed in the next major release.")
1714
func any() -> AnyView {
1815
AnyView(self)
1916
}

0 commit comments

Comments
 (0)