@datadog/mobile-react-navigation 1.5.0 → 1.5.1

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.
@@ -4,9 +4,9 @@ import { InternalLog } from './InternalLog';
4
4
  import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
5
5
  import { SdkVerbosity } from './SdkVerbosity';
6
6
  import { TrackingConsent } from './TrackingConsent';
7
- import { DdTrace } from './foundation';
8
7
  import { DdLogs } from './logs/DdLogs';
9
8
  import { DdRum } from './rum/DdRum';
10
9
  import { RumActionType, ErrorSource, PropagatorType } from './rum/types';
11
10
  import { DatadogProvider } from './sdk/DatadogProvider/DatadogProvider';
11
+ import { DdTrace } from './trace/DdTrace';
12
12
  export { DatadogProvider, DatadogProviderConfiguration, InitializationMode, DdLogs, DdTrace, DdRum, RumActionType, ErrorSource, DdSdkReactNativeConfiguration, DdSdkReactNative, InternalLog, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity, VitalsUpdateFrequency, PropagatorType };
@@ -0,0 +1,3 @@
1
+ import type { DdNativeSdkType } from '../nativeModulesTypes';
2
+ declare const DdSdk: DdNativeSdkType;
3
+ export { DdSdk };
@@ -0,0 +1,3 @@
1
+ import type { DdTraceType } from '../types';
2
+ declare const DdTrace: DdTraceType;
3
+ export { DdTrace };
@@ -1 +1 @@
1
- export declare const version = "1.5.0";
1
+ export declare const version = "1.5.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-navigation",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "A client-side React Native module to interact with Datadog",
5
5
  "keywords": [
6
6
  "datadog",
@@ -36,7 +36,7 @@
36
36
  "prepare": "rm -rf lib && yarn bob build"
37
37
  },
38
38
  "devDependencies": {
39
- "@datadog/mobile-react-native": "^1.5.0",
39
+ "@datadog/mobile-react-native": "^1.5.1",
40
40
  "@react-navigation/native-v5": "npm:@react-navigation/native@5.9.8",
41
41
  "@react-navigation/native-v6": "npm:@react-navigation/native@6.1.2",
42
42
  "@react-navigation/stack-v5": "npm:@react-navigation/stack@5.14.2",
@@ -77,5 +77,5 @@
77
77
  ]
78
78
  ]
79
79
  },
80
- "gitHead": "04d48f34c3fe6f2d793cf4157eff5314253afd87"
80
+ "gitHead": "429c794a983fa4e3a369091f892792d8bc23812b"
81
81
  }
@@ -20,12 +20,14 @@ import { AppStateMock } from './__utils__/AppStateMock';
20
20
  import {
21
21
  FakeNavigator1 as FakeNavigator1v5,
22
22
  FakeNavigator2 as FakeNavigator2v5,
23
- FakeNestedNavigator as FakeNestedNavigatorv5
23
+ FakeNestedNavigator as FakeNestedNavigatorv5,
24
+ FakeTogglableNavigator as FakeTogglableNavigatorv5
24
25
  } from './__utils__/Navigators/NavigatorsV5';
25
26
  import {
26
27
  FakeNavigator1 as FakeNavigator1v6,
27
28
  FakeNavigator2 as FakeNavigator2v6,
28
- FakeNestedNavigator as FakeNestedNavigatorv6
29
+ FakeNestedNavigator as FakeNestedNavigatorv6,
30
+ FakeTogglableNavigator as FakeTogglableNavigatorv6
29
31
  } from './__utils__/Navigators/NavigatorsV6';
30
32
 
31
33
  // TODO: inject this as a global
