UNPKG

@dynatrace/react-native-plugin

Version:

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

49 lines (48 loc) 2.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isDtActionIgnore = exports.modifyElement = exports.instrumentCreateElement = void 0; const Types_1 = require("../model/Types"); const Dynatrace_1 = require("../../lib/core/Dynatrace"); const Picker_1 = require("./components/Picker"); const RefreshControl_1 = require("./components/RefreshControl"); const FunctionalComponent_1 = require("./components/FunctionalComponent"); const ClassComponent_1 = require("./components/ClassComponent"); const instrumentCreateElement = (reactModule) => { if (reactModule != null && reactModule.createElement != null) { const reactCreateElement = reactModule.createElement; reactModule.createElement = (type, props, ...children) => { if (type != null && type._dtInfo != null && !(0, exports.isDtActionIgnore)(props)) { if (type._dtInfo.type === Types_1.Types.FunctionalComponent) { return reactCreateElement(FunctionalComponent_1.DynatraceFunctionalComponent, {}, reactCreateElement(type, props, ...children)); } else if (type._dtInfo.type === Types_1.Types.ClassComponent && type.prototype !== undefined && type.prototype.isReactComponent !== undefined) { return reactCreateElement(ClassComponent_1.DynatraceClassComponent, {}, reactCreateElement(type, props, ...children)); } else { (0, exports.modifyElement)(type, props); } } return reactCreateElement(type, props, ...children); }; } }; exports.instrumentCreateElement = instrumentCreateElement; const modifyElement = (type, props) => { if (props != null) { if (type._dtInfo.type === Types_1.Types.RefreshControl && props.onRefresh != null) { (0, RefreshControl_1.RefreshControlHelper)(Dynatrace_1.Dynatrace).attachOnRefresh(props); } else if (props.onValueChange != null && type._dtInfo.type === Types_1.Types.Picker) { (0, Picker_1.PickerHelper)(Dynatrace_1.Dynatrace).attachOnValueChange(props); } } }; exports.modifyElement = modifyElement; const isDtActionIgnore = (props) => props != null && String(props.dtActionIgnore).toLowerCase() === 'true'; exports.isDtActionIgnore = isDtActionIgnore;