Skip to content

Commit 4375d97

Browse files
author
weiqiangliu
committed
Release 2.1.1
1 parent 337fcee commit 4375d97

File tree

5 files changed

+58
-39
lines changed

5 files changed

+58
-39
lines changed

RNSensorsAnalyticsModule.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Pod::Spec.new do |s|
33
s.name = "RNSensorsAnalyticsModule"
4-
s.version = "2.1.0"
4+
s.version = "2.1.1"
55
s.summary = "The official React Native SDK of Sensors Analytics."
66
s.description = <<-DESC
77
神策分析 RN 组件

SensorsDataRNHook.js

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ var RNSwitchFiles = [dir + '/react-native/Libraries/Components/Switch/Switch.js'
4343
var RNSegmentedControlFilePath = [dir + '/react-native/Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.ios.js',
4444
dir + '/@react-native-community/segmented-control/js/SegmentedControl.ios.js'];
4545
// RN 控制 GestureButtons 的文件
46-
var RNGestureButtonsFilePath = dir + '/react-native-gesture-handler/GestureButtons.js';
46+
var RNGestureButtonsFilePaths = [dir + '/react-native-gesture-handler/GestureButtons.js',
47+
dir + '/react-native-gesture-handler/src/components/GestureButtons.tsx'];
4748
// click 需 hook 的自执行代码
4849
var sensorsdataClickHookCode = "(function(thatThis){ \n"
4950
+" try {\n"
@@ -618,40 +619,58 @@ sensorsdataHookSegmentedControlRN = function (reset = false) {
618619
});
619620
};
620621
// hook GestureButtons
621-
sensorsdataHookGestureButtonsRN = function () {
622-
if (fs.existsSync(RNGestureButtonsFilePath)) {
623-
// 读取文件内容
624-
var fileContent = fs.readFileSync(RNGestureButtonsFilePath, 'utf8');
625-
// 已经 hook 过了,不需要再次 hook
626-
if (fileContent.indexOf('SENSORSDATA HOOK') > -1) {
627-
return;
628-
}
629-
// 获取 hook 的代码插入的位置
630-
var scriptStr = 'this.props.onPress(active);';
631-
var hookIndex = fileContent.indexOf(scriptStr);
632-
// 判断文件是否异常,不存在 touchableHandlePress 方法,导致无法 hook 点击事件
633-
if (hookIndex == -1) {
634-
throw "Can't not find onValueChange function";
622+
sensorsdataHookGestureButtonsRN = function (reset = false) {
623+
RNGestureButtonsFilePaths.forEach(function (onefile) {
624+
if (fs.existsSync(onefile)) {
625+
// 读取文件内容
626+
var fileContent = fs.readFileSync(onefile, 'utf8');
627+
if (reset) {
628+
// 未被 hook 过代码,不需要处理
629+
if (fileContent.indexOf('SENSORSDATA HOOK') == -1) {
630+
return;
631+
}
632+
// 检查备份文件是否存在
633+
var backFilePath = `${onefile}_sensorsdata_backup`;
634+
if (!fs.existsSync(backFilePath)) {
635+
throw `File: ${backFilePath} not found, Please rm -rf node_modules and npm install again`;
636+
}
637+
// 将备份文件重命名恢复 + 自动覆盖被 hook 过的同名文件
638+
fs.renameSync(backFilePath, onefile);
639+
console.log(`found and reset GestureButtons: ${onefile}`);
640+
} else {
641+
// 已经 hook 过了,不需要再次 hook
642+
if (fileContent.indexOf('SENSORSDATA HOOK') > -1) {
643+
return;
644+
}
645+
// 获取 hook 的代码插入的位置
646+
var scriptStr = 'this.props.onPress(active);';
647+
var hookIndex = fileContent.indexOf(scriptStr);
648+
// 判断文件是否异常,不存在 this.props.onPress(active); 导致无法 hook 点击事件
649+
if (hookIndex == -1) {
650+
throw "Can't not find this.props.onPress(active); ";
651+
}
652+
// 插入 hook 代码
653+
var hookedContent = `${fileContent.substring(
654+
0,
655+
hookIndex + scriptStr.length,
656+
)}\n${sensorsdataClickHookCode}\n${fileContent.substring(
657+
hookIndex + scriptStr.length,
658+
)}`;
659+
// 备份目标源文件
660+
fs.renameSync(
661+
onefile,
662+
`${onefile}_sensorsdata_backup`,
663+
);
664+
// 重写修改后的文件
665+
fs.writeFileSync(onefile, hookedContent, 'utf8');
666+
console.log(
667+
`found and modify GestureButtons: ${onefile}`,
668+
);
669+
}
635670
}
636-
// 插入 hook 代码
637-
var hookedContent = `${fileContent.substring(
638-
0,
639-
hookIndex + scriptStr.length
640-
)}\n${sensorsdataClickHookCode}\n${fileContent.substring(
641-
hookIndex + scriptStr.length
642-
)}`;
643-
// 备份 Touchable.js 源文件
644-
fs.renameSync(
645-
RNGestureButtonsFilePath,
646-
`${RNGestureButtonsFilePath}_sensorsdata_backup`
647-
);
648-
// 重写 Touchable.js 文件
649-
fs.writeFileSync(RNGestureButtonsFilePath, hookedContent, 'utf8');
650-
console.log(
651-
`found and modify GestureButtons.js: ${RNGestureButtonsFilePath}`
652-
);
653-
}
671+
});
654672
};
673+
655674
// hook clickable
656675
sensorsdataHookClickableRN = function (reset = false) {
657676
RNClickableFiles.forEach(function (onefile) {
@@ -1138,7 +1157,7 @@ resetAllSensorsdataHookRN = function () {
11381157
sensorsdataHookSliderRN(true);
11391158
sensorsdataHookSwitchRN(true);
11401159
sensorsdataHookSegmentedControlRN(true);
1141-
sensorsdataResetRN(RNGestureButtonsFilePath);
1160+
sensorsdataHookGestureButtonsRN(true)
11421161
// 3 期
11431162
sensorsdataResetRN(RNClickPressabilityFilePath);
11441163
sensorsdataResetRN(reactNavigationPath5X);
@@ -1155,7 +1174,7 @@ allSensorsdataHookRN = function () {
11551174
sensorsdataHookSliderRN();
11561175
sensorsdataHookSwitchRN();
11571176
sensorsdataHookSegmentedControlRN();
1158-
sensorsdataHookGestureButtonsRN();
1177+
sensorsdataHookGestureButtonsRN(false)
11591178
// 3 期
11601179
sensorsdataHookPressabilityClickRN(RNClickPressabilityFilePath);
11611180
sensorsdataHookNavigation5();

android/src/main/java/com/sensorsdata/analytics/RNSensorsAnalyticsPackage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import java.util.List;
2929

3030
public class RNSensorsAnalyticsPackage implements ReactPackage {
31-
public static final String VERSION = "2.1.0";
31+
public static final String VERSION = "2.1.1";
3232
@Override
3333
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
3434
List<NativeModule> modules = new ArrayList<>();

ios/RNSensorsAnalyticsModule.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#import "SAReactNativeManager.h"
3333
#import "SAReactNativeEventProperty.h"
3434

35-
NSString *const kSAReactNativePluginVersion = @"react_native:2.1.0";
35+
NSString *const kSAReactNativePluginVersion = @"react_native:2.1.1";
3636

3737
@implementation RNSensorsAnalyticsModule
3838

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sensorsdata-analytics-react-native",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"private": false,
55
"description": "神策分析 RN 组件",
66
"main": "index.js",

0 commit comments

Comments
 (0)