mirror of
https://github.com/material-components/material-components-ios.git
synced 2026-02-13 06:49:54 +08:00
* [Themes] Remove unnecessary imports. * [TextFields] Remove unnecessary imports. * [Typography] Do not use an umbrella header inside of a component. * [Snackbar] Do not use self umbrella header. * [ActivityIndicator] Do not use self umbrella header. * [AppBar] Use umbrella headers. * [AppBar] Remove self import header. * [ButtonBar] Removed self umbrella header imports. * [Buttons] Removed self umbrella header imports. * [Collections] Update imports. * [Dialogs] Moved import into an m file. * [Collections] Fixed imports. * [FeatureHighlight] Removed self umbrealla imports. * [HeaderStackView] Reordered imports. * [Ink] Replaced imports with forward declarations. * [Slider] Replaced self umbrella import use. * [Snackbar] Removed self umbrella header import. * [Tabs] Changed math import. Replaced self umbrella header import. * [Icons] Removed unnecessary imports. * [Overlay] Replaced umbrella header import. * [ShapeLibrary] Replace Shapes imports with an umbrella header. * [Shapes] Replaced imports with forward declarations. * [AppBar] Replace import with a forward declaration. * [Examples] Updated imports. * Fixed conflicting imports * Added space between different import categories
93 lines
3.3 KiB
Objective-C
93 lines
3.3 KiB
Objective-C
/*
|
|
Copyright 2017-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 "supplemental/CollectionsSectionInsetsExampleSupplemental.h"
|
|
|
|
@implementation CollectionsSectionInsetsExample
|
|
|
|
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
|
|
if (self = [super initWithCoder:aDecoder]) {
|
|
[self collectionsSectionInsetsExampleCommonInit];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
|
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
|
|
[self collectionsSectionInsetsExampleCommonInit];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout {
|
|
if (self = [super initWithCollectionViewLayout:layout]) {
|
|
[self collectionsSectionInsetsExampleCommonInit];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)collectionsSectionInsetsExampleCommonInit {
|
|
_content = [NSMutableArray array];
|
|
_sectionUsesCustomInsets = [NSMutableDictionary dictionaryWithCapacity:kSectionCount];
|
|
}
|
|
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
|
|
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
MDCCollectionViewTextCell *cell =
|
|
[collectionView dequeueReusableCellWithReuseIdentifier:kReusableIdentifierItem
|
|
forIndexPath:indexPath];
|
|
cell.textLabel.text = self.content[indexPath.section][indexPath.item];
|
|
cell.accessibilityIdentifier =
|
|
[NSString stringWithFormat:@"%ld.%ld", (long)indexPath.section, (long)indexPath.row];
|
|
if (indexPath.row == 0) {
|
|
UISwitch *switchControl = [[UISwitch alloc] initWithFrame:CGRectZero];
|
|
[switchControl setOn:[self.sectionUsesCustomInsets[@(indexPath.section)] boolValue]];
|
|
[switchControl addTarget:self
|
|
action:@selector(didSet:)
|
|
forControlEvents:UIControlEventValueChanged];
|
|
switchControl.tag = indexPath.section;
|
|
|
|
cell.accessoryView = switchControl;
|
|
}
|
|
|
|
return cell;
|
|
}
|
|
|
|
#pragma mark - <UICollectionViewDelegateFlowLayout>
|
|
|
|
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView
|
|
layout:(UICollectionViewLayout *)collectionViewLayout
|
|
insetForSectionAtIndex:(NSInteger)section {
|
|
UIEdgeInsets insets = [super collectionView:collectionView
|
|
layout:collectionViewLayout
|
|
insetForSectionAtIndex:section];
|
|
if ([self.sectionUsesCustomInsets[@(section)] boolValue]) {
|
|
insets.left = MIN(40, 8 * section);
|
|
insets.right = insets.left;
|
|
}
|
|
return insets;
|
|
}
|
|
|
|
#pragma mark - UIControlEventHandlers
|
|
|
|
- (void)didSet:(UISwitch *)sender {
|
|
NSUInteger section = sender.tag;
|
|
self.sectionUsesCustomInsets[@(section)] = @(sender.isOn);
|
|
[self.collectionView.collectionViewLayout invalidateLayout];
|
|
}
|
|
|
|
@end
|