react-native-navigation icon indicating copy to clipboard operation
react-native-navigation copied to clipboard

bottomTabs: { backgroundColor } seems to have no effect (iOS 15/Xcode 13)

Open marcshilling opened this issue 5 years ago • 10 comments

🐛 Bug Report

Building with Xcode 13 seems to have broken the bottom tab background color option. The color specified via Navigation.setDefaultOptions has no effect and the bottom tabs are always mounted with the default color.

My bottom tabs each have stack navigation within them. I've noticed that the correct BG color takes effect on some screens after being pushed, and that the bottom tabs remain the correct color as long as that screen is mounted (even if I navigate to other tabs). But as soon as that screen is popped the background color reverts to the default. I haven't found a reason for this yet... I do not alter the bottom tab options ever other than in the initial setDefaultOptions

marcshilling avatar Sep 20 '21 21:09 marcshilling

Tested on [email protected], and [email protected] as well.

andres-torres-marroquin avatar Sep 20 '21 22:09 andres-torres-marroquin

I'm having a similar issue, where switching between tabs multiple times eventually somewhat "fixes" the background color temporarily, until I push or pop a screen.

Edit: it seems like the color is applied only with drawBehind: true. Having translucent: true also has a weird behaviour, however it is not enough to have color. In the best case there's at least some clipping or a glitch for a split second when switching tabs where the tab bar background "disappears".

habovh avatar Sep 21 '21 15:09 habovh

Similar issue to me here when using topBar.noBorder: true building in Xcode 13, when running on an iOS 15 device (release and debug) in the latest RNN and 0.64.2 React Native versions.

TheOtherJFK avatar Sep 21 '21 19:09 TheOtherJFK

Similar issue to me here when using topBar.noBorder: true building in Xcode 13, when running on an iOS 15 device (release and debug) in the latest RNN and 0.64.2 React Native versions.

I noticed this too, but was able to work around it by using

scrollEdgeAppearance: {
  active: true,
  noBorder: true,
}

marcshilling avatar Sep 21 '21 19:09 marcshilling

We've got a transparent Tabbar as well

StasDoskalenkoHover avatar Sep 22 '21 18:09 StasDoskalenkoHover

Same issue here

geroale avatar Sep 22 '21 18:09 geroale

According to this article on medium, it seems like RNN needs to shift to using UIBarAppearance instead of setting .tintColor directly: https://github.com/wix/react-native-navigation/blob/b53f13c60fe6498ad1690adf1dfd7509f602965c/lib/ios/RNNBottomTabsPresenter.m#L10-L12

Unfortunately this seems to be quite a large refactoring, as it is impacting more than just bottom tabs like others mentioned here. I may be wrong with this statement as my experience in native dev is very limited. Also, it needs to be backwards compatible because UIBarAppearance is an iOS 13+ feature.

All in all, I think implementing/fixing this should be a priority, since Xcode 13 is now live.

On a side note, I should mention that apps build using Xcode 12 were running fine on iOS 15. Issues arise when building using Xcode 13 only.

habovh avatar Sep 23 '21 09:09 habovh

Heck, decided to give it a go. Here's the patch I'm using, it seems that every feature that I use is working again!

⚠️ Disclaimer: this is a hot-fix that has not been tested outside of my current usage of RNN. It brings background on bottom tabs as expected. It might fix your specific issue, but might not.

What this patch essentially does, is that it also sets the scrollEdgeAppearance everywhere RNN sets a standardAppearance on its components. I'll open a PR with this so that others can review and eventually get this sorted quickly!

diff --git a/node_modules/react-native-navigation/lib/ios/BottomTabsAppearancePresenter.m b/node_modules/react-native-navigation/lib/ios/BottomTabsAppearancePresenter.m
index 85cfcc5..2ffdf1e 100644
--- a/node_modules/react-native-navigation/lib/ios/BottomTabsAppearancePresenter.m
+++ b/node_modules/react-native-navigation/lib/ios/BottomTabsAppearancePresenter.m
@@ -28,8 +28,12 @@
 
 - (void)setTabBarBackgroundColor:(UIColor *)backgroundColor {
     [self setTabBarOpaqueBackground];
-    for (UIViewController *childViewController in self.tabBarController.childViewControllers)
+    for (UIViewController *childViewController in self.tabBarController.childViewControllers) {
         childViewController.tabBarItem.standardAppearance.backgroundColor = backgroundColor;
+        if (@available(iOS 15.0, *)) {
+            childViewController.tabBarItem.scrollEdgeAppearance.backgroundColor = backgroundColor;
+        }
+    }
 }
 
 - (void)setTabBarTranslucent:(BOOL)translucent {
@@ -46,18 +50,31 @@
 }
 
 - (void)setTabBarTranslucentBackground {
-    for (UIViewController *childViewController in self.tabBarController.childViewControllers)
+    for (UIViewController *childViewController in self.tabBarController.childViewControllers) {
         [childViewController.tabBarItem.standardAppearance configureWithDefaultBackground];
+        if (@available(iOS 15.0, *)) {
+            [childViewController.tabBarItem.scrollEdgeAppearance configureWithDefaultBackground];
+        }
+    }
 }
 
 - (void)setTabBarTransparentBackground {
-    for (UIViewController *childViewController in self.tabBarController.childViewControllers)
+    for (UIViewController *childViewController in self.tabBarController.childViewControllers) {
         [childViewController.tabBarItem.standardAppearance configureWithTransparentBackground];
+        if (@available(iOS 15.0, *)) {
+            [childViewController.tabBarItem.scrollEdgeAppearance configureWithTransparentBackground];
+        }
+    }
+      
 }
 
 - (void)setTabBarOpaqueBackground {
-    for (UIViewController *childViewController in self.tabBarController.childViewControllers)
+    for (UIViewController *childViewController in self.tabBarController.childViewControllers) {
         [childViewController.tabBarItem.standardAppearance configureWithOpaqueBackground];
+        if (@available(iOS 15.0, *)) {
+            [childViewController.tabBarItem.scrollEdgeAppearance configureWithOpaqueBackground];
+        }
+    }
 }
 
 @end
