Просмотр исходного кода

Refactor SwiftUI transition rendering logic

- Extract configuredImage as computed property for better code organization
- Remove unnecessary AnyView wrapping that could impact performance
- Simplify transition application logic by applying it once at the end
- Maintain correct rendering order: configurations -> contentConfiguration -> transition
onevcat 7 месяцев назад
Родитель
Сommit
ff673e68b5
1 измененных файлов с 12 добавлено и 14 удалено
  1. 12 14
      Sources/SwiftUI/KFImageRenderer.swift

+ 12 - 14
Sources/SwiftUI/KFImageRenderer.swift

@@ -103,6 +103,16 @@ struct KFImageRenderer<HoldingView> : View where HoldingView: KFImageHoldingView
     
     @ViewBuilder
     private func renderedImage() -> some View {
+        if let swiftUITransition = context.swiftUITransition {
+            // Apply SwiftUI loadTransition as the last step for correct rendering order
+            configuredImage.transition(swiftUITransition)
+        } else {
+            configuredImage
+        }
+    }
+    
+    @ViewBuilder
+    private var configuredImage: some View {
         let configuredImage = context.configurations
             .reduce(HoldingView.created(from: binder.loadedImage, context: context)) {
                 current, config in config(current)
@@ -110,21 +120,9 @@ struct KFImageRenderer<HoldingView> : View where HoldingView: KFImageHoldingView
         
         // Apply contentConfiguration first, then loadTransition as the final step
         if let contentConfiguration = context.contentConfiguration {
-            let contentView = AnyView(contentConfiguration(configuredImage))
-            // Apply SwiftUI loadTransition as the last step for correct rendering order
-            if let swiftUITransition = context.swiftUITransition {
-                contentView.transition(swiftUITransition)
-            } else {
-                contentView
-            }
+            contentConfiguration(configuredImage)
         } else {
-            let imageView = AnyView(configuredImage)
-            // Apply SwiftUI loadTransition as the last step for correct rendering order
-            if let swiftUITransition = context.swiftUITransition {
-                imageView.transition(swiftUITransition)
-            } else {
-                imageView
-            }
+            configuredImage
         }
     }
 }