Module: CocoapodsRnToolkit::IOS17UIGraphics

Defined in:
lib/cocoapods-rn-toolkit/ios17_uigraphics.rb

Class Method Summary collapse

Class Method Details

.apply(installer) ⇒ Object



3
4
5
6
7
# File 'lib/cocoapods-rn-toolkit/ios17_uigraphics.rb', line 3

def self.apply(installer)
  installer.pod_targets.each do |pod_target|
    update_prefix_header(pod_target)
  end
end

.macroObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cocoapods-rn-toolkit/ios17_uigraphics.rb', line 22

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

.update_prefix_header(pod_target) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/cocoapods-rn-toolkit/ios17_uigraphics.rb', line 11

def self.update_prefix_header(pod_target)
  prefix_path = pod_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