Sha256: a97cce0d222b3cbf6a89f873ed7be1ed4425213740c8400889664cb3f137a35e

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

module CocoapodsRnToolkit
  module IOS17UIGraphics
    def self.apply(installer)
      installer.pods_project.targets.each do |target|
        update_prefix_header(target)
      end
    end

    private

    def self.update_prefix_header(target)
      prefix_path = target.prefix_header_path
      return unless File.exist?(prefix_path)

      content = File.read(prefix_path)
      return if content.include?(macro)

      content = content + "\n" + macro
      File.open(prefix_path, 'w') { |file| file.write(content) }
    end

    def self.macro
      <<~MACRO
        #ifndef UIGraphicsBeginImageContextWithOptions
        #define UIGraphicsBeginImageContextWithOptions(size, opaque, scale) \\
        do {\\
            if (@available(iOS 17.0, *)) {\\
                CGSize _size = CGSizeMake(size.width < 0.01 ? 0.01 : size.width, size.height < 0.01 ? 0.01 : size.height);\\
                UIGraphicsBeginImageContextWithOptions(_size, opaque, scale);\\
            } else {\\
                UIGraphicsBeginImageContextWithOptions(size, opaque, scale);\\
            }\\
        } while(0)
        #endif

        #ifndef UIGraphicsBeginImageContext
        #define UIGraphicsBeginImageContext(size) \\
        do {\\
            if (@available(iOS 17.0, *)) {\\
                CGSize _size = CGSizeMake(size.width < 0.01 ? 0.01 : size.width, size.height < 0.01 ? 0.01 : size.height);\\
                UIGraphicsBeginImageContext(_size);\\
            } else {\\
                UIGraphicsBeginImageContext(size);\\
            }\\
        } while(0)
        #endif
      MACRO
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cocoapods-rn-toolkit-0.0.9 lib/cocoapods-rn-toolkit/ios17_uigraphics.rb