From f84ec5856f2cc0b03d9bb597bc1850359b469887 Mon Sep 17 00:00:00 2001 From: Ahmed alaa Date: Tue, 29 Apr 2025 15:20:16 +0300 Subject: [PATCH] Set bug report types Set extended bug reporting options Disable/Enable bug reporting Set the disclaimer text Set the post sending dialog Set InvocationOption API --- .../default/src/components/InputField.tsx | 4 + examples/default/src/components/ListTile.tsx | 5 +- .../src/screens/BugReportingScreen.tsx | 306 +++++++++++++++--- 3 files changed, 262 insertions(+), 53 deletions(-) diff --git a/examples/default/src/components/InputField.tsx b/examples/default/src/components/InputField.tsx index feef8fd7b5..1426a9d99c 100644 --- a/examples/default/src/components/InputField.tsx +++ b/examples/default/src/components/InputField.tsx @@ -21,6 +21,7 @@ interface InputFieldProps { maxLength?: number; accessibilityLabel?: string; flex?: number; + testID?: string; } export const InputField = forwardRef( @@ -34,6 +35,7 @@ export const InputField = forwardRef( maxLength, keyboardType, errorText, + testID, ...restProps }, ref, @@ -45,9 +47,11 @@ export const InputField = forwardRef( placeholder={placeholder} style={[styles.textInput, style]} maxLength={maxLength} + accessible={true} accessibilityLabel={accessibilityLabel} keyboardType={keyboardType} value={value} + testID={testID} onChangeText={onChangeText} {...restProps} /> diff --git a/examples/default/src/components/ListTile.tsx b/examples/default/src/components/ListTile.tsx index 35540dc85a..b0bed5f540 100644 --- a/examples/default/src/components/ListTile.tsx +++ b/examples/default/src/components/ListTile.tsx @@ -5,15 +5,18 @@ import { Box, HStack, Pressable, Text } from 'native-base'; interface ListTileProps extends PropsWithChildren { title: string; onPress?: () => void; + testID?: string; } -export const ListTile: React.FC = ({ title, onPress, children }) => { +export const ListTile: React.FC = ({ title, onPress, children, testID }) => { return ( { const toast = useToast(); + const [reportTypes, setReportTypes] = useState([]); + const [invocationOptions, setInvocationOptions] = useState([]); + + const [disclaimerText, setDisclaimerText] = useState(''); + + const toggleCheckbox = (value: string, setData: Dispatch>) => { + setData((prev) => + prev.includes(value) ? prev.filter((item) => item !== value) : [...prev, value], + ); + }; + + const handleSetReportTypesButtonPress = () => { + const selectedEnums: ReportType[] = reportTypes.map((val) => { + switch (val) { + case 'bug': + return ReportType.bug; + case 'feedback': + return ReportType.feedback; + case 'question': + return ReportType.question; + default: + throw new Error('Invalid report type selected'); + } + }); + BugReporting.setReportTypes(selectedEnums); + }; + const handleSetInvocationOptionsButtonPress = () => { + const selectedEnums: InvocationEvent[] = invocationOptions.map((val) => { + switch (val) { + case 'floatingButton': + return InvocationEvent.floatingButton; + case 'twoFingersSwipe': + return InvocationEvent.twoFingersSwipe; + case 'screenshot': + return InvocationEvent.screenshot; + case 'shake': + return InvocationEvent.shake; + + default: + throw new Error('Invalid report type selected'); + } + }); + BugReporting.setInvocationEvents(selectedEnums); + }; + + const handleSetDisclamirTextPress = () => { + BugReporting.setDisclaimerText(disclaimerText); + setDisclaimerText(''); + }; + return ( - - Instabug.show()} /> - BugReporting.show(ReportType.bug, [])} /> - BugReporting.show(ReportType.feedback, [InvocationOption.emailFieldHidden])} - /> - BugReporting.show(ReportType.question, [])} /> - - BugReporting.setExtendedBugReportMode(ExtendedBugReportMode.enabledWithRequiredFields) - } - /> - - BugReporting.setExtendedBugReportMode(ExtendedBugReportMode.enabledWithOptionalFields) - } - /> - Instabug.setSessionProfilerEnabled(true)} - /> - Instabug.showWelcomeMessage(WelcomeMessageMode.beta)} - /> - Instabug.showWelcomeMessage(WelcomeMessageMode.live)} - /> - -
+ + + Instabug.show()} /> + + BugReporting.setEnabled(true)} + testID="id_br_enable" + /> BugReporting.setEnabled(false)} + testID="id_br_disable" + /> + + BugReporting.show(ReportType.bug, [])} /> + - BugReporting.onInvokeHandler(function () { - Instabug.appendTags(['Invocation Handler tag1']); - }) + BugReporting.show(ReportType.feedback, [InvocationOption.emailFieldHidden]) } /> BugReporting.show(ReportType.question, [])} + /> + - Instabug.onReportSubmitHandler(() => { - toast.show({ - description: 'Submission succeeded', - }); - }) + BugReporting.setExtendedBugReportMode(ExtendedBugReportMode.enabledWithRequiredFields) } /> - BugReporting.onSDKDismissedHandler(function () { - Instabug.setPrimaryColor('#FF0000'); - }) + BugReporting.setExtendedBugReportMode(ExtendedBugReportMode.enabledWithOptionalFields) } /> -
-
+ Instabug.setSessionProfilerEnabled(true)} + /> + Instabug.showWelcomeMessage(WelcomeMessageMode.beta)} + /> + Instabug.showWelcomeMessage(WelcomeMessageMode.live)} + /> + + + + Bug Reporting Types + + + + + toggleCheckbox('bug', setReportTypes)} + value="bug" + accessible={true} + testID="id_br_report_type_bug" + size="md"> + Bug + + + toggleCheckbox('feedback', setReportTypes)} + value="feedback" + testID="id_br_report_type_feedback" + size="md"> + Feedback + + + toggleCheckbox('question', setReportTypes)} + value="question" + testID="id_br_report_type_question" + size="md"> + Question + + + + + + + + + + Set the disclaimer text + + + + + + + + + + + + Invocation Events + + + + + toggleCheckbox('floatingButton', setInvocationOptions)} + value="floatingButton" + testID="id_br_invoicetion_options_floatingButton" + accessible={true} + size="md"> + Floating button + + + toggleCheckbox('twoFingersSwipe', setInvocationOptions)} + value="twoFingersSwipe" + testID="id_br_invoicetion_options_twoFingersSwipe" + accessible={true} + size="md"> + Two Fingers Swipe + + + + toggleCheckbox('screenshot', setInvocationOptions)} + value="screenshot" + testID="id_br_invoicetion_options_screenshot" + accessible={true} + size="md"> + Screenshot + + toggleCheckbox('shake', setInvocationOptions)} + testID="id_br_invoicetion_options_shake" + accessible={true} + value="shake" + size="md"> + Shake + + + + + + + +
+ + BugReporting.onInvokeHandler(function () { + Instabug.appendTags(['Invocation Handler tag1']); + }) + } + /> + + Instabug.onReportSubmitHandler(() => { + toast.show({ + description: 'Submission succeeded', + }); + }) + } + /> + + BugReporting.onSDKDismissedHandler(function () { + Instabug.setPrimaryColor('#FF0000'); + }) + } + /> +
+ + ); };