@@ -14,38 +14,42 @@ struct ConnectionView: View {
14
14
15
15
@State private( set) var isExpanded = false
16
16
17
- @State private( set) var showConnectionDetailsAnimated = false
18
- @State private( set) var isExpandedAnimated = false
19
17
@State private( set) var scrollViewHeight : CGFloat = 0
20
-
18
+ var hasFeatureIndicators : Bool { !indicatorsViewModel . chips . isEmpty }
21
19
var action : ButtonPanel . Action ?
22
20
23
21
var body : some View {
24
- Spacer ( )
25
- . accessibilityIdentifier ( AccessibilityIdentifier . connectionView. asString)
26
-
27
- VStack ( alignment: . leading, spacing: 16 ) {
28
- VStack ( alignment: . leading, spacing: 16 ) {
29
- HeaderView ( viewModel: connectionViewModel, isExpanded: $isExpanded)
30
-
31
- if showConnectionDetailsAnimated {
22
+ VStack {
23
+ Spacer ( )
24
+ . accessibilityIdentifier ( AccessibilityIdentifier . connectionView. asString)
25
+ VStack ( spacing: 16 ) {
26
+ VStack ( alignment: . leading, spacing: 0 ) {
27
+ HeaderView ( viewModel: connectionViewModel, isExpanded: $isExpanded)
28
+ . padding ( . bottom, 8 )
32
29
Divider ( )
33
30
. background ( UIColor . secondaryTextColor. color)
34
- . showIf ( isExpandedAnimated)
31
+ . padding ( . bottom, 16 )
32
+ . showIf ( isExpanded)
35
33
36
34
ScrollView {
37
- VStack ( alignment : . leading , spacing : 0 ) {
38
- Text ( LocalizedStringKey ( " Active features " ) )
39
- . font ( . footnote . weight ( . semibold ) )
40
- . foregroundStyle ( UIColor . primaryTextColor . color . opacity ( 0.6 ) )
41
- . padding ( . bottom , isExpandedAnimated ? 8 : 0 )
42
- . showIf ( !indicatorsViewModel . chips . isEmpty && isExpandedAnimated )
35
+ HStack {
36
+ VStack ( alignment : . leading , spacing : 0 ) {
37
+ Text ( LocalizedStringKey ( " Active features " ) )
38
+ . font ( . footnote . weight ( . semibold ) )
39
+ . foregroundStyle ( UIColor . primaryTextColor . color . opacity ( 0.6 ) )
40
+ . showIf ( isExpanded && hasFeatureIndicators )
43
41
44
- ChipContainerView ( viewModel: indicatorsViewModel, isExpanded: $isExpanded)
42
+ ChipContainerView ( viewModel: indicatorsViewModel,
43
+ tunnelState: connectionViewModel. tunnelStatus. state,
44
+ isExpanded: $isExpanded)
45
+ . padding ( . bottom, isExpanded ? 16 : 0 )
46
+ . showIf ( hasFeatureIndicators)
45
47
46
- DetailsView ( viewModel: connectionViewModel)
47
- . padding ( . top, indicatorsViewModel. chips. isEmpty ? 0 : 16 )
48
- . showIf ( isExpandedAnimated)
48
+ DetailsView ( viewModel: connectionViewModel)
49
+ . padding ( . bottom, 8 )
50
+ . showIf ( isExpanded)
51
+ }
52
+ Spacer ( )
49
53
}
50
54
. sizeOfView { size in
51
55
withAnimation {
@@ -61,41 +65,34 @@ struct ConnectionView: View {
61
65
$0
62
66
}
63
67
}
64
- . showIf ( isExpandedAnimated || !indicatorsViewModel. chips. isEmpty)
65
68
}
69
+ . transformEffect ( . identity)
70
+ . animation ( . default, value: hasFeatureIndicators)
71
+ ButtonPanel ( viewModel: connectionViewModel, action: action)
66
72
}
67
- . transformEffect ( . identity)
68
-
69
- ButtonPanel ( viewModel: connectionViewModel, action: action)
70
- }
71
- . padding ( )
72
- . background ( BlurView ( style: . dark) )
73
- . cornerRadius ( 12 )
74
- . padding ( )
75
- . onChange ( of: isExpanded) { newValue in
76
- withAnimation {
77
- isExpandedAnimated = newValue
78
- }
79
- }
80
- . onChange ( of: connectionViewModel. showsConnectionDetails) { newValue in
81
- if !newValue {
82
- isExpanded = false
83
- }
84
- withAnimation {
85
- showConnectionDetailsAnimated = newValue
73
+ . padding ( )
74
+ . background ( BlurView ( style: . dark) )
75
+ . cornerRadius ( 12 )
76
+ . padding ( )
77
+ . onChange ( of: connectionViewModel. showsConnectionDetails) { newValue in
78
+ if !newValue {
79
+ withAnimation {
80
+ isExpanded = false
81
+ }
82
+ }
86
83
}
87
84
}
88
85
}
89
86
}
90
87
91
88
#Preview( " ConnectionView (Indicators) " ) {
92
- ConnectionViewComponentPreview ( showIndicators: true , isExpanded : true ) { indicatorModel, viewModel, _ in
89
+ ConnectionViewComponentPreview ( showIndicators: true ) { indicatorModel, viewModel, _ in
93
90
ConnectionView ( connectionViewModel: viewModel, indicatorsViewModel: indicatorModel)
94
91
}
95
92
}
96
93
97
94
#Preview( " ConnectionView (No indicators) " ) {
98
- ConnectionViewComponentPreview ( showIndicators: false , isExpanded : true ) { indicatorModel, viewModel, _ in
95
+ ConnectionViewComponentPreview ( showIndicators: false ) { indicatorModel, viewModel, _ in
99
96
ConnectionView ( connectionViewModel: viewModel, indicatorsViewModel: indicatorModel)
100
97
}
101
98
}
0 commit comments