@@ -22,6 +22,7 @@ - (instancetype)initWithFrame:(CGRect)frame
2222 _font = [UIFont systemFontOfSize: 21 ]; // TODO: selected title default should be 23.5
2323 _selectedIndex = NSNotFound ;
2424 _textAlign = NSTextAlignmentCenter;
25+ _numberOfLines = 1 ;
2526 self.delegate = self;
2627 self.dataSource = self;
2728 [self selectRow: 0 inComponent: 0 animated: YES ]; // Workaround for missing selection indicator lines (see https://stackoverflow.com/questions/39564660/uipickerview-selection-indicator-not-visible-in-ios10)
@@ -48,6 +49,20 @@ - (void)setSelectedIndex:(NSInteger)selectedIndex
4849 }
4950}
5051
52+ - (void )setNumberOfLines : (NSInteger )numberOfLines
53+ {
54+ _numberOfLines = numberOfLines;
55+ [self reloadAllComponents ];
56+ [self setNeedsLayout ];
57+ }
58+
59+ - (void ) setFont : (UIFont *)font
60+ {
61+ _font = font;
62+ [self reloadAllComponents ];
63+ [self setNeedsLayout ];
64+ }
65+
5166#pragma mark - UIPickerViewDataSource protocol
5267
5368- (NSInteger )numberOfComponentsInPickerView : (__unused UIPickerView *)pickerView
@@ -70,33 +85,44 @@ - (NSString *)pickerView:(__unused UIPickerView *)pickerView
7085 return [RCTConvert NSString: _items[row][@" label" ]];
7186}
7287
73- - (CGFloat)pickerView : (__unused UIPickerView *)pickerView rowHeightForComponent : (NSInteger )__unused component {
74- return _font.pointSize + 19 ;
88+ - (CGFloat)pickerView : (__unused UIPickerView *)pickerView rowHeightForComponent : (__unused NSInteger ) component {
89+ return ( _font.lineHeight ) * _numberOfLines + 20 ;
7590}
7691
7792- (UIView *)pickerView : (UIPickerView *)pickerView
7893 viewForRow : (NSInteger )row
7994 forComponent : (NSInteger )component
80- reusingView : (UILabel *)label
95+ reusingView : (UIView *)view
8196{
82- if (!label) {
83- label = [[UILabel alloc ] initWithFrame: (CGRect){
84- CGPointZero,
85- {
86- [pickerView rowSizeForComponent: component].width ,
87- [pickerView rowSizeForComponent: component].height ,
88- }
89- }];
97+ if (!view) {
98+ CGFloat rowHeight = [pickerView rowSizeForComponent: component].height ;
99+ CGFloat rowWidth = [pickerView rowSizeForComponent: component].width ;
100+ view = [[UIView alloc ] initWithFrame: CGRectZero];
101+ RNCPickerLabel* label = [[RNCPickerLabel alloc ] initWithFrame: (CGRect) {
102+ CGPointZero,
103+ {
104+ rowWidth,
105+ rowHeight,
106+ }
107+ }];
108+ [view insertSubview: label atIndex: 0 ];
90109 }
91110
111+ RNCPickerLabel* label = view.subviews [0 ];
92112 label.font = _font;
93113
94114 label.textColor = [RCTConvert UIColor: _items[row][@" textColor" ]] ?: _color;
95115
96116 label.textAlignment = _textAlign;
97117 label.text = [self pickerView: pickerView titleForRow: row forComponent: component];
98118 label.accessibilityIdentifier = _items[row][@" testID" ];
99- return label;
119+
120+ label.numberOfLines = _numberOfLines;
121+
122+ label.leftInset = 20.0 ;
123+ label.rightInset = 20.0 ;
124+
125+ return view;
100126}
101127
102128- (void )pickerView : (__unused UIPickerView *)pickerView
0 commit comments