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

View-only tvOS support #1218

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
172 changes: 171 additions & 1 deletion Example-Objc/FSCalendar.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions FSCalendar.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Pod::Spec.new do |s|

s.platform = :ios
s.ios.deployment_target = '8.0'
s.tvos.deployment_target = '9.0'
s.requires_arc = true
s.framework = 'UIKit', 'QuartzCore'
s.source_files = 'FSCalendar/*.{h,m}'
Expand Down
23 changes: 18 additions & 5 deletions FSCalendar/FSCalendar.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ - (void)initialize
collectionView.delegate = self;
collectionView.internalDelegate = self;
collectionView.backgroundColor = [UIColor clearColor];
#if !TARGET_OS_TV
collectionView.pagingEnabled = YES;
#endif
collectionView.showsHorizontalScrollIndicator = NO;
collectionView.showsVerticalScrollIndicator = NO;
collectionView.allowsMultipleSelection = NO;
Expand All @@ -228,17 +230,20 @@ - (void)initialize
// Assistants
self.transitionCoordinator = [[FSCalendarTransitionCoordinator alloc] initWithCalendar:self];
self.calculator = [[FSCalendarCalculator alloc] initWithCalendar:self];


#if !TARGET_OS_TV
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
#endif
}

- (void)dealloc
{
self.collectionView.delegate = nil;
self.collectionView.dataSource = nil;


#if !TARGET_OS_TV
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
#endif
}

#pragma mark - Overriden methods
Expand Down Expand Up @@ -944,8 +949,10 @@ - (UIPanGestureRecognizer *)scopeGesture
if (!_scopeGesture) {
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self.transitionCoordinator action:@selector(handleScopeGesture:)];
panGesture.delegate = self.transitionCoordinator;
#if !TARGET_OS_TV
panGesture.minimumNumberOfTouches = 1;
panGesture.maximumNumberOfTouches = 2;
#endif
panGesture.enabled = NO;
[self.daysContainer addGestureRecognizer:panGesture];
_scopeGesture = panGesture;
Expand All @@ -959,7 +966,9 @@ - (UILongPressGestureRecognizer *)swipeToChooseGesture
UILongPressGestureRecognizer *pressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeToChoose:)];
pressGesture.enabled = NO;
pressGesture.numberOfTapsRequired = 0;
#if !TARGET_OS_TV
pressGesture.numberOfTouchesRequired = 1;
#endif
pressGesture.minimumPressDuration = 0.7;
[self.daysContainer addGestureRecognizer:pressGesture];
[self.collectionView.panGestureRecognizer requireGestureRecognizerToFail:pressGesture];
Expand Down Expand Up @@ -1306,17 +1315,21 @@ - (void)invalidateLayout
} else if (_deliver) {
[_deliver removeFromSuperview];
}


#if !TARGET_OS_TV
_collectionView.pagingEnabled = YES;
#endif
_collectionViewLayout.scrollDirection = (UICollectionViewScrollDirection)self.scrollDirection;

} else {

[self.calendarHeaderView removeFromSuperview];
[self.deliver removeFromSuperview];
[self.calendarWeekdayView removeFromSuperview];


#if !TARGET_OS_TV
_collectionView.pagingEnabled = NO;
#endif
_collectionViewLayout.scrollDirection = UICollectionViewScrollDirectionVertical;

}
Expand Down
2 changes: 2 additions & 0 deletions FSCalendar/FSCalendarCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ - (void)layoutSubviews

CGFloat titleHeight = self.bounds.size.height*5.0/6.0;
CGFloat diameter = MIN(self.bounds.size.height*5.0/6.0,self.bounds.size.width);
#if !TARGET_OS_TV
diameter = diameter > FSCalendarStandardCellDiameter ? (diameter - (diameter-FSCalendarStandardCellDiameter)*0.5) : diameter;
#endif
_shapeLayer.frame = CGRectMake((self.bounds.size.width-diameter)/2,
(titleHeight-diameter)/2,
diameter,
Expand Down
8 changes: 6 additions & 2 deletions FSCalendar/FSCalendarCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ - (instancetype)initWithFrame:(CGRect)frame

- (void)commonInit
{
#if !TARGET_OS_TV
self.scrollsToTop = NO;
#endif
self.contentInset = UIEdgeInsetsZero;
if (@available(iOS 10.0, *)) self.prefetchingEnabled = NO;
if (@available(iOS 11.0, *)) self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
if (@available(iOS 10.0, tvOS 10.0, *)) self.prefetchingEnabled = NO;
if (@available(iOS 11.0, tvOS 11.0, *)) self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}

- (void)layoutSubviews
Expand All @@ -64,10 +66,12 @@ - (void)setContentInset:(UIEdgeInsets)contentInset
}
}

#if !TARGET_OS_TV
- (void)setScrollsToTop:(BOOL)scrollsToTop
{
[super setScrollsToTop:NO];
}
#endif

@end

Expand Down
8 changes: 7 additions & 1 deletion FSCalendar/FSCalendarCollectionViewLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ - (instancetype)init
self.itemAttributes = NSMutableDictionary.dictionary;
self.headerAttributes = NSMutableDictionary.dictionary;
self.rowSeparatorAttributes = NSMutableDictionary.dictionary;


#if !TARGET_OS_TV
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNotifications:) name:UIDeviceOrientationDidChangeNotification object:nil];
#endif
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNotifications:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];

[self registerClass:FSCalendarSeparatorDecorationView.class forDecorationViewOfKind:kFSCalendarSeparatorInterRows];
Expand All @@ -82,7 +84,9 @@ - (instancetype)init
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
#if !TARGET_OS_TV
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
#endif

free(self.widths);
free(self.heights);
Expand Down Expand Up @@ -511,9 +515,11 @@ - (BOOL)flipsHorizontallyInOppositeLayoutDirection

- (void)didReceiveNotifications:(NSNotification *)notification
{
#if !TARGET_OS_TV
if ([notification.name isEqualToString:UIDeviceOrientationDidChangeNotification]) {
[self invalidateLayout];
}
#endif
if ([notification.name isEqualToString:UIApplicationDidReceiveMemoryWarningNotification]) {
[self.itemAttributes removeAllObjects];
[self.headerAttributes removeAllObjects];
Expand Down
4 changes: 4 additions & 0 deletions FSCalendar/FSCalendarHeaderView.m
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,18 @@ - (instancetype)init
self.minimumLineSpacing = 0;
self.sectionInset = UIEdgeInsetsZero;
self.itemSize = CGSizeMake(1, 1);
#if !TARGET_OS_TV
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(didReceiveOrientationChangeNotification:) name:UIDeviceOrientationDidChangeNotification object:nil];
#endif
}
return self;
}

- (void)dealloc
{
#if !TARGET_OS_TV
[NSNotificationCenter.defaultCenter removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
#endif
}

- (void)prepareLayout
Expand Down