From ca36c025661235315ae71faf69ca0f99e61d9755 Mon Sep 17 00:00:00 2001 From: Toni Kaufmann Date: Tue, 21 Nov 2017 10:09:12 +0100 Subject: [PATCH] sizeThatFits has to be invoked on the main thread --- ios/RNTweetShadowView.m | 11 ++++++----- ios/RNTwitterKitViewManager.m | 13 ++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ios/RNTweetShadowView.m b/ios/RNTweetShadowView.m index ee77bd5..725cd66 100644 --- a/ios/RNTweetShadowView.m +++ b/ios/RNTweetShadowView.m @@ -4,7 +4,7 @@ @implementation RNTweetShadowView - (TWTRTweetView *)tweetViewForMeasuring { - static TWTRTweetView *tweetView = nil;; + static TWTRTweetView *tweetView = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ tweetView = [[TWTRTweetView alloc] initWithTweet:nil style:TWTRTweetViewStyleCompact]; @@ -12,15 +12,16 @@ - (TWTRTweetView *)tweetViewForMeasuring return tweetView; } - - (CGSize)computeIntrinsicSize:(CGFloat)width { static CGSize defaultSize; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - TWTRTweetView *view = [self tweetViewForMeasuring]; - defaultSize = [view sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)]; // 200 is the minimum width required for a tweet - defaultSize.width = UIViewNoIntrinsicMetric; + dispatch_async(dispatch_get_main_queue(), ^{ + TWTRTweetView *view = [self tweetViewForMeasuring]; + defaultSize = [view sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)]; // 200 is the minimum width required for a tweet + defaultSize.width = UIViewNoIntrinsicMetric; + }); }); return defaultSize; diff --git a/ios/RNTwitterKitViewManager.m b/ios/RNTwitterKitViewManager.m index 79b045b..92c1a4c 100644 --- a/ios/RNTwitterKitViewManager.m +++ b/ios/RNTwitterKitViewManager.m @@ -8,6 +8,12 @@ @implementation RNTwitterKitViewManager +// this module is supposed to run in the main queue +- (dispatch_queue_t)methodQueue +{ + return dispatch_get_main_queue(); +} + RCT_EXPORT_MODULE(TweetView); RCT_REMAP_VIEW_PROPERTY(tweetid, TWEETID, NSString); RCT_REMAP_VIEW_PROPERTY(showActionButtons, SHOWACTIONBUTTONS, BOOL); @@ -21,19 +27,14 @@ @implementation RNTwitterKitViewManager RCT_EXPORT_VIEW_PROPERTY(onLoadSuccess, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onLoadError, RCTBubblingEventBlock) -@synthesize bridge = _bridge; - - (UIView *)view { RNTwitterKitView *view = [[RNTwitterKitView alloc] init]; view.delegate = self; view.twitterAPIClient = [self twitterAPIClient]; - return view; } - - - (RCTShadowView *)shadowView { return [RNTweetShadowView new]; @@ -41,14 +42,12 @@ - (RCTShadowView *)shadowView - (void)tweetView:(RNTwitterKitView *)view requestsResize:(CGSize)newSize { - //getting the tweet view UIView *tweetView = view; //create a new size fot the tweet view CGSize newTweetViewSize = newSize; - NSLog(@"new tweet size: %f,%f", newTweetViewSize.width, newTweetViewSize.height); //getting the UI manager and set the intrinsic content size of the tweet view RCTUIManager *UIManager = [self.bridge uiManager];