Repository: airbnb/lottie-ios
File: Sources/Public/iOS/BundleImageProvider.swift (Swift)

Code before:
#if canImport(UIKit)
import UIKit

/// An `AnimationImageProvider` that provides images by name from a specific bundle.
/// The BundleImageProvider is initialized with a bundle and an optional searchPath.
public class BundleImageProvider: AnimationImageProvider {

  // MARK: Lifecycle

  /// Initializes an image provider with a bundle and an optional subpath.
  ///
  /// Provides images for an animation from a bundle. Additionally the provider can
  /// search a specific subpath for the images.
  ///
  /// - Parameter bundle: The bundle containing images for the provider.
  /// - Parameter searchPath: The subpath is a path within the bundle to search for image assets.
  ///
  public init(bundle: Bundle, searchPath: String?, contentsGravity: CALayerContentsGravity = .resize) {
    self.bundle = bundle
    self.searchPath = searchPath
    self.contentsGravity = contentsGravity
  }

  // MARK: Public

  public var contentsGravity: CALayerContentsGravity

  public func imageForAsset(asset: ImageAsset) -> CGImage? {
    if
      let data = Data(imageAsset: asset),
      let image = UIImage(data: data)
    {
      return image.cgImage
    }

    let imagePath: String?
    /// Try to find the image in the bundle.
    if let searchPath = searchPath {
      /// Search in the provided search path for the image
      var directoryPath = URL(fileURLWithPath: searchPath)
      directoryPath.appendPathComponent(asset.directory)

      if let path = bundle.path(forResource: asset.name, ofType: nil, inDirectory: directoryPath.path) {
        /// First search for the image in the asset provided sub directory.
        imagePath = path
      } else if let path = bundle.path(forResource: asset.name, ofType: nil, inDirectory: searchPath) {
        /// Try finding the image in the search path.
        imagePath = path
      } else {
        imagePath = bundle.path(forResource: asset.name, ofType: nil)
      }

Review comment (suggestion):
same here

```suggestion
  let contentsGravity: CALayerContentsGravity
```

Code after:
#if canImport(UIKit)
import UIKit

/// An `AnimationImageProvider` that provides images by name from a specific bundle.
/// The BundleImageProvider is initialized with a bundle and an optional searchPath.
public class BundleImageProvider: AnimationImageProvider {

  // MARK: Lifecycle

  /// Initializes an image provider with a bundle and an optional subpath.
  ///
  /// Provides images for an animation from a bundle. Additionally the provider can
  /// search a specific subpath for the images.
  ///
  /// - Parameter bundle: The bundle containing images for the provider.
  /// - Parameter searchPath: The subpath is a path within the bundle to search for image assets.
  /// - Parameter contentsGravity: The contents gravity to use when rendering the image.
  ///
  public init(bundle: Bundle, searchPath: String?, contentsGravity: CALayerContentsGravity = .resize) {
    self.bundle = bundle
    self.searchPath = searchPath
    self.contentsGravity = contentsGravity
  }

  // MARK: Public

  public func imageForAsset(asset: ImageAsset) -> CGImage? {
    if
      let data = Data(imageAsset: asset),
      let image = UIImage(data: data)
    {
      return image.cgImage
    }

    let imagePath: String?
    /// Try to find the image in the bundle.
    if let searchPath = searchPath {
      /// Search in the provided search path for the image
      var directoryPath = URL(fileURLWithPath: searchPath)
      directoryPath.appendPathComponent(asset.directory)

      if let path = bundle.path(forResource: asset.name, ofType: nil, inDirectory: directoryPath.path) {
        /// First search for the image in the asset provided sub directory.
        imagePath = path
      } else if let path = bundle.path(forResource: asset.name, ofType: nil, inDirectory: searchPath) {
        /// Try finding the image in the search path.
        imagePath = path
      } else {
        imagePath = bundle.path(forResource: asset.name, ofType: nil)
      }
    } else {