Skip to content

Commit 26b7fae

Browse files
TheBuggedYRNymabdallah
authored andcommitted
[MOB-11550] Introduce New Enums (#914)
1 parent 5a39a02 commit 26b7fae

17 files changed

+352
-80
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Bumps Instabug iOS SDK to v11.7.0
55
- Adds monorepo support for source maps scripts
66
- Fixes global error handler not being called.
7+
- Deprecates all module-enums (e.g. `Instabug.invocationEvent`) in favour of standalone-enums (e.g. `InvocationEvent`). See [#914](https://github.com/Instabug/Instabug-React-Native/pull/914) for more info and detailed list of Enums.
78
- Deprecates Instabug.start in favour of Instabug.init that takes a configuration object for SDK initialization.
89
- Deprecates Instabug.setDebugEnabled, Instabug.setSdkDebugLogsLevel, and APM.setLogLevel in favour of debugLogsLevel property, which can be passed to InstabugConfig while initializing the SDK using Instabug.init.
910
- Deprecates the enums: sdkDebugLogsLevel and logLevel in favour of a new enum LogLevel.

example/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect } from 'react';
22

33
import { NavigationContainer } from '@react-navigation/native';
4-
import Instabug, { LogLevel } from 'instabug-reactnative';
4+
import Instabug, { InvocationEvent, LogLevel } from 'instabug-reactnative';
55
import { NativeBaseProvider } from 'native-base';
66

77
import { RootTabNavigator } from './navigation/RootTab';
@@ -12,8 +12,8 @@ export const App: React.FC = () => {
1212
useEffect(() => {
1313
Instabug.init({
1414
token: 'deb1910a7342814af4e4c9210c786f35',
15-
invocationEvents: [Instabug.invocationEvent.floatingButton],
16-
debugLogsLevel: LogLevel.Verbose,
15+
invocationEvents: [InvocationEvent.floatingButton],
16+
debugLogsLevel: LogLevel.verbose,
1717
});
1818
}, []);
1919

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import Instabug, { BugReporting } from 'instabug-reactnative';
3+
import Instabug, { BugReporting, InvocationOption, ReportType } from 'instabug-reactnative';
44

55
import { ListTile } from '../components/ListTile';
66
import { Screen } from '../components/Screen';
@@ -9,22 +9,12 @@ export const BugReportingScreen: React.FC = () => {
99
return (
1010
<Screen>
1111
<ListTile title="Show" onPress={() => Instabug.show()} />
12-
<ListTile
13-
title="Send Bug Report"
14-
onPress={() => BugReporting.show(BugReporting.reportType.bug, [])}
15-
/>
12+
<ListTile title="Send Bug Report" onPress={() => BugReporting.show(ReportType.bug, [])} />
1613
<ListTile
1714
title="Send Feedback"
18-
onPress={() =>
19-
BugReporting.show(BugReporting.reportType.feedback, [
20-
BugReporting.option.emailFieldHidden,
21-
])
22-
}
23-
/>
24-
<ListTile
25-
title="Ask a Question"
26-
onPress={() => BugReporting.show(BugReporting.reportType.question, [])}
15+
onPress={() => BugReporting.show(ReportType.feedback, [InvocationOption.emailFieldHidden])}
2716
/>
17+
<ListTile title="Ask a Question" onPress={() => BugReporting.show(ReportType.question, [])} />
2818
</Screen>
2919
);
3020
};

example/src/screens/SettingsScreen.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react';
22

3-
import Instabug, { BugReporting } from 'instabug-reactnative';
3+
import Instabug, { BugReporting, ColorTheme, InvocationEvent } from 'instabug-reactnative';
44
import { Input, InputGroup, InputLeftAddon } from 'native-base';
55

66
import { ListTile } from '../components/ListTile';
@@ -18,23 +18,23 @@ export const SettingsScreen: React.FC = () => {
1818
items={[
1919
{
2020
label: 'None',
21-
value: Instabug.invocationEvent.none,
21+
value: InvocationEvent.none,
2222
},
2323
{
2424
label: 'Shake',
25-
value: Instabug.invocationEvent.shake,
25+
value: InvocationEvent.shake,
2626
},
2727
{
2828
label: 'Screenshot',
29-
value: Instabug.invocationEvent.screenshot,
29+
value: InvocationEvent.screenshot,
3030
},
3131
{
3232
label: 'Two fingers swipe left',
33-
value: Instabug.invocationEvent.twoFingersSwipe,
33+
value: InvocationEvent.twoFingersSwipe,
3434
},
3535
{
3636
label: 'Floating button',
37-
value: Instabug.invocationEvent.floatingButton,
37+
value: InvocationEvent.floatingButton,
3838
isInitial: true,
3939
},
4040
]}
@@ -68,11 +68,11 @@ export const SettingsScreen: React.FC = () => {
6868
items={[
6969
{
7070
label: 'Light',
71-
value: Instabug.colorTheme.light,
71+
value: ColorTheme.light,
7272
},
7373
{
7474
label: 'Dark',
75-
value: Instabug.colorTheme.dark,
75+
value: ColorTheme.dark,
7676
},
7777
]}
7878
onValueChange={Instabug.setColorTheme}

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as Replies from './modules/Replies';
1313
import type { Survey } from './modules/Surveys';
1414
import * as Surveys from './modules/Surveys';
1515

16+
export * from './utils/Enums';
1617
export {
1718
Report,
1819
Trace,
@@ -24,8 +25,6 @@ export {
2425
Replies,
2526
Surveys,
2627
};
27-
export * from './utils/Enums';
28-
2928
export type { InstabugConfig };
3029
export type { Survey };
3130

src/models/InstabugConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { invocationEvent } from '../utils/ArgsRegistry';
2-
import type { LogLevel } from '../utils/Enums';
2+
import type { InvocationEvent, LogLevel } from '../utils/Enums';
33

44
export interface InstabugConfig {
55
/**
@@ -9,7 +9,7 @@ export interface InstabugConfig {
99
/**
1010
* An array of events that invoke the SDK's UI.
1111
*/
12-
invocationEvents: invocationEvent[];
12+
invocationEvents: invocationEvent[] | InvocationEvent[];
1313
/**
1414
* An optional LogLevel to indicate the verbosity of SDK logs. Default is Error.
1515
*/

src/modules/BugReporting.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import {
1010
position,
1111
reportType,
1212
} from '../utils/ArgsRegistry';
13+
import type {
14+
DismissType,
15+
ExtendedBugReportMode,
16+
FloatingButtonPosition,
17+
InvocationEvent,
18+
InvocationOption,
19+
RecordingButtonPosition,
20+
ReportType,
21+
} from '../utils/Enums';
1322
import IBGEventEmitter from '../utils/IBGEventEmitter';
1423
import InstabugConstants from '../utils/InstabugConstants';
1524

@@ -28,7 +37,7 @@ export const setEnabled = (isEnabled: boolean) => {
2837
* Default is set by `Instabug.init`.
2938
* @param events Array of events that invokes the feedback form.
3039
*/
31-
export const setInvocationEvents = (events: invocationEvent[]) => {
40+
export const setInvocationEvents = (events: invocationEvent[] | InvocationEvent[]) => {
3241
NativeBugReporting.setInvocationEvents(events);
3342
};
3443

@@ -37,7 +46,7 @@ export const setInvocationEvents = (events: invocationEvent[]) => {
3746
* Default is set by `Instabug.init`.
3847
* @param options Array of invocation options
3948
*/
40-
export const setOptions = (options: option[]) => {
49+
export const setOptions = (options: option[] | InvocationOption[]) => {
4150
NativeBugReporting.setOptions(options);
4251
};
4352

@@ -59,7 +68,7 @@ export const onInvokeHandler = (handler: () => void) => {
5968
* @param handler A callback to get executed after dismissing the SDK.
6069
*/
6170
export const onSDKDismissedHandler = (
62-
handler: (dismissType: dismissType, reportType: reportType) => void,
71+
handler: (dismissType: dismissType | DismissType, reportType: reportType | ReportType) => void,
6372
) => {
6473
IBGEventEmitter.addListener(
6574
NativeBugReporting,
@@ -112,15 +121,15 @@ export const setShakingThresholdForAndroid = (threshold: number) => {
112121
* @param mode An enum to disable the extended bug report mode,
113122
* enable it with required or with optional fields.
114123
*/
115-
export const setExtendedBugReportMode = (mode: extendedBugReportMode) => {
124+
export const setExtendedBugReportMode = (mode: extendedBugReportMode | ExtendedBugReportMode) => {
116125
NativeBugReporting.setExtendedBugReportMode(mode);
117126
};
118127

119128
/**
120129
* Sets what type of reports, bug or feedback, should be invoked.
121130
* @param types Array of reportTypes
122131
*/
123-
export const setReportTypes = (types: reportType[]) => {
132+
export const setReportTypes = (types: reportType[] | ReportType[]) => {
124133
NativeBugReporting.setReportTypes(types);
125134
};
126135

@@ -129,7 +138,7 @@ export const setReportTypes = (types: reportType[]) => {
129138
* @param type
130139
* @param options
131140
*/
132-
export const show = (type: reportType, options: option[]) => {
141+
export const show = (type: reportType | ReportType, options: option[] | InvocationOption[]) => {
133142
NativeBugReporting.show(type, options ?? []);
134143
};
135144

@@ -162,7 +171,9 @@ export const setAutoScreenRecordingDurationIOS = (maxDuration: number) => {
162171
* @param buttonPosition is of type position `topLeft` to show on the top left
163172
* of screen, or `bottomRight` to show on the bottom right of screen.
164173
*/
165-
export const setVideoRecordingFloatingButtonPosition = (buttonPosition: position) => {
174+
export const setVideoRecordingFloatingButtonPosition = (
175+
buttonPosition: position | RecordingButtonPosition,
176+
) => {
166177
NativeBugReporting.setVideoRecordingFloatingButtonPosition(buttonPosition);
167178
};
168179

@@ -198,7 +209,10 @@ export const setDidSelectPromptOptionHandler = (handler: (promptOption: string)
198209
* @param edge The screen edge to show the floating button onto. Default is `floatingButtonEdge.right`.
199210
* @param offset The offset of the floating button from the top of the screen. Default is 50.
200211
*/
201-
export const setFloatingButtonEdge = (edge: floatingButtonEdge, offset: number) => {
212+
export const setFloatingButtonEdge = (
213+
edge: floatingButtonEdge | FloatingButtonPosition,
214+
offset: number,
215+
) => {
202216
NativeBugReporting.setFloatingButtonEdge(edge, offset);
203217
};
204218

@@ -237,6 +251,9 @@ export const setDisclaimerText = (text: string) => {
237251
* @param limit int number of characters.
238252
* @param reportTypes (Optional) Array of reportType. If it's not passed, the limit will apply to all report types.
239253
*/
240-
export const setCommentMinimumCharacterCount = (limit: number, reportTypes?: reportType[]) => {
254+
export const setCommentMinimumCharacterCount = (
255+
limit: number,
256+
reportTypes?: reportType[] | ReportType[],
257+
) => {
241258
NativeBugReporting.setCommentMinimumCharacterCount(limit, reportTypes ?? []);
242259
};

src/modules/FeatureRequests.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NativeFeatureRequests } from '../native';
22
import { actionTypes } from '../utils/ArgsRegistry';
3+
import type { ActionType } from '../utils/Enums';
34

45
export { actionTypes };
56

@@ -20,7 +21,10 @@ export const setEnabled = (isEnabled: boolean) => {
2021
* @param isEmailFieldRequired A boolean to indicate whether email field is required or not.
2122
* @param types An enum that indicates which action types will have the isEmailFieldRequired
2223
*/
23-
export const setEmailFieldRequired = (isEmailFieldRequired: boolean, types: actionTypes) => {
24+
export const setEmailFieldRequired = (
25+
isEmailFieldRequired: boolean,
26+
types: actionTypes | ActionType,
27+
) => {
2428
NativeFeatureRequests.setEmailFieldRequiredForFeatureRequests(isEmailFieldRequired, types);
2529
};
2630

src/modules/Instabug.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ import {
2222
strings,
2323
welcomeMessageMode,
2424
} from '../utils/ArgsRegistry';
25-
import { LogLevel } from '../utils/Enums';
25+
import {
26+
ColorTheme,
27+
InvocationEvent,
28+
Locale,
29+
LogLevel,
30+
ReproStepsMode,
31+
StringKey,
32+
WelcomeMessageMode,
33+
} from '../utils/Enums';
2634
import IBGEventEmitter from '../utils/IBGEventEmitter';
2735
import InstabugConstants from '../utils/InstabugConstants';
2836
import InstabugUtils, { stringifyIfNotString } from '../utils/InstabugUtils';
@@ -65,7 +73,7 @@ export const setEnabled = (isEnabled: boolean) => {
6573
* @param token The token that identifies the app, you can find it on your dashboard.
6674
* @param invocationEvents The events that invokes the SDK's UI.
6775
*/
68-
export const start = (token: string, invocationEvents: invocationEvent[]) => {
76+
export const start = (token: string, invocationEvents: invocationEvent[] | InvocationEvent[]) => {
6977
init({ token: token, invocationEvents: invocationEvents });
7078
};
7179

@@ -83,7 +91,7 @@ export const init = (config: InstabugConfig) => {
8391
NativeInstabug.init(
8492
config.token,
8593
config.invocationEvents,
86-
config.debugLogsLevel ?? LogLevel.Error,
94+
config.debugLogsLevel ?? LogLevel.error,
8795
);
8896

8997
_isFirstScreen = true;
@@ -159,15 +167,15 @@ export const setSdkDebugLogsLevel = (level: sdkDebugLogsLevel) => {
159167
* Defaults to the device's current locale.
160168
* @param sdkLocale A locale to set the SDK to.
161169
*/
162-
export const setLocale = (sdkLocale: locale) => {
170+
export const setLocale = (sdkLocale: locale | Locale) => {
163171
NativeInstabug.setLocale(sdkLocale);
164172
};
165173

166174
/**
167175
* Sets the color theme of the SDK's whole UI.
168176
* @param sdkTheme
169177
*/
170-
export const setColorTheme = (sdkTheme: colorTheme) => {
178+
export const setColorTheme = (sdkTheme: colorTheme | ColorTheme) => {
171179
NativeInstabug.setColorTheme(sdkTheme);
172180
};
173181

@@ -212,7 +220,7 @@ export const getTags = (callback: (tags: string[]) => void) => {
212220
* @param key Key of string to override.
213221
* @param string String value to override the default one.
214222
*/
215-
export const setString = (key: strings, string: string) => {
223+
export const setString = (key: strings | StringKey, string: string) => {
216224
NativeInstabug.setString(string, key);
217225
};
218226

@@ -350,7 +358,7 @@ export const clearLogs = () => {
350358
*
351359
* @param mode An enum to set user steps tracking to be enabled, non visual or disabled.
352360
*/
353-
export const setReproStepsMode = (mode: reproStepsMode) => {
361+
export const setReproStepsMode = (mode: reproStepsMode | ReproStepsMode) => {
354362
NativeInstabug.setReproStepsMode(mode);
355363
};
356364

@@ -463,15 +471,15 @@ export const isRunningLive = (callback: (isLive: boolean) => void) => {
463471
* Shows the welcome message in a specific mode.
464472
* @param mode An enum to set the welcome message mode to live, or beta.
465473
*/
466-
export const showWelcomeMessage = (mode: welcomeMessageMode) => {
474+
export const showWelcomeMessage = (mode: welcomeMessageMode | WelcomeMessageMode) => {
467475
NativeInstabug.showWelcomeMessageWithMode(mode);
468476
};
469477

470478
/**
471479
* Sets the welcome message mode to live, beta or disabled.
472480
* @param mode An enum to set the welcome message mode to live, beta or disabled.
473481
*/
474-
export const setWelcomeMessageMode = (mode: welcomeMessageMode) => {
482+
export const setWelcomeMessageMode = (mode: welcomeMessageMode | WelcomeMessageMode) => {
475483
NativeInstabug.setWelcomeMessageMode(mode);
476484
};
477485

src/native.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import {
33
NativeModules as ReactNativeModules,
44
} from 'react-native';
55

6-
export interface NativeModule extends ReactNativeModule, Record<string, any> {}
6+
export interface NativeModule extends ReactNativeModule, Record<string, any> {
7+
getConstants: () => Record<string, any>;
8+
}
79

810
interface InstabugNativeModules {
911
IBGAPM: NativeModule;

0 commit comments

Comments
 (0)