plotline-engage 1.0.2 → 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.
@@ -39,6 +39,6 @@ repositories {
39
39
 
40
40
  dependencies {
41
41
  implementation 'com.facebook.react:react-native:+'
42
- implementation 'com.gitlab.plotline:plotline-android-sdk:2.7.2'
42
+ implementation 'com.gitlab.plotline:plotline-android-sdk:2.7.3'
43
43
  }
44
44
 
@@ -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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plotline-engage",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "React Native plugin for Plotline",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"