|
| 1 | +#import "RNSBarItemView.h" |
| 2 | + |
| 3 | +#import <React/RCTConversions.h> |
| 4 | + |
| 5 | +#import <react/renderer/components/RNSBarViewSpec/ComponentDescriptors.h> |
| 6 | +#import <react/renderer/components/RNSBarViewSpec/EventEmitters.h> |
| 7 | +#import <react/renderer/components/RNSBarViewSpec/Props.h> |
| 8 | +#import <react/renderer/components/RNSBarViewSpec/RCTComponentViewHelpers.h> |
| 9 | + |
| 10 | +#import "BarPropHelpers.h" |
| 11 | +#import "RNSBarView.h" |
| 12 | + |
| 13 | +using namespace facebook::react; |
| 14 | + |
| 15 | +@interface RNSBarView (BarInternal) |
| 16 | +- (void)updateBarItems; |
| 17 | +- (void)updateBarItem:(RNSBarItemView *)itemView; |
| 18 | +@end |
| 19 | + |
| 20 | +@implementation RNSBarItemView |
| 21 | + |
| 22 | ++ (ComponentDescriptorProvider)componentDescriptorProvider |
| 23 | +{ |
| 24 | + return concreteComponentDescriptorProvider<RNSBarItemComponentDescriptor>(); |
| 25 | +} |
| 26 | + |
| 27 | +- (instancetype)initWithFrame:(CGRect)frame |
| 28 | +{ |
| 29 | + if (self = [super initWithFrame:frame]) { |
| 30 | + static const auto defaultProps = std::make_shared<const RNSBarItemProps>(); |
| 31 | + _props = defaultProps; |
| 32 | + |
| 33 | + self.hidden = YES; |
| 34 | + self.userInteractionEnabled = NO; |
| 35 | + } |
| 36 | + |
| 37 | + return self; |
| 38 | +} |
| 39 | + |
| 40 | +- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps |
| 41 | +{ |
| 42 | + const auto &oldItemProps = *std::static_pointer_cast<RNSBarItemProps const>(_props); |
| 43 | + const auto &newItemProps = *std::static_pointer_cast<RNSBarItemProps const>(props); |
| 44 | + |
| 45 | + APPLY_STRING_PROP(self, oldItemProps, newItemProps, title); |
| 46 | + APPLY_STRING_PROP(self, oldItemProps, newItemProps, icon); |
| 47 | + APPLY_STRING_PROP(self, oldItemProps, newItemProps, placement); |
| 48 | + APPLY_STRING_PROP(self, oldItemProps, newItemProps, variant); |
| 49 | + |
| 50 | + APPLY_COLOR_PROP(self, oldItemProps, newItemProps, tintColor); |
| 51 | + |
| 52 | + APPLY_OPTIONAL_DOUBLE_PROP(self, oldItemProps, newItemProps, width); |
| 53 | + APPLY_BOOL_PROP(self, oldItemProps, newItemProps, disabled); |
| 54 | + APPLY_BOOL_PROP(self, oldItemProps, newItemProps, selected); |
| 55 | + APPLY_STRING_PROP(self, oldItemProps, newItemProps, accessibilityLabel); |
| 56 | + APPLY_STRING_PROP(self, oldItemProps, newItemProps, accessibilityHint); |
| 57 | + APPLY_STRING_PROP(self, oldItemProps, newItemProps, testID); |
| 58 | + APPLY_STRING_PROP(self, oldItemProps, newItemProps, titleFontFamily); |
| 59 | + APPLY_STRING_PROP(self, oldItemProps, newItemProps, titleFontWeight); |
| 60 | + APPLY_OPTIONAL_DOUBLE_PROP(self, oldItemProps, newItemProps, titleFontSize); |
| 61 | + |
| 62 | + APPLY_COLOR_PROP(self, oldItemProps, newItemProps, titleColor); |
| 63 | + |
| 64 | + APPLY_STRING_PROP(self, oldItemProps, newItemProps, identifier); |
| 65 | + APPLY_BOOL_PROP(self, oldItemProps, newItemProps, hidesSharedBackground); |
| 66 | + APPLY_BOOL_PROP(self, oldItemProps, newItemProps, sharesBackground); |
| 67 | + APPLY_BOOL_PROP(self, oldItemProps, newItemProps, hasSharesBackground); |
| 68 | + APPLY_BOOL_PROP(self, oldItemProps, newItemProps, hasBadge); |
| 69 | + |
| 70 | + APPLY_NUMBER_PROP(self, oldItemProps, newItemProps, badgeCount); |
| 71 | + |
| 72 | + APPLY_STRING_PROP(self, oldItemProps, newItemProps, badgeValue); |
| 73 | + |
| 74 | + APPLY_COLOR_PROP(self, oldItemProps, newItemProps, badgeForegroundColor); |
| 75 | + APPLY_COLOR_PROP(self, oldItemProps, newItemProps, badgeBackgroundColor); |
| 76 | + |
| 77 | + APPLY_STRING_PROP(self, oldItemProps, newItemProps, badgeFontFamily); |
| 78 | + APPLY_STRING_PROP(self, oldItemProps, newItemProps, badgeFontWeight); |
| 79 | + APPLY_OPTIONAL_DOUBLE_PROP(self, oldItemProps, newItemProps, badgeFontSize); |
| 80 | + |
| 81 | + [super updateProps:props oldProps:oldProps]; |
| 82 | + |
| 83 | + if (self.barParent != nil) { |
| 84 | + [self.barParent updateBarItem:self]; |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +- (void)emitPress |
| 89 | +{ |
| 90 | + if (self.disabled) { |
| 91 | + return; |
| 92 | + } |
| 93 | + |
| 94 | + if (auto eventEmitter = std::static_pointer_cast<RNSBarItemEventEmitter const>(_eventEmitter)) { |
| 95 | + eventEmitter->onItemPress({}); |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +@end |
0 commit comments