Wenyu Zhang b6d752d52c
[ChipTextField] Use MDCChipTextFieldScrollView to replace leftView functionality for flexibility and extensibility (proof of concept) (#6167)
This PR is dependent on https://github.com/material-components/material-components-ios/pull/6035. And there is no new API change on MDCChipTextField class level.

This PR is meant to solve the problem mentioned in https://github.com/material-components/material-components-ios/pull/6035 -> "Enabling scrolling of the Chips and the remaining alignment issues will be resolved in followup PRs." 
The issues it solves:
(1) Alignment (a way to adjust it also)
(2) clear button
(3) the coupling issue with apple's leftView in the original PR.

Screenshots:
![simulator screen shot - iphone xs - 2019-01-02 at 11 30 50](https://user-images.githubusercontent.com/8836258/50601363-f249be80-0e81-11e9-8afc-515322a22e52.png)
![simulator screen shot - iphone xs - 2019-01-02 at 11 30 54](https://user-images.githubusercontent.com/8836258/50601366-f4138200-0e81-11e9-9869-27d70871a957.png)
![simulator screen shot - iphone xs - 2019-01-02 at 11 30 57](https://user-images.githubusercontent.com/8836258/50601370-f544af00-0e81-11e9-88f1-7da072b1d5b9.png)
2019-01-09 13:28:45 -05:00

53 lines
1.7 KiB
Objective-C

// Copyright 2018-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 "MaterialChips.h"
@class MDCChipTextFieldScrollView;
@protocol MDCChipTextFieldScrollViewDelegate <NSObject, UIScrollViewDelegate>
// TODO: delegate methods to handle touch event
@end
@protocol MDCChipTextFieldScrollViewDataSource <NSObject>
- (NSInteger)numberOfChipsInScrollView:(nonnull MDCChipTextFieldScrollView *)scrollView;
- (nullable MDCChipView *)scrollView:(nonnull MDCChipTextFieldScrollView *)scrollView
chipForIndex:(NSInteger)index;
@end
@interface MDCChipTextFieldScrollView : UIScrollView
@property(nonatomic, weak, nullable) id<MDCChipTextFieldScrollViewDelegate> delegate;
@property(nonatomic, weak, nullable) id<MDCChipTextFieldScrollViewDataSource> dataSource;
/**
The spacing between chips in this scroll view.
*/
@property(nonatomic) CGFloat chipSpacing;
- (void)scrollToLeft;
- (void)scrollToRight;
// TODO: remove these methods if we decide to go with data source. Needs revisit.
- (void)appendChipView:(nonnull MDCChipView *)chipView;
- (void)removeChipView:(nonnull MDCChipView *)chipView;
@end