UNPKG

@dynatrace/react-native-plugin

Version:

This plugin gives you the ability to use the Dynatrace Mobile agent in your react native application.

58 lines (57 loc) 2.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SwitchHelper = void 0; const IDynatraceProperties_1 = require("../IDynatraceProperties"); const ConfigurationHandler_1 = require("../../../lib/core/configuration/ConfigurationHandler"); const SwitchHelper = (Dynatrace) => ({ attachOnValueChange: (switchProps) => { if ((0, IDynatraceProperties_1.isDynatraceIgnored)(switchProps)) { return; } const origOnValueChange = switchProps.onValueChange; const nameOfAction = _findActionName(switchProps); if (origOnValueChange != null) { switchProps.onValueChange = (value) => { const useGenericName = nameOfAction == null || (!(0, IDynatraceProperties_1.isDynatraceNaming)(switchProps) && ConfigurationHandler_1.ConfigurationHandler.isActionNamePrivacyEnabled()); const finalNameOfAction = useGenericName ? `Touch on Switch to ${value}` : `Touch on ${nameOfAction} to ${value}`; const action = Dynatrace.enterAutoAction(finalNameOfAction); let isSyncError = true; try { const returnValue = origOnValueChange(value); if (_isPromise(returnValue)) { isSyncError = false; return returnValue.finally(() => { action.leaveAction(); }); } else { action.leaveAction(); } isSyncError = false; } finally { if (isSyncError) { action.leaveAction(); } } }; } }, }); exports.SwitchHelper = SwitchHelper; const _findActionName = (switchProps) => { if ((0, IDynatraceProperties_1.isDynatraceNaming)(switchProps)) { return switchProps.dtActionName; } else if (switchProps.accessibilityLabel != null) { return switchProps.accessibilityLabel; } return null; }; const _isPromise = (object) => object != null && typeof object.then === 'function' && typeof object.catch === 'function';