rn-pendo-sdk
Version:
Pendo Mobile React Native SDK
1 lines • 7.06 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:true});exports.traverseOnComponent=traverseOnComponent;var _reactNative=require("react-native");var _common=require("./common");var _fiberTypes=require("./fiber-types");var _nativeParams=require("./nativeParams");var _pendoLogger=require("./pendoLogger");var _pendoTypes=require("./pendoTypes");var ReactNativePendo=_reactNative.NativeModules.ReactNativePendo;function traverseOnComponent(options){_pendoLogger.Logger.debug('traverseOnComponent entry');var rootFiberNode=_fiberTypes.TagFinder.fiberNodeFromComponent(options.reactComponent);if(!rootFiberNode){var _results=new _nativeParams.NativeParams();_results.error='androidAnalyzer: React component does not exist';return _results;}if(options.startFromRoot){_pendoLogger.Logger.debug('traverseOnComponent: Finding real root node');while(rootFiberNode.return!=null){rootFiberNode=rootFiberNode.return;}}var results=analyzeFiberTree(rootFiberNode,options);results.isNativeStack=options.isNativeStack;return results;}function analyzeFiberTree(rootFiberNode,options){var results=new _nativeParams.NativeParams();var traverseTree=_fiberTypes.TagFinder.buildTraverseTree(rootFiberNode,options);_pendoLogger.Logger.debug(`traversing ${traverseTree.nodeList.length} nodes`);for(var node of traverseTree.nodeList){if(!node){continue;}_fiberTypes.TagFinder.LogFiberNodeMatchingElement(node,options);if(_fiberTypes.TagFinder.isRootNode(node,options)){_fiberTypes.TagFinder.findAndAddRootTags(node,options,results,true,false);}if(options.isDrawerVisible&&_fiberTypes.TagFinder.isDrawerRelatedNode(node,options.drawerBaseNameCandidates)){if(results.drawerTag===0||!options.drawerTakeFirstTag){var drawerTag=_fiberTypes.TagFinder.closestNativeNodeTag(node,options.drawerTraverseDirection,options.drawerTakeRCTView,options.nativeNodeIterationCount);if(drawerTag){if(!ReactNativePendo.viewsVisible([drawerTag])){_pendoLogger.Logger.debug('Invalid Drawer discovered ',drawerTag);}else{results.drawerTag=drawerTag;_common.Utils.addRootTag(results,drawerTag,'Drawer discovered: ');}}}}if(results.modalTag==null){var modalType=_fiberTypes.TagFinder.getModalType(node,options);if(modalType!==_pendoTypes.ModalType.None){var nodeName=_fiberTypes.TagFinder.getNodeTypeName(node);_pendoLogger.Logger.debug(`Modal detected: type=${_fiberTypes.TagFinder.getModalTypeName(modalType)}, node="${nodeName}"`);var modalTag=null;if(modalType===_pendoTypes.ModalType.GorhomModal||modalType===_pendoTypes.ModalType.ReactNativeModals){modalTag=_fiberTypes.TagFinder.findModalTagViaPortal(node,modalType,options);if(modalTag&&!ReactNativePendo.viewsVisible([modalTag])){_pendoLogger.Logger.debug(`Invalid portal modal discovered (${_fiberTypes.TagFinder.getModalTypeName(modalType)})`,modalTag);modalTag=null;}}if(!modalTag){var modalOptions=_fiberTypes.TagFinder.getModalOptionsByType(modalType,null,options);modalTag=_fiberTypes.TagFinder.closestNativeNodeTag(node,modalOptions.traverseDirection,modalOptions.takeRCTView,modalOptions.nativeNodeIterationCount);}if(modalTag){if(!ReactNativePendo.viewsVisible([modalTag])){_pendoLogger.Logger.debug(`Invalid Modal discovered of type ${modalType}`,modalTag);}else{results.modalTag=modalTag;results.modalType=modalType;_common.Utils.addRootTag(results,modalTag,`${_fiberTypes.TagFinder.getModalTypeName(modalType)} modal discovered: `,true);}}else{_pendoLogger.Logger.debug(`Modal: No native tag found for type ${_fiberTypes.TagFinder.getModalTypeName(modalType)}`);}}}if(_fiberTypes.TagFinder.isNavigationBar(node,options.navigationBarBaseNameCandidates)){if(!options.navigationBarTakeFirstTag||results.navigationBarTag===null){var navigationBarTag=_fiberTypes.TagFinder.closestNativeNodeTag(node,options.navigationBarTraverseDirection,options.navigationBarTakeRCTView,options.nativeNodeIterationCount);if(navigationBarTag){if(!ReactNativePendo.viewsVisible([navigationBarTag])){_pendoLogger.Logger.debug('Invalid NavigationBar discovered ',navigationBarTag);}else{results.navigationBarTag=navigationBarTag;_common.Utils.addRootTag(results,navigationBarTag,'NavigationBar discovered: ');}}}}if(_fiberTypes.TagFinder.isTabBarNavigator(node,options.tabBarBaseNameCandidates)){var tabBarTag=_fiberTypes.TagFinder.closestNativeNodeTag(node,options.tabBarTraverseDirection,options.tabBarTakeRCTView,options.nativeNodeIterationCount);if(tabBarTag){if(!ReactNativePendo.viewsVisible([tabBarTag])){_pendoLogger.Logger.debug('Invalid TabBar discovered ',tabBarTag);}else{results.tabBarTag=tabBarTag;_common.Utils.addRootTag(results,tabBarTag,'TabBar Navigator discovered: ');}}}if(_fiberTypes.TagFinder.isBottomTabBar(node,options.bottomBarBaseNameCandidates)){if(!options.bottomBarTakeFirstTag||results.bottomBarTag===null){var bottomBarTag=_fiberTypes.TagFinder.closestNativeNodeTag(node,options.bottomBarTraverseDirection,options.bottomBarTakeRCTView,options.nativeNodeIterationCount);if(bottomBarTag){if(!ReactNativePendo.viewsVisible([bottomBarTag])){_pendoLogger.Logger.debug('Invalid Bottom Tab Bar discovered ',bottomBarTag);}else{results.bottomBarTag=bottomBarTag;_common.Utils.addRootTag(results,bottomBarTag,'Bottom Tab Bar discovered: ');}}}}if(_fiberTypes.TagFinder.isMaterialBottomTabNavigator(node,options.materialBottomTabBaseNameCandidates)){var materialBottomBarTag=_fiberTypes.TagFinder.closestNativeNodeTag(node,options.materialBottomTabTraverseDirection,options.materialBottomTabTakeRCTView,options.nativeNodeIterationCount);if(materialBottomBarTag){if(!ReactNativePendo.viewsVisible([materialBottomBarTag])){_pendoLogger.Logger.debug('Invalid MaterialTabBar discovered ',materialBottomBarTag);}else{results.materialBottomTabTag=materialBottomBarTag;_common.Utils.addRootTag(results,materialBottomBarTag,'MaterialTabBar discovered: ');}}}if(_fiberTypes.TagFinder.isBottomSheet(node,options.bottomSheetBaseNameCandidates)){var bottomSheetTag=_fiberTypes.TagFinder.closestNativeNodeTag(node,options.bottomSheetTraverseDirection,options.bottomSheetTakeRCTView,options.nativeNodeIterationCount);if(bottomSheetTag){if(!ReactNativePendo.viewsVisible([bottomSheetTag])){_pendoLogger.Logger.debug('Invalid Bottom Sheet discovered ',bottomSheetTag);}else if(!results.bottomSheetTags.includes(bottomSheetTag)){results.bottomSheetTags.push(bottomSheetTag);_common.Utils.addRootTag(results,bottomSheetTag,'Bottom Sheet discovered: ');}}}if(_fiberTypes.TagFinder.isNodeClickable(node,options.clickableElementsNativeIDsRegex)){_fiberTypes.TagFinder.addClickableElement(node,options,results);}}if(options.integrationType===_pendoTypes.IntegrationType.expoRouter||results.rootTags.length===0&&options.integrationType===_pendoTypes.IntegrationType.reactNavigation){if(options.integrationType===_pendoTypes.IntegrationType.reactNavigation){_pendoLogger.Logger.debug('No rootTags were found, will try to find screenContainer tag');}_fiberTypes.TagFinder.findScreenContainerRootTag(rootFiberNode,options,results);}_pendoLogger.Logger.debug(`Analysis complete: modalTag=${results.modalTag}, rootTags=[${results.rootTags.join(', ')}]`);return results;}