plotline-engage 4.1.6 → 4.1.7
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/index.d.ts +3 -6
- package/index.js +45 -32
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { ScrollViewProps } from 'react-native';
|
|
2
|
-
import { FlatListProps } from 'react-native';
|
|
3
1
|
import React from 'react';
|
|
2
|
+
import { NavigationContainerProps } from '@react-navigation/native';
|
|
4
3
|
|
|
5
4
|
declare class plotline {
|
|
6
5
|
track(eventName: string, properties: {[key: string]: string}): void;
|
|
@@ -16,10 +15,8 @@ declare class plotline {
|
|
|
16
15
|
setPlotlineRedirectListener(listener: (keyValuePairs: {[key: string]: any}) => void): void;
|
|
17
16
|
logout(): void;
|
|
18
17
|
}
|
|
19
|
-
declare class ScrollView extends React.Component<ScrollViewProps> {
|
|
20
|
-
}
|
|
21
18
|
|
|
22
|
-
declare class
|
|
19
|
+
declare class NavigationContainer extends React.Component<NavigationContainerProps> {
|
|
23
20
|
}
|
|
24
21
|
|
|
25
22
|
interface PlotlineWidgetProps extends ViewProps {
|
|
@@ -30,5 +27,5 @@ declare class PlotlineWidget extends React.Component<PlotlineWidgetProps> {
|
|
|
30
27
|
}
|
|
31
28
|
|
|
32
29
|
declare const Plotline: plotline;
|
|
33
|
-
export {
|
|
30
|
+
export { NavigationContainer, PlotlineWidget };
|
|
34
31
|
export default Plotline;
|
package/index.js
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
|
|
2
2
|
import { NativeModules, DeviceEventEmitter, Platform, NativeEventEmitter, requireNativeComponent } from 'react-native';
|
|
3
|
-
import { View
|
|
3
|
+
import { View } from 'react-native';
|
|
4
4
|
import React, { useEffect, useState } from 'react';
|
|
5
5
|
const { RNPlotline } = NativeModules;
|
|
6
|
+
import { NavigationContainer as RNNavigationContainer, useNavigationContainerRef } from '@react-navigation/native';
|
|
7
|
+
|
|
8
|
+
function getRouteName(state) {
|
|
9
|
+
if (!state || !state.routes || state.index === undefined || state.index === null) {
|
|
10
|
+
return 'unrecognized-path'
|
|
11
|
+
}
|
|
12
|
+
const route = state.routes[state.index]
|
|
13
|
+
if (route.state) {
|
|
14
|
+
return getRouteName(route.state)
|
|
15
|
+
}
|
|
16
|
+
return route.name
|
|
17
|
+
}
|
|
6
18
|
|
|
7
19
|
function convertToStringValues(obj) {
|
|
8
20
|
const convertedObj = {};
|
|
@@ -141,36 +153,6 @@ class plotline {
|
|
|
141
153
|
|
|
142
154
|
const Plotline = new plotline();
|
|
143
155
|
|
|
144
|
-
const ScrollView = (props) => {
|
|
145
|
-
const handleScroll = (event) => {
|
|
146
|
-
Plotline.notifyScroll();
|
|
147
|
-
if (props.onScroll) {
|
|
148
|
-
props.onScroll(event);
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
return (
|
|
153
|
-
<RNScrollView {...props} onScroll={handleScroll} scrollEventThrottle={16}>
|
|
154
|
-
{props.children}
|
|
155
|
-
</RNScrollView>
|
|
156
|
-
);
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
const FlatList = (props) => {
|
|
160
|
-
const handleScroll = (event) => {
|
|
161
|
-
Plotline.notifyScroll();
|
|
162
|
-
if (props.onScroll) {
|
|
163
|
-
props.onScroll(event);
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
return (
|
|
168
|
-
<RNFlatList {...props} onScroll={handleScroll} scrollEventThrottle={16}>
|
|
169
|
-
{props.children}
|
|
170
|
-
</RNFlatList>
|
|
171
|
-
);
|
|
172
|
-
};
|
|
173
|
-
|
|
174
156
|
const { PlotlineWidgetEventEmitter } = NativeModules;
|
|
175
157
|
const plotlineEvents = new NativeEventEmitter(PlotlineWidgetEventEmitter);
|
|
176
158
|
const PlotlineView = requireNativeComponent('PlotlineView');
|
|
@@ -217,5 +199,36 @@ const PlotlineWidget = ({ testID }) => {
|
|
|
217
199
|
return null;
|
|
218
200
|
};
|
|
219
201
|
|
|
202
|
+
const NavigationContainer = ({children, ...others}) => {
|
|
203
|
+
const containerRef = useNavigationContainerRef()
|
|
204
|
+
|
|
205
|
+
useEffect(() => {
|
|
206
|
+
if (containerRef.current) {
|
|
207
|
+
const currentRoute = containerRef.current.getCurrentRoute()
|
|
208
|
+
if (currentRoute) {
|
|
209
|
+
Plotline.trackPage(currentRoute.name);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}, [containerRef])
|
|
213
|
+
|
|
214
|
+
const handleStateChange = (state) => {
|
|
215
|
+
if (others?.onStateChange != null) {
|
|
216
|
+
others.onStateChange(state)
|
|
217
|
+
}
|
|
218
|
+
const routeName = getRouteName(state)
|
|
219
|
+
Plotline.trackPage(routeName);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return (
|
|
223
|
+
<RNNavigationContainer
|
|
224
|
+
onStateChange={handleStateChange}
|
|
225
|
+
{...others}
|
|
226
|
+
ref={containerRef}
|
|
227
|
+
>
|
|
228
|
+
{children}
|
|
229
|
+
</RNNavigationContainer>
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
|
|
220
233
|
export default Plotline;
|
|
221
|
-
export {
|
|
234
|
+
export {PlotlineWidget, NavigationContainer};
|