Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for better orientation detection and also layout not updating correctly upon orientation change! #1407

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions FSCalendar/FSCalendar.m
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,8 @@ - (void)layoutSubviews

if (_needsAdjustingViewFrame) {
_needsAdjustingViewFrame = NO;

if (CGSizeEqualToSize(_transitionCoordinator.cachedMonthSize, CGSizeZero)) {
_transitionCoordinator.cachedMonthSize = self.frame.size;
}

_transitionCoordinator.cachedMonthSize = self.frame.size;

_contentView.frame = self.bounds;
CGFloat headerHeight = self.preferredHeaderHeight;
Expand Down Expand Up @@ -650,6 +648,8 @@ - (void)orientationDidChange:(NSNotification *)notification
self.orientation = self.currentCalendarOrientation;
}



#pragma mark - Properties

- (void)setScrollDirection:(FSCalendarScrollDirection)scrollDirection
Expand Down Expand Up @@ -874,6 +874,7 @@ - (void)setOrientation:(FSCalendarOrientation)orientation
_preferredWeekdayHeight = FSCalendarAutomaticDimension;
_preferredRowHeight = FSCalendarAutomaticDimension;
_preferredHeaderHeight = FSCalendarAutomaticDimension;

[self setNeedsLayout];
}
}
Expand Down Expand Up @@ -1529,14 +1530,22 @@ - (void)invalidateViewFrames
}

// The best way to detect orientation
// http://stackoverflow.com/questions/25830448/what-is-the-best-way-to-detect-orientation-in-an-app-extension/26023538#26023538
- (FSCalendarOrientation)currentCalendarOrientation
{
CGFloat scale = [UIScreen mainScreen].scale;
CGSize nativeSize = [UIScreen mainScreen].currentMode.size;
CGSize sizeInPoints = [UIScreen mainScreen].bounds.size;
FSCalendarOrientation orientation = scale * sizeInPoints.width == nativeSize.width ? FSCalendarOrientationPortrait : FSCalendarOrientationLandscape;
return orientation;
if (@available(iOS 13.0, *)) {
UIWindowScene *windowScene = nil;
for (UIWindowScene *scene in UIApplication.sharedApplication.connectedScenes) {
if ([scene isKindOfClass:UIWindowScene.class] && scene.activationState == UISceneActivationStateForegroundActive) {
windowScene = scene;
break;
}
}
return windowScene.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || windowScene.interfaceOrientation == UIInterfaceOrientationLandscapeRight ? FSCalendarOrientationLandscape : FSCalendarOrientationPortrait;
} else {
//deprecated
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
return orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight ? FSCalendarOrientationLandscape : FSCalendarOrientationPortrait;
}
}

- (void)adjustMonthPosition
Expand Down