-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGIOInjector.js
690 lines (640 loc) · 22.3 KB
/
GIOInjector.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
var fs = require("fs");
var common = require("./GIOCommon");
/*
* filePath: ReactNative的文件夹地址
*/
function injectReactNative(dirPath, reset = false) {
if (!dirPath.endsWith("/")) {
dirPath += "/";
}
var touchableJsFilePath = `${dirPath}Libraries/Components/Touchable/Touchable.js`;
if (reset) {
common.resetFile(touchableJsFilePath);
} else {
console.log(`found and modify Touchable.js: ${touchableJsFilePath}`);
injectOnPressScript(touchableJsFilePath);
}
var pressabilityJsFilePath = `${dirPath}Libraries/Pressability/Pressability.js`;
if (reset) {
common.resetFile(pressabilityJsFilePath);
} else {
console.log(`found and modify Pressability.js: ${pressabilityJsFilePath}`);
injectNewOnPressScript(pressabilityJsFilePath);
}
var createViewJsFiles = [
"Libraries/Renderer/src/renderers/native/ReactNativeFiber.js",
"Libraries/Renderer/src/renderers/native/ReactNativeFiber-dev.js",
"Libraries/Renderer/src/renderers/native/ReactNativeFiber-prod.js",
"Libraries/Renderer/src/renderers/native/ReactNativeFiber-profiling.js",
"Libraries/Renderer/ReactNativeFiber-dev.js",
"Libraries/Renderer/ReactNativeFiber-prod.js",
"Libraries/Renderer/oss/ReactNativeRenderer-dev.js",
"Libraries/Renderer/oss/ReactNativeRenderer-prod.js",
"Libraries/Renderer/ReactNativeStack-dev.js",
"Libraries/Renderer/ReactNativeStack-prod.js",
"Libraries/Renderer/oss/ReactNativeRenderer-profiling.js",
"Libraries/Renderer/ReactNativeRenderer-dev.js",
"Libraries/Renderer/ReactNativeRenderer-prod.js",
];
createViewJsFiles.forEach(function (createViewFilePath) {
var jsFile = `${dirPath}${createViewFilePath}`;
if (fs.existsSync(jsFile)) {
if (reset) {
common.resetFile(jsFile);
} else {
console.log(`found and modify render.js: ${jsFile}`);
injectCreateViewScript(jsFile);
}
}
});
var createNewViewJsFiles = [
"Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js",
"Libraries/Renderer/implementations/ReactNativeRenderer-dev.js",
"Libraries/Renderer/implementations/ReactNativeRenderer-prod.js",
];
createNewViewJsFiles.forEach(function (createNewViewFilePath) {
var jsFile = `${dirPath}${createNewViewFilePath}`;
if (fs.existsSync(jsFile)) {
if (reset) {
common.resetFile(jsFile);
} else {
console.log(`found and modify render.js: ${jsFile}`);
injectNewCreateViewScript(jsFile);
}
}
});
}
/**
* hook react navigation
*/
function injectReactNavigation(dirPath, reset = false) {
if (!dirPath.endsWith("/")) {
dirPath += "/";
}
var createNavigationContainerJsFilePath = `${dirPath}src/createNavigationContainer.js`;
var getChildEventSubscriberJsFilePath = `${dirPath}src/getChildEventSubscriber.js`;
if (!fs.existsSync(createNavigationContainerJsFilePath)) {
return;
}
if (!fs.existsSync(getChildEventSubscriberJsFilePath)) {
return;
}
console.log(
`found and modify createNavigationContainer.js: ${createNavigationContainerJsFilePath}`
);
console.log(
`found and modify getChildEventSubscriber.js: ${getChildEventSubscriberJsFilePath}`
);
if (reset) {
common.resetFile(createNavigationContainerJsFilePath);
common.resetFile(getChildEventSubscriberJsFilePath);
} else {
injectNavigationScript(
createNavigationContainerJsFilePath,
getChildEventSubscriberJsFilePath
);
}
}
function injectReactNavigation3(dirPath, reset = false) {
injectReactNavigationFrom3To4(dirPath, "src/createAppContainer.js", reset);
}
function injectReactNavigation4(dirPath, reset = false) {
injectReactNavigationFrom3To4(
dirPath,
"lib/module/createAppContainer.js",
reset
);
}
/**
* hook react navigation 3.x
* @param dirPath @react-navigation/native的地址
*/
function injectReactNavigationFrom3To4(dirPath, filePath, reset = false) {
if (!dirPath.endsWith("/")) {
dirPath += "/";
}
var createAppContainerJsFilePath = `${dirPath}${filePath}`;
if (!fs.existsSync(createAppContainerJsFilePath)) {
return;
}
console.log(
`found and modify createAppContainer.js: ${createAppContainerJsFilePath}`
);
if (reset) {
common.resetFile(createAppContainerJsFilePath);
} else {
common.modifyFile(
createAppContainerJsFilePath,
onNavigationStateChangeTransformer3
);
}
}
/**
* hook 点参考 https://reactnavigation.org/docs/screen-tracking
* hook react navigation 6.x
* @param dirPath @react-navigation/core的地址
*/
function injectReactNavigation6(dirPath, reset = false) {
if (!dirPath.endsWith("/")) {
dirPath += "/";
}
const BaseNavigationContainerJsFilePath = `${dirPath}src/BaseNavigationContainer.tsx`;
if (!fs.existsSync(BaseNavigationContainerJsFilePath)) {
return;
}
console.log(
`found and modify BaseNavigationContainer.js: ${BaseNavigationContainerJsFilePath}`
);
if (reset) {
common.resetFile(BaseNavigationContainerJsFilePath);
} else {
common.modifyFile(
BaseNavigationContainerJsFilePath,
onNavigationStateChangeTransformer6
);
}
}
/**
* hook react native navigation
*/
function injectReactNativeNavigation(dirPath, reset = false) {
if (!dirPath.endsWith("/")) {
dirPath += "/";
}
var screenJsFilePath = `${dirPath}src/Screen.js`;
var androidPlatformSpecificJsFilePath = `${dirPath}src/platformSpecific.android.js`;
var iOSPlatformSpecificJsFilePath = `${dirPath}src/deprecated/platformSpecificDeprecated.ios.js`;
// only judge screenJsFilePath
if (!fs.existsSync(screenJsFilePath)) {
console.log(`not fond NativeNavigation: ${screenJsFilePath} , and return`);
return;
}
if (reset) {
common.resetFile(screenJsFilePath);
} else {
injectReactNativeNavigationScreenScript(screenJsFilePath);
}
var reactNativeNavigationPlatformJSFiles = [
androidPlatformSpecificJsFilePath,
iOSPlatformSpecificJsFilePath,
];
reactNativeNavigationPlatformJSFiles.forEach(function (jsFilePath, index) {
if (fs.existsSync(jsFilePath)) {
if (reset) {
common.resetFile(jsFilePath);
} else {
injectReactNativeNavigationPlatformScript(jsFilePath);
}
}
});
}
function injectReactNativeNavigationScreenScript(jsFilePath) {
console.log(`find and modify Screen.js: ${jsFilePath}`);
common.modifyFile(jsFilePath, onReactNativeNavigationScreenTransformer);
}
function injectReactNativeNavigationPlatformScript(jsFilePath) {
console.log(`find and modify PlatformScript.js: ${jsFilePath}`);
common.modifyFile(jsFilePath, onReactNativeNavigationPlatformTransformer);
}
function injectNavigationScript(
createNavigationContainerJsFilePath,
getChildEventSubscriberJsFilePath
) {
common.modifyFile(
createNavigationContainerJsFilePath,
onNavigationStateChangeTransformer
);
common.modifyFile(
getChildEventSubscriberJsFilePath,
onEventSubscriberTransformer
);
}
/**
* filePath: 对应的JS文件地址
*/
function injectCreateViewScript(filePath) {
common.modifyFile(filePath, createViewTransformer);
}
function injectNewCreateViewScript(filePath) {
common.modifyFile(filePath, newCreateViewTransformer);
}
function injectOnPressScript(filePath) {
common.modifyFile(filePath, onPressTransformer);
}
function injectNewOnPressScript(filePath) {
common.modifyFile(filePath, newOnPressTransformer);
}
function onNavigationStateChangeTransformer(content) {
var index = content.indexOf(
"if (typeof this.props.onNavigationStateChange === 'function') {"
);
if (index == -1) throw "index is -1";
content =
content.substring(0, index) +
common.anonymousJsFunctionCall(navigationString("nav", "action")) +
"\n" +
content.substring(index);
var didMountIndex = content.indexOf("componentDidMount() {");
if (didMountIndex == -1) throw "didMountIndex is -1";
var forEachIndex = content.indexOf(
"this._actionEventSubscribers.forEach(subscriber =>",
didMountIndex
);
var clojureEnd = content.indexOf(";", forEachIndex);
content =
content.substring(0, forEachIndex) +
"{" +
common.anonymousJsFunctionCall(navigationString("this.state.nav", null)) +
"\n" +
content.substring(forEachIndex, clojureEnd + 1) +
"}" +
content.substring(clojureEnd + 1);
return content;
}
function onNavigationStateChangeTransformer3(content) {
var index = content.indexOf(
"if (typeof this.props.onNavigationStateChange === 'function') {"
);
if (index == -1) throw "index is -1";
content =
content.substring(0, index) +
common.anonymousJsFunctionCall(
navigationString3("prevNav", "nav", "action")
) +
"\n" +
content.substring(index);
var didMountIndex = content.indexOf("componentDidMount() {");
if (didMountIndex == -1) throw "didMountIndex is -1";
var forEachIndex = content.indexOf(
"this._actionEventSubscribers.forEach(subscriber =>",
didMountIndex
);
var clojureEnd = content.indexOf(";", forEachIndex);
content =
content.substring(0, forEachIndex) +
"{" +
common.anonymousJsFunctionCall(
navigationString3(null, "this.state.nav", null)
) +
"\n" +
content.substring(forEachIndex, clojureEnd + 1) +
"}" +
content.substring(clojureEnd + 1);
return content;
}
function onNavigationStateChangeTransformer6(content) {
var index = content.indexOf(
"if (!isFirstMountRef.current && onStateChangeRef.current) {"
);
if (index == -1) throw "index is -1";
content =
content.substring(0, index) +
common.anonymousJsFunctionCall(navigationString6("getRootState()")) +
"\n" +
content.substring(index);
return content;
}
function onEventSubscriberTransformer(content) {
var script = "const emit = (type, payload) => {";
var index = content.indexOf(script);
if (index == -1) throw "index is -1";
content =
content.substring(0, index + script.length) +
common.anonymousJsFunctionCall(navigationEventString()) +
"\n" +
content.substring(index + script.length);
return content;
}
function onReactNativeNavigationScreenTransformer(content) {
var importScript = "const NavigationSpecific = {";
var importScriptIndex = content.indexOf(importScript);
if (importScriptIndex == -1)
throw "cann't find NavigationSpecific, please check your react-native-navigation version, and resport to GrowingIO";
var injectImportScript =
"import anotherPlatformSpecific from './platformSpecific'\n";
content =
content.substring(0, importScriptIndex) +
injectImportScript +
content.substring(importScriptIndex);
var script = "onNavigatorEvent(event) {";
var index = content.indexOf(script);
if (index == -1) throw "index is -1";
content =
content.substring(0, index + script.length) +
common.anonymousJsFunctionCall(reactNativeNavigationScreenString()) +
"\n" +
content.substring(index + script.length);
var constructorEndScript = "this.navigatorEventSubscription = null;";
var constructorIndex = content.indexOf(constructorEndScript);
if (constructorIndex == -1)
throw "cann't find Screen.js's constructor, please check your react-native-navigation version, and report to GrowingIO";
var injectEndScript = "\nthis._registerNavigatorEvent();";
var injectPoint = constructorIndex + constructorEndScript.length;
content =
content.substring(0, injectPoint) +
injectEndScript +
content.substring(injectPoint);
return content;
}
function onReactNativeNavigationPlatformTransformer(content) {
var saveScript = "function savePassProps(params) {";
var index = content.indexOf(saveScript);
if (index == -1) throw "index is -1";
content =
content.substring(0, index + saveScript.length) +
common.anonymousJsFunctionCall(reactNativeNavigationPlatformString()) +
"\n" +
content.substring(index + saveScript.length);
var propsScript = `const GrowingScreenProps = {};`;
var getPageNameFuncScript = `function getGrowingPageName(screenInstanceID) {
return GrowingScreenProps[screenInstanceID];
}`;
content =
content.substring(0, index) +
propsScript +
"\n" +
getPageNameFuncScript +
`\n` +
content.substring(index);
var exportIOSScript = "export default {";
var exportAndroidScript = "module.exports = {";
index = content.indexOf(exportIOSScript);
var exportScriptLength;
if (index == -1) {
index = content.indexOf(exportAndroidScript);
if (index == -1) {
throw "index is -1";
}
exportScriptLength = exportAndroidScript.length;
} else {
exportScriptLength = exportIOSScript.length;
}
content =
content.substring(0, index + exportScriptLength) +
`\n` +
`getGrowingPageName,` +
content.substring(index + exportScriptLength);
return content;
}
function reactNativeNavigationScreenString() {
var script = `var growingPageName = null;
if(platformSpecific.getGrowingPageName){
growingPageName = platformSpecific.getGrowingPageName(this.screenInstanceID);
}else{
growingPageName = anotherPlatformSpecific.getGrowingPageName(this.screenInstanceID);
}
if(growingPageName == null){
return;
}
if (event.id == "willAppear") {
require('react-native').NativeModules.GrowingIOModule.onPagePrepare(growingPageName);
} else if (event.id == "didAppear") {
require('react-native').NativeModules.GrowingIOModule.onPageShow(growingPageName);
}`;
return script;
}
function reactNativeNavigationPlatformString() {
var script = `if (params.navigationParams) {
var screenInstanceID = params.navigationParams.screenInstanceID;
if (params.growingPagePath) {
GrowingScreenProps[screenInstanceID] = params.growingPagePath;
} else if (params.title) {
GrowingScreenProps[screenInstanceID] = params.title;
} else {
GrowingScreenProps[screenInstanceID] = params.screen;
}
}`;
return script;
}
function navigationString(currentStateVarName, actionName) {
var script = `function $$$getActivePageName$$$(navigationState){
if(!navigationState)
return null;
const route = navigationState.routes[navigationState.index];
if(route.routes){
return $$$getActivePageName$$$(route);
}else{
if(route.params && route.params["growingPagePath"]) {
return route.params["growingPagePath"]
} else {
return route.routeName;
}
}
}
`;
if (actionName) {
script = `${script}
var type = ${actionName}.type;
if(type == 'Navigation/SET_PARAMS' || type == 'Navigation/COMPLETE_TRANSITION') {
return;
}
`;
}
script = `${script} var pageName = $$$getActivePageName$$$(${currentStateVarName});
if (require('react-native').Platform.OS === 'android') {
require('react-native').NativeModules.GrowingIOModule.onPageShow(pageName);}`;
return script;
}
function navigationString3(prevStateVarName, currentStateVarName, actionName) {
var script = `function $$$getActivePageName$$$(navigationState){
if(!navigationState)
return null;
const route = navigationState.routes[navigationState.index];
if(route.routes){
return $$$getActivePageName$$$(route);
}else{
if(route.params && route.params["growingPagePath"]) {
return route.params["growingPagePath"]
} else {
return route.routeName;
}
}
}
`;
if (actionName) {
script = `${script}
var type = ${actionName}.type;
var iosOnPagePrepare = false;
var iosOnPageShow = false;
if (require('react-native').Platform.OS === 'android') {
if(type == 'Navigation/SET_PARAMS' || type == 'Navigation/COMPLETE_TRANSITION') {
return;
}
} else if (require('react-native').Platform.OS === 'ios') {
if((type == 'Navigation/BACK' && (${currentStateVarName} && !${currentStateVarName}.isTransitioning))
|| type == 'Navigation/COMPLETE_TRANSITION'
|| type == 'Navigation/JUMP_TO') {
iosOnPageShow = true;
} else if (type != 'Navigation/SET_PARAMS') {
iosOnPagePrepare = true;
}
if (!iosOnPagePrepare && !iosOnPageShow) {
return;
}
}
`;
}
script = `${script} var pageName = $$$getActivePageName$$$(${currentStateVarName});
if (require('react-native').Platform.OS === 'android') {
if (${prevStateVarName}){
var prevPageName = $$$getActivePageName$$$(${prevStateVarName});
if (pageName == prevPageName){
return;
}
}
require('react-native').NativeModules.GrowingIOModule.onPageShow(pageName);
} else if (require('react-native').Platform.OS === 'ios') {
if (!${actionName} || iosOnPageShow) {
require('react-native').NativeModules.GrowingIOModule.onPageShow(pageName);
} else if (iosOnPagePrepare) {
require('react-native').NativeModules.GrowingIOModule.onPagePrepare(pageName);
}
}`;
return script;
}
/**
* 6.x版本该变量名无变化,可以直接使用
* 采用拼接构造路径,参考checkDuplicateRouteNames
*/
function navigationString6(hydratedState) {
var raw = "${path}/${route.name}";
var script = `function $$$getActivePageName$$$(state){
if(!state)
return null;
let path = 'Root';
let route = state.routes[state.index];
while(route.state) {
path = \`${raw}\`;
route = route.state.routes[route.state.index];
}
path = \`${raw}\`
if(route.params && route.params["growingPagePath"]) {
return route.params["growingPagePath"]
} else {
return path;
}
}`;
script = `${script} let pageName = $$$getActivePageName$$$(${hydratedState});
require('react-native').NativeModules.GrowingIOModule.onPageShow(pageName);`;
return script;
}
function navigationEventString() {
var script = `if(require('react-native').Platform.OS !== 'ios') {
return;
}
if(payload && payload.state && payload.state.key && payload.state.routeName && payload.state.key != payload.state.routeName) {
var growingPageName = payload.state.routeName;
if(payload.state.params && payload.state.params.growingPagePath) {
growingPageName = payload.state.params.growingPagePath;
}
if(type == 'willFocus') {
require('react-native').NativeModules.GrowingIOModule.onPagePrepare(growingPageName);
} else if(type == 'didFocus') {
require('react-native').NativeModules.GrowingIOModule.onPageShow(growingPageName);
}
}
`;
return script;
}
function onPressTransformer(content) {
var index = content.indexOf("this.touchableHandlePress(");
if (index == -1) throw "Can't not hook onPress function";
var injectScript =
"var ReactNative = require('react-native');\n" +
"this.props.onPress&&ReactNative.NativeModules.GrowingIOModule.onClick(ReactNative.findNodeHandle(this));";
injectScript = common.anonymousJsFunctionCall(injectScript);
var result = `${content.substring(
0,
index
)}\n${injectScript}\n${content.substring(index)}`;
return result;
}
/**
* 首个onPress用于部分text优化
* onLongPress会取消onPress,目前不考虑onLongPress对应的事件,后续切换新的无埋点实现
*/
function newOnPressTransformer(content) {
var index = content.lastIndexOf("onPress(event)");
if (index == -1) throw "Can't not hook onPress function";
var injectScript =
"var ReactNative = require('react-native');\n" +
"var growingTag = event.target && event.target._nativeTag;\n" +
"if(!growingTag) {\n" +
" growingTag = event.nativeEvent && event.nativeEvent.target;\n" +
"}\n" +
"if(typeof growingTag === 'number') {\n" +
" ReactNative.NativeModules.GrowingIOModule.onClick(growingTag);\n" +
"}\n";
injectScript = common.anonymousJsFunctionCall(injectScript);
var result = `${content.substring(
0,
index
)}\n${injectScript}\n${content.substring(index)}`;
return result;
}
/**
* 不能直接取updatePayload,viewConfig.validAttributes,除非增加一个注入把growingParams加入到默认属性中
* 理论上应该commit阶段的 commitUpdate增加属性的更新,后续更换新的RN无埋点实现,不再使用源码注入,暂时不做适配
*/
function newCreateViewTransformer(content) {
return createViewTransformer(content, true);
}
function createViewTransformer(content, isNew = false) {
var objRe;
if (isNew) {
objRe =
/ReactNativePrivateInterface\.UIManager\.createView\([\s\S]{1,60}\.uiViewClassName,[\s\S]*?\)[,;]/;
} else {
objRe =
/UIManager\.createView\([\s\S]{1,60}\.uiViewClassName,[\s\S]*?\)[,;]/;
}
var match = objRe.exec(content);
if (!match) throw "can't inject createView, please connect with GrowingIO";
var lastParentheses = content.lastIndexOf(")", match.index);
var lastCommaIndex = content.lastIndexOf(",", lastParentheses);
if (lastCommaIndex == -1)
throw "can't inject createView,and lastCommaIndex is -1";
var nextCommaIndex = content.indexOf(",", match.index);
if (nextCommaIndex == -1)
throw "can't inject createView, and nextCommaIndex is -1";
var propsName = lastArgumentName(content, lastCommaIndex).trim();
var tagName = lastArgumentName(content, nextCommaIndex).trim();
//console.log(`propsName: ${propsName}, and tagName: ${tagName}`);
var functionBody = `var clickable = false;
var growingParams = ${propsName}.growingParams;
if(${propsName}.onStartShouldSetResponder){
clickable = true;
}
require('react-native').NativeModules.GrowingIOModule.prepareView(${tagName}, clickable, growingParams);
`;
var call = common.anonymousJsFunctionCall(functionBody);
var lastReturn = content.lastIndexOf("return", match.index);
var splitIndex = match.index;
if (lastReturn > lastParentheses) {
splitIndex = lastReturn;
}
var result = `${content.substring(
0,
splitIndex
)}\n${call}\n${content.substring(splitIndex)}`;
return result;
}
function lastArgumentName(content, index) {
--index;
var lastComma = content.lastIndexOf(",", index);
var lastParentheses = content.lastIndexOf("(", index);
var start = Math.max(lastComma, lastParentheses);
return content.substring(start + 1, index + 1);
}
module.exports = {
injectCreateViewScript: injectCreateViewScript,
createViewTransformer: createViewTransformer,
injectOnPressScript: injectOnPressScript,
injectNavigationScript: injectNavigationScript,
injectReactNative: injectReactNative,
injectReactNavigation: injectReactNavigation,
injectReactNavigation3,
injectReactNavigation4,
injectReactNavigation6,
injectReactNativeNavigation: injectReactNativeNavigation,
};