-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sizeThatFits has to be invoked on the main thread #17
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,23 +4,24 @@ @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]; | ||
}); | ||
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(), ^{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are calling Perhaps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course, you’re right. |
||
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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,12 @@ | |
|
||
@implementation RNTwitterKitViewManager | ||
|
||
// this module is supposed to run in the main queue | ||
- (dispatch_queue_t)methodQueue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for moving the execution of the view manager on the main queue? It is not apparent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it is indeed not required at the moment. However, it will be, once the library exports constants. I added it to prevent future thread problems. Since you might need it in the future anyway, the run time model remains the same. But of course, you can remove it if you wish. Should’t hurt at the moment. |
||
{ | ||
return dispatch_get_main_queue(); | ||
} | ||
|
||
RCT_EXPORT_MODULE(TweetView); | ||
RCT_REMAP_VIEW_PROPERTY(tweetid, TWEETID, NSString); | ||
RCT_REMAP_VIEW_PROPERTY(showActionButtons, SHOWACTIONBUTTONS, BOOL); | ||
|
@@ -21,34 +27,27 @@ @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]; | ||
} | ||
|
||
- (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]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem also arises here,
dispatch_sync
should be called instead ofdispatch_once
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, alloc can be safely called in a bkgnd thread. The initWithTweet is bkgnd thread is safe also – at least thats what Apple’s code analyser says.