mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
introduce RCTComputeScreenScale
Summary: Changelog: [Internal] in this diff, we add a function that allows us to retrieve screen scale. enforcing thread safety will be dependent on the consumer to make sure it's used on main thread. i'd like for this to be a more temporary solution, i think we should have a more scalable screen solution for consumers to handle the gambit of uiscreen use cases. Reviewed By: sammy-SC Differential Revision: D31163909 fbshipit-source-id: 78104e9ef982b47c60697461141afb4b06eede72
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c744528da1
commit
99f706e5df
@@ -40,6 +40,9 @@ RCT_EXTERN void RCTExecuteOnMainQueue(dispatch_block_t block);
|
||||
// Please do not use this unless you know what you're doing.
|
||||
RCT_EXTERN void RCTUnsafeExecuteOnMainQueueSync(dispatch_block_t block);
|
||||
|
||||
// Get screen scale, can be only used on main
|
||||
RCT_EXTERN void RCTComputeScreenScale(void);
|
||||
|
||||
// Get screen metrics in a thread-safe way
|
||||
RCT_EXTERN CGFloat RCTScreenScale(void);
|
||||
RCT_EXTERN CGFloat RCTFontSizeMultiplier(void);
|
||||
|
||||
+13
-6
@@ -296,16 +296,23 @@ static void RCTUnsafeExecuteOnMainQueueOnceSync(dispatch_once_t *onceToken, disp
|
||||
}
|
||||
}
|
||||
|
||||
static dispatch_once_t onceTokenScreenScale;
|
||||
static CGFloat screenScale;
|
||||
|
||||
void RCTComputeScreenScale()
|
||||
{
|
||||
dispatch_once(&onceTokenScreenScale, ^{
|
||||
screenScale = [UIScreen mainScreen].scale;
|
||||
});
|
||||
}
|
||||
|
||||
CGFloat RCTScreenScale()
|
||||
{
|
||||
static dispatch_once_t onceToken;
|
||||
static CGFloat scale;
|
||||
|
||||
RCTUnsafeExecuteOnMainQueueOnceSync(&onceToken, ^{
|
||||
scale = [UIScreen mainScreen].scale;
|
||||
RCTUnsafeExecuteOnMainQueueOnceSync(&onceTokenScreenScale, ^{
|
||||
screenScale = [UIScreen mainScreen].scale;
|
||||
});
|
||||
|
||||
return scale;
|
||||
return screenScale;
|
||||
}
|
||||
|
||||
CGFloat RCTFontSizeMultiplier()
|
||||
|
||||
Reference in New Issue
Block a user