UNPKG

@dynatrace/react-native-plugin

Version:

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

51 lines (50 loc) 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PickerHelper = void 0; const ComponentUtil_1 = require("./ComponentUtil"); const PickerHelper = (Dynatrace) => ({ attachOnValueChange: (pickerProps) => { if ((0, ComponentUtil_1.isDynatraceIgnored)(pickerProps)) { return; } const origOnValueChange = pickerProps.onValueChange; const nameOfAction = _findActionName(pickerProps); if (origOnValueChange != null) { pickerProps.onValueChange = (itemValue, itemNumber) => { const value = _getPickerItemValue(itemNumber, itemValue, pickerProps.children); if (value !== undefined) { const finalNameOfAction = nameOfAction == null ? `Picked Value: ${value}` : `Picker ${nameOfAction} Picked Value: ${value}`; const action = Dynatrace.enterAutoAction(finalNameOfAction); try { origOnValueChange(itemValue, itemNumber); } finally { action.leaveAction(); } } }; } }, }); exports.PickerHelper = PickerHelper; const isPickerItemProps = (props) => props.label !== undefined; const _findActionName = (pickerProps) => { if ((0, ComponentUtil_1.isDynatraceNaming)(pickerProps)) { return pickerProps.dtActionName; } else if (pickerProps.accessibilityLabel != null) { return pickerProps.accessibilityLabel; } return null; }; const _getPickerItemValue = (index, value, children) => { if (children != null && index >= 0 && children.length > index && isPickerItemProps(children[index].props)) { return children[index].props.label; } return value; };