From 80548b6972dabcc3b6c56bb988434e108ed2a8ca Mon Sep 17 00:00:00 2001 From: yangtao Date: Sat, 12 Dec 2020 15:53:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E4=BA=AB=E5=A2=9E=E5=8A=A0=E5=BA=95?= =?UTF-8?q?=E9=83=A8=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/.flutter-plugins-dependencies | 2 +- ios/Classes/Api/MOP_showBotomSheetModel.h | 37 ++++ ios/Classes/Api/MOP_showBotomSheetModel.m | 199 ++++++++++++++++++++++ ios/Classes/MopPlugin.h | 1 + ios/Classes/MopPlugin.m | 6 + 5 files changed, 244 insertions(+), 1 deletion(-) create mode 100644 ios/Classes/Api/MOP_showBotomSheetModel.h create mode 100644 ios/Classes/Api/MOP_showBotomSheetModel.m diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index 791625d..8a697b2 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"mop","path":"/Users/cenxiaozhong/Desktop/workspace/fino-sprite/mop-flutter-sdk/","dependencies":[]}],"android":[{"name":"mop","path":"/Users/cenxiaozhong/Desktop/workspace/fino-sprite/mop-flutter-sdk/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"mop","dependencies":[]}],"date_created":"2020-11-25 20:28:28.692104","version":"1.22.4"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"mop","path":"/Users/hujianhui/Desktop/fantaizhushou/mop-flutter-sdk/","dependencies":[]}],"android":[{"name":"mop","path":"/Users/hujianhui/Desktop/fantaizhushou/mop-flutter-sdk/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"mop","dependencies":[]}],"date_created":"2020-12-12 15:40:41.141320","version":"1.22.4"} \ No newline at end of file diff --git a/ios/Classes/Api/MOP_showBotomSheetModel.h b/ios/Classes/Api/MOP_showBotomSheetModel.h new file mode 100644 index 0000000..4d444f7 --- /dev/null +++ b/ios/Classes/Api/MOP_showBotomSheetModel.h @@ -0,0 +1,37 @@ +// +// MOP_showBotomSheetModel.h +// mop +// +// Created by 胡健辉 on 2020/12/11. +// + +#import +#import "MOPBaseApi.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MOP_showBotomSheetModel : MOPBaseApi +@property(nonatomic, strong) NSString *appId; + +@end + + +typedef void (^MOP_shareBottomViewTypeBlock)(NSInteger type); + +@interface MOP_shareBottomView : UIView +@property(nonatomic, copy) MOP_shareBottomViewTypeBlock didSelcetTypeBlock; + ++ (instancetype)view; +- (void)show; +- (void)dismiss; + +@end + +@interface MOP_shareBottomViewCell : UICollectionViewCell +@property(nonatomic, assign) NSInteger type; +@property(nonatomic, strong) UIImageView *imageView; +@property(nonatomic, strong) UILabel *label; + + +@end +NS_ASSUME_NONNULL_END diff --git a/ios/Classes/Api/MOP_showBotomSheetModel.m b/ios/Classes/Api/MOP_showBotomSheetModel.m new file mode 100644 index 0000000..f86728a --- /dev/null +++ b/ios/Classes/Api/MOP_showBotomSheetModel.m @@ -0,0 +1,199 @@ +// +// MOP_showBotomSheetModel.m +// mop +// +// Created by 胡健辉 on 2020/12/11. +// + +#import "MOP_showBotomSheetModel.h" +#import "MopPlugin.h" + + +@implementation MOP_showBotomSheetModel + +- (void)setupApiWithSuccess:(void (^)(NSDictionary * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel { + NSLog(@"showBotomSheetModel"); + MOP_shareBottomView *view = [MOP_shareBottomView view]; + [view show]; + [view setDidSelcetTypeBlock:^(NSInteger type) { + FlutterMethodChannel *channel = [[MopPlugin instance] shareMethodChannel]; + [channel invokeMethod:@"shareApi:doShare" arguments:@{@"type":@(type)} result:^(id _Nullable result) { + + }]; + }]; + success(@{}); +} + +@end + + +//获取安全区域距离 +#define kFinoSafeAreaTop kFinoWindowSafeAreaInset.top +#define kFinoSafeAreaBottom kFinoWindowSafeAreaInset.bottom + +#define kFinoWindowSafeAreaInset \ +({\ +UIEdgeInsets returnInsets = UIEdgeInsetsMake([UIApplication sharedApplication].statusBarFrame.size.height, 0, 0, 0);\ +UIWindow * keyWindow = [UIApplication sharedApplication].keyWindow;\ +if ([keyWindow respondsToSelector:NSSelectorFromString(@"safeAreaInsets")]) {\ +UIEdgeInsets inset = [[keyWindow valueForKeyPath:@"safeAreaInsets"] UIEdgeInsetsValue];\ +if (inset.top < [UIApplication sharedApplication].statusBarFrame.size.height) {\ +inset.top = [UIApplication sharedApplication].statusBarFrame.size.height;\ +}\ +returnInsets = inset;\ +}\ +(returnInsets);\ +})\ + +@interface MOP_shareBottomView () +/** + 整个内容的View + */ +@property (nonatomic, strong) UIView *contentView; + +/** + 取消按钮 + */ +@property (nonatomic, strong) UIButton *cancelButton; + +@property(nonatomic, strong) UICollectionView *collectionView; + +@property(nonatomic, strong) NSArray *dataArray; + +@end + +@implementation MOP_shareBottomView + +- (instancetype)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + self.dataArray = @[@(0)]; + self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4f]; + self.contentView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height - 150 - kFinoSafeAreaBottom, self.frame.size.width, 150 + kFinoSafeAreaBottom)]; + self.contentView.backgroundColor = [UIColor whiteColor]; + [self addSubview:self.contentView]; + + self.cancelButton = [UIButton buttonWithType:UIButtonTypeCustom]; + [self.cancelButton setTitle:@"取消" forState:UIControlStateNormal]; + [self.cancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; + [self.contentView addSubview:self.cancelButton]; + self.cancelButton.frame = CGRectMake(0, self.contentView.frame.size.height - kFinoSafeAreaBottom - 50, self.contentView.frame.size.width, 50); + + UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.cancelButton.frame.size.width, 0.5)]; + line.backgroundColor = [UIColor lightGrayColor]; + [self.cancelButton addSubview:line]; + + [self.contentView addSubview:self.collectionView]; + self.collectionView.frame = CGRectMake(0, 0, frame.size.width, 100); + + } + return self; +} + ++ (instancetype)view { + return [[self alloc] initWithFrame:[UIScreen mainScreen].bounds]; +} + +- (void)show { + if (self.superview) { + return; + } + [UIView animateWithDuration:0.3 animations:^{ + UIWindow * window=[UIApplication sharedApplication].keyWindow; + [window addSubview:self]; + } completion:^(BOOL finished) { + }]; +} + +- (void)dismiss +{ + [UIView animateWithDuration:0.25 animations:^{ + self.contentView.transform = CGAffineTransformMakeTranslation(0, self.contentView.frame.size.height); + self.alpha = 0.5f; + } completion:^(BOOL finished) { + [self removeFromSuperview]; + }]; +} + +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { + [self dismiss]; +} + +#pragma mark colletionview ------------------------------ +static NSString *cellID = @"cellid"; +- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { + MOP_shareBottomViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath]; + cell.type = [self.dataArray[indexPath.row] intValue]; + return cell; +} + +- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { + if (self.didSelcetTypeBlock) { + MOP_shareBottomViewCell *cell = (MOP_shareBottomViewCell *)[collectionView cellForItemAtIndexPath:indexPath]; + self.didSelcetTypeBlock(cell.type); + } + [self dismiss]; +} + +- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { + return 1; +} + +- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { + return self.dataArray.count; +} + +- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { + return CGSizeMake(self.collectionView.frame.size.width / self.dataArray.count, self.collectionView.frame.size.height); +} + +- (UICollectionViewFlowLayout *)layout { + UICollectionViewFlowLayout *collectionViewLayout = [[UICollectionViewFlowLayout alloc] init]; + collectionViewLayout.minimumLineSpacing = 0; + collectionViewLayout.minimumInteritemSpacing = 0; + collectionViewLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal; + return collectionViewLayout; +} + +- (UICollectionView *)collectionView { + if (!_collectionView) { + _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:[self layout]]; + _collectionView.delegate = self; + _collectionView.dataSource = self; + [_collectionView registerClass:[MOP_shareBottomViewCell class] forCellWithReuseIdentifier:cellID]; + _collectionView.pagingEnabled = YES; + _collectionView.showsVerticalScrollIndicator = NO; + _collectionView.showsHorizontalScrollIndicator = NO; + } + return _collectionView;; +} +@end + +@implementation MOP_shareBottomViewCell +- (instancetype)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + self.backgroundColor = [UIColor whiteColor]; + self.imageView = [UIImageView new]; + self.imageView.frame = CGRectMake((frame.size.width-50)/2, 10, 50, 50); + [self.contentView addSubview:self.imageView]; + + self.label = [[UILabel alloc] initWithFrame:CGRectMake((frame.size.width-50)/2, 65, frame.size.width, 30)]; + self.label.font = [UIFont systemFontOfSize:14]; + self.label.textColor = [UIColor grayColor]; + [self.contentView addSubview:self.label]; + + } + return self; +} + +- (void)setType:(NSInteger)type { + _type = type; + if (_type == 0) { + self.label.text = @"微信好友"; + self.imageView.image = [UIImage imageNamed:@"turkey_share_wechat"]; + } +} +@end diff --git a/ios/Classes/MopPlugin.h b/ios/Classes/MopPlugin.h index 6c2a24e..70db2b6 100644 --- a/ios/Classes/MopPlugin.h +++ b/ios/Classes/MopPlugin.h @@ -7,6 +7,7 @@ @interface MopPlugin : NSObject @property MopEventStream *mopEventStreamHandler; @property FlutterMethodChannel *methodChannel; +@property FlutterMethodChannel *shareMethodChannel; + (instancetype) instance; @end diff --git a/ios/Classes/MopPlugin.m b/ios/Classes/MopPlugin.m index 0ee5cb8..d927950 100644 --- a/ios/Classes/MopPlugin.m +++ b/ios/Classes/MopPlugin.m @@ -41,6 +41,12 @@ static MopPlugin *_instance; FlutterEventChannel *mopEventChannel = [FlutterEventChannel eventChannelWithName:@"plugins.mop.finogeeks.com/mop_event" binaryMessenger:[registrar messenger]]; _instance.mopEventStreamHandler = [[MopEventStream alloc] init]; [mopEventChannel setStreamHandler:_instance.mopEventStreamHandler]; + + FlutterMethodChannel* shareChannel = [FlutterMethodChannel + methodChannelWithName:@"plugins.finosprite.finogeeks.com/share" + binaryMessenger:[registrar messenger]]; + [registrar addMethodCallDelegate:_instance channel:shareChannel]; + _instance.shareMethodChannel = shareChannel; } + (instancetype)instance{