require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '15.0'
use_frameworks! :linkage => :static
$RN_FABRIC_ENABLED = true
$RN_TURBOMODULE_ENABLED = true

target 'example' do
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    :fabric_enabled => $RN_FABRIC_ENABLED,
    :hermes_enabled => true
  )

  target 'exampleTests' do
    inherit! :complete
    # Pods for testing
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable these next few lines.
#  use_flipper!
#  post_install do |installer|
#    flipper_post_install(installer)
#  end
  post_install do |installer|
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['SWIFT_VERSION'] = '5.0'
        deployment_target = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET']
          target_components = deployment_target.split
            if target_components.length > 0
              target_initial = target_components[0].to_i
                if target_initial < 12
                  config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "12.0"
                end
            end 
       end
     end
    # see https://github.com/facebook/react-native/issues/33174#issuecomment-1064081540
    react_native_post_install(installer)
    # Xcode 14 build issues - https://github.com/facebook/react-native/issues/34673
    installer.pods_project.build_configurations.each do |config|
        config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||=['$(inherited)', '_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']
    end
   end
end
