Skip to content

Commit

Permalink
#Tabs Add nullability annotations
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 620068266
  • Loading branch information
codeman7 authored and material-automation committed Mar 28, 2024
1 parent fdfeaf6 commit 69f2f02
Show file tree
Hide file tree
Showing 20 changed files with 122 additions and 42 deletions.
4 changes: 4 additions & 0 deletions components/Tabs/src/TabBarView/MDCTabBarItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

#import "MDCTabBarItemCustomViewing.h"

NS_ASSUME_NONNULL_BEGIN

/**
A subclass of @c UITabBarItem that supports a custom view property.
*/
__attribute__((objc_subclassing_restricted)) @interface MDCTabBarItem
: UITabBarItem<MDCTabBarItemCustomViewing>
@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions components/Tabs/src/TabBarView/MDCTabBarItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@

#import "MDCTabBarItem.h"

NS_ASSUME_NONNULL_BEGIN

@implementation MDCTabBarItem

@synthesize mdc_customView = _mdc_customView;

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions components/Tabs/src/TabBarView/MDCTabBarItemCustomViewing.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#import "MDCTabBarViewCustomViewable.h"

NS_ASSUME_NONNULL_BEGIN

/**
Defines the necessary APIs for MDCTabBarView to use a UITabBarItem for a custom view property.
Expand All @@ -28,3 +30,5 @@
@property(nullable, nonatomic, strong) UIView<MDCTabBarViewCustomViewable> *mdc_customView;

@end

NS_ASSUME_NONNULL_END
6 changes: 5 additions & 1 deletion components/Tabs/src/TabBarView/MDCTabBarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#import "MDCAvailability.h"

NS_ASSUME_NONNULL_BEGIN

@protocol MDCTabBarViewDelegate;
@protocol MDCTabBarViewIndicatorTemplate;

Expand Down Expand Up @@ -271,7 +273,7 @@ __attribute__((objc_subclassing_restricted)) @interface MDCTabBarView : UIScroll
@param item The tab bar item to be centered.
@param animated Whether to animate the scroll.
*/
- (void)scrollToItem:(UITabBarItem *)item animated:(BOOL)animated;
- (void)scrollToItem:(nonnull UITabBarItem *)item animated:(BOOL)animated;

