Skip to content

Commit

Permalink
Release 2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiangliu committed Jun 8, 2021
1 parent 337fcee commit 4375d97
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 39 deletions.
2 changes: 1 addition & 1 deletion RNSensorsAnalyticsModule.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = "RNSensorsAnalyticsModule"
s.version = "2.1.0"
s.version = "2.1.1"
s.summary = "The official React Native SDK of Sensors Analytics."
s.description = <<-DESC
神策分析 RN 组件
Expand Down
89 changes: 54 additions & 35 deletions SensorsDataRNHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ var RNSwitchFiles = [dir + '/react-native/Libraries/Components/Switch/Switch.js'
var RNSegmentedControlFilePath = [dir + '/react-native/Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.ios.js',
dir + '/@react-native-community/segmented-control/js/SegmentedControl.ios.js'];
// RN 控制 GestureButtons 的文件
var RNGestureButtonsFilePath = dir + '/react-native-gesture-handler/GestureButtons.js';
var RNGestureButtonsFilePaths = [dir + '/react-native-gesture-handler/GestureButtons.js',
dir + '/react-native-gesture-handler/src/components/GestureButtons.tsx'];
// click 需 hook 的自执行代码
var sensorsdataClickHookCode = "(function(thatThis){ \n"
+" try {\n"
Expand Down Expand Up @@ -618,40 +619,58 @@ sensorsdataHookSegmentedControlRN = function (reset = false) {
});
};
// hook GestureButtons
sensorsdataHookGestureButtonsRN = function () {
if (fs.existsSync(RNGestureButtonsFilePath)) {
// 读取文件内容
var fileContent = fs.readFileSync(RNGestureButtonsFilePath, 'utf8');
// 已经 hook 过了,不需要再次 hook
if (fileContent.indexOf('SENSORSDATA HOOK') > -1) {
return;
}
// 获取 hook 的代码插入的位置
var scriptStr = 'this.props.onPress(active);';
var hookIndex = fileContent.indexOf(scriptStr);
// 判断文件是否异常,不存在 touchableHandlePress 方法,导致无法 hook 点击事件
if (hookIndex == -1) {
throw "Can't not find onValueChange function";
sensorsdataHookGestureButtonsRN = function (reset = false) {
RNGestureButtonsFilePaths.forEach(function (onefile) {
if (fs.existsSync(onefile)) {
// 读取文件内容
var fileContent = fs.readFileSync(onefile, 'utf8');
if (reset) {
// 未被 hook 过代码,不需要处理
if (fileContent.indexOf('SENSORSDATA HOOK') == -1) {
return;
}
// 检查备份文件是否存在
var backFilePath = `${onefile}_sensorsdata_backup`;
if (!fs.existsSync(backFilePath)) {
throw `File: ${backFilePath} not found, Please rm -rf node_modules and npm install again`;
}
// 将备份文件重命名恢复 + 自动覆盖被 hook 过的同名文件
fs.renameSync(backFilePath, onefile);
console.log(`found and reset GestureButtons: ${onefile}`);
} else {
// 已经 hook 过了,不需要再次 hook
if (fileContent.indexOf('SENSORSDATA HOOK') > -1) {
return;
}
// 获取 hook 的代码插入的位置
var scriptStr = 'this.props.onPress(active);';
var hookIndex = fileContent.indexOf(scriptStr);
// 判断文件是否异常,不存在 this.props.onPress(active); 导致无法 hook 点击事件
if (hookIndex == -1) {
throw "Can't not find this.props.onPress(active); ";
}
// 插入 hook 代码
var hookedContent = `${fileContent.substring(
0,
hookIndex + scriptStr.length,
)}\n${sensorsdataClickHookCode}\n${fileContent.substring(
hookIndex + scriptStr.length,
)}`;
// 备份目标源文件
fs.renameSync(
onefile,
`${onefile}_sensorsdata_backup`,
);
// 重写修改后的文件
fs.writeFileSync(onefile, hookedContent, 'utf8');
console.log(
`found and modify GestureButtons: ${onefile}`,
);
}
}
// 插入 hook 代码
var hookedContent = `${fileContent.substring(
0,
hookIndex + scriptStr.length
)}\n${sensorsdataClickHookCode}\n${fileContent.substring(
hookIndex + scriptStr.length
)}`;
// 备份 Touchable.js 源文件
fs.renameSync(
RNGestureButtonsFilePath,
`${RNGestureButtonsFilePath}_sensorsdata_backup`
);
// 重写 Touchable.js 文件
fs.writeFileSync(RNGestureButtonsFilePath, hookedContent, 'utf8');
console.log(
`found and modify GestureButtons.js: ${RNGestureButtonsFilePath}`
);
}
});
};

// hook clickable
sensorsdataHookClickableRN = function (reset = false) {
RNClickableFiles.forEach(function (onefile) {
Expand Down Expand Up @@ -1138,7 +1157,7 @@ resetAllSensorsdataHookRN = function () {
sensorsdataHookSliderRN(true);
sensorsdataHookSwitchRN(true);
sensorsdataHookSegmentedControlRN(true);
sensorsdataResetRN(RNGestureButtonsFilePath);
sensorsdataHookGestureButtonsRN(true)
// 3 期
sensorsdataResetRN(RNClickPressabilityFilePath);
sensorsdataResetRN(reactNavigationPath5X);
Expand All @@ -1155,7 +1174,7 @@ allSensorsdataHookRN = function () {
sensorsdataHookSliderRN();
sensorsdataHookSwitchRN();
sensorsdataHookSegmentedControlRN();
sensorsdataHookGestureButtonsRN();
sensorsdataHookGestureButtonsRN(false)
// 3 期
sensorsdataHookPressabilityClickRN(RNClickPressabilityFilePath);
sensorsdataHookNavigation5();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.List;

public class RNSensorsAnalyticsPackage implements ReactPackage {
public static final String VERSION = "2.1.0";
public static final String VERSION = "2.1.1";
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
Expand Down
2 changes: 1 addition & 1 deletion ios/RNSensorsAnalyticsModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#import "SAReactNativeManager.h"
#import "SAReactNativeEventProperty.h"

NSString *const kSAReactNativePluginVersion = @"react_native:2.1.0";
NSString *const kSAReactNativePluginVersion = @"react_native:2.1.1";

@implementation RNSensorsAnalyticsModule

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sensorsdata-analytics-react-native",
"version": "2.1.0",
"version": "2.1.1",
"private": false,
"description": "神策分析 RN 组件",
"main": "index.js",
Expand Down

0 comments on commit 4375d97

Please sign in to comment.