Skip to content

Commit

Permalink
fix(ios): fix threads competion bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ozonelmy committed Nov 20, 2020
1 parent d80b04a commit 258a480
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions ios/sdk/utils/HippyUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -276,30 +276,30 @@ void HippyExecuteOnMainThread(dispatch_block_t block, BOOL sync)

CGFloat HippyScreenScale()
{
static CGFloat scale;
static CGFloat scale = CGFLOAT_MAX;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if (CGFLOAT_MAX == scale) {
HippyExecuteOnMainThread(^{
scale = [UIScreen mainScreen].scale;
dispatch_once(&onceToken, ^{
scale = [UIScreen mainScreen].scale;
});
}, YES);
});
}

return scale;
}

CGSize HippyScreenSize()
{
// FIXME: this caches the bounds at app start, whatever those were, and then
// doesn't update when the device is rotated. We need to find another thread-
// safe way to get the screen size.

static CGSize size;
static CGSize size = {0, 0};
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if (CGSizeEqualToSize(CGSizeZero, size)) {
HippyExecuteOnMainThread(^{
size = [UIScreen mainScreen].bounds.size;
dispatch_once(&onceToken, ^{
size = [UIScreen mainScreen].bounds.size;
});
}, YES);
});
}

return size;
}
Expand Down

0 comments on commit 258a480

Please sign in to comment.