diff --git a/node_modules/react-native-navigation/lib/ios/RNNBottomTabsController.m b/node_modules/react-native-navigation/lib/ios/RNNBottomTabsController.m
index 0472198..826ac1e 100644
--- a/node_modules/react-native-navigation/lib/ios/RNNBottomTabsController.m
+++ b/node_modules/react-native-navigation/lib/ios/RNNBottomTabsController.m
@@ -41,6 +41,10 @@
         self.tabBar.standardAppearance = [UITabBarAppearance new];
     }
 
+    if (@available(iOS 15.0, *)) {
+        self.tabBar.scrollEdgeAppearance = [UITabBarAppearance new];
+    }
+
     self.longPressRecognizer =
         [[UILongPressGestureRecognizer alloc] initWithTarget:self
                                                       action:@selector(handleLongPressGesture:)];
diff --git a/node_modules/react-native-navigation/lib/ios/TabBarItemAppearanceCreator.m b/node_modules/react-native-navigation/lib/ios/TabBarItemAppearanceCreator.m
index 36b98b5..a49024e 100644
--- a/node_modules/react-native-navigation/lib/ios/TabBarItemAppearanceCreator.m
+++ b/node_modules/react-native-navigation/lib/ios/TabBarItemAppearanceCreator.m
@@ -6,6 +6,10 @@
     UITabBarItem *tabBarItem = [super createTabBarItem:mergeItem];
     tabBarItem.standardAppearance =
         mergeItem.standardAppearance ?: [[UITabBarAppearance alloc] init];
+    if (@available(iOS 15.0, *)) {
+        tabBarItem.scrollEdgeAppearance =
+            mergeItem.scrollEdgeAppearance ?: [[UITabBarAppearance alloc] init];
+    }
     return tabBarItem;
 }
 
@@ -14,6 +18,12 @@
     tabItem.standardAppearance.compactInlineLayoutAppearance.normal.titleTextAttributes =
         titleAttributes;
     tabItem.standardAppearance.inlineLayoutAppearance.normal.titleTextAttributes = titleAttributes;
+    if (@available(iOS 15.0, *)) {
+        tabItem.scrollEdgeAppearance.stackedLayoutAppearance.normal.titleTextAttributes = titleAttributes;
+        tabItem.scrollEdgeAppearance.compactInlineLayoutAppearance.normal.titleTextAttributes =
+            titleAttributes;
+        tabItem.scrollEdgeAppearance.inlineLayoutAppearance.normal.titleTextAttributes = titleAttributes;
+    }
 }
 
 + (void)setSelectedTitleAttributes:(UITabBarItem *)tabItem
@@ -24,6 +34,14 @@
         selectedTitleAttributes;
     tabItem.standardAppearance.inlineLayoutAppearance.selected.titleTextAttributes =
         selectedTitleAttributes;
+    if (@available(iOS 15.0, *)) {
+        tabItem.scrollEdgeAppearance.stackedLayoutAppearance.selected.titleTextAttributes =
+            selectedTitleAttributes;
+        tabItem.scrollEdgeAppearance.compactInlineLayoutAppearance.selected.titleTextAttributes =
+            selectedTitleAttributes;
+        tabItem.scrollEdgeAppearance.inlineLayoutAppearance.selected.titleTextAttributes =
+            selectedTitleAttributes;
+    }
 }
 
 @end
diff --git a/node_modules/react-native-navigation/lib/ios/UIViewController+RNNOptions.m b/node_modules/react-native-navigation/lib/ios/UIViewController+RNNOptions.m
index fc670ad..ec3263a 100644
--- a/node_modules/react-native-navigation/lib/ios/UIViewController+RNNOptions.m
+++ b/node_modules/react-native-navigation/lib/ios/UIViewController+RNNOptions.m
@@ -98,6 +98,10 @@ const NSInteger BLUR_STATUS_TAG = 78264801;
     if (@available(iOS 13.0, *)) {
         self.tabBarItem.standardAppearance.stackedLayoutAppearance.normal.badgeBackgroundColor =
             badgeColor;
+        if (@available(iOS 15.0, *)) {
+            self.tabBarItem.scrollEdgeAppearance.stackedLayoutAppearance.normal.badgeBackgroundColor =
+                badgeColor;
+        }
     } else {
         self.tabBarItem.badgeColor = badgeColor;
     }

habovh avatar Sep 23 '21 10:09 habovh

ETA on a new release for this?

marcshilling avatar Sep 30 '21 15:09 marcshilling

@marcshilling The PR just got merged today, I'm not sure how the release cycle works here but if the next release is based off master I guess we can expect this to be released any day now! Also if it's blocking for you there's a patch file you can use for the time being!

Edit: I realize this comment is quite moot since the patch is right here in this thread, I thought this was another issue, sorry.

habovh avatar Sep 30 '21 15:09 habovh