@fullstory/react-native
Version:
The official FullStory React Native plugin
118 lines (117 loc) • 4.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "FSPage", {
enumerable: true,
get: function () {
return _FSPage.FSPage;
}
});
exports.PrivateInterface = void 0;
exports.applyFSPropertiesWithRef = applyFSPropertiesWithRef;
exports.default = void 0;
var _reactNative = require("react-native");
var _codegenNativeCommands = _interopRequireDefault(require("react-native/Libraries/Utilities/codegenNativeCommands"));
var _utils = require("./utils");
var _fullstoryInterface = require("./fullstoryInterface");
var _FSPage = require("./FSPage");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const FullStory = _utils.isTurboModuleEnabled ? require('./NativeFullStory').default : _reactNative.NativeModules.FullStory;
const {
anonymize,
identify,
setUserVars,
onReady,
getCurrentSession,
getCurrentSessionURL,
consent,
event,
shutdown,
restart,
log,
resetIdleTimer
} = FullStory;
const FullStoryPrivate = _utils.isTurboModuleEnabled ? require('./NativeFullStoryPrivate').default : _reactNative.NativeModules.FullStoryPrivate;
const identifyWithProperties = (uid, userVars = {}) => identify(uid, userVars);
/*
Calling these commands sequentially will *not* lead to an intermediate state where views
have incomplete attribute values. React's rendering phases protects against this race condition.
See DOC-1863 for more information.
*/
const SUPPORTED_FS_ATTRIBUTES = ['fsClass', 'fsAttribute', 'fsTagName', 'dataElement', 'dataComponent', 'dataSourceFile'];
const Commands = (0, _codegenNativeCommands.default)({
supportedCommands: SUPPORTED_FS_ATTRIBUTES
});
let getInternalInstanceHandleFromPublicInstance;
try {
getInternalInstanceHandleFromPublicInstance = require('react-native/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance').getInternalInstanceHandleFromPublicInstance;
} catch (e) {}
function applyFSPropertiesWithRef(existingRef) {
return function (element) {
if (_utils.isTurboModuleEnabled && _reactNative.Platform.OS === 'ios') {
let currentProps;
if (getInternalInstanceHandleFromPublicInstance && element) {
var _getInternalInstanceH;
currentProps = (_getInternalInstanceH = getInternalInstanceHandleFromPublicInstance(element)) === null || _getInternalInstanceH === void 0 || (_getInternalInstanceH = _getInternalInstanceH.stateNode) === null || _getInternalInstanceH === void 0 ? void 0 : _getInternalInstanceH.canonical.currentProps;
} else {
// https://github.com/facebook/react-native/blob/87d2ea9c364c7ea393d11718c195dfe580c916ef/packages/react-native/Libraries/Components/TextInput/TextInputState.js#L109C23-L109C67
// @ts-expect-error `currentProps` is missing in `NativeMethods`
currentProps = element === null || element === void 0 ? void 0 : element.currentProps;
}
if (currentProps) {
const fsClass = currentProps.fsClass;
if (fsClass) {
Commands.fsClass(element, fsClass);
}
const fsAttribute = currentProps.fsAttribute;
if (fsAttribute) {
Commands.fsAttribute(element, fsAttribute);
}
const fsTagName = currentProps.fsTagName;
if (fsTagName) {
Commands.fsTagName(element, fsTagName);
}
const dataElement = currentProps.dataElement;
if (dataElement) {
Commands.dataElement(element, dataElement);
}
const dataComponent = currentProps.dataComponent;
if (dataComponent) {
Commands.dataComponent(element, dataComponent);
}
const dataSourceFile = currentProps.dataSourceFile;
if (dataSourceFile) {
Commands.dataSourceFile(element, dataSourceFile);
}
}
}
if (existingRef) {
if (existingRef instanceof Function) {
existingRef(element);
} else {
existingRef.current = element;
}
}
};
}
const FullstoryAPI = {
anonymize,
identify: identifyWithProperties,
setUserVars,
onReady,
getCurrentSession,
getCurrentSessionURL,
consent,
event,
shutdown,
restart,
log,
resetIdleTimer,
LogLevel: _fullstoryInterface.LogLevel
};
const PrivateInterface = exports.PrivateInterface = _reactNative.Platform.OS === 'android' ? {
onFSPressForward: FullStoryPrivate.onFSPressForward
} : {};
var _default = exports.default = FullstoryAPI;
//# sourceMappingURL=index.js.map