mirror of
https://github.com/status-im/react-native.git
synced 2025-01-14 11:34:23 +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.
|
||||
* 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
|
||||
|
@ -327,39 +327,46 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation)
|
||||
return _shadowViewRegistry[reactTag];
|
||||
}
|
||||
|
||||
- (void)setAvailableSize:(CGSize)availableSize forRootView:(UIView *)rootView
|
||||
- (void)_executeBlockWithShadowView:(void (^)(RCTShadowView *shadowView))block forTag:(NSNumber *)tag
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
shadowView.availableSize = availableSize;
|
||||
[self setNeedsLayout];
|
||||
block(shadowView);
|
||||
});
|
||||
}
|
||||
|
||||
- (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
|
||||
{
|
||||
RCTAssertMainQueue();
|
||||
NSNumber *tag = view.reactTag;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
[self _executeBlockWithShadowView:^(RCTShadowView *shadowView) {
|
||||
shadowView.localData = localData;
|
||||
[self setNeedsLayout];
|
||||
});
|
||||
} forTag:view.reactTag];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -392,56 +399,40 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation)
|
||||
- (void)setSize:(CGSize)size forView:(UIView *)view
|
||||
{
|
||||
RCTAssertMainQueue();
|
||||
|
||||
NSNumber *reactTag = view.reactTag;
|
||||
RCTExecuteOnUIManagerQueue(^{
|
||||
RCTShadowView *shadowView = self->_shadowViewRegistry[reactTag];
|
||||
RCTAssert(shadowView != nil, @"Could not locate shadow view with tag #%@", reactTag);
|
||||
|
||||
[self _executeBlockWithShadowView:^(RCTShadowView *shadowView) {
|
||||
if (CGSizeEqualToSize(size, shadowView.size)) {
|
||||
return;
|
||||
}
|
||||
|
||||
shadowView.size = size;
|
||||
[self setNeedsLayout];
|
||||
});
|
||||
} forTag:view.reactTag];
|
||||
}
|
||||
|
||||
- (void)setIntrinsicContentSize:(CGSize)size forView:(UIView *)view
|
||||
- (void)setIntrinsicContentSize:(CGSize)intrinsicContentSize forView:(UIView *)view
|
||||
{
|
||||
RCTAssertMainQueue();
|
||||
|
||||
NSNumber *reactTag = view.reactTag;
|
||||
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);
|
||||
[self _executeBlockWithShadowView:^(RCTShadowView *shadowView) {
|
||||
if (CGSizeEqualToSize(shadowView.intrinsicContentSize, intrinsicContentSize)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CGSizeEqualToSize(shadowView.intrinsicContentSize, size)) {
|
||||
shadowView.intrinsicContentSize = size;
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
});
|
||||
shadowView.intrinsicContentSize = intrinsicContentSize;
|
||||
} forTag:view.reactTag];
|
||||
}
|
||||
|
||||
- (void)setBackgroundColor:(UIColor *)color forView:(UIView *)view
|
||||
{
|
||||
RCTAssertMainQueue();
|
||||
|
||||
NSNumber *reactTag = view.reactTag;
|
||||
RCTExecuteOnUIManagerQueue(^{
|
||||
[self _executeBlockWithShadowView:^(RCTShadowView *shadowView) {
|
||||
if (!self->_viewRegistry) {
|
||||
return;
|
||||
}
|
||||
|
||||
RCTShadowView *shadowView = self->_shadowViewRegistry[reactTag];
|
||||
RCTAssert(shadowView != nil, @"Could not locate root view with tag #%@", reactTag);
|
||||
shadowView.backgroundColor = color;
|
||||
[self _amendPendingUIBlocksWithStylePropagationUpdateForShadowView:shadowView];
|
||||
[self flushUIBlocks];
|
||||
});
|
||||
} forTag:view.reactTag];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user