import * as path from '../../path' ; import * as fs from '../../fs' ; import { Config } from '../../../types' ; import { logInfo } from '../../../helpers' ; see https param { object } configuration export function preLink ( configuration ) { logInfo ( 'Patching iOS for react-native-navigation' ) ; const bottomTabsAppearancePresenterPath = path . project . resolve ( 'node_modules' , 'react-native-navigation' , 'lib' , 'ios' , 'BottomTabsAppearancePresenter.m' ) ; if ( fs . doesKeywordExist ( bottomTabsAppearancePresenterPath , 'iOS 15.0' ) ) { logInfo ( 'react-native-navigation appears to have already been patched for ios 15 tab bars' ) ; return ; } fs . update ( bottomTabsAppearancePresenterPath , /for \(UIViewController\* childViewController in self\.tabBarController\.childViewControllers\)/g , 'for (UIViewController* childViewController in self.tabBarController.childViewControllers) {' ) ; fs . update ( bottomTabsAppearancePresenterPath , 'childViewController.tabBarItem.standardAppearance.backgroundColor = backgroundColor;' , `childViewController.tabBarItem.standardAppearance.backgroundColor = backgroundColor;
        #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000
            if (@available(iOS 15.0, *)) {
                childViewController.tabBarItem.scrollEdgeAppearance.backgroundColor = backgroundColor;
            }
        #endif
    }` ) ; fs . update ( bottomTabsAppearancePresenterPath , '[childViewController.tabBarItem.standardAppearance configureWithDefaultBackground];' , `[childViewController.tabBarItem.standardAppearance configureWithDefaultBackground];
        #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000
            if (@available(iOS 15.0, *)) {
                [childViewController.tabBarItem.scrollEdgeAppearance configureWithDefaultBackground];
            }
        #endif
    }` ) ; fs . update ( bottomTabsAppearancePresenterPath , '[childViewController.tabBarItem.standardAppearance configureWithTransparentBackground];' , `[childViewController.tabBarItem.standardAppearance configureWithTransparentBackground];
        #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000
            if (@available(iOS 15.0, *)) {
                [childViewController.tabBarItem.scrollEdgeAppearance configureWithTransparentBackground];
            }
        #endif
    }` ) ; fs . update ( bottomTabsAppearancePresenterPath , '[childViewController.tabBarItem.standardAppearance configureWithOpaqueBackground];' , `[childViewController.tabBarItem.standardAppearance configureWithOpaqueBackground];
        #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000
            if (@available(iOS 15.0, *)) {
                [childViewController.tabBarItem.scrollEdgeAppearance configureWithOpaqueBackground];
            }
        #endif
    }` ) ; const rnnBottomTabsControllerPath = path . project . resolve ( 'node_modules' , 'react-native-navigation' , 'lib' , 'ios' , 'RNNBottomTabsController.m' ) ; fs . update ( rnnBottomTabsControllerPath , 'self.longPressRecognizer =' , `#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000
        if (@available(iOS 15.0, *)) {
            self.tabBar.scrollEdgeAppearance = [UITabBarAppearance new];
        }
    #endif

    self.longPressRecognizer =` ) ; const tabBarItemApperanceCreatorPath = path . project . resolve ( 'node_modules' , 'react-native-navigation' , 'lib' , 'ios' , 'TabBarItemAppearanceCreator.m' ) ; fs . update ( tabBarItemApperanceCreatorPath , 'tabBarItem.standardAppearance =' , `#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000
        if (@available(iOS 15.0, *)) {
            tabBarItem.scrollEdgeAppearance =
                mergeItem.scrollEdgeAppearance ?: [[UITabBarAppearance alloc] init];
        }
    #endif

    tabBarItem.standardAppearance =` ) ; fs . update ( tabBarItemApperanceCreatorPath , 'tabItem.standardAppearance.inlineLayoutAppearance.normal.titleTextAttributes = titleAttributes;' , `tabItem.standardAppearance.inlineLayoutAppearance.normal.titleTextAttributes = titleAttributes;

    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000
        if (@available(iOS 15.0, *)) {
            tabItem.scrollEdgeAppearance.stackedLayoutAppearance.normal.titleTextAttributes = titleAttributes;
            tabItem.scrollEdgeAppearance.compactInlineLayoutAppearance.normal.titleTextAttributes =
                titleAttributes;
            tabItem.scrollEdgeAppearance.inlineLayoutAppearance.normal.titleTextAttributes = titleAttributes;
        }
    #endif` ) ; fs . update ( tabBarItemApperanceCreatorPath , 'tabItem.standardAppearance.inlineLayoutAppearance.selected.titleTextAttributes = selectedTitleAttributes;' , `tabItem.standardAppearance.inlineLayoutAppearance.selected.titleTextAttributes = selectedTitleAttributes;

    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000
        if (@available(iOS 15.0, *)) {
          tabItem.scrollEdgeAppearance.stackedLayoutAppearance.selected.titleTextAttributes =
              selectedTitleAttributes;
          tabItem.scrollEdgeAppearance.compactInlineLayoutAppearance.selected.titleTextAttributes =
              selectedTitleAttributes;
          tabItem.scrollEdgeAppearance.inlineLayoutAppearance.selected.titleTextAttributes =
              selectedTitleAttributes;
        }
    #endif` ) ; const uiViewControllerRNNOptionsPath = path . project . resolve ( 'node_modules' , 'react-native-navigation' , 'lib' , 'ios' , 'UIViewController+RNNOptions.m' ) ; fs . update ( uiViewControllerRNNOptionsPath , 'self.tabBarItem.standardAppearance.stackedLayoutAppearance.normal.badgeBackgroundColor = badgeColor;' , `self.tabBarItem.standardAppearance.stackedLayoutAppearance.normal.badgeBackgroundColor = badgeColor;

        #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000
            if (@available(iOS 15.0, *)) {
                self.tabBarItem.scrollEdgeAppearance.stackedLayoutAppearance.normal.badgeBackgroundColor =
                    badgeColor;
            }
        #endif` ) ; logInfo ( 'Successfully patched iOS for react-native-navigation' ) ; }