Last active
March 29, 2025 14:30
-
-
Save cjhodge/860a0d8463d9bf691026d2be300c00b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SwiftUITextExpansion.swift | |
// rpg | |
// | |
// Created by Chris Hodge on 3/29/25. | |
// | |
import SwiftUI | |
struct SwiftUITextExpansion: View { | |
@State private var isExpanded = false | |
var body: some View { | |
GeometryReader { geo in | |
VStack { | |
Text("Example:") | |
.foregroundStyle(.white) | |
.padding(.top, 80) | |
HStack { | |
Spacer() | |
VStack { | |
Text("As the child of traveling merchants, you discovered a weathered spellbook hidden in your family's wagon - payment from a desperate wizard years ago. Teaching yourself magic in secret during long journeys between cities, you've developed an unconventional style that combines spells from vastly different traditions.") | |
.lineLimit(10) | |
.foregroundStyle( | |
Color(#colorLiteral(red: 0.9999960065, green: 1, blue: 1, alpha: 1)) | |
.shadow(.inner(color: Color(#colorLiteral(red: 0.8156862745, green: 0.6274509804, blue: 0.3764705882, alpha: 1)).opacity(0.2), radius: 3, x: 1, y: 1)) | |
) | |
.padding(.horizontal) | |
.padding(.top, 6) | |
.padding(.bottom, 10) | |
.background( | |
Color(#colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)) | |
.cornerRadius(4) | |
.overlay( | |
ZStack { | |
RoundedRectangle(cornerRadius: 4) | |
.stroke(Color(#colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)), lineWidth: 4) | |
RoundedRectangle(cornerRadius: 4) | |
.stroke(Color(#colorLiteral(red: 0.8156862745, green: 0.3764705882, blue: 0, alpha: 1)), lineWidth: 1) | |
} | |
) | |
) | |
.frame(maxWidth: isExpanded ? .infinity : abs(geo.size.width - 128 * 2)) | |
.onTapGesture() { | |
withAnimation(.spring(duration: 0.15, bounce: 0.4, blendDuration: 0).repeatCount(0, autoreverses: true)) { | |
isExpanded.toggle() | |
} | |
} | |
Text("Origin #1 Goals: 3/5") | |
.foregroundStyle(.white) | |
.glow(color: .black, radius: 3) | |
} | |
.overlay( | |
VStack { | |
Spacer() | |
if isExpanded { | |
Text("Goals: Kill 20 Mobs, Rescue 10 villagers") | |
.foregroundStyle(.white) | |
.glow(color: .black, radius: 3) | |
} else { | |
} | |
Spacer().frame(height: 32) | |
} | |
.allowsHitTesting(false) | |
) | |
} | |
} | |
} | |
.padding() | |
.background(.black) | |
.edgesIgnoringSafeArea(.all) | |
} | |
} | |
#Preview { | |
SwiftUITextExpansion() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment