From 5270cd033d41f4fdc492d4963ab104812849a0f2 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Wed, 13 Dec 2017 02:49:58 +0000 Subject: [PATCH] Allow user to specify picker row height on iOS (#204) Allow user to specify row height for iOS --- README.md | 1 + index.d.ts | 10 ++++++++++ index.js | 2 +- ios/RCTBEEPickerManager/BzwPicker.h | 5 +++-- ios/RCTBEEPickerManager/BzwPicker.m | 9 ++++++++- ios/RCTBEEPickerManager/RCTBEEPickerManager.m | 11 +++++------ 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 16079cb..7d269b8 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ |pickerToolBarFontSize | |number |16 | |wheelFlex | |array |[1, 1, 1] | |pickerFontSize | |number |16 | +|pickerRowHeight | |number |24 | |pickerFontColor | |array |[31, 31, 31, 1] | |pickerData | |array | | |selectedValue | |array | | diff --git a/index.d.ts b/index.d.ts index 5269d3a..85c0616 100644 --- a/index.d.ts +++ b/index.d.ts @@ -148,6 +148,16 @@ interface PickerOptions { */ pickerFontSize?: number + /** + * Row height of the items in the picker + * + * Default is 24 + * + * @type {number} + * @memberof PickerOptions + */ + pickerRowHeight?: number + /** * Color of the text for the items in the picker * diff --git a/index.js b/index.js index e1902b8..ec2af0f 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,7 @@ const options = { pickerTitleColor: [20, 20, 20, 1], pickerToolBarBg: [232, 232, 232, 1], pickerBg: [196, 199, 206, 1], + pickerRowHeight: 24, wheelFlex: [1, 1, 1], pickerData: [], selectedValue: [], @@ -29,7 +30,6 @@ const options = { }; export default { - init(params){ const opt = { ...options, diff --git a/ios/RCTBEEPickerManager/BzwPicker.h b/ios/RCTBEEPickerManager/BzwPicker.h index 2642aa8..0da6fcf 100755 --- a/ios/RCTBEEPickerManager/BzwPicker.h +++ b/ios/RCTBEEPickerManager/BzwPicker.h @@ -41,7 +41,8 @@ typedef void(^backBolock)(NSDictionary * ); @property(strong,nonatomic)NSString *rightStr; @property(strong,nonatomic)NSString *pickerToolBarFontSize; @property(strong,nonatomic)NSString *pickerFontSize; -@property(strong,nonatomic)NSArray*pickerFontColor; +@property(strong,nonatomic)NSArray *pickerFontColor; +@property(strong,nonatomic)NSString *pickerRowHeight; @@ -78,7 +79,7 @@ typedef void(^backBolock)(NSDictionary * ); -(instancetype)initWithFrame:(CGRect)frame dic:(NSDictionary *)dic leftStr:(NSString *)leftStr centerStr:(NSString *)centerStr rightStr:(NSString *)rightStr topbgColor:(NSArray *)topbgColor bottombgColor:(NSArray *)bottombgColor leftbtnbgColor:(NSArray *)leftbtnbgColor rightbtnbgColor:(NSArray *)rightbtnbgColor centerbtnColor:(NSArray *)centerbtnColor selectValueArry:(NSArray *)selectValueArry weightArry:(NSArray *)weightArry - pickerToolBarFontSize:(NSString *)pickerToolBarFontSize pickerFontSize:(NSString *)pickerFontSize pickerFontColor:(NSArray *)pickerFontColor; + pickerToolBarFontSize:(NSString *)pickerToolBarFontSize pickerFontSize:(NSString *)pickerFontSize pickerFontColor:(NSArray *)pickerFontColor pickerRowHeight:(NSString *)pickerRowHeight; -(void)selectRow; @end diff --git a/ios/RCTBEEPickerManager/BzwPicker.m b/ios/RCTBEEPickerManager/BzwPicker.m index 9ab529a..f1b7fe2 100755 --- a/ios/RCTBEEPickerManager/BzwPicker.m +++ b/ios/RCTBEEPickerManager/BzwPicker.m @@ -12,7 +12,7 @@ @implementation BzwPicker -(instancetype)initWithFrame:(CGRect)frame dic:(NSDictionary *)dic leftStr:(NSString *)leftStr centerStr:(NSString *)centerStr rightStr:(NSString *)rightStr topbgColor:(NSArray *)topbgColor bottombgColor:(NSArray *)bottombgColor leftbtnbgColor:(NSArray *)leftbtnbgColor rightbtnbgColor:(NSArray *)rightbtnbgColor centerbtnColor:(NSArray *)centerbtnColor selectValueArry:(NSArray *)selectValueArry weightArry:(NSArray *)weightArry - pickerToolBarFontSize:(NSString *)pickerToolBarFontSize pickerFontSize:(NSString *)pickerFontSize pickerFontColor:(NSArray *)pickerFontColor + pickerToolBarFontSize:(NSString *)pickerToolBarFontSize pickerFontSize:(NSString *)pickerFontSize pickerFontColor:(NSArray *)pickerFontColor pickerRowHeight:(NSString *)pickerRowHeight { self = [super initWithFrame:frame]; @@ -30,6 +30,7 @@ self.pickerToolBarFontSize=pickerToolBarFontSize; self.pickerFontSize=pickerFontSize; self.pickerFontColor=pickerFontColor; + self.pickerRowHeight=pickerRowHeight; [self getStyle]; [self getnumStyle]; dispatch_async(dispatch_get_main_queue(), ^{ @@ -469,6 +470,12 @@ self.bolock(dic); } } + +- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component +{ + return self.pickerRowHeight.integerValue; +} + //判断进来的类型是那种 -(void)getStyle { diff --git a/ios/RCTBEEPickerManager/RCTBEEPickerManager.m b/ios/RCTBEEPickerManager/RCTBEEPickerManager.m index 7820e36..2721ae3 100644 --- a/ios/RCTBEEPickerManager/RCTBEEPickerManager.m +++ b/ios/RCTBEEPickerManager/RCTBEEPickerManager.m @@ -8,7 +8,7 @@ #import "RCTBEEPickerManager.h" #import "BzwPicker.h" -#import "RCTEventDispatcher.h" +#import @interface RCTBEEPickerManager() @@ -55,7 +55,7 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){ NSString *pickerToolBarFontSize=[NSString stringWithFormat:@"%@",indic[@"pickerToolBarFontSize"]]; NSString *pickerFontSize=[NSString stringWithFormat:@"%@",indic[@"pickerFontSize"]]; NSArray *pickerFontColor=indic[@"pickerFontColor"]; - + NSString *pickerRowHeight=indic[@"pickerRowHeight"]; id pickerData=indic[@"pickerData"]; NSMutableDictionary *dataDic=[[NSMutableDictionary alloc]init]; @@ -78,10 +78,9 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){ }else{ self.height=220; } - - self.pick=[[BzwPicker alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, self.height) dic:dataDic leftStr:pickerCancelBtnText centerStr:pickerTitleText rightStr:pickerConfirmBtnText topbgColor:pickerToolBarBg bottombgColor:pickerBg leftbtnbgColor:pickerCancelBtnColor rightbtnbgColor:pickerConfirmBtnColor centerbtnColor:pickerTitleColor selectValueArry:selectArry weightArry:weightArry pickerToolBarFontSize:pickerToolBarFontSize pickerFontSize:pickerFontSize pickerFontColor:pickerFontColor]; - - + + self.pick=[[BzwPicker alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, self.height) dic:dataDic leftStr:pickerCancelBtnText centerStr:pickerTitleText rightStr:pickerConfirmBtnText topbgColor:pickerToolBarBg bottombgColor:pickerBg leftbtnbgColor:pickerCancelBtnColor rightbtnbgColor:pickerConfirmBtnColor centerbtnColor:pickerTitleColor selectValueArry:selectArry weightArry:weightArry pickerToolBarFontSize:pickerToolBarFontSize pickerFontSize:pickerFontSize pickerFontColor:pickerFontColor pickerRowHeight: pickerRowHeight]; + _pick.bolock=^(NSDictionary *backinfoArry){ dispatch_async(dispatch_get_main_queue(), ^{ -- 2.26.2