@@ -53,7 +55,8 @@ jest.mock('@datadog/mobile-react-native', () => {
53
55
  DdRum: {
54
56
  // eslint-disable-next-line @typescript-eslint/no-empty-function
55
57
  startView: jest.fn().mockImplementation(() => {}),
56
- stopView: jest.fn().mockImplementation(() => {})
58
+ stopView: jest.fn().mockImplementation(() => {}),
59
+ addError: jest.fn().mockImplementation(() => {})
57
60
  },
58
61
  SdkVerbosity: {
59
62
  DEBUG: 'debug',
@@ -91,7 +94,8 @@ describe.each([
91
94
  {
92
95
  FakeNavigator1: FakeNavigator1v5,
93
96
  FakeNavigator2: FakeNavigator2v5,
94
- FakeNestedNavigator: FakeNestedNavigatorv5
97
+ FakeNestedNavigator: FakeNestedNavigatorv5,
98
+ FakeTogglableNavigator: FakeTogglableNavigatorv5
95
99
  }
96
100
  ],
97
101
  [
@@ -99,12 +103,21 @@ describe.each([
99
103
  {
100
104
  FakeNavigator1: FakeNavigator1v6,
101
105
  FakeNavigator2: FakeNavigator2v6,
102
- FakeNestedNavigator: FakeNestedNavigatorv6
106
+ FakeNestedNavigator: FakeNestedNavigatorv6,
107
+ FakeTogglableNavigator: FakeTogglableNavigatorv6
103
108
  }
104
109
  ]
105
110
  ])(
106
111
  'DdRumReactNavigationTracking on react-navigation v%s',
107
- (version, { FakeNavigator1, FakeNavigator2, FakeNestedNavigator }) => {
112
+ (
113
+ version,
114
+ {
115
+ FakeNavigator1,
116
+ FakeNavigator2,
117
+ FakeNestedNavigator,
118
+ FakeTogglableNavigator
119
+ }
120
+ ) => {
108
121
  describe('startTrackingViews', () => {
109
122
  it('sends a related RUM ViewEvent when switching screens { navigationContainer listener attached }', async () => {
110
123
  // GIVEN
@@ -521,6 +534,26 @@ describe.each([
521
534
  }
522
535
  );
523
536
 
537
+ describe('Togglable navigators', () => {
538
+ it('does not send an error when a navigator is toggled and tracking is stopped', async () => {
539
+ const navigationRef = createRef<any>();
540
+ const { findByText } = render(
541
+ <FakeTogglableNavigator navigationRef={navigationRef} />
542
+ );
543
+
544
+ const hideNavButton = await findByText('display nav 2');
545
+ fireEvent(hideNavButton, 'press');
546
+
547
+ expect(DdRum.startView).toHaveBeenCalledTimes(1);
548
+
549
+ const switchNav = await findByText('display nav 1');
550
+ fireEvent(switchNav, 'press');
551
+ expect(DdRum.startView).toHaveBeenCalledTimes(2);
552
+
553
+ expect(InternalLog.log).not.toHaveBeenCalled();
554
+ });
555
+ });
556
+
524
557
  describe('Android back handler', () => {
525
558
  it('does not send an error when the app closes with Android back button', async () => {
526
559
  // GIVEN
@@ -8,7 +8,9 @@ import type { NavigationContainerRef } from '@react-navigation/native-v5';
8
8
  import { NavigationContainer } from '@react-navigation/native-v5';
9
9
  import { createStackNavigator } from '@react-navigation/stack-v5';
10
10
  import { View, Text, Button } from 'react-native';
11
- import React from 'react';
11
+ import React, { useEffect, useState } from 'react';
12
+
13
+ import { DdRumReactNavigationTracking } from '../../../../../rum/instrumentation/DdRumReactNavigationTracking';
12
14
 
13
15
  const { Screen, Navigator } = createStackNavigator();
14
16
 
@@ -103,3 +105,47 @@ export function FakeNestedNavigator(props: {
103
105
  </NavigationContainer>
104
106
  );
105
107
  }
108
+
109
+ export function FakeTogglableNavigator(props: {
110
+ navigationRef: React.RefObject<NavigationContainerRef>;
111
+ }) {
112
+ const [showNavigator, setShowNavigator] = useState(true);
113
+ const FakeToggleScreen = (screenProps: any) => {
114
+ return (
115
+ <Button
116
+ title={screenProps.route.params.text || 'no text provided'}
117
+ onPress={() => setShowNavigator(s => !s)}
118
+ />
119
+ );
120
+ };
121
+
122
+ const navigationRef = props.navigationRef;
123
+
124
+ useEffect(() => {
125
+ DdRumReactNavigationTracking.stopTrackingViews(navigationRef.current);
126
+ }, [showNavigator]);
127
+
128
+ return showNavigator ? (
129
+ <NavigationContainer
130
+ ref={navigationRef}
131
+ onReady={() => {
132
+ DdRumReactNavigationTracking.startTrackingViews(
133
+ navigationRef.current
134
+ );
135
+ }}
136
+ >
137
+ <Navigator>
138
+ <Screen
139
+ name="Profile1"
140
+ component={FakeToggleScreen}
141
+ initialParams={{ text: 'display nav 2' }}
142
+ />
143
+ </Navigator>
144
+ </NavigationContainer>
145
+ ) : (
146
+ <Button
147
+ title="display nav 1"
148
+ onPress={() => setShowNavigator(s => !s)}
149
+ />
150
+ );
151
+ }
@@ -8,7 +8,9 @@ import type { NavigationContainerRef } from '@react-navigation/native-v6';
8
8
  import { NavigationContainer } from '@react-navigation/native-v6';
9
9
  import { createStackNavigator } from '@react-navigation/stack-v6';
10
10
  import { View, Text, Button } from 'react-native';
11
- import React from 'react';
11
+ import React, { useEffect, useState } from 'react';
12
+
13
+ import { DdRumReactNavigationTracking } from '../../../../../rum/instrumentation/DdRumReactNavigationTracking';
12
14
 
13
15
  const { Screen, Navigator } = createStackNavigator();
14
16
 
@@ -103,3 +105,47 @@ export function FakeNestedNavigator(props: {
103
105
  </NavigationContainer>
104
106
  );
105
107
  }
108
+
109
+ export function FakeTogglableNavigator(props: {
110
+ navigationRef: React.RefObject<NavigationContainerRef<unknown>>;
111
+ }) {
112
+ const [showNavigator, setShowNavigator] = useState(true);
113
+ const FakeToggleScreen = (screenProps: any) => {
114
+ return (
115
+ <Button
116
+ title={screenProps.route.params.text || 'no text provided'}
117
+ onPress={() => setShowNavigator(s => !s)}
118
+ />
119
+ );
120
+ };
121
+
122
+ const navigationRef = props.navigationRef;
123
+
124
+ useEffect(() => {
125
+ DdRumReactNavigationTracking.stopTrackingViews(navigationRef.current);
126
+ }, [showNavigator]);
127
+
128
+ return showNavigator ? (
129
+ <NavigationContainer
130
+ ref={navigationRef}
131
+ onReady={() => {
132
+ DdRumReactNavigationTracking.startTrackingViews(
133
+ navigationRef.current
134
+ );
135
+ }}
136
+ >
137
+ <Navigator>
138
+ <Screen
139
+ name="Profile1"
140
+ component={FakeToggleScreen}
141
+ initialParams={{ text: 'display nav 2' }}
142
+ />
143
+ </Navigator>
144
+ </NavigationContainer>
145
+ ) : (
146
+ <Button
147
+ title="display nav 1"
148
+ onPress={() => setShowNavigator(s => !s)}
149
+ />
150
+ );
151
+ }
@@ -1,5 +0,0 @@
1
- import { DdSdkConfiguration, DdTraceType } from './types';
2
- import type { DdNativeSdkType } from './nativeModulesTypes';
3
- declare const DdSdk: DdNativeSdkType;
4
- declare const DdTrace: DdTraceType;
5
- export { DdSdkConfiguration, DdSdk, DdTrace };