Skip to content

Commit

Permalink
ViewThatFits sample
Browse files Browse the repository at this point in the history
  • Loading branch information
TahaTesser committed Oct 6, 2024
1 parent b95f89b commit 98bf05c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Binary file not shown.
8 changes: 8 additions & 0 deletions SwiftUIPlayground/Samples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,12 @@ public let samples: [String: AnyView] = [
"ProgressView": AnyView(ProgressViewSample()),
]
)),
"Layout Fundamentals": AnyView(SamplesList(
title: "Layout Fundamentals", samples:
[
// https://developer.apple.com/documentation/swiftui/viewthatfits
"ViewThatFits": AnyView(ViewThatFitsSample()),
]
)),

]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// ViewThatFitsSample.swift
// SwiftUIPlayground
//
// Created by Taha Tesser on 10/6/24.
//

import SwiftUI

struct ViewThatFitsSample: View {
var body: some View {
VStack {
UploadProgressView(uploadProgress: 0.75)
.frame(maxWidth: 200)
UploadProgressView(uploadProgress: 0.75)
.frame(maxWidth: 100)
UploadProgressView(uploadProgress: 0.75)
.frame(maxWidth: 50)
}
}
}

#Preview {
ViewThatFitsSample()
}

struct UploadProgressView: View {
var uploadProgress: Double

var body: some View {
ViewThatFits(in: .horizontal) {
HStack {
Text("\(uploadProgress.formatted(.percent))")
ProgressView(value: uploadProgress)
.frame(width: 100)
}
ProgressView(value: uploadProgress)
.frame(width: 100)
Text("\(uploadProgress.formatted(.percent))")
}

}
}

0 comments on commit 98bf05c

Please sign in to comment.