1import { FileTransforms } from '../../../Transforms.types';
2
3type Config = {
4  [key: string]: FileTransforms;
5};
6
7export default function vendoredModulesTransformsFactory(prefix: string): Config {
8  return {
9    '@stripe/stripe-react-native': {
10      content: [
11        {
12          paths: '*.m',
13          find: /RCT_EXTERN_MODULE\((ApplePayButtonManager|CardFieldManager|AuBECSDebitFormManager|StripeSdk|StripeContainerManager|CardFormManager)/,
14          replaceWith: `RCT_EXTERN_REMAP_MODULE($1, ${prefix}$1`,
15        },
16        {
17          paths: '',
18          find: /\.reactFocus\(/,
19          replaceWith: `.${prefix.toLowerCase()}ReactFocus(`,
20        },
21      ],
22    },
23    'lottie-react-native': {
24      content: [
25        {
26          paths: 'LRNAnimationViewManagerObjC.m',
27          find: /RCT_EXTERN_MODULE\(/,
28          replaceWith: `RCT_EXTERN_REMAP_MODULE(LottieAnimationView, ${prefix}`,
29        },
30        {
31          paths: 'ContainerView.swift',
32          find: /\breactSetFrame/g,
33          replaceWith: `${prefix.toLowerCase()}ReactSetFrame`,
34        },
35      ],
36    },
37    'react-native-webview': {
38      content: [
39        {
40          paths: 'RNCWebView.m',
41          find: new RegExp(`#import "objc/${prefix}runtime\\.h"`, ''),
42          replaceWith: '#import "objc/runtime.h"',
43        },
44        {
45          paths: 'RNCWebView.m',
46          find: /\b(_SwizzleHelperWK)\b/g,
47          replaceWith: `${prefix}$1`,
48        },
49        {
50          // see issue: https://github.com/expo/expo/issues/4463
51          paths: 'RNCWebView.m',
52          find: /MessageHandlerName = @"ABI\d+_\d+_\d+ReactNativeWebView";/,
53          replaceWith: `MessageHandlerName = @"ReactNativeWebView";`,
54        },
55        {
56          paths: 'RNCWebView.m',
57          find: 'NSString *const CUSTOM_SELECTOR',
58          replaceWith: 'static NSString *const CUSTOM_SELECTOR',
59        },
60      ],
61    },
62    'react-native-reanimated': {
63      content: [
64        {
65          find: 'namespace reanimated',
66          replaceWith: `namespace ${prefix}reanimated`,
67        },
68        {
69          find: /\breanimated::/g,
70          replaceWith: `${prefix}reanimated::`,
71        },
72        {
73          paths: '*.h',
74          find: new RegExp(`ReactCommon/(?!${prefix})`, 'g'),
75          replaceWith: `ReactCommon/${prefix}`,
76        },
77        {
78          paths: '**/Transitioning/*.m',
79          find: `RCTConvert+${prefix}REATransition.h`,
80          replaceWith: 'RCTConvert+REATransition.h',
81        },
82        {
83          paths: 'REAUIManager.{h,mm}',
84          find: /(blockSetter|_toBeRemovedRegister|_parentMapper|_animationsManager|_scheduler)/g,
85          replaceWith: `${prefix}$1`,
86        },
87        {
88          paths: 'REATransitionAnimation.m',
89          find: /(SimAnimationDragCoefficient)\(/g,
90          replaceWith: `${prefix}$1(`,
91        },
92        {
93          paths: 'REAAnimationsManager.m',
94          find: /^(#import <.*React)\/UIView\+(.+)\.h>/gm,
95          replaceWith: `$1/${prefix}UIView+$2.h>`,
96        },
97        {
98          paths: 'REAAnimationsManager.m',
99          find: `UIView+${prefix}React.h`,
100          replaceWith: `UIView+React.h`,
101        },
102        {
103          paths: 'REAAnimationsManager.m',
104          // `dataComponenetsByName[@"ABI44_0_0RCTView"];` -> `dataComponenetsByName[@"RCTView"];`
105          // the RCTComponentData internal view name is not versioned
106          find: new RegExp(`(RCTComponentData .+)\\[@"${prefix}(RCT.+)"\\];`, 'g'),
107          replaceWith: '$1[@"$2"];',
108        },
109      ],
110    },
111    'react-native-gesture-handler': {
112      path: [
113        {
114          find: /\bRN(\w+?)\.(h|m|mm)/,
115          replaceWith: `${prefix}RN$1.$2`,
116        },
117      ],
118      content: [
119        {
120          find: `UIView+${prefix}React.h`,
121          replaceWith: `${prefix}UIView+React.h`,
122        },
123        {
124          // `RNG*` symbols are already prefixed at this point,
125          // but there are some new symbols in RNGH that don't have "G".
126          paths: '*.{h,m}',
127          find: /\bRN(\w+?)\b/g,
128          replaceWith: `${prefix}RN$1`,
129        },
130      ],
131    },
132    'react-native-pager-view': {
133      path: [
134        {
135          find: /(ReactNativePageView|ReactViewPagerManager)\.(h|m)/,
136          replaceWith: `${prefix}$1.$2`,
137        },
138      ],
139      content: [
140        {
141          find: `UIView+${prefix}React.h`,
142          replaceWith: `${prefix}UIView+React.h`,
143        },
144        {
145          find: `${prefix}JKBigInteger.h`,
146          replaceWith: `JKBigInteger.h`,
147        },
148      ],
149    },
150    '@react-native-segmented-control/segmented-control': {
151      content: [
152        {
153          find: `UIView+${prefix}React.h`,
154          replaceWith: `${prefix}UIView+React.h`,
155        },
156      ],
157    },
158    'react-native-screens': {
159      content: [],
160    },
161  };
162}
163