/**
The color for the Ripple effect for touch feedback.
Expand All @@ -298,3 +300,5 @@ __attribute__((objc_subclassing_restricted)) @interface MDCTabBarView : UIScroll
UILargeContentViewerInteractionDelegate>
@end
#endif // MDC_AVAILABLE_SDK_IOS(13_0)

NS_ASSUME_NONNULL_END
54 changes: 29 additions & 25 deletions components/Tabs/src/TabBarView/MDCTabBarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#import <CoreGraphics/CoreGraphics.h>
#import <QuartzCore/QuartzCore.h>

NS_ASSUME_NONNULL_BEGIN

// KVO contexts
static char *const kKVOContextMDCTabBarView = "kKVOContextMDCTabBarView";

Expand Down Expand Up @@ -149,7 +151,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self commonMDCTabBarViewInit];
Expand Down Expand Up @@ -220,11 +222,11 @@ - (void)dealloc {

#pragma mark - Properties

- (void)setBarTintColor:(UIColor *)barTintColor {
- (void)setBarTintColor:(nullable UIColor *)barTintColor {
self.backgroundColor = barTintColor;
}

- (UIColor *)barTintColor {
- (nullable UIColor *)barTintColor {
return self.backgroundColor;
}

Expand All @@ -243,7 +245,7 @@ - (void)setRippleColor:(UIColor *)rippleColor {
[self updateRippleColorForAllViews];
}

- (void)setSelectionIndicatorStrokeColor:(UIColor *)selectionIndicatorStrokeColor {
- (void)setSelectionIndicatorStrokeColor:(nullable UIColor *)selectionIndicatorStrokeColor {
_selectionIndicatorStrokeColor = selectionIndicatorStrokeColor ?: UIColor.blackColor;
self.selectionIndicatorView.tintColor = self.selectionIndicatorStrokeColor;
}
Expand Down Expand Up @@ -383,11 +385,11 @@ - (void)setDisableRippleBehavior:(BOOL)disableRippleBehavior {
}
}

- (void)setSelectedItem:(UITabBarItem *)selectedItem {
- (void)setSelectedItem:(nullable UITabBarItem *)selectedItem {
[self setSelectedItem:selectedItem animated:YES];
}

- (void)setSelectedItem:(UITabBarItem *)selectedItem animated:(BOOL)animated {
- (void)setSelectedItem:(nullable UITabBarItem *)selectedItem animated:(BOOL)animated {
if (self.selectedItem == selectedItem) {
return;
}
Expand Down Expand Up @@ -458,12 +460,12 @@ - (void)updateImageTintColorForAllViews {
}
}

- (void)setImageTintColor:(UIColor *)imageTintColor forState:(UIControlState)state {
- (void)setImageTintColor:(nullable UIColor *)imageTintColor forState:(UIControlState)state {
self.stateToImageTintColor[@(state)] = imageTintColor;
[self updateImageTintColorForAllViews];
}

- (UIColor *)imageTintColorForState:(UIControlState)state {
- (nullable UIColor *)imageTintColorForState:(UIControlState)state {
UIColor *color = self.stateToImageTintColor[@(state)];
if (color == nil) {
color = self.stateToImageTintColor[@(UIControlStateNormal)];
Expand Down Expand Up @@ -506,12 +508,12 @@ - (void)updateTitleColorForAllViewsAnimated:(BOOL)animated {
}
}

- (void)setTitleColor:(UIColor *)titleColor forState:(UIControlState)state {
- (void)setTitleColor:(nullable UIColor *)titleColor forState:(UIControlState)state {
self.stateToTitleColor[@(state)] = titleColor;
[self updateTitleColorForAllViewsAnimated:NO];
}

- (UIColor *)titleColorForState:(UIControlState)state {
- (nullable UIColor *)titleColorForState:(UIControlState)state {
UIColor *titleColor = self.stateToTitleColor[@(state)];
if (!titleColor) {
titleColor = self.stateToTitleColor[@(UIControlStateNormal)];
Expand Down Expand Up @@ -543,12 +545,12 @@ - (void)updateTitleFontForAllViews {
}
}

- (void)setTitleFont:(UIFont *)titleFont forState:(UIControlState)state {
- (void)setTitleFont:(nullable UIFont *)titleFont forState:(UIControlState)state {
self.stateToTitleFont[@(state)] = titleFont;
[self updateTitleFontForAllViews];
}

- (UIFont *)titleFontForState:(UIControlState)state {
- (nullable UIFont *)titleFontForState:(UIControlState)state {
UIFont *titleFont = self.stateToTitleFont[@(state)];
if (!titleFont) {
titleFont = self.stateToTitleFont[@(UIControlStateNormal)];
Expand Down Expand Up @@ -610,7 +612,7 @@ - (UIAccessibilityTraits)accessibilityTraits {

#pragma mark - Custom APIs

- (id)accessibilityElementForItem:(UITabBarItem *)item {
- (nullable id)accessibilityElementForItem:(UITabBarItem *)item {
NSUInteger itemIndex = [self.items indexOfObject:item];
if (itemIndex == NSNotFound || itemIndex >= self.itemViews.count) {
return nil;
Expand Down Expand Up @@ -721,10 +723,10 @@ - (void)removeObserversFromTabBarItems {
}
}

- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary<NSKeyValueChangeKey, id> *)change
context:(void *)context {
- (void)observeValueForKeyPath:(nullable NSString *)keyPath
ofObject:(nullable id)object
change:(nullable NSDictionary<NSKeyValueChangeKey, id> *)change
context:(nullable void *)context {
if (context == kKVOContextMDCTabBarView) {
if (!object) {
return;
Expand Down Expand Up @@ -844,7 +846,7 @@ - (void)layoutSubviews {
CGRectGetWidth(self.bounds), kBottomDividerHeight);
}

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
- (void)traitCollectionDidChange:(nullable UITraitCollection *)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];

if (self.traitCollectionDidChangeBlock) {
Expand Down Expand Up @@ -1063,7 +1065,7 @@ - (void)layoutSubviewsForNonFixedClusteredCentered {
[self updateItemViewsShouldProcessRippleWithScrollViewGestures:YES];
}

- (void)willMoveToSuperview:(UIView *)newSuperview {
- (void)willMoveToSuperview:(nullable UIView *)newSuperview {
[super willMoveToSuperview:newSuperview];
self.needsScrollToSelectedItem = YES;
}
Expand Down Expand Up @@ -1457,8 +1459,8 @@ - (UIView *)selectedItemView {
#pragma mark - UIPointerInteractionDelegate

#ifdef __IPHONE_13_4
- (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction
styleForRegion:(UIPointerRegion *)region API_AVAILABLE(ios(13.4)) {
- (nullable UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction
styleForRegion:(UIPointerRegion *)region API_AVAILABLE(ios(13.4)) {
UIPointerStyle *pointerStyle = nil;
if (interaction.view) {
UITargetedPreview *targetedPreview = [[UITargetedPreview alloc] initWithView:interaction.view];
Expand All @@ -1485,9 +1487,9 @@ - (UIView *)itemViewForPoint:(CGPoint)point {
}

#if MDC_AVAILABLE_SDK_IOS(13_0)
- (id<UILargeContentViewerItem>)largeContentViewerInteraction:
(UILargeContentViewerInteraction *)interaction
itemAtPoint:(CGPoint)point
- (nullable id<UILargeContentViewerItem>)largeContentViewerInteraction:
(UILargeContentViewerInteraction *)interaction
itemAtPoint:(CGPoint)point
NS_AVAILABLE_IOS(13_0) {
if (!CGRectContainsPoint(self.bounds, point)) {
// The touch has wandered outside of the view. Do not display the content viewer.
Expand Down Expand Up @@ -1525,7 +1527,7 @@ - (UIView *)itemViewForPoint:(CGPoint)point {
}

- (void)largeContentViewerInteraction:(UILargeContentViewerInteraction *)interaction
didEndOnItem:(id<UILargeContentViewerItem>)item
didEndOnItem:(nullable id<UILargeContentViewerItem>)item
atPoint:(CGPoint)point NS_AVAILABLE_IOS(13_0) {
if (item) {
for (NSUInteger i = 0; i < self.items.count; i++) {
Expand All @@ -1546,3 +1548,5 @@ - (void)largeContentViewerInteraction:(UILargeContentViewerInteraction *)interac
#endif // MDC_AVAILABLE_SDK_IOS(13_0)

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions components/Tabs/src/TabBarView/MDCTabBarViewCustomViewable.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

/**
A simple protocol that custom views rendered in MDCTabBarView must adopt.
Expand Down Expand Up @@ -46,3 +48,5 @@
- (void)setSelected:(BOOL)selected animated:(BOOL)animated;

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions components/Tabs/src/TabBarView/MDCTabBarViewDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@class MDCTabBarView;

/**
Expand Down Expand Up @@ -46,3 +48,5 @@
- (void)tabBarView:(nonnull MDCTabBarView *)tabBarView didSelectItem:(nonnull UITabBarItem *)item;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

/** Defines how a tab bar indicator should appear in a specific context. */
@interface MDCTabBarViewIndicatorAttributes : NSObject <NSCopying>

