react-native-quicktracking-analytics-module 1.0.4 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/QTSDKManager.java +93 -0
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/{QuicktrackingAnalyticsModuleModule.java → QuicktrackingAnalyticsModule.java} +35 -12
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/QuicktrackingAnalyticsModulePackage.java +1 -1
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/property/QTViewProperties.java +48 -0
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/QTLog.java +122 -0
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/RNPropertyManager.java +29 -0
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/RNTouchTargetHelper.java +139 -0
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/RNUtils.java +188 -0
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/RNViewUtils.java +148 -0
- package/ios/NSObject+QTReactNativeSwizzler.h +19 -0
- package/ios/NSObject+QTReactNativeSwizzler.m +38 -0
- package/ios/QTRNUtils.h +21 -0
- package/ios/QTRNUtils.m +48 -0
- package/ios/QTReactNativeRootViewManager.h +41 -0
- package/ios/QTReactNativeRootViewManager.m +100 -0
- package/ios/QTReactNativeViewProperty.h +28 -0
- package/ios/QTReactNativeViewProperty.m +27 -0
- package/ios/QuickTrackingSDKManager.h +25 -0
- package/ios/QuickTrackingSDKManager.m +140 -0
- package/ios/QuicktrackingAnalyticsModule.h +11 -1
- package/ios/QuicktrackingAnalyticsModule.m +46 -3
- package/ios/RCTRootView+QTReactNative.h +23 -0
- package/ios/RCTRootView+QTReactNative.m +56 -0
- package/lib/typescript/index.d.ts +3 -2
- package/package.json +27 -4
- package/react-native-quicktracking-analytics-module.podspec +2 -2
- package/src/hook.js +679 -0
- package/HISTORY.md +0 -17
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.4/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.4/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/7.4.2/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4.2/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.4.2/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.4.2/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4.2/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4.2/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/MainApplication.java +0 -47
- package/ios/.DS_Store +0 -0
- package/ios/QuicktrackingAnalyticsModule.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -4
- package/ios/QuicktrackingAnalyticsModule.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/QuicktrackingAnalyticsModule.xcodeproj/project.xcworkspace/xcuserdata/yuzhao.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/QuicktrackingAnalyticsModule.xcodeproj/xcuserdata/yuzhao.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
package/android/build.gradle
CHANGED
|
@@ -134,7 +134,7 @@ dependencies {
|
|
|
134
134
|
// implementation fileTree(include:['*.jar'], dir:'libs')
|
|
135
135
|
implementation "com.facebook.react:react-native:+"
|
|
136
136
|
//友盟基础库
|
|
137
|
-
implementation "com.
|
|
137
|
+
implementation "com.lydaas.qtsdk:qt-px-common:1.8.3.PX"
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
if (isNewArchitectureEnabled()) {
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
package com.reactnativequicktrackinganalyticsmodule;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
4
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
5
|
+
import com.facebook.react.uimanager.JSTouchDispatcher;
|
|
6
|
+
import com.facebook.react.uimanager.events.EventDispatcher;
|
|
7
|
+
import com.quick.qt.analytics.QtTrackAgent;
|
|
8
|
+
|
|
9
|
+
import java.lang.reflect.Field;
|
|
10
|
+
import java.util.Map;
|
|
11
|
+
import java.util.WeakHashMap;
|
|
12
|
+
import android.util.SparseArray;
|
|
13
|
+
import android.view.MotionEvent;
|
|
14
|
+
import android.view.View;
|
|
15
|
+
import android.view.ViewGroup;
|
|
16
|
+
|
|
17
|
+
import com.reactnativequicktrackinganalyticsmodule.property.QTViewProperties;
|
|
18
|
+
import com.reactnativequicktrackinganalyticsmodule.utils.*;
|
|
19
|
+
import org.json.JSONObject;
|
|
20
|
+
|
|
21
|
+
public class QTSDKManager {
|
|
22
|
+
public static final WeakHashMap jsTouchDispatcherViewGroupWeakHashMap = new WeakHashMap();
|
|
23
|
+
private static SparseArray<QTViewProperties> viewPropertiesArray = new SparseArray<>();
|
|
24
|
+
|
|
25
|
+
public static void handleTouchEvent(JSTouchDispatcher jsTouchDispatcher, MotionEvent event, EventDispatcher eventDispatcher) {
|
|
26
|
+
try {
|
|
27
|
+
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
28
|
+
ViewGroup viewGroup = (ViewGroup) jsTouchDispatcherViewGroupWeakHashMap.get(jsTouchDispatcher);
|
|
29
|
+
if (viewGroup == null) {
|
|
30
|
+
try {
|
|
31
|
+
Field viewGroupField = jsTouchDispatcher.getClass().getDeclaredField("mRootViewGroup");
|
|
32
|
+
viewGroupField.setAccessible(true);
|
|
33
|
+
viewGroup = (ViewGroup) viewGroupField.get(jsTouchDispatcher);
|
|
34
|
+
jsTouchDispatcherViewGroupWeakHashMap.put(jsTouchDispatcher, viewGroup);
|
|
35
|
+
} catch (Exception e) {
|
|
36
|
+
QTLog.printStackTrace(e);
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
View nativeTargetView = RNTouchTargetHelper.findTouchTargetView(new float[]{event.getX(), event.getY()}, viewGroup);
|
|
40
|
+
if (nativeTargetView != null) {
|
|
41
|
+
View reactTargetView = RNTouchTargetHelper.findClosestReactAncestor(nativeTargetView);
|
|
42
|
+
if (reactTargetView != null) {
|
|
43
|
+
nativeTargetView = reactTargetView;
|
|
44
|
+
}
|
|
45
|
+
RNViewUtils.setOnTouchView(nativeTargetView);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} catch (Exception ignored) {
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static void trackViewClick(int viewId, ReactApplicationContext ctx) {
|
|
55
|
+
try {
|
|
56
|
+
View clickView = RNViewUtils.getViewByTag(viewId);
|
|
57
|
+
QTLog.t("current clickView ===" + clickView);
|
|
58
|
+
if (clickView != null) {
|
|
59
|
+
JSONObject properties = new JSONObject();
|
|
60
|
+
if (RNViewUtils.getTitle() != null) {
|
|
61
|
+
properties.put("title", RNViewUtils.getTitle());
|
|
62
|
+
}
|
|
63
|
+
if (RNViewUtils.getScreenName() != null) {
|
|
64
|
+
properties.put("$screen_name", RNViewUtils.getScreenName());
|
|
65
|
+
}
|
|
66
|
+
QTViewProperties viewProperties = viewPropertiesArray.get(viewId);
|
|
67
|
+
if (viewProperties != null && viewProperties.properties != null && viewProperties.properties.length() > 0) {
|
|
68
|
+
//TODO: ignore 这个字段名是否需要重构
|
|
69
|
+
if (viewProperties.properties.optBoolean("ignore", false)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
viewProperties.properties.remove("ignore");
|
|
73
|
+
RNUtils.mergeJSONObject(viewProperties.properties, properties);
|
|
74
|
+
}
|
|
75
|
+
String eventID = RNUtils.MD5(Integer.toString(viewId));
|
|
76
|
+
JSONObject mergedProperties = RNPropertyManager.mergeProperty(properties, true);
|
|
77
|
+
Map<String, Object> map = RNUtils.convertToMap(mergedProperties);
|
|
78
|
+
QtTrackAgent.onEventObject(ctx, eventID, map);
|
|
79
|
+
}
|
|
80
|
+
} catch (Exception e) {
|
|
81
|
+
QTLog.printStackTrace(e);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static void saveViewProperties(int viewTag, boolean clickable, ReadableMap viewProperties) {
|
|
86
|
+
QTLog.t("currentView Tag ===" + viewTag);
|
|
87
|
+
QTLog.t("currentView clickable ===" + clickable);
|
|
88
|
+
if (clickable) {
|
|
89
|
+
QTLog.t("before invoke viewPropertiesArray");
|
|
90
|
+
viewPropertiesArray.put(viewTag, new QTViewProperties(clickable, viewProperties));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -2,39 +2,40 @@ package com.reactnativequicktrackinganalyticsmodule;
|
|
|
2
2
|
|
|
3
3
|
import androidx.annotation.NonNull;
|
|
4
4
|
|
|
5
|
-
import java.util.ArrayList;
|
|
6
5
|
import java.util.HashMap;
|
|
7
|
-
import java.util.List;
|
|
8
6
|
import java.util.Map;
|
|
9
|
-
import org.json.JSONObject;
|
|
10
|
-
import org.json.JSONException;
|
|
11
7
|
import java.util.Iterator;
|
|
12
8
|
|
|
13
|
-
import com.facebook.react.bridge.Callback;
|
|
14
9
|
import com.facebook.react.bridge.Promise;
|
|
15
10
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
16
11
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
17
12
|
import com.facebook.react.bridge.ReactMethod;
|
|
18
|
-
import com.facebook.react.bridge.ReadableArray;
|
|
19
13
|
import com.facebook.react.bridge.ReadableMap;
|
|
20
14
|
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
|
21
15
|
import com.facebook.react.bridge.ReadableNativeMap;
|
|
22
16
|
import com.facebook.react.bridge.ReadableType;
|
|
23
17
|
import com.facebook.react.module.annotations.ReactModule;
|
|
18
|
+
import com.facebook.react.bridge.LifecycleEventListener;
|
|
24
19
|
|
|
25
20
|
import com.quick.qt.analytics.QtTrackAgent;
|
|
26
21
|
import com.quick.qt.commonsdk.QtConfigure;
|
|
27
22
|
import com.quick.qt.spm.SpmAgent;
|
|
23
|
+
import com.reactnativequicktrackinganalyticsmodule.utils.*;
|
|
28
24
|
|
|
29
|
-
@ReactModule(name =
|
|
30
|
-
public class
|
|
25
|
+
@ReactModule(name = QuicktrackingAnalyticsModule.NAME)
|
|
26
|
+
public class QuicktrackingAnalyticsModule extends ReactContextBaseJavaModule {
|
|
31
27
|
public static final String NAME = "QuicktrackingAnalyticsModule";
|
|
32
28
|
public static final String TAG = "QuickTracking == ";
|
|
33
29
|
private ReactApplicationContext context;
|
|
34
30
|
|
|
35
|
-
public
|
|
31
|
+
public QuicktrackingAnalyticsModule(ReactApplicationContext reactContext) {
|
|
36
32
|
super(reactContext);
|
|
37
33
|
context = reactContext;
|
|
34
|
+
try {
|
|
35
|
+
reactContext.addLifecycleEventListener(new QTDataLifecycleListener());
|
|
36
|
+
} catch (Exception e) {
|
|
37
|
+
|
|
38
|
+
}
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
@Override
|
|
@@ -45,13 +46,11 @@ public class QuicktrackingAnalyticsModuleModule extends ReactContextBaseJavaModu
|
|
|
45
46
|
|
|
46
47
|
@ReactMethod
|
|
47
48
|
public void onPageStart(String pageName) {
|
|
48
|
-
// android.util.Log.e("xxxxxx","onPageStart="+mPageName);
|
|
49
49
|
QtTrackAgent.onPageStart(pageName);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
@ReactMethod
|
|
53
53
|
public void onPageEnd(String pageName) {
|
|
54
|
-
//android.util.Log.e("xxxxxx","onPageEnd="+mPageName);
|
|
55
54
|
QtTrackAgent.onPageEnd(pageName);
|
|
56
55
|
}
|
|
57
56
|
|
|
@@ -131,13 +130,17 @@ public class QuicktrackingAnalyticsModuleModule extends ReactContextBaseJavaModu
|
|
|
131
130
|
@ReactMethod
|
|
132
131
|
public void onEventForH5(String content) {
|
|
133
132
|
try {
|
|
134
|
-
// android.util.Log.e(TAG, " " + content);
|
|
135
133
|
SpmAgent.CALL(content);
|
|
136
134
|
} catch (Exception e) {
|
|
137
135
|
android.util.Log.e(TAG, "桥接事件发送失败!", e);
|
|
138
136
|
}
|
|
139
137
|
}
|
|
140
138
|
|
|
139
|
+
@ReactMethod
|
|
140
|
+
public void onEventAutoCLK(int viewId) {
|
|
141
|
+
QTSDKManager.trackViewClick(viewId, context);
|
|
142
|
+
}
|
|
143
|
+
|
|
141
144
|
@ReactMethod
|
|
142
145
|
public void registerGlobalProperties(ReadableMap map) throws Exception {
|
|
143
146
|
try {
|
|
@@ -216,4 +219,24 @@ public class QuicktrackingAnalyticsModuleModule extends ReactContextBaseJavaModu
|
|
|
216
219
|
public void initWithAppkey(String AppKey, String Channel) {
|
|
217
220
|
QtConfigure.init(context, AppKey, Channel, QtConfigure.DEVICE_TYPE_PHONE, "");
|
|
218
221
|
}
|
|
222
|
+
|
|
223
|
+
@ReactMethod
|
|
224
|
+
public void saveViewProperties(int viewId, boolean clickable, ReadableMap viewProperties) {
|
|
225
|
+
QTSDKManager.saveViewProperties(viewId, clickable, viewProperties);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
class QTDataLifecycleListener implements LifecycleEventListener {
|
|
230
|
+
public void onHostResume() {
|
|
231
|
+
RNViewUtils.onActivityResumed(getCurrentActivity());
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
public void onHostPause() {
|
|
235
|
+
RNViewUtils.onActivityPaused();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
public void onHostDestroy() {
|
|
239
|
+
|
|
240
|
+
}
|
|
241
|
+
}
|
|
219
242
|
}
|
|
@@ -16,7 +16,7 @@ public class QuicktrackingAnalyticsModulePackage implements ReactPackage {
|
|
|
16
16
|
@Override
|
|
17
17
|
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
18
18
|
List<NativeModule> modules = new ArrayList<>();
|
|
19
|
-
modules.add(new
|
|
19
|
+
modules.add(new QuicktrackingAnalyticsModule(reactContext));
|
|
20
20
|
return modules;
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
|
|
2
|
+
package com.reactnativequicktrackinganalyticsmodule.property;
|
|
3
|
+
import com.reactnativequicktrackinganalyticsmodule.utils.RNUtils;
|
|
4
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
5
|
+
import org.json.JSONObject;
|
|
6
|
+
|
|
7
|
+
import android.content.Context;
|
|
8
|
+
import android.view.View;
|
|
9
|
+
import android.widget.ScrollView;
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
public class QTViewProperties {
|
|
13
|
+
public static final String TAG = "QuickTracking == ";
|
|
14
|
+
private boolean clickable;
|
|
15
|
+
public JSONObject properties;
|
|
16
|
+
private int viewTagKey = 0;
|
|
17
|
+
|
|
18
|
+
public QTViewProperties(boolean clickable, ReadableMap params) {
|
|
19
|
+
this.clickable = clickable;
|
|
20
|
+
this.properties = RNUtils.convertToJSONObject(params);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public void setViewClickable(View view) {
|
|
24
|
+
try {
|
|
25
|
+
if (view != null && !(view instanceof ScrollView)) {
|
|
26
|
+
view.setClickable(clickable);
|
|
27
|
+
}
|
|
28
|
+
} catch (Exception e) {
|
|
29
|
+
android.util.Log.e(TAG, e.getMessage());
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public void setViewTag(View view) {
|
|
34
|
+
try {
|
|
35
|
+
if (view != null) {
|
|
36
|
+
if (viewTagKey == 0) {
|
|
37
|
+
Context context = view.getContext();
|
|
38
|
+
viewTagKey = context.getResources().getIdentifier("qt_rn_tag_view_rn_key", "id", context.getPackageName());
|
|
39
|
+
}
|
|
40
|
+
if (viewTagKey != 0) {
|
|
41
|
+
view.setTag(viewTagKey, true);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
} catch (Exception e) {
|
|
45
|
+
android.util.Log.e(TAG, "设置viewTag 失败!" + e.getMessage());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
package com.reactnativequicktrackinganalyticsmodule.utils;
|
|
2
|
+
|
|
3
|
+
import android.util.Log;
|
|
4
|
+
|
|
5
|
+
public class QTLog {
|
|
6
|
+
private static boolean debug;
|
|
7
|
+
private static boolean enableLog;
|
|
8
|
+
private static boolean disableSDK;
|
|
9
|
+
private static final int CHUNK_SIZE = 4000;
|
|
10
|
+
|
|
11
|
+
public static void d(String tag, String msg) {
|
|
12
|
+
if (debug && !disableSDK) {
|
|
13
|
+
info(tag, msg, null);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public static void t(String msg, Object... object) {
|
|
18
|
+
if (enableLog && !disableSDK) {
|
|
19
|
+
i("===TEST===", msg, object);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public static void d(String tag, String msg, Throwable tr) {
|
|
24
|
+
if (debug && !disableSDK) {
|
|
25
|
+
info(tag, msg, tr);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public static void i(String tag, String msg) {
|
|
30
|
+
if (enableLog && !disableSDK) {
|
|
31
|
+
info(tag, msg, null);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public static void i(String tag, Throwable tr) {
|
|
36
|
+
if (enableLog && !disableSDK) {
|
|
37
|
+
info(tag, "", tr);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public static void i(String tag, String msg, Throwable tr) {
|
|
42
|
+
if (enableLog && !disableSDK) {
|
|
43
|
+
info(tag, msg, tr);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public static void i(String tag, String msg, Object... object) {
|
|
48
|
+
if (enableLog && !disableSDK) {
|
|
49
|
+
info(tag, String.format(msg, object), null);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public static void info(String tag, String msg, Throwable tr) {
|
|
54
|
+
try {
|
|
55
|
+
if (msg != null) {
|
|
56
|
+
byte[] bytes = msg.getBytes();
|
|
57
|
+
int length = bytes.length;
|
|
58
|
+
if (length <= CHUNK_SIZE) {
|
|
59
|
+
Log.i(tag, msg, tr);
|
|
60
|
+
} else {
|
|
61
|
+
int index = 0, lastIndexOfLF = 0;
|
|
62
|
+
//当最后一次剩余值小于 CHUNK_SIZE 时,不需要再截断
|
|
63
|
+
while (index < length - CHUNK_SIZE) {
|
|
64
|
+
lastIndexOfLF = lastIndexOfLF(bytes, index);
|
|
65
|
+
int chunkLength = lastIndexOfLF - index;
|
|
66
|
+
Log.i(tag, new String(bytes, index, chunkLength), null);
|
|
67
|
+
if (chunkLength < CHUNK_SIZE) {
|
|
68
|
+
//跳过换行符
|
|
69
|
+
index = lastIndexOfLF + 1;
|
|
70
|
+
} else {
|
|
71
|
+
index = lastIndexOfLF;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (length > index) {
|
|
75
|
+
Log.i(tag, new String(bytes, index, length - index), tr);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
Log.i(tag, null, tr);
|
|
80
|
+
}
|
|
81
|
+
} catch (Exception e) {
|
|
82
|
+
printStackTrace(e);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private static int lastIndexOfLF(byte[] bytes, int fromIndex) {
|
|
87
|
+
int index = Math.min(fromIndex + CHUNK_SIZE, bytes.length - 1);
|
|
88
|
+
for (int i = index; i > index - CHUNK_SIZE; i--) {
|
|
89
|
+
//返回换行符的位置
|
|
90
|
+
if (bytes[i] == (byte) 10) {
|
|
91
|
+
return i;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return index;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public static void printStackTrace(Exception e) {
|
|
98
|
+
if (enableLog && !disableSDK && e != null) {
|
|
99
|
+
Log.e("QuickTracking Exception", "", e);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static void setDebug(boolean isDebug) {
|
|
104
|
+
debug = isDebug;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public static void setEnableLog(boolean isEnableLog) {
|
|
108
|
+
enableLog = isEnableLog;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public static void setDisableSDK(boolean configDisableSDK) {
|
|
112
|
+
disableSDK = configDisableSDK;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public static boolean isLogEnabled() {
|
|
116
|
+
return enableLog;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public static boolean isDebug() {
|
|
120
|
+
return debug;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
package com.reactnativequicktrackinganalyticsmodule.utils;
|
|
2
|
+
|
|
3
|
+
import org.json.JSONObject;
|
|
4
|
+
|
|
5
|
+
import java.util.ArrayList;
|
|
6
|
+
import java.util.List;
|
|
7
|
+
|
|
8
|
+
public class RNPropertyManager {
|
|
9
|
+
public static List<Interceptor> interceptors = new ArrayList<>();
|
|
10
|
+
|
|
11
|
+
public static void addInterceptor(Interceptor interceptor){
|
|
12
|
+
interceptors.add(interceptor);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public static JSONObject mergeProperty(JSONObject properties){
|
|
16
|
+
return mergeProperty(properties, false);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public static JSONObject mergeProperty(JSONObject properties, boolean isAuto){
|
|
20
|
+
for(Interceptor interceptor:interceptors){
|
|
21
|
+
properties = interceptor.proceed(properties, isAuto);
|
|
22
|
+
}
|
|
23
|
+
return properties;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface Interceptor{
|
|
27
|
+
JSONObject proceed(JSONObject properties, boolean isAuto);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
package com.reactnativequicktrackinganalyticsmodule.utils;
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint;
|
|
4
|
+
import android.graphics.Matrix;
|
|
5
|
+
import android.graphics.PointF;
|
|
6
|
+
import android.graphics.Rect;
|
|
7
|
+
import android.view.View;
|
|
8
|
+
import android.view.ViewGroup;
|
|
9
|
+
|
|
10
|
+
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
|
|
11
|
+
import com.facebook.react.bridge.UiThreadUtil;
|
|
12
|
+
import com.facebook.react.touch.ReactHitSlopView;
|
|
13
|
+
import com.facebook.react.uimanager.PointerEvents;
|
|
14
|
+
import com.facebook.react.uimanager.ReactCompoundView;
|
|
15
|
+
import com.facebook.react.uimanager.ReactCompoundViewGroup;
|
|
16
|
+
import com.facebook.react.uimanager.ReactPointerEventsView;
|
|
17
|
+
|
|
18
|
+
public class RNTouchTargetHelper {
|
|
19
|
+
private static final float[] mEventCoords = new float[2];
|
|
20
|
+
private static final Matrix mInverseMatrix = new Matrix();
|
|
21
|
+
private static final float[] mMatrixTransformCoords = new float[2];
|
|
22
|
+
private static final PointF mTempPoint = new PointF();
|
|
23
|
+
|
|
24
|
+
public static int findTargetTagForTouch(float eventX, float eventY, ViewGroup viewGroup) {
|
|
25
|
+
return findTargetTagAndCoordinatesForTouch(eventX, eventY, viewGroup, mEventCoords);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static int findTargetTagAndCoordinatesForTouch(float eventX, float eventY, ViewGroup viewGroup, float[] viewCoords) {
|
|
29
|
+
UiThreadUtil.assertOnUiThread();
|
|
30
|
+
int targetTag = viewGroup.getId();
|
|
31
|
+
viewCoords[0] = eventX;
|
|
32
|
+
viewCoords[1] = eventY;
|
|
33
|
+
View nativeTargetView = findTouchTargetView(viewCoords, viewGroup);
|
|
34
|
+
if (nativeTargetView == null) {
|
|
35
|
+
return targetTag;
|
|
36
|
+
}
|
|
37
|
+
View reactTargetView = findClosestReactAncestor(nativeTargetView);
|
|
38
|
+
if (reactTargetView != null) {
|
|
39
|
+
return getTouchTargetForView(reactTargetView, viewCoords[0], viewCoords[1]);
|
|
40
|
+
}
|
|
41
|
+
return targetTag;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@SuppressLint("ResourceType")
|
|
45
|
+
public static View findClosestReactAncestor(View view) {
|
|
46
|
+
while (view != null && view.getId() <= 0) {
|
|
47
|
+
view = (View) view.getParent();
|
|
48
|
+
}
|
|
49
|
+
return view;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public static View findTouchTargetView(float[] eventCoords, ViewGroup viewGroup) {
|
|
53
|
+
for (int i = viewGroup.getChildCount() - 1; i >= 0; i--) {
|
|
54
|
+
View child = viewGroup.getChildAt(i);
|
|
55
|
+
PointF childPoint = mTempPoint;
|
|
56
|
+
if (isTransformedTouchPointInView(eventCoords[0], eventCoords[1], viewGroup, child, childPoint)) {
|
|
57
|
+
float restoreX = eventCoords[0];
|
|
58
|
+
float restoreY = eventCoords[1];
|
|
59
|
+
eventCoords[0] = childPoint.x;
|
|
60
|
+
eventCoords[1] = childPoint.y;
|
|
61
|
+
View targetView = findTouchTargetViewWithPointerEvents(eventCoords, child);
|
|
62
|
+
if (targetView != null) {
|
|
63
|
+
return targetView;
|
|
64
|
+
}
|
|
65
|
+
eventCoords[0] = restoreX;
|
|
66
|
+
eventCoords[1] = restoreY;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return viewGroup;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private static boolean isTransformedTouchPointInView(float x, float y, ViewGroup parent, View child, PointF outLocalPoint) {
|
|
73
|
+
float localX = (((float) parent.getScrollX()) + x) - ((float) child.getLeft());
|
|
74
|
+
float localY = (((float) parent.getScrollY()) + y) - ((float) child.getTop());
|
|
75
|
+
Matrix matrix = child.getMatrix();
|
|
76
|
+
if (!matrix.isIdentity()) {
|
|
77
|
+
float[] localXY = mMatrixTransformCoords;
|
|
78
|
+
localXY[0] = localX;
|
|
79
|
+
localXY[1] = localY;
|
|
80
|
+
Matrix inverseMatrix = mInverseMatrix;
|
|
81
|
+
matrix.invert(inverseMatrix);
|
|
82
|
+
inverseMatrix.mapPoints(localXY);
|
|
83
|
+
localX = localXY[0];
|
|
84
|
+
localY = localXY[1];
|
|
85
|
+
}
|
|
86
|
+
if ((child instanceof ReactHitSlopView) && ((ReactHitSlopView) child).getHitSlopRect() != null) {
|
|
87
|
+
Rect hitSlopRect = ((ReactHitSlopView) child).getHitSlopRect();
|
|
88
|
+
if (localX < ((float) (-hitSlopRect.left)) || localX >= ((float) ((child.getRight() - child.getLeft()) + hitSlopRect.right)) || localY < ((float) (-hitSlopRect.top)) || localY >= ((float) ((child.getBottom() - child.getTop()) + hitSlopRect.bottom))) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
outLocalPoint.set(localX, localY);
|
|
92
|
+
return true;
|
|
93
|
+
} else if (localX < 0.0f || localX >= ((float) (child.getRight() - child.getLeft())) || localY < 0.0f || localY >= ((float) (child.getBottom() - child.getTop()))) {
|
|
94
|
+
return false;
|
|
95
|
+
} else {
|
|
96
|
+
outLocalPoint.set(localX, localY);
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private static View findTouchTargetViewWithPointerEvents(float[] eventCoords, View view) {
|
|
102
|
+
PointerEvents pointerEvents = view instanceof ReactPointerEventsView ? ((ReactPointerEventsView) view).getPointerEvents() : PointerEvents.AUTO;
|
|
103
|
+
if (pointerEvents == PointerEvents.NONE) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
if (pointerEvents == PointerEvents.BOX_ONLY) {
|
|
107
|
+
return view;
|
|
108
|
+
}
|
|
109
|
+
if (pointerEvents == PointerEvents.BOX_NONE) {
|
|
110
|
+
if (view instanceof ViewGroup) {
|
|
111
|
+
View targetView = findTouchTargetView(eventCoords, (ViewGroup) view);
|
|
112
|
+
if (targetView != view) {
|
|
113
|
+
return targetView;
|
|
114
|
+
}
|
|
115
|
+
if (!(view instanceof ReactCompoundView) || ((ReactCompoundView) view).reactTagForTouch(eventCoords[0], eventCoords[1]) == view.getId()) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return view;
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
} else if (pointerEvents != PointerEvents.AUTO) {
|
|
122
|
+
StringBuilder stringBuilder = new StringBuilder();
|
|
123
|
+
stringBuilder.append("Unknown pointer event type: ");
|
|
124
|
+
stringBuilder.append(pointerEvents.toString());
|
|
125
|
+
throw new JSApplicationIllegalArgumentException(stringBuilder.toString());
|
|
126
|
+
} else if ((!(view instanceof ReactCompoundViewGroup) || !((ReactCompoundViewGroup) view).interceptsTouchEvent(eventCoords[0], eventCoords[1])) && (view instanceof ViewGroup)) {
|
|
127
|
+
return findTouchTargetView(eventCoords, (ViewGroup) view);
|
|
128
|
+
} else {
|
|
129
|
+
return view;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public static int getTouchTargetForView(View targetView, float eventX, float eventY) {
|
|
134
|
+
if (targetView instanceof ReactCompoundView) {
|
|
135
|
+
return ((ReactCompoundView) targetView).reactTagForTouch(eventX, eventY);
|
|
136
|
+
}
|
|
137
|
+
return targetView.getId();
|
|
138
|
+
}
|
|
139
|
+
}
|