-
Notifications
You must be signed in to change notification settings - Fork 944
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tabs] Add initial support for custom view. (#7678)
Creates basic support for a custom view property on UITabBarItem. Although not
a category on UITabBarItem, it can be used in the same places UITabBarItem can
be used. This will allow clients of MDCTabBarView to provide a custom view to
replace the default presentation of the title and image.
Closes #7676
- Loading branch information
Robert Moore
committed
Jun 24, 2019
1 parent
b13f781
commit 325e269
Showing
6 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2019-present the Material Components for iOS authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#import "MDCTabBarItemCustomViewing.h" | ||
|
||
/** | ||
A subclass of @c UITabBarItem that supports a custom view property. | ||
*/ | ||
__attribute__((objc_subclassing_restricted)) @interface MDCTabBarItem | ||
: UITabBarItem<MDCTabBarItemCustomViewing> | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2019-present the Material Components for iOS authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import "MDCTabBarItem.h" | ||
|
||
@implementation MDCTabBarItem | ||
|
||
@synthesize mdc_customView = _mdc_customView; | ||
|
||
@end |
31 changes: 31 additions & 0 deletions
31
components/Tabs/src/TabBarView/MDCTabBarItemCustomViewing.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2019-present the Material Components for iOS authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import "MDCTabBarSelectionIndicatorSupporting.h" | ||
|
||
/** | ||
Defines the necessary APIs for MDCTabBarView to use a UITabBarItem for a custom view property. | ||
@note Although UIKit defines such a property on @c UIBarButtonItem, no similar property is publicly | ||
documented on @c UITabBarItem. | ||
*/ | ||
@protocol MDCTabBarItemCustomViewing | ||
|
||
/** A custom view to be displayed for a tab bar item. */ | ||
@property(nullable, nonatomic, strong) | ||
UIView<MDCTabBarSelectionIndicatorSupporting> *mdc_customView; | ||
|
||
@end |
36 changes: 36 additions & 0 deletions
36
components/Tabs/src/TabBarView/MDCTabBarSelectionIndicatorSupporting.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2019-present the Material Components for iOS authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
/** | ||
A simple protocol that indicates the responder can be targeted by an | ||
@c MDCTabBarSelectionIndicatorTemplate. | ||
@seealso MDCTabBarIndicatorTemplate | ||
*/ | ||
@protocol MDCTabBarSelectionIndicatorSupporting | ||
|
||
/** | ||
The bounds of the receiver. | ||
*/ | ||
@property(readonly) CGRect bounds; | ||
|
||
/** | ||
The frame of the content of the receiver. Used to position the Selection Indicator relative to | ||
the content. | ||
*/ | ||
@property(readonly) CGRect contentFrame; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
components/Tabs/tests/unit/TabBarView/MDCTabBarItemTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2019-present the Material Components for iOS authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import "MaterialTabs+TabBarView.h" | ||
|
||
@interface MDCTabBarItemTestCustomViewTestFake : UIView <MDCTabBarSelectionIndicatorSupporting> | ||
@end | ||
|
||
@implementation MDCTabBarItemTestCustomViewTestFake | ||
|
||
- (CGRect)contentFrame { | ||
return CGRectZero; | ||
} | ||
|
||
@end | ||
|
||
@interface MDCTabBarItemTests : XCTestCase | ||
@end | ||
|
||
@implementation MDCTabBarItemTests | ||
|
||
- (void)testGetterSetterForCustomView { | ||
// Given | ||
MDCTabBarItemTestCustomViewTestFake *customView = | ||
[[MDCTabBarItemTestCustomViewTestFake alloc] init]; | ||
MDCTabBarItem *barItem = [[MDCTabBarItem alloc] init]; | ||
|
||
// When | ||
barItem.mdc_customView = customView; | ||
|
||
// Then | ||
XCTAssertEqual(barItem.mdc_customView, customView); | ||
} | ||
|
||
@end |