/** If non-nil, a path that should be filled with the indicator tint color. */
@property(nonatomic, nullable) UIBezierPath *path;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

#import "MDCTabBarViewIndicatorAttributes.h"

NS_ASSUME_NONNULL_BEGIN

@implementation MDCTabBarViewIndicatorAttributes

#pragma mark - NSCopying

- (instancetype)copyWithZone:(__unused NSZone *)zone {
- (instancetype)copyWithZone:(nullable __unused NSZone *)zone {
MDCTabBarViewIndicatorAttributes *attributes = [[[self class] alloc] init];
attributes.path = _path;
return attributes;
Expand Down Expand Up @@ -49,3 +51,5 @@ - (NSUInteger)hash {
}

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

/** Information about the context in which a tab bar indicator will be displayed. */
@protocol MDCTabBarViewIndicatorContext <NSObject>

Expand All @@ -37,3 +39,5 @@
@property(nonatomic, readonly) CGRect contentFrame;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@class MDCTabBarViewIndicatorAttributes;
@protocol MDCTabBarViewIndicatorContext;

Expand All @@ -32,3 +34,5 @@
(nonnull id<MDCTabBarViewIndicatorContext>)context;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

#import "MDCTabBarViewIndicatorTemplate.h"

NS_ASSUME_NONNULL_BEGIN

/*
Default indicator template which produces a fixed-height solid line underneath the selected tab.
*/
@interface MDCTabBarViewUnderlineIndicatorTemplate : NSObject <MDCTabBarViewIndicatorTemplate>
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#import "MDCTabBarViewIndicatorAttributes.h"
#import "MDCTabBarViewIndicatorContext.h"

NS_ASSUME_NONNULL_BEGIN

/// Height in points of the underline shown under selected items.
static const CGFloat kUnderlineIndicatorHeight = 2;

Expand All @@ -34,3 +36,5 @@ - (MDCTabBarViewIndicatorAttributes *)indicatorAttributesForContext:
}

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@class MDCTabBarViewIndicatorAttributes;

/** View responsible for drawing the indicator behind tab content and animating changes. */
Expand All @@ -38,3 +40,5 @@
- (void)applySelectionIndicatorAttributes:(nonnull MDCTabBarViewIndicatorAttributes *)attributes;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 69f2f02

Please sign in to comment.