From 62c8606f554cbd96e981e186f95cc4a0f77b1f5a Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Mon, 27 May 2019 13:15:37 +0200 Subject: [PATCH] Fixed on-screen navigation detection --- .../TGAttachmentCarouselItemView.m | 6 +++- .../TGCameraPhotoPreviewController.m | 2 +- .../TGLocationMapViewController.h | 1 + .../TGLocationMapViewController.m | 4 +++ LegacyComponents/TGLocationPickerController.m | 8 +++--- LegacyComponents/TGLocationViewController.m | 8 +++--- LegacyComponents/TGMediaAssetsController.m | 4 +-- .../TGMediaAssetsPickerController.m | 8 ++++-- LegacyComponents/TGMediaPickerController.m | 4 +-- LegacyComponents/TGMenuSheetController.m | 2 +- .../TGPhotoAvatarCropController.m | 8 +++--- LegacyComponents/TGPhotoCropController.m | 4 +-- LegacyComponents/TGPhotoEditorController.m | 2 +- .../TGPhotoEditorItemController.m | 2 +- LegacyComponents/TGPhotoEditorTabController.m | 4 +-- LegacyComponents/TGPhotoPaintController.h | 2 +- LegacyComponents/TGPhotoPaintController.m | 28 +++++++++++++++---- LegacyComponents/TGPhotoQualityController.m | 6 ++-- LegacyComponents/TGPhotoToolsController.m | 8 +++--- LegacyComponents/TGViewController.mm | 6 ++-- 20 files changed, 73 insertions(+), 44 deletions(-) diff --git a/LegacyComponents/TGAttachmentCarouselItemView.m b/LegacyComponents/TGAttachmentCarouselItemView.m index cb2eed6a81..a8119d2466 100644 --- a/LegacyComponents/TGAttachmentCarouselItemView.m +++ b/LegacyComponents/TGAttachmentCarouselItemView.m @@ -855,7 +855,7 @@ const NSUInteger TGAttachmentDisplayedAssetLimit = 500; { id windowManager = [_context makeOverlayWindowManager]; - TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:[windowManager context] item:asset intent:_disableStickers ? TGPhotoEditorControllerSignupAvatarIntent : TGPhotoEditorControllerAvatarIntent adjustments:nil caption:nil screenImage:thumbnailImage availableTabs:[TGPhotoEditorController defaultTabsForAvatarIntent] selectedTab:TGPhotoEditorCropTab]; + TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:[windowManager context] item:asset intent:_disableStickers ? TGPhotoEditorControllerSignupAvatarIntent : TGPhotoEditorControllerAvatarIntent adjustments:nil caption:nil screenImage:thumbnailImage availableTabs:[TGPhotoEditorController defaultTabsForAvatarIntent] selectedTab:TGPhotoEditorCropTab]; controller.editingContext = _editingContext; controller.dontHideStatusBar = true; @@ -1211,6 +1211,10 @@ const NSUInteger TGAttachmentDisplayedAssetLimit = 500; - (UIViewController *)previewingContext:(id)previewingContext viewControllerForLocation:(CGPoint)location { + if (self.openEditor) { + return nil; + } + NSIndexPath *indexPath = [_collectionView indexPathForItemAtPoint:location]; if (indexPath == nil) return nil; diff --git a/LegacyComponents/TGCameraPhotoPreviewController.m b/LegacyComponents/TGCameraPhotoPreviewController.m index 38ae0af1b6..aa650c39ee 100644 --- a/LegacyComponents/TGCameraPhotoPreviewController.m +++ b/LegacyComponents/TGCameraPhotoPreviewController.m @@ -1128,7 +1128,7 @@ bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || _context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || _context.safeAreaInset.bottom > FLT_EPSILON; CGSize referenceSize = [self referenceViewSizeForOrientation:originalOrientation]; UIEdgeInsets safeAreaInset = [TGViewController safeAreaInsetForOrientation:orientation hasOnScreenNavigation:hasOnScreenNavigation]; diff --git a/LegacyComponents/TGLocationMapViewController.h b/LegacyComponents/TGLocationMapViewController.h index fc25bfc33b..3a7484e750 100644 --- a/LegacyComponents/TGLocationMapViewController.h +++ b/LegacyComponents/TGLocationMapViewController.h @@ -65,6 +65,7 @@ - (CGFloat)visibleContentHeight; - (CGFloat)mapHeight; +- (CGFloat)safeAreaInsetBottom; - (bool)hasUserLocation; - (SSignal *)userLocationSignal; diff --git a/LegacyComponents/TGLocationMapViewController.m b/LegacyComponents/TGLocationMapViewController.m index 4edaee059b..73d55621ab 100644 --- a/LegacyComponents/TGLocationMapViewController.m +++ b/LegacyComponents/TGLocationMapViewController.m @@ -330,6 +330,10 @@ const CGFloat TGLocationMapInset = 100.0f; return 0.0f; } +- (CGFloat)safeAreaInsetBottom { + return MAX(self.context.safeAreaInset.bottom, self.controllerSafeAreaInset.bottom); +} + #pragma mark - - (void)setMapCenterCoordinate:(CLLocationCoordinate2D)coordinate offset:(CGPoint)offset animated:(bool)animated diff --git a/LegacyComponents/TGLocationPickerController.m b/LegacyComponents/TGLocationPickerController.m index 495678d64e..5dcb1fbb89 100644 --- a/LegacyComponents/TGLocationPickerController.m +++ b/LegacyComponents/TGLocationPickerController.m @@ -212,9 +212,9 @@ const CGPoint TGLocationPickerPinOffset = { 0.0f, 33.0f }; _activityIndicator.alpha = 0.0f; [self setIsLoading:true]; - if (self.controllerSafeAreaInset.bottom > FLT_EPSILON) + if (self.safeAreaInsetBottom > FLT_EPSILON) { - _safeAreaCurtainView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, _tableView.frame.size.width, self.controllerSafeAreaInset.bottom)]; + _safeAreaCurtainView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, _tableView.frame.size.width, self.safeAreaInsetBottom)]; _safeAreaCurtainView.backgroundColor = self.pallete != nil ? self.pallete.sectionHeaderBackgroundColor : UIColorRGB(0xf7f7f7); } @@ -680,7 +680,7 @@ const CGPoint TGLocationPickerPinOffset = { 0.0f, 33.0f }; void (^changeBlock)(void) = ^ { _tableView.contentOffset = CGPointMake(0, -_tableView.contentInset.top); - _tableView.frame = CGRectMake(_tableView.frame.origin.x, self.view.frame.size.height - [self mapHeight] - TGLocationCurrentLocationCellHeight - self.controllerInset.top - self.controllerSafeAreaInset.bottom, _tableView.frame.size.width, _tableView.frame.size.height); + _tableView.frame = CGRectMake(_tableView.frame.origin.x, self.view.frame.size.height - [self mapHeight] - TGLocationCurrentLocationCellHeight - self.controllerInset.top - self.safeAreaInsetBottom, _tableView.frame.size.width, _tableView.frame.size.height); _mapViewWrapper.frame = CGRectMake(0, TGLocationMapClipHeight - self.view.frame.size.height + self.controllerInset.top + 20, _mapViewWrapper.frame.size.width, self.view.frame.size.height - self.controllerInset.top - 10.0f); _mapView.center = CGPointMake(_mapView.center.x, _mapViewWrapper.frame.size.height / 2); @@ -1298,7 +1298,7 @@ const CGPoint TGLocationPickerPinOffset = { 0.0f, 33.0f }; - (CGFloat)visibleContentHeight { - return (_allowLiveLocationSharing ? 165.0f : 97.0f) + self.controllerSafeAreaInset.bottom; + return (_allowLiveLocationSharing ? 165.0f : 97.0f) + self.safeAreaInsetBottom; } @end diff --git a/LegacyComponents/TGLocationViewController.m b/LegacyComponents/TGLocationViewController.m index 5f876bb47a..084578d1c1 100644 --- a/LegacyComponents/TGLocationViewController.m +++ b/LegacyComponents/TGLocationViewController.m @@ -1164,9 +1164,9 @@ - (CGFloat)visibleContentHeight { if (![self isLiveLocation]) - return TGLocationInfoCellHeight + self.controllerSafeAreaInset.bottom; + return TGLocationInfoCellHeight + self.safeAreaInsetBottom; else - return TGLocationLiveCellHeight + self.controllerSafeAreaInset.bottom; + return TGLocationLiveCellHeight + self.safeAreaInsetBottom; } - (CGFloat)possibleContentHeight @@ -1182,7 +1182,7 @@ count = MIN(1.5f, count); height += count * TGLocationLiveCellHeight; } - return height + self.controllerSafeAreaInset.bottom; + return height + self.safeAreaInsetBottom; } else { @@ -1191,7 +1191,7 @@ count += 1; count = MIN(2.5f, count); CGFloat height = count * TGLocationLiveCellHeight; - return height + self.controllerSafeAreaInset.bottom; + return height + self.safeAreaInsetBottom; } } diff --git a/LegacyComponents/TGMediaAssetsController.m b/LegacyComponents/TGMediaAssetsController.m index 770f38fb3d..a97ce15cec 100644 --- a/LegacyComponents/TGMediaAssetsController.m +++ b/LegacyComponents/TGMediaAssetsController.m @@ -391,7 +391,7 @@ bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || _context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || _context.safeAreaInset.bottom > FLT_EPSILON; CGFloat inset = [TGViewController safeAreaInsetForOrientation:self.interfaceOrientation hasOnScreenNavigation:hasOnScreenNavigation].bottom; _toolbarView = [[TGMediaPickerToolbarView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - TGMediaPickerToolbarHeight - inset, self.view.frame.size.width, TGMediaPickerToolbarHeight + inset)]; @@ -464,7 +464,7 @@ bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || _context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || _context.safeAreaInset.bottom > FLT_EPSILON; _toolbarView.safeAreaInset = [TGViewController safeAreaInsetForOrientation:orientation hasOnScreenNavigation:hasOnScreenNavigation]; diff --git a/LegacyComponents/TGMediaAssetsPickerController.m b/LegacyComponents/TGMediaAssetsPickerController.m index 5e172e175e..2adfbf9067 100644 --- a/LegacyComponents/TGMediaAssetsPickerController.m +++ b/LegacyComponents/TGMediaAssetsPickerController.m @@ -149,8 +149,6 @@ { [super viewDidLoad]; - [self setRightBarButtonItem:[(TGMediaAssetsController *)self.navigationController rightBarButtonItem]]; - SSignal *groupSignal = nil; if (_assetGroup != nil) groupSignal = [SSignal single:_assetGroup]; @@ -219,6 +217,7 @@ [super viewWillAppear:animated]; [self setup3DTouch]; + [self setRightBarButtonItem:[(TGMediaAssetsController *)self.navigationController rightBarButtonItem]]; } #pragma mark - @@ -448,6 +447,11 @@ return; _checked3dTouch = true; + + if (_intent == TGMediaAssetsControllerSetProfilePhotoIntent || _intent == TGMediaAssetsControllerSetSignupProfilePhotoIntent) { + return; + } + if (iosMajorVersion() >= 9) { if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) diff --git a/LegacyComponents/TGMediaPickerController.m b/LegacyComponents/TGMediaPickerController.m index ba995224d1..dbc109f32d 100644 --- a/LegacyComponents/TGMediaPickerController.m +++ b/LegacyComponents/TGMediaPickerController.m @@ -98,7 +98,7 @@ bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || self.context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || self.context.safeAreaInset.bottom > FLT_EPSILON; UIInterfaceOrientation orientation = UIInterfaceOrientationPortrait; if (self.view.frame.size.width > self.view.frame.size.height) @@ -292,7 +292,7 @@ bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || self.context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || self.context.safeAreaInset.bottom > FLT_EPSILON; UIEdgeInsets safeAreaInset = [TGViewController safeAreaInsetForOrientation:orientation hasOnScreenNavigation:hasOnScreenNavigation]; diff --git a/LegacyComponents/TGMenuSheetController.m b/LegacyComponents/TGMenuSheetController.m index 68ed00b23c..81b1e09496 100644 --- a/LegacyComponents/TGMenuSheetController.m +++ b/LegacyComponents/TGMenuSheetController.m @@ -943,7 +943,7 @@ typedef enum { bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || _context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || _context.safeAreaInset.bottom > FLT_EPSILON; UIEdgeInsets safeAreaInset = [TGViewController safeAreaInsetForOrientation:orientation hasOnScreenNavigation:hasOnScreenNavigation]; if (safeAreaInset.bottom > FLT_EPSILON) diff --git a/LegacyComponents/TGPhotoAvatarCropController.m b/LegacyComponents/TGPhotoAvatarCropController.m index 647061e49d..bd7b74f52e 100644 --- a/LegacyComponents/TGPhotoAvatarCropController.m +++ b/LegacyComponents/TGPhotoAvatarCropController.m @@ -310,7 +310,7 @@ const CGFloat TGPhotoAvatarCropButtonsWrapperSize = 61.0f; bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || self.context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || self.context.safeAreaInset.bottom > FLT_EPSILON; CGRect cropRectFrame = [_cropView cropRectFrameForView:self.view]; CGSize referenceSize = [self referenceViewSizeForOrientation:orientation]; @@ -319,7 +319,7 @@ const CGFloat TGPhotoAvatarCropButtonsWrapperSize = 61.0f; if (self.switchingToTab == TGPhotoEditorPaintTab) { - containerFrame = [TGPhotoPaintController photoContainerFrameForParentViewFrame:referenceBounds toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoPaintTopPanelSize + TGPhotoPaintBottomPanelSize]; + containerFrame = [TGPhotoPaintController photoContainerFrameForParentViewFrame:referenceBounds toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoPaintTopPanelSize + TGPhotoPaintBottomPanelSize hasOnScreenNavigation:hasOnScreenNavigation]; } CGSize fittedSize = TGScaleToSize(cropRectFrame.size, containerFrame.size); @@ -435,7 +435,7 @@ const CGFloat TGPhotoAvatarCropButtonsWrapperSize = 61.0f; bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || self.context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || self.context.safeAreaInset.bottom > FLT_EPSILON; if ([self inFormSheet] || [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) orientation = UIInterfaceOrientationPortrait; @@ -527,7 +527,7 @@ const CGFloat TGPhotoAvatarCropButtonsWrapperSize = 61.0f; bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || self.context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || self.context.safeAreaInset.bottom > FLT_EPSILON; UIEdgeInsets safeAreaInset = [TGViewController safeAreaInsetForOrientation:orientation hasOnScreenNavigation:hasOnScreenNavigation]; UIEdgeInsets screenEdges = UIEdgeInsetsMake((screenSide - self.view.frame.size.height) / 2, (screenSide - self.view.frame.size.width) / 2, (screenSide + self.view.frame.size.height) / 2, (screenSide + self.view.frame.size.width) / 2); diff --git a/LegacyComponents/TGPhotoCropController.m b/LegacyComponents/TGPhotoCropController.m index 83e9ca2c56..1f2dbdfd46 100644 --- a/LegacyComponents/TGPhotoCropController.m +++ b/LegacyComponents/TGPhotoCropController.m @@ -383,7 +383,7 @@ NSString * const TGPhotoCropOriginalAspectRatio = @"original"; bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || _context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || _context.safeAreaInset.bottom > FLT_EPSILON; CGRect containerFrame = [TGPhotoCropController photoContainerFrameForParentViewFrame:CGRectMake(0, 0, referenceSize.width, referenceSize.height) toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation hasArbitraryRotation:_cropView.hasArbitraryRotation hasOnScreenNavigation:hasOnScreenNavigation]; containerFrame = CGRectInset(containerFrame, TGPhotoCropAreaInsetSize.width, TGPhotoCropAreaInsetSize.height); @@ -806,7 +806,7 @@ NSString * const TGPhotoCropOriginalAspectRatio = @"original"; bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || _context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || _context.safeAreaInset.bottom > FLT_EPSILON; UIEdgeInsets safeAreaInset = [TGViewController safeAreaInsetForOrientation:orientation hasOnScreenNavigation:hasOnScreenNavigation]; UIEdgeInsets screenEdges = UIEdgeInsetsMake((screenSide - referenceSize.height) / 2 , (screenSide - referenceSize.width) / 2, (screenSide + referenceSize.height) / 2, (screenSide + referenceSize.width) / 2); diff --git a/LegacyComponents/TGPhotoEditorController.m b/LegacyComponents/TGPhotoEditorController.m index 1c89bce22f..ba3da96b98 100644 --- a/LegacyComponents/TGPhotoEditorController.m +++ b/LegacyComponents/TGPhotoEditorController.m @@ -286,7 +286,7 @@ bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || _context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || _context.safeAreaInset.bottom > FLT_EPSILON; CGRect containerFrame = [TGPhotoEditorTabController photoContainerFrameForParentViewFrame:self.view.frame toolbarLandscapeSize:TGPhotoEditorToolbarSize orientation:orientation panelSize:TGPhotoEditorPanelSize hasOnScreenNavigation:hasOnScreenNavigation]; CGSize fittedSize = TGScaleToSize(_photoEditor.rotatedCropSize, containerFrame.size); diff --git a/LegacyComponents/TGPhotoEditorItemController.m b/LegacyComponents/TGPhotoEditorItemController.m index 76a3e837ee..659c96c8cd 100644 --- a/LegacyComponents/TGPhotoEditorItemController.m +++ b/LegacyComponents/TGPhotoEditorItemController.m @@ -682,7 +682,7 @@ bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || self.context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || self.context.safeAreaInset.bottom > FLT_EPSILON; CGRect containerFrame = [TGPhotoEditorTabController photoContainerFrameForParentViewFrame:CGRectMake(0, 0, referenceSize.width, referenceSize.height) toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoEditorPanelSize hasOnScreenNavigation:hasOnScreenNavigation]; CGSize fittedSize = TGScaleToSize(photoEditor.rotatedCropSize, containerFrame.size); diff --git a/LegacyComponents/TGPhotoEditorTabController.m b/LegacyComponents/TGPhotoEditorTabController.m index b3d73e921b..76d7ac95a2 100644 --- a/LegacyComponents/TGPhotoEditorTabController.m +++ b/LegacyComponents/TGPhotoEditorTabController.m @@ -301,7 +301,7 @@ const CGFloat TGPhotoEditorToolbarSize = 49.0f; { bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || self.context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || self.context.safeAreaInset.bottom > FLT_EPSILON; CGRect containerFrame = [TGPhotoEditorTabController photoContainerFrameForParentViewFrame:self.view.frame toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoEditorPanelSize hasOnScreenNavigation:hasOnScreenNavigation]; CGSize fittedSize = TGScaleToSize(referenceFrame.size, containerFrame.size); @@ -328,7 +328,7 @@ const CGFloat TGPhotoEditorToolbarSize = 49.0f; bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || self.context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || self.context.safeAreaInset.bottom > FLT_EPSILON; CGRect containerFrame = [TGPhotoEditorTabController photoContainerFrameForParentViewFrame:CGRectMake(0, 0, referenceSize.width, referenceSize.height) toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoEditorPanelSize hasOnScreenNavigation:hasOnScreenNavigation]; CGSize fittedSize = TGScaleToSize(fromFrame.size, containerFrame.size); diff --git a/LegacyComponents/TGPhotoPaintController.h b/LegacyComponents/TGPhotoPaintController.h index dca873fef2..d343bc4453 100644 --- a/LegacyComponents/TGPhotoPaintController.h +++ b/LegacyComponents/TGPhotoPaintController.h @@ -11,7 +11,7 @@ - (TGPaintingData *)paintingData; -+ (CGRect)photoContainerFrameForParentViewFrame:(CGRect)parentViewFrame toolbarLandscapeSize:(CGFloat)toolbarLandscapeSize orientation:(UIInterfaceOrientation)orientation panelSize:(CGFloat)panelSize; ++ (CGRect)photoContainerFrameForParentViewFrame:(CGRect)parentViewFrame toolbarLandscapeSize:(CGFloat)toolbarLandscapeSize orientation:(UIInterfaceOrientation)orientation panelSize:(CGFloat)panelSize hasOnScreenNavigation:(bool)hasOnScreenNavigation; @end diff --git a/LegacyComponents/TGPhotoPaintController.m b/LegacyComponents/TGPhotoPaintController.m index 836c0ca16c..a00ee1e6f7 100644 --- a/LegacyComponents/TGPhotoPaintController.m +++ b/LegacyComponents/TGPhotoPaintController.m @@ -1569,7 +1569,11 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) orientation = UIInterfaceOrientationPortrait; - CGRect containerFrame = [TGPhotoPaintController photoContainerFrameForParentViewFrame:CGRectMake(0, 0, referenceSize.width, referenceSize.height) toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoPaintTopPanelSize + TGPhotoPaintBottomPanelSize]; + bool hasOnScreenNavigation = false; + if (iosMajorVersion() >= 11) + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || _context.safeAreaInset.bottom > FLT_EPSILON; + + CGRect containerFrame = [TGPhotoPaintController photoContainerFrameForParentViewFrame:CGRectMake(0, 0, referenceSize.width, referenceSize.height) toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoPaintTopPanelSize + TGPhotoPaintBottomPanelSize hasOnScreenNavigation:hasOnScreenNavigation]; CGSize fittedSize = TGScaleToSize(fromFrame.size, containerFrame.size); CGRect toFrame = CGRectMake(containerFrame.origin.x + (containerFrame.size.width - fittedSize.width) / 2, containerFrame.origin.y + (containerFrame.size.height - fittedSize.height) / 2, fittedSize.width, fittedSize.height); @@ -1650,7 +1654,11 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; - (CGRect)transitionOutSourceFrameForReferenceFrame:(CGRect)referenceFrame orientation:(UIInterfaceOrientation)orientation { - CGRect containerFrame = [TGPhotoPaintController photoContainerFrameForParentViewFrame:self.view.frame toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoPaintTopPanelSize + TGPhotoPaintBottomPanelSize]; + bool hasOnScreenNavigation = false; + if (iosMajorVersion() >= 11) + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || _context.safeAreaInset.bottom > FLT_EPSILON; + + CGRect containerFrame = [TGPhotoPaintController photoContainerFrameForParentViewFrame:self.view.frame toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoPaintTopPanelSize + TGPhotoPaintBottomPanelSize hasOnScreenNavigation:hasOnScreenNavigation]; CGSize fittedSize = TGScaleToSize(referenceFrame.size, containerFrame.size); return CGRectMake(containerFrame.origin.x + (containerFrame.size.width - fittedSize.width) / 2, containerFrame.origin.y + (containerFrame.size.height - fittedSize.height) / 2, fittedSize.width, fittedSize.height); @@ -1666,11 +1674,15 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; TGPhotoEditorPreviewView *previewView = self.previewView; [previewView prepareForTransitionOut]; + bool hasOnScreenNavigation = false; + if (iosMajorVersion() >= 11) + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || _context.safeAreaInset.bottom > FLT_EPSILON; + UIInterfaceOrientation orientation = self.interfaceOrientation; if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) orientation = UIInterfaceOrientationPortrait; - CGRect containerFrame = [TGPhotoPaintController photoContainerFrameForParentViewFrame:self.view.frame toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoPaintTopPanelSize + TGPhotoPaintBottomPanelSize]; + CGRect containerFrame = [TGPhotoPaintController photoContainerFrameForParentViewFrame:self.view.frame toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoPaintTopPanelSize + TGPhotoPaintBottomPanelSize hasOnScreenNavigation:hasOnScreenNavigation]; CGRect referenceFrame = CGRectMake(0, 0, self.photoEditor.rotatedCropSize.width, self.photoEditor.rotatedCropSize.height); CGRect rect = CGRectOffset([self transitionOutSourceFrameForReferenceFrame:referenceFrame orientation:orientation], -containerFrame.origin.x, -containerFrame.origin.y); previewView.frame = rect; @@ -1896,7 +1908,7 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || _context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || _context.safeAreaInset.bottom > FLT_EPSILON; UIEdgeInsets safeAreaInset = [TGViewController safeAreaInsetForOrientation:orientation hasOnScreenNavigation:hasOnScreenNavigation]; UIEdgeInsets screenEdges = UIEdgeInsetsMake((screenSide - referenceSize.height) / 2, (screenSide - referenceSize.width) / 2, (screenSide + referenceSize.height) / 2, (screenSide + referenceSize.width) / 2); @@ -1905,7 +1917,7 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; screenEdges.bottom -= safeAreaInset.bottom; screenEdges.right -= safeAreaInset.right; - CGRect containerFrame = [TGPhotoPaintController photoContainerFrameForParentViewFrame:CGRectMake(0, 0, referenceSize.width, referenceSize.height) toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoPaintTopPanelSize + TGPhotoPaintBottomPanelSize]; + CGRect containerFrame = [TGPhotoPaintController photoContainerFrameForParentViewFrame:CGRectMake(0, 0, referenceSize.width, referenceSize.height) toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoPaintTopPanelSize + TGPhotoPaintBottomPanelSize hasOnScreenNavigation:hasOnScreenNavigation]; _settingsViewWrapper.frame = self.parentViewController.view.bounds; @@ -2077,10 +2089,14 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; if ([self inFormSheet] || [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) orientation = UIInterfaceOrientationPortrait; + bool hasOnScreenNavigation = false; + if (iosMajorVersion() >= 11) + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || _context.safeAreaInset.bottom > FLT_EPSILON; + CGSize referenceSize = [self referenceViewSize]; CGFloat screenSide = MAX(referenceSize.width, referenceSize.height) + 2 * TGPhotoPaintBottomPanelSize; - CGRect containerFrame = [TGPhotoPaintController photoContainerFrameForParentViewFrame:CGRectMake(0, 0, referenceSize.width, referenceSize.height) toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoPaintTopPanelSize + TGPhotoPaintBottomPanelSize]; + CGRect containerFrame = [TGPhotoPaintController photoContainerFrameForParentViewFrame:CGRectMake(0, 0, referenceSize.width, referenceSize.height) toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoPaintTopPanelSize + TGPhotoPaintBottomPanelSize hasOnScreenNavigation:hasOnScreenNavigation]; CGFloat visibleArea = self.view.frame.size.height - height; CGFloat yCenter = visibleArea / 2.0f; diff --git a/LegacyComponents/TGPhotoQualityController.m b/LegacyComponents/TGPhotoQualityController.m index cb11a96f38..5df162adfc 100644 --- a/LegacyComponents/TGPhotoQualityController.m +++ b/LegacyComponents/TGPhotoQualityController.m @@ -443,7 +443,7 @@ const NSTimeInterval TGPhotoQualityPreviewDuration = 15.0f; { bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || self.context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || self.context.safeAreaInset.bottom > FLT_EPSILON; CGRect containerFrame = [TGPhotoQualityController photoContainerFrameForParentViewFrame:self.view.frame toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoEditorQualityPanelSize hasOnScreenNavigation:hasOnScreenNavigation]; CGSize fittedSize = TGScaleToSize(referenceFrame.size, containerFrame.size); @@ -462,7 +462,7 @@ const NSTimeInterval TGPhotoQualityPreviewDuration = 15.0f; bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || self.context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || self.context.safeAreaInset.bottom > FLT_EPSILON; CGRect containerFrame = [TGPhotoQualityController photoContainerFrameForParentViewFrame:CGRectMake(0, 0, referenceSize.width, referenceSize.height) toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoEditorQualityPanelSize hasOnScreenNavigation:hasOnScreenNavigation]; CGSize fittedSize = TGScaleToSize(fromFrame.size, containerFrame.size); @@ -516,7 +516,7 @@ const NSTimeInterval TGPhotoQualityPreviewDuration = 15.0f; bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || self.context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || self.context.safeAreaInset.bottom > FLT_EPSILON; UIEdgeInsets safeAreaInset = [TGViewController safeAreaInsetForOrientation:orientation hasOnScreenNavigation:hasOnScreenNavigation]; UIEdgeInsets screenEdges = UIEdgeInsetsMake((screenSide - referenceSize.height) / 2 , (screenSide - referenceSize.width) / 2, (screenSide + referenceSize.height) / 2, (screenSide + referenceSize.width) / 2); diff --git a/LegacyComponents/TGPhotoToolsController.m b/LegacyComponents/TGPhotoToolsController.m index a835f09c1f..6e7ac44a2b 100644 --- a/LegacyComponents/TGPhotoToolsController.m +++ b/LegacyComponents/TGPhotoToolsController.m @@ -765,7 +765,7 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize { bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || self.context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || self.context.safeAreaInset.bottom > FLT_EPSILON; CGRect containerFrame = [TGPhotoToolsController photoContainerFrameForParentViewFrame:self.view.frame toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoEditorPanelSize hasOnScreenNavigation:hasOnScreenNavigation]; CGSize fittedSize = TGScaleToSize(referenceFrame.size, containerFrame.size); @@ -784,7 +784,7 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || self.context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || self.context.safeAreaInset.bottom > FLT_EPSILON; CGRect containerFrame = [TGPhotoToolsController photoContainerFrameForParentViewFrame:CGRectMake(0, 0, referenceSize.width, referenceSize.height) toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoEditorPanelSize hasOnScreenNavigation:hasOnScreenNavigation]; CGSize fittedSize = TGScaleToSize(fromFrame.size, containerFrame.size); @@ -821,7 +821,7 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || self.context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || self.context.safeAreaInset.bottom > FLT_EPSILON; UIEdgeInsets safeAreaInset = [TGViewController safeAreaInsetForOrientation:orientation hasOnScreenNavigation:hasOnScreenNavigation]; UIEdgeInsets screenEdges = UIEdgeInsetsMake((screenSide - referenceSize.height) / 2, (screenSide - referenceSize.width) / 2, (screenSide + referenceSize.height) / 2, (screenSide + referenceSize.width) / 2); @@ -948,7 +948,7 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || self.context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || self.context.safeAreaInset.bottom > FLT_EPSILON; CGRect containerFrame = _preview ? CGRectMake(0.0f, 0.0f, referenceSize.width, referenceSize.height) : [TGPhotoToolsController photoContainerFrameForParentViewFrame:CGRectMake(0, 0, referenceSize.width, referenceSize.height) toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoEditorPanelSize hasOnScreenNavigation:hasOnScreenNavigation]; CGSize fittedSize = TGScaleToSize(photoEditor.rotatedCropSize, containerFrame.size); diff --git a/LegacyComponents/TGViewController.mm b/LegacyComponents/TGViewController.mm index 775c29fd9f..9b7324e91e 100644 --- a/LegacyComponents/TGViewController.mm +++ b/LegacyComponents/TGViewController.mm @@ -1089,9 +1089,9 @@ static id _defaultContext = nil; bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || _context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || _context.safeAreaInset.bottom > FLT_EPSILON; - return [TGViewController safeAreaInsetForOrientation:orientation hasOnScreenNavigation: hasOnScreenNavigation]; + return [TGViewController safeAreaInsetForOrientation:orientation hasOnScreenNavigation:hasOnScreenNavigation]; } + (UIEdgeInsets)safeAreaInsetForOrientation:(UIInterfaceOrientation)orientation hasOnScreenNavigation:(bool)hasOnScreenNavigation @@ -1122,7 +1122,7 @@ static id _defaultContext = nil; { bool hasOnScreenNavigation = false; if (iosMajorVersion() >= 11) - hasOnScreenNavigation = self.view.safeAreaInsets.bottom > FLT_EPSILON || _context.safeAreaInset.bottom > FLT_EPSILON; + hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || _context.safeAreaInset.bottom > FLT_EPSILON; UIEdgeInsets safeAreaInset = [TGViewController safeAreaInsetForOrientation:orientation hasOnScreenNavigation:hasOnScreenNavigation]; CGFloat navigationBarHeight = ([self navigationBarShouldBeHidden] || [self shouldIgnoreNavigationBar]) ? 0 : [self navigationBarHeightForInterfaceOrientation:orientation];