@dynatrace/react-native-plugin
Version:
This plugin gives you the ability to use the Dynatrace Mobile agent in your react native application.
68 lines (67 loc) • 3.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDtActionIgnore = exports.modifyElement = exports.instrumentCreateElement = void 0;
const Types_1 = require("../model/Types");
const TypesUtil_1 = require("../model/TypesUtil");
const Dynatrace_1 = require("../../lib/core/Dynatrace");
const ConsoleLogger_1 = require("../../lib/core/logging/ConsoleLogger");
const Picker_1 = require("./components/Picker");
const Touchable_1 = require("./components/Touchable");
const RefreshControl_1 = require("./components/RefreshControl");
const Switch_1 = require("./components/Switch");
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, ...children);
}
}
return reactCreateElement(type, props, ...children);
};
}
};
exports.instrumentCreateElement = instrumentCreateElement;
const modifyElement = (type, props, ...children) => {
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 (type._dtInfo.type === Types_1.Types.Switch &&
props.onValueChange != null) {
(0, Switch_1.SwitchHelper)(Dynatrace_1.Dynatrace).attachOnValueChange(props);
}
else if (type._dtInfo.type === Types_1.Types.Button ||
type._dtInfo.type === Types_1.Types.Text ||
type._dtInfo.type === Types_1.Types.Pressable ||
(0, TypesUtil_1.isTypeTouchable)(type._dtInfo.type)) {
if (props.onPress != null) {
props.onPress = (0, Touchable_1.TouchableHelper)(Dynatrace_1.Dynatrace, new ConsoleLogger_1.ConsoleLogger('TouchableHelper')).attachOnPress(false, props, children, type._dtInfo.type);
}
if (props.onLongPress != null) {
props.onLongPress = (0, Touchable_1.TouchableHelper)(Dynatrace_1.Dynatrace, new ConsoleLogger_1.ConsoleLogger('TouchableHelper')).attachOnPress(true, props, children, type._dtInfo.type);
}
}
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;