diff --git a/lib/ios/RNNDotIndicatorPresenter.m b/lib/ios/RNNDotIndicatorPresenter.m index d0f16ecec75..6869d071e20 100644 --- a/lib/ios/RNNDotIndicatorPresenter.m +++ b/lib/ios/RNNDotIndicatorPresenter.m @@ -49,12 +49,18 @@ - (void)apply:(UIViewController *)child options:(DotIndicatorOptions *)options { if ([self hasIndicator:child]) [self remove:child]; + UITabBarController *bottomTabs = [self getTabBarController:child]; + int index = (int)[[bottomTabs childViewControllers] indexOfObject:child]; + UIView *tabIcon = [bottomTabs getTabIcon:index]; + + if (!tabIcon) { + return; + } + UIView *indicator = [self createIndicator:options]; [child tabBarItem].tag = indicator.tag; - UITabBarController *bottomTabs = [self getTabBarController:child]; - int index = (int)[[bottomTabs childViewControllers] indexOfObject:child]; - [[bottomTabs getTabView:index] addSubview:indicator]; + [tabIcon addSubview:indicator]; [self applyConstraints:options badge:indicator tabBar:bottomTabs index:index]; } @@ -85,14 +91,14 @@ - (BOOL)currentIndicatorEquals:(UIViewController *)child options:(DotIndicatorOp if (![self hasIndicator:child]) return NO; UIView *currentIndicator = [self getCurrentIndicator:child]; - return - [[currentIndicator backgroundColor] isEqual:[options.color withDefault:[UIColor redColor]]]; + + return [[currentIndicator backgroundColor] isEqual:[options.color withDefault:[UIColor redColor]]]; } - (UIView *)getCurrentIndicator:(UIViewController *)child { UITabBarController *bottomTabs = [self getTabBarController:child]; int tabIndex = (int)[[bottomTabs childViewControllers] indexOfObject:child]; - return [[bottomTabs getTabView:tabIndex] viewWithTag:[child tabBarItem].tag]; + return [[bottomTabs getTabIcon:tabIndex] viewWithTag:[child tabBarItem].tag]; } - (BOOL)hasIndicator:(UIViewController *)child { diff --git a/playground/ios/NavigationTests/RNNDotIndicatorPresenterTest.m b/playground/ios/NavigationTests/RNNDotIndicatorPresenterTest.m index d37c4b2be3a..6a4e1453f76 100644 --- a/playground/ios/NavigationTests/RNNDotIndicatorPresenterTest.m +++ b/playground/ios/NavigationTests/RNNDotIndicatorPresenterTest.m @@ -75,17 +75,17 @@ - (void)testApply_itDoesNotRecreateIfEqualToCurrentlyVisibleIndicator { - (void)testApply_itAddsIndicatorToCorrectTabView { [self applyIndicator]; UIView *indicator1 = [self getIndicator]; - XCTAssertEqualObjects([indicator1 superview], [_bottomTabs getTabView:0]); + XCTAssertEqualObjects([indicator1 superview], [_bottomTabs getTabIcon:0]); } - (void)testApply_itRemovesPreviousDotIndicator { - NSUInteger childCountBeforeApplyingIndicator = [[_bottomTabs getTabView:0] subviews].count; + NSUInteger childCountBeforeApplyingIndicator = [[_bottomTabs getTabIcon:0] subviews].count; [self applyIndicator]; - NSUInteger childCountAfterApplyingIndicatorOnce = [[_bottomTabs getTabView:0] subviews].count; + NSUInteger childCountAfterApplyingIndicatorOnce = [[_bottomTabs getTabIcon:0] subviews].count; XCTAssertEqual(childCountBeforeApplyingIndicator + 1, childCountAfterApplyingIndicatorOnce); [self applyIndicator:[UIColor greenColor]]; - NSUInteger childCountAfterApplyingIndicatorTwice = [[_bottomTabs getTabView:0] subviews].count; + NSUInteger childCountAfterApplyingIndicatorTwice = [[_bottomTabs getTabIcon:0] subviews].count; XCTAssertEqual([[self getIndicator] backgroundColor], [UIColor greenColor]); XCTAssertEqual(childCountAfterApplyingIndicatorOnce, childCountAfterApplyingIndicatorTwice); } @@ -112,7 +112,7 @@ - (void)testApply_indicatorIsAlignedToTopRightOfIcon { UIView *indicator = [self getIndicator]; UIView *icon = [_bottomTabs getTabIcon:0]; - NSArray *alignmentConstraints = [_bottomTabs getTabView:0].constraints; + NSArray *alignmentConstraints = [_bottomTabs getTabIcon:0].constraints; XCTAssertEqual([alignmentConstraints count], 2); XCTAssertEqual([alignmentConstraints[0] constant], -4); XCTAssertEqual([alignmentConstraints[0] firstItem], indicator);