You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// If `aspectRatio` is not `nil`, always scale to fill and SwiftUI will layout the container with custom aspect ratio.
286
281
#if os(macOS)
287
-
view.wrapped.imageScaling=.scaleAxesIndependently
282
+
contentMode=.scaleAxesIndependently
288
283
#elseif os(iOS) || os(tvOS)
289
-
view.wrapped.contentMode =.scaleToFill
284
+
contentMode =.scaleToFill
290
285
#elseif os(watchOS)
291
-
view.wrapped.setContentMode(.fill)
286
+
contentMode =.fill
292
287
#endif
288
+
}else{
289
+
// If `aspectRatio` is `nil`, the resulting view maintains this view's aspect ratio.
290
+
switch imageLayout.contentMode {
291
+
case.fill:
292
+
#if os(macOS)
293
+
// Actually, NSImageView have no `.aspectFill` unlike UIImageView, only `CALayerContentsGravity.resizeAspectFill` have the same concept, but it does not work here
294
+
// TODO: Need SwiftUI officialy provide a solution
295
+
contentMode =.scaleProportionallyUpOrDown
296
+
#elseif os(iOS) || os(tvOS)
297
+
contentMode =.scaleAspectFill
298
+
#elseif os(watchOS)
299
+
contentMode =.aspectFill
300
+
#endif
301
+
case.fit:
302
+
#if os(macOS)
303
+
contentMode =.scaleProportionallyUpOrDown
304
+
#elseif os(iOS) || os(tvOS)
305
+
contentMode =.scaleAspectFit
306
+
#elseif os(watchOS)
307
+
contentMode =.aspectFit
308
+
#endif
309
+
case.none:
310
+
// If `contentMode` is not set at all, using scale to fill as SwiftUI default value
311
+
#if os(macOS)
312
+
contentMode =.scaleAxesIndependently
313
+
#elseif os(iOS) || os(tvOS)
314
+
contentMode =.scaleToFill
315
+
#elseif os(watchOS)
316
+
contentMode =.fill
317
+
#endif
318
+
}
293
319
}
294
320
321
+
#if os(macOS)
322
+
view.wrapped.imageScaling = contentMode
323
+
#elseif os(iOS) || os(tvOS)
324
+
view.wrapped.contentMode = contentMode
325
+
#elseif os(watchOS)
326
+
view.wrapped.setContentMode(contentMode)
327
+
#endif
328
+
295
329
// Animated Image does not support resizing mode and rendering mode
0 commit comments