plotline-engage 1.0.1 → 1.0.3
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
CHANGED
|
@@ -15,27 +15,12 @@ import com.facebook.react.bridge.ReactMethod;
|
|
|
15
15
|
import com.facebook.react.bridge.ReadableMap;
|
|
16
16
|
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
|
17
17
|
import com.facebook.react.bridge.ReadableType;
|
|
18
|
-
import com.facebook.react.uimanager.util.ReactFindViewUtil;
|
|
19
18
|
|
|
20
|
-
import org.json.JSONArray;
|
|
21
19
|
import org.json.JSONObject;
|
|
22
20
|
import org.json.JSONException;
|
|
23
21
|
|
|
24
|
-
import so.plotline.insights.FlowViews.PlotlineInternal;
|
|
25
|
-
import so.plotline.insights.FlowViews.PlotlineViewPositionCallback;
|
|
26
|
-
import so.plotline.insights.FlowViews.PlotlineViewPositionCompleteListener;
|
|
27
|
-
import so.plotline.insights.FlowViews.PlotlineScreenshotPositionsCompleteListener;
|
|
28
|
-
import so.plotline.insights.FlowViews.PlotlineViewsPresenceListener;
|
|
29
|
-
import so.plotline.insights.FlowViews.ElementSearchObject;
|
|
30
|
-
|
|
31
|
-
import so.plotline.insights.Models.ViewPosition;
|
|
32
22
|
import so.plotline.insights.Plotline;
|
|
33
23
|
|
|
34
|
-
import java.util.ArrayList;
|
|
35
|
-
import java.util.List;
|
|
36
|
-
import java.util.HashSet;
|
|
37
|
-
import java.util.Set;
|
|
38
|
-
|
|
39
24
|
public class RNPlotline extends ReactContextBaseJavaModule {
|
|
40
25
|
|
|
41
26
|
private final ReactApplicationContext reactContext;
|
|
@@ -50,167 +35,13 @@ public class RNPlotline extends ReactContextBaseJavaModule {
|
|
|
50
35
|
return "RNPlotline";
|
|
51
36
|
}
|
|
52
37
|
|
|
53
|
-
public static JSONArray getAllElements(@NonNull Activity activity) {
|
|
54
|
-
Set<String> includedElements = new HashSet<>();
|
|
55
|
-
ViewGroup viewGroup = (ViewGroup) activity.findViewById(android.R.id.content);
|
|
56
|
-
JSONArray elements = new JSONArray();
|
|
57
|
-
for(int i=0; i < viewGroup.getChildCount(); i++) {
|
|
58
|
-
ArrayList<View> children = getAllChildren( viewGroup.getChildAt(i));
|
|
59
|
-
for(int j=0; j<children.size(); j++) {
|
|
60
|
-
View childElement = children.get(j);
|
|
61
|
-
String nativeId = getNativeId(childElement);
|
|
62
|
-
if (includedElements.contains(nativeId))
|
|
63
|
-
continue;
|
|
64
|
-
|
|
65
|
-
if (nativeId != null) {
|
|
66
|
-
includedElements.add(nativeId);
|
|
67
|
-
int[] location = new int[2];
|
|
68
|
-
childElement.getLocationInWindow(location);
|
|
69
|
-
JSONObject element = new JSONObject();
|
|
70
|
-
try {
|
|
71
|
-
element.put("clientElementId", nativeId);
|
|
72
|
-
JSONObject position = new JSONObject();
|
|
73
|
-
position.put("x", location[0]);
|
|
74
|
-
position.put("y", location[1]);
|
|
75
|
-
position.put("width", childElement.getWidth());
|
|
76
|
-
position.put("height", childElement.getHeight());
|
|
77
|
-
element.put("position", position);
|
|
78
|
-
elements.put(element);
|
|
79
|
-
} catch (JSONException e) {
|
|
80
|
-
e.printStackTrace();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return elements;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
public static ArrayList<View> getAllChildren(View v) {
|
|
89
|
-
if (!(v instanceof ViewGroup)) {
|
|
90
|
-
ArrayList<View> viewArrayList = new ArrayList<>();
|
|
91
|
-
viewArrayList.add(v);
|
|
92
|
-
return viewArrayList;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
ArrayList<View> result = new ArrayList<>();
|
|
96
|
-
|
|
97
|
-
ViewGroup viewGroup = (ViewGroup) v;
|
|
98
|
-
for (int i = 0; i < viewGroup.getChildCount(); i++) {
|
|
99
|
-
|
|
100
|
-
View child = viewGroup.getChildAt(i);
|
|
101
|
-
|
|
102
|
-
ArrayList<View> viewArrayList = new ArrayList<>();
|
|
103
|
-
viewArrayList.add(v);
|
|
104
|
-
viewArrayList.addAll(getAllChildren(child));
|
|
105
|
-
|
|
106
|
-
result.addAll(viewArrayList);
|
|
107
|
-
}
|
|
108
|
-
return result;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public static RectF calculeRectOnScreen(View view) {
|
|
112
|
-
int[] location = new int[2];
|
|
113
|
-
view.getLocationOnScreen(location);
|
|
114
|
-
return new RectF(location[0], location[1], location[0] + view.getMeasuredWidth(), location[1] + view.getMeasuredHeight());
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public static RectF calculeRectInWindow(View view) {
|
|
118
|
-
int[] location = new int[2];
|
|
119
|
-
view.getLocationInWindow(location);
|
|
120
|
-
return new RectF(location[0], location[1], location[0] + view.getMeasuredWidth(), location[1] + view.getMeasuredHeight());
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
private static String getNativeId(View view) {
|
|
124
|
-
Object tag = view.getTag(R.id.view_tag_native_id);
|
|
125
|
-
return tag instanceof String ? (String) tag : null;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
38
|
@ReactMethod
|
|
129
39
|
public void init(String apiKey, String userId, String endpoint) {
|
|
130
40
|
final Activity activity = getCurrentActivity();
|
|
131
41
|
Plotline.init(activity, apiKey, userId, endpoint);
|
|
132
42
|
Plotline.setFramework("REACT_NATIVE");
|
|
133
|
-
PlotlineInternal.setPositionCallback(new PlotlineViewPositionCallback() {
|
|
134
|
-
@Override
|
|
135
|
-
public void getAllElements(Activity activity, PlotlineScreenshotPositionsCompleteListener plotlineScreenshotPositionsCompleteListener) {
|
|
136
|
-
plotlineScreenshotPositionsCompleteListener.onPositionsReady(RNPlotline.getAllElements(activity));
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
@Override
|
|
140
|
-
public void getViewPosition(Activity activity, String fragmentId, String nativeId, PlotlineViewPositionCompleteListener plotlineViewPositionCompleteListener) {
|
|
141
|
-
final Activity activityInternal = getCurrentActivity();
|
|
142
|
-
View view = ReactFindViewUtil.findView(activityInternal.getWindow().getDecorView().getRootView(), nativeId);
|
|
143
|
-
|
|
144
|
-
if (view == null) {
|
|
145
|
-
plotlineViewPositionCompleteListener.onViewReady(null);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
view.post(() -> {
|
|
150
|
-
boolean isVisible = false;
|
|
151
|
-
try {
|
|
152
|
-
AccessibilityNodeInfo nodeInfo = AccessibilityNodeInfo.obtain();
|
|
153
|
-
view.onInitializeAccessibilityNodeInfo(nodeInfo);
|
|
154
|
-
isVisible = nodeInfo.isVisibleToUser();
|
|
155
|
-
nodeInfo.recycle();
|
|
156
|
-
} catch (Exception e) {
|
|
157
|
-
e.printStackTrace();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (isVisible) {
|
|
161
|
-
ViewPosition viewPosition = new ViewPosition(calculeRectOnScreen(view), calculeRectInWindow(view));
|
|
162
|
-
plotlineViewPositionCompleteListener.onViewReady(viewPosition);
|
|
163
|
-
} else {
|
|
164
|
-
plotlineViewPositionCompleteListener.onViewReady(null);
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
public boolean isViewPresent(Activity activity, String fragmentId, String nativeId) {
|
|
170
|
-
final Activity activityInternal = getCurrentActivity();
|
|
171
|
-
View view = ReactFindViewUtil.findView(activityInternal.getWindow().getDecorView().getRootView(), nativeId);
|
|
172
|
-
|
|
173
|
-
if (view == null)
|
|
174
|
-
return false;
|
|
175
|
-
|
|
176
|
-
try {
|
|
177
|
-
AccessibilityNodeInfo nodeInfo = AccessibilityNodeInfo.obtain();
|
|
178
|
-
view.onInitializeAccessibilityNodeInfo(nodeInfo);
|
|
179
|
-
boolean isVisible = nodeInfo.isVisibleToUser();
|
|
180
|
-
nodeInfo.recycle();
|
|
181
|
-
return (view.getWidth() != 0 && view.getHeight() != 0 && isVisible);
|
|
182
|
-
} catch (Exception e) {
|
|
183
|
-
e.printStackTrace();
|
|
184
|
-
}
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
@Override
|
|
189
|
-
public void areViewsPresent(Activity activity, List<ElementSearchObject> elementSearchObjects, PlotlineViewsPresenceListener plotlineViewsPresenceListener) {
|
|
190
|
-
List<ElementSearchObject> presentElements = new ArrayList<>();
|
|
191
|
-
if (elementSearchObjects.size() == 0) {
|
|
192
|
-
plotlineViewsPresenceListener.onViewsPresent(presentElements);
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
for(ElementSearchObject elementSearchObject: elementSearchObjects) {
|
|
197
|
-
if (isViewPresent(activity, elementSearchObject.clientFragmentId, elementSearchObject.clientElementId)) {
|
|
198
|
-
presentElements.add(elementSearchObject);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
plotlineViewsPresenceListener.onViewsPresent(presentElements);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
@Override
|
|
206
|
-
public View getView(Activity activity, String fragmentId, String nativeId) {
|
|
207
|
-
final Activity activityInternal = getCurrentActivity();
|
|
208
|
-
View view = ReactFindViewUtil.findView(activityInternal.getWindow().getDecorView().getRootView(), nativeId);
|
|
209
|
-
return view;
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
43
|
}
|
|
213
|
-
|
|
44
|
+
|
|
214
45
|
@ReactMethod
|
|
215
46
|
public void track(String eventName) {
|
|
216
47
|
final Activity activity = getCurrentActivity();
|
|
@@ -294,4 +125,9 @@ public class RNPlotline extends ReactContextBaseJavaModule {
|
|
|
294
125
|
final Activity activity = getCurrentActivity();
|
|
295
126
|
Plotline.trackPage(pageId, activity);
|
|
296
127
|
}
|
|
128
|
+
|
|
129
|
+
@ReactMethod
|
|
130
|
+
public void debug() {
|
|
131
|
+
Plotline.debug(true);
|
|
132
|
+
}
|
|
297
133
|
}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -12,7 +12,6 @@ class plotline {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
init (apiKey, refId, endpoint = null) {
|
|
15
|
-
console.log("[Plotline] init called");
|
|
16
15
|
RNPlotline.init(apiKey, refId, endpoint);
|
|
17
16
|
}
|
|
18
17
|
|
|
@@ -33,9 +32,12 @@ class plotline {
|
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
trackPage (pageId) {
|
|
36
|
-
console.log("[Plotline] track called");
|
|
37
35
|
RNPlotline.trackPage(pageId);
|
|
38
36
|
}
|
|
37
|
+
|
|
38
|
+
debug () {
|
|
39
|
+
RNPlotline.debug();
|
|
40
|
+
}
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
const Plotline = new plotline();
|
package/ios/RNPlotline.m
CHANGED
|
@@ -6,15 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
RCT_EXPORT_METHOD(init:(NSString *)apiKey userId:(NSString *)userId endpoint:(NSString *)endpoint)
|
|
8
8
|
{
|
|
9
|
-
printf("Plotline Init Called");
|
|
10
|
-
[Plotline debugWithShouldDebug:true];
|
|
11
9
|
if (endpoint != nil) {
|
|
12
10
|
[Plotline initializeWithApiKey:apiKey userId:userId endpoint:endpoint];
|
|
13
11
|
} else {
|
|
14
12
|
[Plotline initializeWithApiKey:apiKey userId:userId];
|
|
15
13
|
}
|
|
16
14
|
[Plotline setPlotlineFrameworkWithFramework:@"REACT_NATIVE"];
|
|
17
|
-
// [Plotline trackPageWithPageName:@"MainActivity"];
|
|
18
15
|
}
|
|
19
16
|
|
|
20
17
|
RCT_EXPORT_METHOD(track:(NSString *)eventName properties: (NSDictionary *) properties)
|
|
@@ -54,7 +51,6 @@ RCT_EXPORT_METHOD(debug)
|
|
|
54
51
|
|
|
55
52
|
RCT_EXPORT_METHOD(trackPage:(NSString *)pageName)
|
|
56
53
|
{
|
|
57
|
-
printf("Plotline Track Page Called");
|
|
58
54
|
[Plotline trackPageWithPageName:pageName];
|
|
59
55
|
}
|
|
60
56
|
|