mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Misc improvements to ASViewController (#2653)
- Remove layoutThatFit: call in viewWillAppear: - Deprecate nodeConstrainedSize - Use the view’s bounds to layout the node
This commit is contained in:
committed by
Hannah Troisi
parent
b075aa2851
commit
c7ea15a5e4
@@ -132,11 +132,12 @@
|
||||
[self progagateNewEnvironmentTraitCollection:environmentTraitCollection];
|
||||
}];
|
||||
} else {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
// Call layoutThatFits: to let the node prepare for a layout that will happen shortly in the layout pass of the view.
|
||||
// If the node's constrained size didn't change between the last layout pass it's a no-op
|
||||
[_node layoutThatFits:[self nodeConstrainedSize]];
|
||||
}
|
||||
|
||||
if (!AS_AT_LEAST_IOS9) {
|
||||
[self _legacyHandleViewDidLayoutSubviews];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,10 +157,9 @@ ASVisibilityDidMoveToParentViewController;
|
||||
[super viewWillAppear:animated];
|
||||
_ensureDisplayed = YES;
|
||||
|
||||
// A measure as well as layout pass is forced this early to get nodes like ASCollectionNode, ASTableNode etc.
|
||||
// A layout pass is forced this early to get nodes like ASCollectionNode, ASTableNode etc.
|
||||
// into the hierarchy before UIKit applies the scroll view inset adjustments, if automatic subnode management
|
||||
// is enabled. Otherwise the insets would not be applied.
|
||||
[_node layoutThatFits:[self nodeConstrainedSize]];
|
||||
[_node.view layoutIfNeeded];
|
||||
|
||||
if (_parentManagesVisibilityDepth == NO) {
|
||||
@@ -239,12 +239,7 @@ ASVisibilityDepthImplementation;
|
||||
|
||||
- (ASSizeRange)nodeConstrainedSize
|
||||
{
|
||||
if (AS_AT_LEAST_IOS9) {
|
||||
CGSize viewSize = self.view.bounds.size;
|
||||
return ASSizeRangeMake(viewSize);
|
||||
} else {
|
||||
return [self _legacyConstrainedSize];
|
||||
}
|
||||
return ASSizeRangeMake(self.view.bounds.size);
|
||||
}
|
||||
|
||||
- (ASInterfaceState)interfaceState
|
||||
@@ -252,51 +247,6 @@ ASVisibilityDepthImplementation;
|
||||
return _node.interfaceState;
|
||||
}
|
||||
|
||||
#pragma mark - Legacy Layout Handling
|
||||
|
||||
- (BOOL)_shouldLayoutTheLegacyWay
|
||||
{
|
||||
BOOL isModalViewController = (self.presentingViewController != nil && self.presentedViewController == nil);
|
||||
BOOL hasNavigationController = (self.navigationController != nil);
|
||||
BOOL hasParentViewController = (self.parentViewController != nil);
|
||||
if (isModalViewController && !hasNavigationController && !hasParentViewController) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
// Check if the view controller is a root view controller
|
||||
BOOL isRootViewController = self.view.window.rootViewController == self;
|
||||
if (isRootViewController) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (ASSizeRange)_legacyConstrainedSize
|
||||
{
|
||||
// In modal presentation the view does not have the right bounds in iOS7 and iOS8. As workaround using the superviews
|
||||
// view bounds
|
||||
UIView *view = self.view;
|
||||
CGSize viewSize = view.bounds.size;
|
||||
if ([self _shouldLayoutTheLegacyWay]) {
|
||||
UIView *superview = view.superview;
|
||||
if (superview != nil) {
|
||||
viewSize = superview.bounds.size;
|
||||
}
|
||||
}
|
||||
return ASSizeRangeMake(viewSize, viewSize);
|
||||
}
|
||||
|
||||
- (void)_legacyHandleViewDidLayoutSubviews
|
||||
{
|
||||
// In modal presentation or as root viw controller the view does not automatic resize in iOS7 and iOS8.
|
||||
// As workaround we adjust the frame of the view manually
|
||||
if ([self _shouldLayoutTheLegacyWay]) {
|
||||
CGSize maxConstrainedSize = [self nodeConstrainedSize].max;
|
||||
_node.frame = (CGRect){.origin = CGPointZero, .size = maxConstrainedSize};
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - ASEnvironmentTraitCollection
|
||||
|
||||
- (ASEnvironmentTraitCollection)environmentTraitCollectionForUITraitCollection:(UITraitCollection *)traitCollection
|
||||
@@ -325,10 +275,12 @@ ASVisibilityDepthImplementation;
|
||||
for (id<ASEnvironment> child in children) {
|
||||
ASEnvironmentStatePropagateDown(child, environmentState.environmentTraitCollection);
|
||||
}
|
||||
|
||||
// once we've propagated all the traits, layout this node.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
// Once we've propagated all the traits, layout this node.
|
||||
// Remeasure the node with the latest constrained size – old constrained size may be incorrect.
|
||||
[self.node layoutThatFits:[self nodeConstrainedSize]];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user