From 85b119f7eb275fa10b9ad7f385b5a59b3b3164d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=B4=8B=E6=B4=8B?= Date: Mon, 29 May 2023 17:32:45 +0800 Subject: [PATCH] Release 2.3.6 --- RNSensorsAnalyticsModule.podspec | 2 +- .../analytics/RNSensorsAnalyticsPackage.java | 2 +- ios/RNSensorsAnalyticsModule.m | 2 +- ios/SAReactNativeRootViewManager.m | 45 +++++++++++++------ package.json | 2 +- 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/RNSensorsAnalyticsModule.podspec b/RNSensorsAnalyticsModule.podspec index 2f756d4..b9f2587 100644 --- a/RNSensorsAnalyticsModule.podspec +++ b/RNSensorsAnalyticsModule.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "RNSensorsAnalyticsModule" - s.version = "2.3.5" + s.version = "2.3.6" s.summary = "The official React Native SDK of Sensors Analytics." s.description = <<-DESC 神策分析 RN 组件 diff --git a/android/src/main/java/com/sensorsdata/analytics/RNSensorsAnalyticsPackage.java b/android/src/main/java/com/sensorsdata/analytics/RNSensorsAnalyticsPackage.java index 05df84c..37f80c7 100644 --- a/android/src/main/java/com/sensorsdata/analytics/RNSensorsAnalyticsPackage.java +++ b/android/src/main/java/com/sensorsdata/analytics/RNSensorsAnalyticsPackage.java @@ -28,7 +28,7 @@ import java.util.List; public class RNSensorsAnalyticsPackage implements ReactPackage { - public static final String VERSION = "2.3.5"; + public static final String VERSION = "2.3.6"; @Override public List createNativeModules(ReactApplicationContext reactContext) { diff --git a/ios/RNSensorsAnalyticsModule.m b/ios/RNSensorsAnalyticsModule.m index ae4800b..9a84e05 100644 --- a/ios/RNSensorsAnalyticsModule.m +++ b/ios/RNSensorsAnalyticsModule.m @@ -32,7 +32,7 @@ #import "SAReactNativeManager.h" #import "SAReactNativeEventProperty.h" -NSString *const kSAReactNativePluginVersion = @"react_native:2.3.5"; +NSString *const kSAReactNativePluginVersion = @"react_native:2.3.6"; @implementation RNSensorsAnalyticsModule diff --git a/ios/SAReactNativeRootViewManager.m b/ios/SAReactNativeRootViewManager.m index a0c77a2..3eefff0 100644 --- a/ios/SAReactNativeRootViewManager.m +++ b/ios/SAReactNativeRootViewManager.m @@ -21,10 +21,19 @@ #import "SAReactNativeRootViewManager.h" #import +void sensors_reactnative_dispatch_safe_sync(dispatch_queue_t queue,DISPATCH_NOESCAPE dispatch_block_t block) { + if ((dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)) == dispatch_queue_get_label(queue)) { + block(); + } else { + dispatch_sync(queue, block); + } +} + @interface SAReactNativeRootViewManager () @property (nonatomic, strong) NSPointerArray *rootViews; @property (nonatomic, strong) NSMutableDictionary *viewProperties; +@property (nonatomic, strong) dispatch_queue_t serialQueue; @end @@ -44,6 +53,7 @@ - (instancetype)init { if (self) { _rootViews = [NSPointerArray weakObjectsPointerArray]; _viewProperties = [NSMutableDictionary dictionary]; + _serialQueue = dispatch_queue_create("cn.SensorsData.SAReactNativeRootViewManagerQueue", DISPATCH_QUEUE_SERIAL); } return self; } @@ -76,20 +86,25 @@ - (void)addViewProperty:(SAReactNativeViewProperty *)property withRootTag:(NSNum return; } - NSMutableSet *viewProperties = self.viewProperties[rootTag]; - if (!viewProperties) { - viewProperties = [NSMutableSet set]; - self.viewProperties[rootTag] = viewProperties; - } - [viewProperties addObject:property]; + sensors_reactnative_dispatch_safe_sync(self.serialQueue, ^{ + NSMutableSet *viewProperties = self.viewProperties[rootTag]; + if (!viewProperties) { + viewProperties = [NSMutableSet set]; + self.viewProperties[rootTag] = viewProperties; + } + [viewProperties addObject:property]; + }); } - (NSSet *)viewPropertiesWithRootTag:(NSNumber *)rootTag { - NSSet *viewProperties = self.viewProperties[rootTag]; - if (!viewProperties) { - return nil; - } - return [[NSSet alloc] initWithSet:viewProperties copyItems:YES]; + __block NSSet *viewProperties = nil; + sensors_reactnative_dispatch_safe_sync(self.serialQueue, ^{ + NSSet *tempProperties = self.viewProperties[rootTag]; + if (tempProperties) { + viewProperties = [[NSSet alloc] initWithSet:tempProperties copyItems:YES]; + } + }); + return viewProperties; } #pragma mark - utils @@ -109,9 +124,11 @@ - (void)compact { [rootTags addObject:rootView.reactTag]; } - NSMutableSet *removeTags = [NSMutableSet setWithArray:[self.viewProperties allKeys]]; - [removeTags minusSet:rootTags]; - [self.viewProperties removeObjectsForKeys:removeTags.allObjects]; + sensors_reactnative_dispatch_safe_sync(self.serialQueue, ^{ + NSMutableSet *removeTags = [NSMutableSet setWithArray:[self.viewProperties allKeys]]; + [removeTags minusSet:rootTags]; + [self.viewProperties removeObjectsForKeys:removeTags.allObjects]; + }); } @end diff --git a/package.json b/package.json index 1299804..5630c39 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sensorsdata-analytics-react-native", - "version": "2.3.5", + "version": "2.3.6", "private": false, "description": "神策分析 RN 组件", "main": "index.js",