// // RCTBEEPickerManager.m // RCTBEEPickerManager // // Created by MFHJ-DZ-001-417 on 16/9/6. // Copyright © 2016年 MFHJ-DZ-001-417. All rights reserved. // #import "RCTBEEPickerManager.h" #import "BzwPicker.h" #import "RCTEventDispatcher.h" @interface RCTBEEPickerManager() @property(nonatomic,strong)BzwPicker *pick; @end @implementation RCTBEEPickerManager @synthesize bridge = _bridge; RCT_EXPORT_MODULE(); RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){ UIViewController *result = nil; UIWindow * window = [[UIApplication sharedApplication] keyWindow]; if (window.windowLevel != UIWindowLevelNormal) { NSArray *windows = [[UIApplication sharedApplication] windows]; for(UIWindow * tmpWin in windows) { if (tmpWin.windowLevel == UIWindowLevelNormal) { window = tmpWin; break; } } } UIView *frontView = [[window subviews] objectAtIndex:0]; id nextResponder = [frontView nextResponder]; if ([nextResponder isKindOfClass:[UIViewController class]]) result = nextResponder; else result = window.rootViewController; NSString *pickerConfirmBtnText=indic[@"pickerConfirmBtnText"]; NSString *pickerCancelBtnText=indic[@"pickerCancelBtnText"]; NSString *pickerTitleText=indic[@"pickerTitleText"]; NSArray *pickerConfirmBtnColor=indic[@"pickerConfirmBtnColor"]; NSArray *pickerCancelBtnColor=indic[@"pickerCancelBtnColor"]; NSArray *pickerTitleColor=indic[@"pickerTitleColor"]; NSArray *pickerToolBarBg=indic[@"pickerToolBarBg"]; NSArray *pickerBg=indic[@"pickerBg"]; NSArray *selectArry=indic[@"selectedValue"]; NSArray *weightArry=indic[@"wheelFlex"]; id pickerData=indic[@"pickerData"]; NSMutableDictionary *dataDic=[[NSMutableDictionary alloc]init]; dataDic[@"pickerData"]=pickerData; [result.view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if ([obj isKindOfClass:[BzwPicker class]]) { dispatch_async(dispatch_get_main_queue(), ^{ [obj removeFromSuperview]; }); } }]; self.pick=[[BzwPicker alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 250) dic:dataDic leftStr:pickerCancelBtnText centerStr:pickerTitleText rightStr:pickerConfirmBtnText topbgColor:pickerToolBarBg bottombgColor:pickerBg leftbtnbgColor:pickerCancelBtnColor rightbtnbgColor:pickerConfirmBtnColor centerbtnColor:pickerTitleColor selectValueArry:selectArry weightArry:weightArry]; _pick.bolock=^(NSDictionary *backinfoArry){ dispatch_async(dispatch_get_main_queue(), ^{ [self.bridge.eventDispatcher sendAppEventWithName:@"pickerEvent" body:backinfoArry]; }); }; dispatch_async(dispatch_get_main_queue(), ^{ [result.view addSubview:_pick]; [UIView animateWithDuration:.3 animations:^{ [_pick setFrame:CGRectMake(0, SCREEN_HEIGHT-250, SCREEN_WIDTH, 250)]; }]; }); } RCT_EXPORT_METHOD(show){ if (self.pick) { dispatch_async(dispatch_get_main_queue(), ^{ [UIView animateWithDuration:.3 animations:^{ [_pick setFrame:CGRectMake(0, SCREEN_HEIGHT-250, SCREEN_WIDTH, 250)]; }]; }); }return; } RCT_EXPORT_METHOD(hide){ if (self.pick) { dispatch_async(dispatch_get_main_queue(), ^{ [UIView animateWithDuration:.3 animations:^{ [_pick setFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 250)]; }]; }); }return; } RCT_EXPORT_METHOD(isPickerShow:(RCTResponseSenderBlock)getBack){ if (self.pick) { CGFloat pickY=_pick.frame.origin.y; if (pickY==SCREEN_HEIGHT) { getBack(@[@YES]); }else { getBack(@[@NO]); } }else{ getBack(@[@"picker不存在"]); } } @end