mirror of
https://github.com/status-im/react-native.git
synced 2025-01-15 03:56:03 +00:00
Introducing [RCTUIManager _executeBlockWithShadowView:forTag:]
Summary: New super simple abstraction in RCTUIManager. Nothing really changed and RCTUIManager became shorter. Reviewed By: rsnara Differential Revision: D5990342 fbshipit-source-id: b38397b789a999168ac14625585065eda73d328f
This commit is contained in:
parent
343c5a97a0
commit
71b498b082
@ -86,7 +86,7 @@ RCT_EXTERN NSString *const RCTUIManagerWillUpdateViewsDueToContentSizeMultiplier
|
|||||||
* Use `UIViewNoIntrinsicMetric` to ignore a dimension.
|
* Use `UIViewNoIntrinsicMetric` to ignore a dimension.
|
||||||
* The `size` must NOT include padding and border.
|
* The `size` must NOT include padding and border.
|
||||||
*/
|
*/
|
||||||
- (void)setIntrinsicContentSize:(CGSize)size forView:(UIView *)view;
|
- (void)setIntrinsicContentSize:(CGSize)intrinsicContentSize forView:(UIView *)view;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the background color of a view. The source of truth for
|
* Update the background color of a view. The source of truth for
|
||||||
|
@ -327,39 +327,46 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation)
|
|||||||
return _shadowViewRegistry[reactTag];
|
return _shadowViewRegistry[reactTag];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setAvailableSize:(CGSize)availableSize forRootView:(UIView *)rootView
|
- (void)_executeBlockWithShadowView:(void (^)(RCTShadowView *shadowView))block forTag:(NSNumber *)tag
|
||||||
{
|
{
|
||||||
RCTAssertMainQueue();
|
RCTAssertMainQueue();
|
||||||
NSNumber *reactTag = rootView.reactTag;
|
|
||||||
RCTExecuteOnUIManagerQueue(^{
|
|
||||||
RCTRootShadowView *shadowView = (RCTRootShadowView *)self->_shadowViewRegistry[reactTag];
|
|
||||||
RCTAssert(shadowView != nil, @"Could not locate shadow view with tag #%@", reactTag);
|
|
||||||
RCTAssert([shadowView isKindOfClass:[RCTRootShadowView class]], @"Located shadow view (with tag #%@) is actually not root view.", reactTag);
|
|
||||||
|
|
||||||
if (CGSizeEqualToSize(availableSize, shadowView.availableSize)) {
|
RCTExecuteOnUIManagerQueue(^{
|
||||||
|
RCTShadowView *shadowView = self->_shadowViewRegistry[tag];
|
||||||
|
|
||||||
|
if (shadowView == nil) {
|
||||||
|
RCTLogInfo(@"Could not locate shadow view with tag #%@, this is probably caused by a temporary inconsistency between native views and shadow views.", tag);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
shadowView.availableSize = availableSize;
|
block(shadowView);
|
||||||
[self setNeedsLayout];
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setAvailableSize:(CGSize)availableSize forRootView:(UIView *)rootView
|
||||||
|
{
|
||||||
|
RCTAssertMainQueue();
|
||||||
|
[self _executeBlockWithShadowView:^(RCTShadowView *shadowView) {
|
||||||
|
RCTAssert([shadowView isKindOfClass:[RCTRootShadowView class]], @"Located shadow view is actually not root view.");
|
||||||
|
|
||||||
|
RCTRootShadowView *rootShadowView = (RCTRootShadowView *)shadowView;
|
||||||
|
|
||||||
|
if (CGSizeEqualToSize(availableSize, rootShadowView.availableSize)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rootShadowView.availableSize = availableSize;
|
||||||
|
[self setNeedsLayout];
|
||||||
|
} forTag:rootView.reactTag];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setLocalData:(NSObject *)localData forView:(UIView *)view
|
- (void)setLocalData:(NSObject *)localData forView:(UIView *)view
|
||||||
{
|
{
|
||||||
RCTAssertMainQueue();
|
RCTAssertMainQueue();
|
||||||
NSNumber *tag = view.reactTag;
|
[self _executeBlockWithShadowView:^(RCTShadowView *shadowView) {
|
||||||
|
|
||||||
RCTExecuteOnUIManagerQueue(^{
|
|
||||||
RCTShadowView *shadowView = self->_shadowViewRegistry[tag];
|
|
||||||
if (shadowView == nil) {
|
|
||||||
RCTLogWarn(@"Could not locate shadow view with tag #%@, this is probably caused by a temporary inconsistency between native views and shadow views.", tag);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
shadowView.localData = localData;
|
shadowView.localData = localData;
|
||||||
[self setNeedsLayout];
|
[self setNeedsLayout];
|
||||||
});
|
} forTag:view.reactTag];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -392,56 +399,40 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation)
|
|||||||
- (void)setSize:(CGSize)size forView:(UIView *)view
|
- (void)setSize:(CGSize)size forView:(UIView *)view
|
||||||
{
|
{
|
||||||
RCTAssertMainQueue();
|
RCTAssertMainQueue();
|
||||||
|
[self _executeBlockWithShadowView:^(RCTShadowView *shadowView) {
|
||||||
NSNumber *reactTag = view.reactTag;
|
|
||||||
RCTExecuteOnUIManagerQueue(^{
|
|
||||||
RCTShadowView *shadowView = self->_shadowViewRegistry[reactTag];
|
|
||||||
RCTAssert(shadowView != nil, @"Could not locate shadow view with tag #%@", reactTag);
|
|
||||||
|
|
||||||
if (CGSizeEqualToSize(size, shadowView.size)) {
|
if (CGSizeEqualToSize(size, shadowView.size)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
shadowView.size = size;
|
shadowView.size = size;
|
||||||
[self setNeedsLayout];
|
[self setNeedsLayout];
|
||||||
});
|
} forTag:view.reactTag];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setIntrinsicContentSize:(CGSize)size forView:(UIView *)view
|
- (void)setIntrinsicContentSize:(CGSize)intrinsicContentSize forView:(UIView *)view
|
||||||
{
|
{
|
||||||
RCTAssertMainQueue();
|
RCTAssertMainQueue();
|
||||||
|
[self _executeBlockWithShadowView:^(RCTShadowView *shadowView) {
|
||||||
NSNumber *reactTag = view.reactTag;
|
if (CGSizeEqualToSize(shadowView.intrinsicContentSize, intrinsicContentSize)) {
|
||||||
RCTExecuteOnUIManagerQueue(^{
|
|
||||||
RCTShadowView *shadowView = self->_shadowViewRegistry[reactTag];
|
|
||||||
if (shadowView == nil) {
|
|
||||||
RCTLogWarn(@"Could not locate shadow view with tag #%@, this is probably caused by a temporary inconsistency between native views and shadow views.", reactTag);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CGSizeEqualToSize(shadowView.intrinsicContentSize, size)) {
|
shadowView.intrinsicContentSize = intrinsicContentSize;
|
||||||
shadowView.intrinsicContentSize = size;
|
} forTag:view.reactTag];
|
||||||
[self setNeedsLayout];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setBackgroundColor:(UIColor *)color forView:(UIView *)view
|
- (void)setBackgroundColor:(UIColor *)color forView:(UIView *)view
|
||||||
{
|
{
|
||||||
RCTAssertMainQueue();
|
RCTAssertMainQueue();
|
||||||
|
[self _executeBlockWithShadowView:^(RCTShadowView *shadowView) {
|
||||||
NSNumber *reactTag = view.reactTag;
|
|
||||||
RCTExecuteOnUIManagerQueue(^{
|
|
||||||
if (!self->_viewRegistry) {
|
if (!self->_viewRegistry) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RCTShadowView *shadowView = self->_shadowViewRegistry[reactTag];
|
|
||||||
RCTAssert(shadowView != nil, @"Could not locate root view with tag #%@", reactTag);
|
|
||||||
shadowView.backgroundColor = color;
|
shadowView.backgroundColor = color;
|
||||||
[self _amendPendingUIBlocksWithStylePropagationUpdateForShadowView:shadowView];
|
[self _amendPendingUIBlocksWithStylePropagationUpdateForShadowView:shadowView];
|
||||||
[self flushUIBlocks];
|
[self flushUIBlocks];
|
||||||
});
|
} forTag:view.reactTag];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user