1
1
#import " RNSTabBarAppearanceCoordinator.h"
2
2
#import < React/RCTFont.h>
3
3
#import " RNSConversions.h"
4
+ #import " RNSTabBarAppearanceProvider.h"
4
5
#import " RNSTabsScreenViewController.h"
5
6
6
7
@implementation RNSTabBarAppearanceCoordinator
@@ -18,8 +19,7 @@ - (void)updateAppearanceOfTabBar:(nullable UITabBar *)tabBar
18
19
19
20
// Step 2 - general settings
20
21
if (hostComponentView != nil ) {
21
- appearance.backgroundColor = hostComponentView.tabBarBackgroundColor ;
22
- appearance.backgroundEffect = hostComponentView.tabBarBlurEffect ;
22
+ [self configureTabBarAppearance: appearance fromAppearanceProvider: hostComponentView];
23
23
24
24
[self configureTabBarItemAppearance: appearance.stackedLayoutAppearance withTabsHost: hostComponentView];
25
25
[self configureTabBarItemAppearance: appearance.compactInlineLayoutAppearance withTabsHost: hostComponentView];
@@ -45,6 +45,8 @@ - (void)updateAppearanceOfTabBar:(nullable UITabBar *)tabBar
45
45
// Inherit general properties from host
46
46
UITabBarAppearance *tabAppearance = [[UITabBarAppearance alloc ] initWithBarAppearance: appearance];
47
47
48
+ [self configureTabBarAppearance: tabAppearance fromAppearanceProvider: tabScreenCtrl.tabScreenComponentView];
49
+
48
50
[self configureTabBarItemAppearance: tabAppearance.compactInlineLayoutAppearance
49
51
forTabScreenController: tabScreenCtrl
50
52
withHostComponentView: hostComponentView];
@@ -55,11 +57,31 @@ - (void)updateAppearanceOfTabBar:(nullable UITabBar *)tabBar
55
57
forTabScreenController: tabScreenCtrl
56
58
withHostComponentView: hostComponentView];
57
59
58
- tabScreenCtrl.tabBarItem .standardAppearance = tabAppearance;
59
- tabScreenCtrl.tabBarItem .scrollEdgeAppearance = tabAppearance;
60
+ [self configureTabBarItemForTabScreenController: tabScreenCtrl withAppearace: tabAppearance];
61
+ }
62
+ }
63
+
64
+ - (void )configureTabBarAppearance : (nonnull UITabBarAppearance *)appearance
65
+ fromAppearanceProvider : (id <RNSTabBarAppearanceProvider>)appearanceProvider
66
+ {
67
+ if (appearanceProvider.tabBarBackgroundColor != nil ) {
68
+ appearance.backgroundColor = appearanceProvider.tabBarBackgroundColor ;
69
+ }
70
+
71
+ if (appearanceProvider.tabBarBlurEffect != nil ) {
72
+ appearance.backgroundEffect = appearanceProvider.tabBarBlurEffect ;
60
73
}
61
74
}
62
75
76
+ - (void )configureTabBarItemForTabScreenController : (nonnull RNSTabsScreenViewController *)tabScreenCtrl
77
+ withAppearace : (nonnull UITabBarAppearance *)tabAppearance
78
+ {
79
+ UITabBarItem *tabBarItem = tabScreenCtrl.tabBarItem ;
80
+
81
+ tabBarItem.standardAppearance = tabAppearance;
82
+ tabBarItem.scrollEdgeAppearance = tabAppearance;
83
+ }
84
+
63
85
- (void )configureTabBarItemAppearance : (nonnull UITabBarItemAppearance *)tabBarItemAppearance
64
86
withTabsHost : (nonnull RNSBottomTabsHostComponentView *)hostComponent
65
87
{
@@ -77,16 +99,16 @@ - (void)configureTabBarItemAppearance:(nonnull UITabBarItemAppearance *)tabBarIt
77
99
}
78
100
79
101
[self configureTabBarItemStateAppearance: tabBarItemAppearance.normal
80
- withTabsHost : hostComponent
102
+ withAppearanceProvider : hostComponent
81
103
withTitleTextAttributes: titleTextAttributes];
82
104
[self configureTabBarItemStateAppearance: tabBarItemAppearance.selected
83
- withTabsHost : hostComponent
105
+ withAppearanceProvider : hostComponent
84
106
withTitleTextAttributes: titleTextAttributes];
85
107
[self configureTabBarItemStateAppearance: tabBarItemAppearance.focused
86
- withTabsHost : hostComponent
108
+ withAppearanceProvider : hostComponent
87
109
withTitleTextAttributes: titleTextAttributes];
88
110
[self configureTabBarItemStateAppearance: tabBarItemAppearance.disabled
89
- withTabsHost : hostComponent
111
+ withAppearanceProvider : hostComponent
90
112
withTitleTextAttributes: titleTextAttributes];
91
113
}
92
114
@@ -96,46 +118,40 @@ - (void)configureTabBarItemAppearance:(nonnull UITabBarItemAppearance *)tabBarIt
96
118
{
97
119
NSMutableDictionary *titleTextAttributes = nil ;
98
120
99
- if (tabScreenCtrl.tabScreenComponentView .titleFontSize != nil ) {
121
+ if (tabScreenCtrl.tabScreenComponentView .tabBarItemTitleFontSize != nil ) {
100
122
titleTextAttributes = [[NSMutableDictionary alloc ] init ];
101
- titleTextAttributes[NSFontAttributeName ] = [RCTFont updateFont: nil
102
- withFamily: nil
103
- size: tabScreenCtrl.tabScreenComponentView.titleFontSize
104
- weight: nil
105
- style: nil
106
- variant: nil
107
- scaleMultiplier: 1.0 ];
123
+ titleTextAttributes[NSFontAttributeName ] =
124
+ [RCTFont updateFont: nil
125
+ withFamily: nil
126
+ size: tabScreenCtrl.tabScreenComponentView.tabBarItemTitleFontSize
127
+ weight: nil
128
+ style: nil
129
+ variant: nil
130
+ scaleMultiplier: 1.0 ];
108
131
}
109
132
110
133
[self configureTabBarItemStateAppearance: tabBarItemAppearance.normal
111
- forTabScreenController : tabScreenCtrl
134
+ withAppearanceProvider : tabScreenCtrl.tabScreenComponentView
112
135
withTitleTextAttributes: titleTextAttributes];
113
136
[self configureTabBarItemStateAppearance: tabBarItemAppearance.selected
114
- forTabScreenController : tabScreenCtrl
137
+ withAppearanceProvider : tabScreenCtrl.tabScreenComponentView
115
138
withTitleTextAttributes: titleTextAttributes];
116
139
[self configureTabBarItemStateAppearance: tabBarItemAppearance.focused
117
- forTabScreenController : tabScreenCtrl
140
+ withAppearanceProvider : tabScreenCtrl.tabScreenComponentView
118
141
withTitleTextAttributes: titleTextAttributes];
119
142
[self configureTabBarItemStateAppearance: tabBarItemAppearance.disabled
120
- forTabScreenController : tabScreenCtrl
143
+ withAppearanceProvider : tabScreenCtrl.tabScreenComponentView
121
144
withTitleTextAttributes: titleTextAttributes];
122
145
}
123
146
124
147
- (void )configureTabBarItemStateAppearance : (nonnull UITabBarItemStateAppearance *)tabBarItemStateAppearance
125
- forTabScreenController : (nonnull RNSTabsScreenViewController *) tabScreenCtrl
148
+ withAppearanceProvider : ( id <RNSTabBarAppearanceProvider>) appearanceProvider
126
149
withTitleTextAttributes : (nullable NSDictionary <NSAttributedStringKey, id> *)titleTextAttributes
127
150
{
128
- tabBarItemStateAppearance.badgeBackgroundColor = tabScreenCtrl.tabScreenComponentView .badgeColor ;
129
-
130
- if (titleTextAttributes != nil ) {
131
- tabBarItemStateAppearance.titleTextAttributes = titleTextAttributes;
151
+ if (appearanceProvider.tabBarItemBadgeBackgroundColor != nil ) {
152
+ tabBarItemStateAppearance.badgeBackgroundColor = appearanceProvider.tabBarItemBadgeBackgroundColor ;
132
153
}
133
- }
134
154
135
- - (void )configureTabBarItemStateAppearance : (nonnull UITabBarItemStateAppearance *)tabBarItemStateAppearance
136
- withTabsHost : (nonnull RNSBottomTabsHostComponentView *)hostComponent
137
- withTitleTextAttributes : (nullable NSDictionary <NSAttributedStringKey, id> *)titleTextAttributes
138
- {
139
155
if (titleTextAttributes != nil ) {
140
156
tabBarItemStateAppearance.titleTextAttributes = titleTextAttributes;
141
157
}
0 commit comments