@@ -669,22 +669,83 @@ sensorsdataHookClickableRN = function (reset = false) {
669669 throw "can't inject clickable js" ;
670670 }
671671 var lastParentheses = content . lastIndexOf ( ')' , match . index ) ;
672- var lastCommaIndex = content . lastIndexOf ( ',' , lastParentheses ) ;
673- if ( lastCommaIndex == - 1 )
674- throw "can't inject clickable js,and lastCommaIndex is -1" ;
675672 var nextCommaIndex = content . indexOf ( ',' , match . index ) ;
676673 if ( nextCommaIndex == - 1 )
677674 throw "can't inject clickable js, and nextCommaIndex is -1" ;
678- var propsName = lastArgumentName ( content , lastCommaIndex ) . trim ( ) ;
679675 var tagName = lastArgumentName ( content , nextCommaIndex ) . trim ( ) ;
680- var functionBody = `var clickable = false;
681- if(${ propsName } .onStartShouldSetResponder){
682- clickable = true;
683- }
684- var ReactNative = require('react-native');
685- var dataModule = ReactNative.NativeModules.RNSensorsDataModule;
686- dataModule && dataModule.saveViewProperties && dataModule.saveViewProperties(${ tagName } , clickable , null);
687- ` ;
676+ var functionBody = `
677+ var saElement;
678+ if(typeof internalInstanceHandle !== 'undefined'){
679+ saElement = internalInstanceHandle;
680+ }else if(typeof workInProgress !== 'undefined'){
681+ saElement = workInProgress;
682+ }else if(typeof thatThis._currentElement !== 'undefined'){
683+ saElement = thatThis._currentElement;
684+ }
685+ var eachProgress = function (workInProgress){
686+ if(workInProgress == null){
687+ return;
688+ }
689+ var props;
690+ if(workInProgress.memoizedProps){
691+ props = workInProgress.memoizedProps;
692+ }else if(workInProgress.props){
693+ props = workInProgress.props;
694+ }
695+ if(props && props.sensorsdataparams){
696+ return props.sensorsdataparams;
697+ }else {
698+ if(!props ||
699+ !workInProgress.type ||
700+ workInProgress.type.displayName === 'TouchableOpacity' ||
701+ workInProgress.type.displayName === 'TouchableHighlight' ||
702+ workInProgress.type.displayName === 'TouchableWithoutFeedback'||
703+ workInProgress.type.displayName === 'TouchableNativeFeedback'||
704+ workInProgress.type.displayName === 'Pressable'||
705+ workInProgress.type.name === 'TouchableOpacity' ||
706+ workInProgress.type.name === 'TouchableHighlight' ||
707+ workInProgress.type.name === 'TouchableNativeFeedback'||
708+ workInProgress.type.name === 'TouchableWithoutFeedback'||
709+ workInProgress.type.displayName === undefined||
710+ workInProgress.type.name === undefined ||
711+ !props.onPress){
712+ if(workInProgress.return){
713+ return eachProgress(workInProgress.return);
714+ }else{
715+ if(workInProgress._owner && workInProgress._owner._currentElement){
716+ return eachProgress(workInProgress._owner._currentElement);
717+ }else{
718+ return eachProgress(workInProgress._owner);
719+ }
720+ }
721+ }
722+ }
723+ };
724+ var elementProps;
725+ if(saElement && saElement.memoizedProps){
726+ elementProps = saElement.memoizedProps;
727+ }else if(saElement && saElement.props){
728+ elementProps = saElement.props;
729+ }
730+ if(elementProps){
731+ // iOS 兼容 SegmentedControl 逻辑
732+ var isSegmentedControl = (saElement &&
733+ (saElement.type === 'RNCSegmentedControl' ||
734+ saElement.type === 'RCTSegmentedControl' ||
735+ saElement.type.name === 'RNCSegmentedControl' ||
736+ saElement.type.name === 'RCTSegmentedControl' ||
737+ saElement.type.displayName === 'RNCSegmentedControl' ||
738+ saElement.type.displayName === 'RCTSegmentedControl'));
739+ if(elementProps.onStartShouldSetResponder || isSegmentedControl) {
740+ var saProps = eachProgress(saElement);
741+ if(saProps){
742+ console.log(saProps);
743+ }
744+ var ReactNative = require('react-native');
745+ var dataModule = ReactNative.NativeModules.RNSensorsDataModule;
746+ dataModule && dataModule.saveViewProperties && dataModule.saveViewProperties(${ tagName } , true , saProps);
747+ }
748+ }` ;
688749 var call = addTryCatch ( functionBody ) ;
689750 var lastReturn = content . lastIndexOf ( 'return' , match . index ) ;
690751 var splitIndex = match . index ;
@@ -778,47 +839,46 @@ navigationString3 = function (
778839 }` ;
779840
780841 if ( actionName ) {
781- script = `${ script }
782- var type = ${ actionName } .type;
783- var iosOnPageShow = false;
784-
785- if (require('react-native').Platform.OS === 'android') {
786- if(type == 'Navigation/SET_PARAMS' || type == 'Navigation/COMPLETE_TRANSITION') {
787- return;
788- }
789- } else if (require('react-native').Platform.OS === 'ios') {
790- if(type == 'Navigation/BACK' && (${ currentStateVarName } && !${ currentStateVarName } .isTransitioning)) {
791- iosOnPageShow = true;
792- } else if (!(type == 'Navigation/SET_PARAMS' || type == 'Navigation/COMPLETE_TRANSITION')) {
793- iosOnPageShow = true;
794- }
795- if (!iosOnPageShow) {
796- return;
797- }
798- }
799-
842+ script = `
843+ ${ script }
844+ var type = ${ actionName } .type;
845+ var iosOnPageShow = false;
800846
801- ` ;
847+ if (require('react-native').Platform.OS === 'android') {
848+ if(type == 'Navigation/SET_PARAMS' || type == 'Navigation/COMPLETE_TRANSITION') {
849+ return;
850+ }
851+ } else if (require('react-native').Platform.OS === 'ios') {
852+ if(type == 'Navigation/BACK' && (${ currentStateVarName } && !${ currentStateVarName } .isTransitioning)) {
853+ iosOnPageShow = true;
854+ } else if (!(type == 'Navigation/SET_PARAMS' || type == 'Navigation/COMPLETE_TRANSITION')) {
855+ iosOnPageShow = true;
856+ }
857+ if (!iosOnPageShow) {
858+ return;
859+ }
860+ }` ;
802861 }
803862
804- script = `${ script } var params = $$$getActivePageName$$$(${ currentStateVarName } );
805- if (require('react-native').Platform.OS === 'android') {
806- if (${ prevStateVarName } ){
807- var prevParams = $$$getActivePageName$$$(${ prevStateVarName } );
808- if (params.sensorsdataurl == prevParams.sensorsdataurl){
809- return;
810- }
811- }
812- var ReactNative = require('react-native');
813- var dataModule = ReactNative.NativeModules.RNSensorsDataModule;
814- dataModule && dataModule.trackViewScreen && dataModule.trackViewScreen(params);
815- } else if (require('react-native').Platform.OS === 'ios') {
816- if (!${ actionName } || iosOnPageShow) {
817- var ReactNative = require('react-native');
818- var dataModule = ReactNative.NativeModules.RNSensorsDataModule;
819- dataModule && dataModule.trackViewScreen && dataModule.trackViewScreen(params);
820- }
821- }` ;
863+ script = `
864+ ${ script } var params = $$$getActivePageName$$$(${ currentStateVarName } );
865+ if (require('react-native').Platform.OS === 'android') {
866+ if (${ prevStateVarName } ){
867+ var prevParams = $$$getActivePageName$$$(${ prevStateVarName } );
868+ if (params.sensorsdataurl == prevParams.sensorsdataurl){
869+ return;
870+ }
871+ }
872+ var ReactNative = require('react-native');
873+ var dataModule = ReactNative.NativeModules.RNSensorsDataModule;
874+ dataModule && dataModule.trackViewScreen && dataModule.trackViewScreen(params);
875+ } else if (require('react-native').Platform.OS === 'ios') {
876+ if (!${ actionName } || iosOnPageShow) {
877+ var ReactNative = require('react-native');
878+ var dataModule = ReactNative.NativeModules.RNSensorsDataModule;
879+ dataModule && dataModule.trackViewScreen && dataModule.trackViewScreen(params);
880+ }
881+ }` ;
822882 return script ;
823883} ;
824884navigationEventString = function ( ) {
@@ -1089,6 +1149,7 @@ allSensorsdataHookRN = function () {
10891149// 命令行
10901150switch ( process . argv [ 2 ] ) {
10911151 case '-run' :
1152+ resetAllSensorsdataHookRN ( ) ;
10921153 allSensorsdataHookRN ( ) ;
10931154 break ;
10941155 case '-reset' :
0 commit comments