From 6fce8de2ffc78accd5874c9fe5f70879781e97ed Mon Sep 17 00:00:00 2001 From: kenken <43767445+tkhs0604@users.noreply.github.com> Date: Fri, 11 Aug 2023 02:08:59 +0900 Subject: [PATCH] expand the description if it exceeds its line limit --- .../Modules/Sources/Session/SessionView.swift | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app-ios/Modules/Sources/Session/SessionView.swift b/app-ios/Modules/Sources/Session/SessionView.swift index 95ce82a45..475fa2cde 100644 --- a/app-ios/Modules/Sources/Session/SessionView.swift +++ b/app-ios/Modules/Sources/Session/SessionView.swift @@ -14,7 +14,8 @@ private let startDateFormatter: DateFormatter = { public struct SessionView: View { let viewModel: SessionViewModel - @State var isDescriptionExpanded: Bool = false + @State private var isDescriptionExpanded: Bool = false + @State private var canBeExpanded = false public init(timetableItem: TimetableItem) { self.viewModel = .init(timetableItem: timetableItem) @@ -66,9 +67,21 @@ public struct SessionView: View { VStack(alignment: .leading, spacing: 16) { Text(session.description_) .lineLimit(isDescriptionExpanded ? nil : 5) - if !isDescriptionExpanded { + .background { + ViewThatFits(in: .vertical) { + Text(session.description_) + .hidden() + // Just for receiving onAppear event if the description exceeds its line limit + Color.clear + .onAppear { + canBeExpanded = true + } + } + } + if canBeExpanded { Button { isDescriptionExpanded = true + canBeExpanded = false } label: { Text("続きを読む") .font(Font.system(size: 14, weight: .medium)) @@ -78,7 +91,6 @@ public struct SessionView: View { Capsule() .stroke(AssetColors.outline.swiftUIColor) } - } } }