File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #if canImport(AndroidSwiftUI)
2+ import AndroidSwiftUI
3+ #else
4+ import SwiftUI
5+ #endif
6+
7+ struct GeometryPlayground : View {
8+
9+ @State private var tall = false
10+
11+ var body : some View {
12+ VStack ( alignment: . leading, spacing: 16 ) {
13+ Text ( " A GeometryReader reports the space its parent offers. " )
14+
15+ GeometryReader { geometry in
16+ VStack ( alignment: . leading, spacing: 10 ) {
17+ Text ( " Offered: \( Int ( geometry. size. width) ) × \( Int ( geometry. size. height) ) " )
18+ // bars sized from the measurement — proof the number is live
19+ Text ( " half width " )
20+ Rectangle ( )
21+ . fill ( . blue)
22+ . frame ( width: geometry. size. width / 2 , height: 22 )
23+ Text ( " one quarter " )
24+ Rectangle ( )
25+ . fill ( . green)
26+ . frame ( width: geometry. size. width / 4 , height: 22 )
27+ }
28+ }
29+ . frame ( height: tall ? 320 : 200 )
30+
31+ Button ( tall ? " Shrink the reader " : " Grow the reader " ) { tall. toggle ( ) }
32+ }
33+ . padding ( )
34+ . navigationTitle ( " GeometryReader " )
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments