Skip to content

Commit

Permalink
fix(ios): make Ti.UI.TableViewSection.rowCount NSNumber*, not NSInteger
Browse files Browse the repository at this point in the history
theoretically this should avoid crash
  • Loading branch information
sgtcoolguy committed Oct 28, 2020
1 parent 026fe12 commit c25a9dd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 31 deletions.
10 changes: 5 additions & 5 deletions iphone/Classes/TiUITableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ - (NSInteger)rowIndexForIndexPath:(NSIndexPath *)index andSections:(NSArray *)se
dataIndex += rowIndex;
break;
}
dataIndex += [section rowCount];
dataIndex += section.rowCount.integerValue;
c++;
}
return dataIndex;
Expand Down Expand Up @@ -941,11 +941,11 @@ - (UIView *)titleViewForText:(NSString *)text footer:(BOOL)footer

- (TiUITableViewRowProxy *)rowForIndexPath:(NSIndexPath *)indexPath
{
TiUITableViewSectionProxy *section = [self sectionForIndex:[indexPath section]];
if (!indexPath || [section rowCount] <= [indexPath row]) {
TiUITableViewSectionProxy *section = [self sectionForIndex:indexPath.section];
if (!indexPath || section.rowCount.unsignedIntegerValue <= indexPath.row) {
return nil;
}
return [section rowAtIndex:[indexPath row]];
return [section rowAtIndex:indexPath.row];
}

- (void)changeEditing:(BOOL)yn
Expand Down Expand Up @@ -2068,7 +2068,7 @@ - (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)sec
}

TiUITableViewSectionProxy *sectionProxy = [self sectionForIndex:section];
return sectionProxy.rowCount;
return sectionProxy.rowCount.integerValue;
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
Expand Down
34 changes: 17 additions & 17 deletions iphone/Classes/TiUITableViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,23 @@ - (NSArray *)keySequence

- (NSInteger)indexForRow:(TiUITableViewRowProxy *)row
{
int index = 0;
NSInteger index = 0;
for (TiUITableViewSectionProxy *thisSection in sections) {
if (thisSection == row.section) {
return index + row.row;
}
index += [thisSection rowCount];
index += thisSection.rowCount.integerValue;
}
return index;
}

- (NSInteger)sectionIndexForIndex:(NSInteger)theindex
{
int index = 0;
int section = 0;
NSInteger index = 0;
NSInteger section = 0;

for (TiUITableViewSectionProxy *thisSection in sections) {
index += [thisSection rowCount];
index += thisSection.rowCount.integerValue;
if (theindex < index) {
return section;
}
Expand All @@ -141,7 +141,7 @@ - (TiUITableViewRowProxy *)rowForIndex:(NSInteger)index section:(NSInteger *)sec
int sectionIdx = 0;

for (TiUITableViewSectionProxy *sectionProxy in sections) {
NSInteger rowCount = [sectionProxy rowCount];
NSUInteger rowCount = sectionProxy.rowCount.unsignedIntegerValue;
if (rowCount + current > index) {
if (section != nil) {
*section = sectionIdx;
Expand All @@ -166,7 +166,7 @@ - (NSIndexPath *)indexPathFromInt:(NSInteger)index
NSInteger row = index;

for (TiUITableViewSectionProxy *thisSection in sections) {
NSInteger rowCount = [thisSection rowCount];
NSUInteger rowCount = thisSection.rowCount.unsignedIntegerValue;
if (rowCount + current > index) {
NSMutableArray *searchIndex = ((TiUITableView *)self.view).searchResultIndexes;
if (searchIndex.count > 0) {
Expand Down Expand Up @@ -200,15 +200,15 @@ - (NSIndexPath *)indexPathFromInt:(NSInteger)index

- (NSInteger)indexForIndexPath:(NSIndexPath *)path
{
int index = 0;
NSInteger index = 0;
int section = 0;

for (TiUITableViewSectionProxy *thisSection in sections) {
if (section == [path section]) {
return index + [path row];
}
section++;
index += [thisSection rowCount];
index += thisSection.rowCount.integerValue;
}

return 0;
Expand Down Expand Up @@ -275,15 +275,15 @@ - (TiUITableViewRowProxy *)tableRowFromArg:(id)data

- (TiUITableViewSectionProxy *)sectionForIndex:(NSInteger)index row:(TiUITableViewRowProxy **)rowOut
{
int current = 0;
NSUInteger current = 0;
NSInteger row = index;
int sectionIdx = 0;
NSUInteger sectionIdx = 0;

TiUITableViewRowProxy *rowProxy = nil;
TiUITableViewSectionProxy *sectionProxy = nil;

for (sectionProxy in sections) {
NSInteger rowCount = [sectionProxy rowCount];
NSUInteger rowCount = sectionProxy.rowCount.unsignedIntegerValue;
if (rowCount + current > index) {
rowProxy = [sectionProxy rowAtIndex:row];
if (rowOut != nil) {
Expand Down Expand Up @@ -394,7 +394,7 @@ - (void)updateRow:(id)args
id data = nil;
NSDictionary *anim = nil;

ENSURE_INT_AT_INDEX(index, args, 0);
ENSURE_INT_AT_INDEX(index, args, 0); // FIXME: Support larger number by coercing to uint32?
ENSURE_ARG_AT_INDEX(data, args, 1, NSObject);
ENSURE_ARG_OR_NIL_AT_INDEX(anim, args, 2, NSDictionary);

Expand All @@ -404,13 +404,13 @@ - (void)updateRow:(id)args

TiThreadPerformOnMainThread(
^{
int current = 0;
int row = index;
int sectionIdx = 0;
NSUInteger current = 0;
NSUInteger row = index;
NSUInteger sectionIdx = 0;
TiUITableViewSectionProxy *sectionProxy = nil;

for (sectionProxy in sections) {
NSInteger rowCount = [sectionProxy rowCount];
NSUInteger rowCount = sectionProxy.rowCount.unsignedIntegerValue;
if (rowCount + current > index) {
rowProxy = [sectionProxy rowAtIndex:row];
break;
Expand Down
2 changes: 1 addition & 1 deletion iphone/Classes/TiUITableViewRowProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ - (void)configureBackground:(UITableViewCell *)cell
}
}
selectedBGView.fillColor = theColor;
NSInteger count = [section rowCount];
NSUInteger count = section.rowCount.unsignedIntegerValue;
if (count == 1) {
selectedBGView.position = TiCellBackgroundViewPositionSingleLine;
} else {
Expand Down
8 changes: 4 additions & 4 deletions iphone/Classes/TiUITableViewSectionProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@

@interface TiUITableViewSectionProxy : TiViewProxy <TiProxyDelegate, NSFastEnumeration> {
@private
NSMutableArray *rows;
NSMutableArray<TiUITableViewRowProxy *> *rows;
TiUITableView *table;
NSInteger section;
}

@property (nonatomic, readonly) NSMutableArray *rows;
@property (nonatomic, readonly) NSInteger rowCount;
@property (nonatomic, readonly) NSMutableArray<TiUITableViewRowProxy *> *rows;
@property (nonatomic, readonly) NSNumber *rowCount;
@property (nonatomic, readonly, assign) NSString *headerTitle;
@property (nonatomic, readonly, assign) NSString *footerTitle;

- (void)add:(id)proxy;
- (void)remove:(id)proxy;

#pragma mark Framework
- (TiUITableViewRowProxy *)rowAtIndex:(NSInteger)index;
- (TiUITableViewRowProxy *)rowAtIndex:(NSUInteger)index;
@property (nonatomic, readwrite, assign) TiUITableView *table;
@property (nonatomic, readwrite, assign) NSInteger section;

Expand Down
7 changes: 3 additions & 4 deletions iphone/Classes/TiUITableViewSectionProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state object
return [rows countByEnumeratingWithState:state objects:stackbuf count:len];
}

- (NSInteger)rowCount
- (NSNumber *)rowCount
{
//The result of a method call on a nil is 0;
return [rows count];
return NUMUINTEGER((rows != nil) ? rows.count : 0);
}

- (void)add:(id)proxy
Expand Down Expand Up @@ -103,7 +102,7 @@ - (UIView *)view
return nil;
}

- (TiUITableViewRowProxy *)rowAtIndex:(NSInteger)index
- (TiUITableViewRowProxy *)rowAtIndex:(NSUInteger)index
{
//Because rowAtIndex is used internally, with an int, it can't be used by the Javascript.
//The javascript passes in an NSArray pointer, not an index. And things blow up.
Expand Down

0 comments on commit c25a9dd

Please sign in to comment.