@@ -60,39 +60,16 @@ struct ChatPanelToolbar: View {
6060
6161struct ChatPanelMessages : View {
6262 @ObservedObject var chat : ChatProvider
63- @AppStorage ( \. disableLazyVStack) var disableLazyVStack
64- @State var height : Double = 0
65-
66- struct HeightPreferenceKey : PreferenceKey {
67- static var defaultValue : Double = 0
68- static func reduce( value: inout Double , nextValue: ( ) -> Double ) {
69- value = nextValue ( ) + value
70- }
71- }
72-
73- struct UpdateHeightModifier : ViewModifier {
74- func body( content: Content ) -> some View {
75- content
76- . background {
77- GeometryReader { proxy in
78- Color . clear
79- . preference ( key: HeightPreferenceKey . self, value: proxy. size. height)
80- }
81- }
82- }
83- }
84-
63+
8564 var body : some View {
8665 List {
8766 Group {
8867 Spacer ( )
89- . modifier ( UpdateHeightModifier ( ) )
9068
9169 if chat. isReceivingMessage {
9270 StopRespondingButton ( chat: chat)
9371 . padding ( . vertical, 4 )
9472 . listRowInsets ( EdgeInsets ( top: 0 , leading: - 8 , bottom: 0 , trailing: - 8 ) )
95- . modifier ( UpdateHeightModifier ( ) )
9673 }
9774
9875 if chat. history. isEmpty {
@@ -102,7 +79,6 @@ struct ChatPanelMessages: View {
10279 . scaleEffect ( x: - 1 , y: - 1 , anchor: . center)
10380 . foregroundStyle ( . secondary)
10481 . listRowInsets ( EdgeInsets ( top: 0 , leading: - 8 , bottom: 0 , trailing: - 8 ) )
105- . modifier ( UpdateHeightModifier ( ) )
10682 }
10783
10884 ForEach ( chat. history. reversed ( ) , id: \. id) { message in
@@ -120,20 +96,14 @@ struct ChatPanelMessages: View {
12096 }
12197 }
12298 . listItemTint ( . clear)
123- . modifier ( UpdateHeightModifier ( ) )
12499
125100 Spacer ( )
126- . modifier ( UpdateHeightModifier ( ) )
127101 }
128102 . scaleEffect ( x: - 1 , y: 1 , anchor: . center)
129103 }
130104 . id ( " \( chat. history. count) , \( chat. isReceivingMessage) " )
131105 . listStyle ( . plain)
132- . frame ( idealHeight: max ( 50 , height + 16 ) )
133106 . scaleEffect ( x: 1 , y: - 1 , anchor: . center)
134- . onPreferenceChange ( HeightPreferenceKey . self) { newHeight in
135- height = newHeight
136- }
137107 }
138108}
139109
0 commit comments