mirror of
https://github.com/status-im/react-native.git
synced 2025-01-15 20:15:11 +00:00
5baffa03fd
- [ReactNative] Use deprecated ix in TabBarExample | Amjad Masad - [ReactNative] Expanded license on obj-c files | Christopher Chedeau - [ReactNative] Expanded license on js files | Christopher Chedeau - [ReactNative] Fix React Devtools integration | Alex Kotliarskyi - [Text] Account for font leading so descenders are not clipped | James Ide - [ReactNative] Expanded license on js packager files | Christopher Chedeau - more UIExplorer flow | Basil Hosmer - [react-packager] Pick up package changes while running | Amjad Masad - Added a graph view and a ReactNative metric that displays current queue and execution time for the JS thread. | Bryce Redd - [ReactNative] Add NativeModules and DeviceEventEmitter to react-native exports | Alex Kotliarskyi
91 lines
2.4 KiB
Objective-C
91 lines
2.4 KiB
Objective-C
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
#import "RCTTabBarItem.h"
|
|
|
|
#import "RCTConvert.h"
|
|
#import "RCTLog.h"
|
|
#import "UIView+ReactKit.h"
|
|
|
|
@implementation RCTTabBarItem
|
|
|
|
@synthesize barItem = _barItem;
|
|
|
|
- (UITabBarItem *)barItem
|
|
{
|
|
if (!_barItem) {
|
|
_barItem = [[UITabBarItem alloc] init];
|
|
}
|
|
return _barItem;
|
|
}
|
|
|
|
- (void)setIcon:(NSString *)icon
|
|
{
|
|
static NSDictionary *systemIcons;
|
|
static dispatch_once_t onceToken;
|
|
dispatch_once(&onceToken, ^{
|
|
systemIcons = @{
|
|
@"more": @(UITabBarSystemItemMore),
|
|
@"favorites": @(UITabBarSystemItemFavorites),
|
|
@"featured": @(UITabBarSystemItemFeatured),
|
|
@"topRated": @(UITabBarSystemItemTopRated),
|
|
@"recents": @(UITabBarSystemItemRecents),
|
|
@"contacts": @(UITabBarSystemItemContacts),
|
|
@"history": @(UITabBarSystemItemHistory),
|
|
@"bookmarks": @(UITabBarSystemItemBookmarks),
|
|
@"search": @(UITabBarSystemItemSearch),
|
|
@"downloads": @(UITabBarSystemItemDownloads),
|
|
@"mostRecent": @(UITabBarSystemItemMostRecent),
|
|
@"mostViewed": @(UITabBarSystemItemMostViewed),
|
|
};
|
|
});
|
|
|
|
// Update icon
|
|
BOOL wasSystemIcon = (systemIcons[_icon] != nil);
|
|
_icon = [icon copy];
|
|
|
|
// Check if string matches any custom images first
|
|
UIImage *image = [RCTConvert UIImage:_icon];
|
|
UITabBarItem *oldItem = _barItem;
|
|
if (image) {
|
|
|
|
// Recreate barItem if previous item was a system icon
|
|
if (wasSystemIcon) {
|
|
_barItem = nil;
|
|
self.barItem.image = image;
|
|
} else {
|
|
self.barItem.image = image;
|
|
return;
|
|
}
|
|
|
|
} else {
|
|
|
|
// Not a custom image, may be a system item?
|
|
NSNumber *systemIcon = systemIcons[icon];
|
|
if (!systemIcon) {
|
|
RCTLogError(@"The tab bar icon '%@' did not match any known image or system icon", icon);
|
|
return;
|
|
}
|
|
_barItem = [[UITabBarItem alloc] initWithTabBarSystemItem:[systemIcon integerValue] tag:oldItem.tag];
|
|
}
|
|
|
|
// Reapply previous properties
|
|
_barItem.title = oldItem.title;
|
|
_barItem.imageInsets = oldItem.imageInsets;
|
|
_barItem.selectedImage = oldItem.selectedImage;
|
|
_barItem.badgeValue = oldItem.badgeValue;
|
|
}
|
|
|
|
- (UIViewController *)backingViewController
|
|
{
|
|
return self.superview.backingViewController;
|
|
}
|
|
|
|
@end
|