Skip to content

Instantly share code, notes, and snippets.

@robb
Forked from christianselig/image-expansion.swift
Last active October 15, 2022 22:36
Show Gist options
  • Select an option

  • Save robb/3bc7b916e24d1dbc362f168b582357ec to your computer and use it in GitHub Desktop.

Select an option

Save robb/3bc7b916e24d1dbc362f168b582357ec to your computer and use it in GitHub Desktop.

Revisions

  1. robb revised this gist May 16, 2022. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion image-expansion.swift
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,6 @@ struct ContentView: View {
    .fixedSize(horizontal: false, vertical: true)
    .frame(height: pictureExpanded ? 311 : 0.0)
    .clipped()
    .frame(height: pictureExpanded ? 311 : 0.0)
    .contentShape(Rectangle())

    Text("The giraffe's name was Leonard, and together George and Leonard became the best of friends and did all sorts of cool things together like climbing a mountain.")
  2. robb revised this gist May 16, 2022. 1 changed file with 10 additions and 5 deletions.
    15 changes: 10 additions & 5 deletions image-expansion.swift
    Original file line number Diff line number Diff line change
    @@ -2,23 +2,28 @@ import SwiftUI

    struct ContentView: View {
    @State var pictureExpanded = false

    var body: some View {
    VStack(alignment: .leading, spacing: 20.0) {
    Text("Once upon a time there was a turtle named George who made friends with a giraffe at the local water park and then they went on lots of adventures together.")

    Button {
    withAnimation {
    pictureExpanded.toggle()
    }
    } label: {
    Text("Tap to \(pictureExpanded ? "hide" : "see") a pretty picture")
    }
    Image("chacha")

    Image("cat")
    .resizable()
    .aspectRatio(contentMode: .fit)
    .fixedSize(horizontal: false, vertical: true)
    .frame(height: pictureExpanded ? 311 : 0.0)

    .clipped()
    .frame(height: pictureExpanded ? 311 : 0.0)
    .contentShape(Rectangle())

    Text("The giraffe's name was Leonard, and together George and Leonard became the best of friends and did all sorts of cool things together like climbing a mountain.")
    }
    }
  3. @christianselig christianselig created this gist May 16, 2022.
    31 changes: 31 additions & 0 deletions image-expansion.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    import SwiftUI

    struct ContentView: View {
    @State var pictureExpanded = false

    var body: some View {
    VStack(alignment: .leading, spacing: 20.0) {
    Text("Once upon a time there was a turtle named George who made friends with a giraffe at the local water park and then they went on lots of adventures together.")

    Button {
    withAnimation {
    pictureExpanded.toggle()
    }
    } label: {
    Text("Tap to \(pictureExpanded ? "hide" : "see") a pretty picture")
    }

    Image("chacha")
    .resizable()
    .frame(height: pictureExpanded ? 311 : 0.0)

    Text("The giraffe's name was Leonard, and together George and Leonard became the best of friends and did all sorts of cool things together like climbing a mountain.")
    }
    }
    }

    struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
    ContentView()
    }
    }