3636#import " SAReactNativeswizzler.h"
3737#import < objc/runtime.h>
3838
39+
40+ @interface UIView (SAReactNative)
41+ @property (nonatomic , copy ) NSDictionary *sa_reactnative_screenProperties;
42+ @end
43+
44+ @implementation UIView (SAReactNative)
45+
46+ - (NSDictionary *)sa_reactnative_screenProperties {
47+ return objc_getAssociatedObject (self, @" SensorsAnalyticsRNScreenProperties" );
48+ }
49+
50+ - (void )setSa_reactnative_screenProperties : (NSDictionary *)sa_reactnative_screenProperties {
51+ objc_setAssociatedObject (self, @" SensorsAnalyticsRNScreenProperties" , sa_reactnative_screenProperties, OBJC_ASSOCIATION_COPY_NONATOMIC );
52+ }
53+
54+ @end
55+
3956@interface SAReactNativeManager ()
4057
41- @property (nonatomic , copy ) NSString *currentScreenName;
42- @property (nonatomic , copy ) NSString *currentTitle;
58+ @property (nonatomic , copy ) NSDictionary *screenProperties;
4359@property (nonatomic , strong ) NSSet *ignoreClasses;
4460@property (nonatomic , strong ) NSMutableSet *clickableViewTags;
4561@property (nonatomic , assign ) BOOL isRootViewVisible;
@@ -167,14 +183,18 @@ - (instancetype)init {
167183
168184#pragma mark - visualize
169185- (NSDictionary *)visualizeProperties {
170- return _isRootViewVisible ? [ self screenProperties ] : nil ;
186+ return _isRootViewVisible ? self. screenProperties : nil ;
171187}
172188
173189- (BOOL )clickableForView : (UIView *)view {
174190 if ([_ignoreClasses containsObject: NSStringFromClass (view.class)]) {
175191 return NO ;
176192 }
177- return [_clickableViewTags containsObject: view.reactTag];
193+ BOOL clickable = [_clickableViewTags containsObject: view.reactTag];
194+ if (clickable) {
195+ view.sa_reactnative_screenProperties = self.screenProperties ;
196+ }
197+ return clickable;
178198}
179199
180200- (BOOL )prepareView : (NSNumber *)reactTag clickable : (BOOL )clickable paramters : (NSDictionary *)paramters {
@@ -198,8 +218,7 @@ - (void)trackViewClick:(NSNumber *)reactTag {
198218 dispatch_async (dispatch_get_main_queue (), ^{
199219 UIView *view = [[SAReactNativeManager sharedInstance ] viewForTag: reactTag];
200220 NSMutableDictionary *properties = [NSMutableDictionary dictionary ];
201- NSDictionary *screenProperties = [self screenProperties ];
202- [properties addEntriesFromDictionary: screenProperties];
221+ [properties addEntriesFromDictionary: self .screenProperties];
203222 properties[@" $element_content" ] = [view.accessibilityLabel stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet ]];
204223
205224 [[SensorsAnalyticsSDK sharedInstance ] trackViewAppClick: view withProperties: [properties copy ]];
@@ -213,8 +232,11 @@ - (void)trackViewScreen:(nullable NSString *)url properties:(nullable NSDictiona
213232 return ;
214233 }
215234 NSString *screenName = properties[@" $screen_name" ] ?: url;
216- NSString *title = properties[@" $title" ];
217- NSDictionary *pageProps = [self viewScreenProperties: screenName title: title];
235+ NSString *title = properties[@" $title" ] ?: screenName;
236+ NSMutableDictionary *pageProps = [NSMutableDictionary dictionary ];
237+ pageProps[@" $screen_name" ] = screenName;
238+ pageProps[@" $title" ] = title;
239+ self.screenProperties = pageProps;
218240
219241 if (autoTrack && ![[SensorsAnalyticsSDK sharedInstance ] isAutoTrackEnabled ]) {
220242 return ;
@@ -268,17 +290,4 @@ - (UIView *)viewForTag:(NSNumber *)reactTag {
268290 return [manager viewForReactTag: reactTag];
269291}
270292
271- - (NSDictionary *)viewScreenProperties : (NSString *)screenName title : (NSString *)title {
272- _currentScreenName = screenName;
273- _currentTitle = title ?: screenName;
274- return [self screenProperties ];
275- }
276-
277- - (NSDictionary *)screenProperties {
278- NSMutableDictionary *properties = [NSMutableDictionary dictionary ];
279- properties[@" $screen_name" ] = _currentScreenName;
280- properties[@" $title" ] = _currentTitle;
281- return [properties copy ];
282- }
283-
284293@end
0 commit comments