Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-28200
Browse files Browse the repository at this point in the history
  • Loading branch information
janvennemann committed Oct 22, 2020
2 parents 344024b + c91972d commit 481fd30
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,16 @@ public void updateBadge(int index)
return;
}

Object badgeValue = tabProxy.getProperty(TiC.PROPERTY_BADGE);
if ((badgeValue == null) && !TiUIHelper.isUsingMaterialTheme(this.mBottomNavigationView.getContext())) {
return;
}

int menuItemId = this.mBottomNavigationView.getMenu().getItem(index).getItemId();
BadgeDrawable badgeDrawable = this.mBottomNavigationView.getOrCreateBadge(menuItemId);
if (tabProxy.getProperty(TiC.PROPERTY_BADGE) != null) {
if (badgeValue != null) {
badgeDrawable.setVisible(true);
badgeDrawable.setNumber(TiConvert.toInt(tabProxy.getProperty(TiC.PROPERTY_BADGE), 0));
badgeDrawable.setNumber(TiConvert.toInt(badgeValue, 0));
} else {
badgeDrawable.setVisible(false);
}
Expand All @@ -314,8 +319,8 @@ public void updateBadgeColor(int index)
return;
}

int menuItemId = this.mBottomNavigationView.getMenu().getItem(index).getItemId();
if (tabProxy.getProperty(TiC.PROPERTY_BADGE_COLOR) != null) {
int menuItemId = this.mBottomNavigationView.getMenu().getItem(index).getItemId();
BadgeDrawable badgeDrawable = this.mBottomNavigationView.getOrCreateBadge(menuItemId);
badgeDrawable.setBackgroundColor(
TiConvert.toColor((String) tabProxy.getProperty(TiC.PROPERTY_BADGE_COLOR)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,15 @@ public void updateBadge(int index)
return;
}

Object badgeValue = tabProxy.getProperty(TiC.PROPERTY_BADGE);
if ((badgeValue == null) && !TiUIHelper.isUsingMaterialTheme(this.mTabLayout.getContext())) {
return;
}

BadgeDrawable badgeDrawable = this.mTabLayout.getTabAt(index).getOrCreateBadge();
if (tabProxy.getProperty(TiC.PROPERTY_BADGE) != null) {
if (badgeValue != null) {
badgeDrawable.setVisible(true);
badgeDrawable.setNumber(TiConvert.toInt(tabProxy.getProperty(TiC.PROPERTY_BADGE), 0));
badgeDrawable.setNumber(TiConvert.toInt(badgeValue, 0));
} else {
badgeDrawable.setVisible(false);
}
Expand All @@ -300,8 +305,8 @@ public void updateBadgeColor(int index)
return;
}

BadgeDrawable badgeDrawable = this.mTabLayout.getTabAt(index).getOrCreateBadge();
if (tabProxy.getProperty(TiC.PROPERTY_BADGE_COLOR) != null) {
BadgeDrawable badgeDrawable = this.mTabLayout.getTabAt(index).getOrCreateBadge();
badgeDrawable.setVisible(true);
badgeDrawable.setBackgroundColor(
TiConvert.toColor((String) tabProxy.getProperty(TiC.PROPERTY_BADGE_COLOR)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import android.content.DialogInterface.OnClickListener;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Bitmap.Config;
Expand Down Expand Up @@ -1288,6 +1289,25 @@ public static String getBackgroundColorForState(TiBackgroundDrawable backgroundD
return null;
}

/**
* Determines if the given context has been assigned a "Theme.MaterialComponents" derived theme.
* @param context Reference to the context such as an Activity or Application object to inspect. Can be null.
* @return Returns true if assigned a material theme. Returns false if not or argument is null.
*/
public static boolean isUsingMaterialTheme(Context context)
{
if (context == null) {
return false;
}

TypedArray typedArray = context.obtainStyledAttributes(new int[] {
com.google.android.material.R.attr.colorPrimaryVariant
});
boolean isMaterial = typedArray.hasValue(0);
typedArray.recycle();
return isMaterial;
}

public static String hexStringFrom(int colorInt)
{
return String.format("#%08X", 0xFFFFFFFF & colorInt);
Expand Down
9 changes: 5 additions & 4 deletions iphone/Classes/TiUITableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ - (void)replaceData:(NSMutableArray *)data animation:(UITableViewRowAnimation)an
//won't have any problems in the case that it is actually nil.
TiUITableViewProxy *ourProxy = (TiUITableViewProxy *)[self proxy];

NSUInteger oldCount = [ourProxy sectionCount];
NSUInteger oldCount = ourProxy.sectionCount.unsignedIntegerValue;

for (TiUITableViewSectionProxy *section in [(TiUITableViewProxy *)[self proxy] internalSections]) {
if ([section parent] == ourProxy) {
Expand Down Expand Up @@ -1313,7 +1313,8 @@ - (void)updateSearchResultIndexes
}
NSEnumerator *searchResultIndexEnumerator;
if (searchResultIndexes == nil) {
searchResultIndexes = [[NSMutableArray alloc] initWithCapacity:[(TiUITableViewProxy *)[self proxy] sectionCount]];
NSUInteger sectionCount = [(TiUITableViewProxy *)[self proxy] sectionCount].unsignedIntegerValue;
searchResultIndexes = [[NSMutableArray alloc] initWithCapacity:sectionCount];
searchResultIndexEnumerator = nil;
} else {
searchResultIndexEnumerator = [searchResultIndexes objectEnumerator];
Expand Down Expand Up @@ -2124,7 +2125,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)ourTableView
return 1;
}
// One quirk of UITableView is that it really hates having 0 sections. Instead, supply 1 section, no rows.
NSUInteger result = [(TiUITableViewProxy *)[self proxy] sectionCount];
NSUInteger result = [(TiUITableViewProxy *)[self proxy] sectionCount].unsignedIntegerValue;
return MAX(1, result);
}

Expand Down Expand Up @@ -2166,7 +2167,7 @@ - (void)tableView:(UITableView *)ourTableView commitEditingStyle:(UITableViewCel
[table beginUpdates];
if (emptySection) {
NSIndexSet *thisSectionSet = [NSIndexSet indexSetWithIndex:[indexPath section]];
if ([(TiUITableViewProxy *)[self proxy] sectionCount] > 0) {
if ([(TiUITableViewProxy *)[self proxy] sectionCount].unsignedIntegerValue > 0) {
[table deleteSections:thisSectionSet withRowAnimation:UITableViewRowAnimationFade];
} else //There always must be at least one section. So instead, we have it reload to clear out the header and footer, etc.
{
Expand Down
2 changes: 1 addition & 1 deletion iphone/Classes/TiUITableViewProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
- (NSArray *)data;
//Sections and Data are the sanitized version.
@property (nonatomic, readwrite, copy) NSArray *sections;
- (NSUInteger)sectionCount;
- (NSNumber *)sectionCount;

#pragma mark NON-JS functionality
//internalSections is until TODO: Stop JS from using ValueForKey
Expand Down
4 changes: 2 additions & 2 deletions iphone/Classes/TiUITableViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -882,9 +882,9 @@ - (void)willShow
[(TiUITableView *)[self view] refreshSearchControllerUsingReload:YES];
}

- (NSUInteger)sectionCount
- (NSNumber *)sectionCount
{ //TODO: Shouldn't this be in the main thread, too?
return [sections count];
return NUMUINTEGER((sections != nil) ? sections.count : 0);
}

- (TiUITableViewSectionProxy *)tableSectionFromArg:(id)arg
Expand Down

0 comments on commit 481fd30

Please sign in to comment.