Skip to content

Commit 4669412

Browse files
authoredFeb 1, 2024
Activity Indicator: Remove branching views to improve performance (#1957)
1 parent ae6228e commit 4669412

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed
 

‎ios/FluentUI/ActivityIndicator/ActivityIndicator.swift

+9-15
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,16 @@ public struct ActivityIndicator: View, TokenizedControlView {
7777
#endif
7878

7979
return semiRing
80-
.modifyIf(state.isAnimating, { animatedView in
81-
animatedView
82-
.rotationEffect(.degrees(rotationAngle), anchor: .center)
83-
.onAppear {
84-
startAnimation()
85-
}
86-
})
87-
.modifyIf(!state.isAnimating) { staticView in
88-
staticView
89-
.onAppear {
90-
stopAnimation()
91-
}
80+
.onAppear {
81+
if state.isAnimating {
82+
startAnimation()
83+
}
84+
}
85+
.opacity(!state.isAnimating && state.hidesWhenStopped ? 0 : 1)
86+
.rotationEffect(.degrees(rotationAngle), anchor: .center)
87+
.onChange(of: state.isAnimating) { newValue in
88+
newValue ? startAnimation() : stopAnimation()
9289
}
93-
.modifyIf(!state.isAnimating && state.hidesWhenStopped, { view in
94-
view.hidden()
95-
})
9690
.frame(width: side,
9791
height: side,
9892
alignment: .center)

0 commit comments

Comments
 (0)
Please sign in to comment.