Skip to content

Commit ebda803

Browse files
committed
refactor(bottom-tabs,iOS): prop renaming (avoid conflicts with UIKit) & workarounds for codegen issues (#18)
## Description See particular commits description for full context. - **Rename isFocused -> isSelectedScreen in platform code** - **Flatten props namespace due to codegen limitations** Closes #17 ## Changes :point_up: ## Test code and steps to reproduce N/A ## Checklist - [ ] Ensured that CI passes
1 parent ea98952 commit ebda803

7 files changed

+21
-22
lines changed

apps/src/tests/TestBottomTabs.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ function App() {
3434
<View style={{ flex: 1 }}>
3535
<BottomTabs
3636
tabBarBackgroundColor={Colors.NavyLight100}
37-
tabBarAppearance={{ backgroundColor: Colors.NavyLight100 }}
38-
tabBarItemAppearance={{ titleFontSize: 28 }}
37+
tabBarItemTitleFontSize={14}
3938
>
4039
<BottomTabsScreen
4140
isFocused={focusedTab % 3 === 0}

ios/bottom-tabs/RNSBottomTabsHostComponentView.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props
149149
rnscreens::conversion::RNSUIBlurEffectFromRNSBottomTabsTabBarBlurEffect(newComponentProps.tabBarBlurEffect);
150150
}
151151

152-
if (newComponentProps.tabBarItemAppearance.titleFontSize != oldComponentProps.tabBarItemAppearance.titleFontSize) {
153-
_tabBarItemTitleFontSize = [NSNumber numberWithFloat:newComponentProps.tabBarItemAppearance.titleFontSize];
152+
if (newComponentProps.tabBarItemTitleFontSize != oldComponentProps.tabBarItemTitleFontSize) {
153+
_tabBarItemTitleFontSize = [NSNumber numberWithFloat:newComponentProps.tabBarItemTitleFontSize];
154154
_needsTabBarAppearanceUpdate = YES;
155155
}
156156

ios/bottom-tabs/RNSBottomTabsScreenComponentView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
3131
*/
3232
@interface RNSBottomTabsScreenComponentView ()
3333

34-
@property (nonatomic, readonly) BOOL isFocused;
34+
@property (nonatomic, readonly) BOOL isSelectedScreen;
3535
@property (nonatomic, readonly, nullable) NSString *badgeValue;
3636
@property (nonatomic, readonly, nullable) UIColor *badgeColor;
3737

ios/bottom-tabs/RNSBottomTabsScreenComponentView.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ - (void)initState
3939

4040
- (void)resetProps
4141
{
42-
_isFocused = NO;
42+
_isSelectedScreen = NO;
4343
_badgeValue = nil;
4444
_title = nil;
4545
_badgeColor = nil;
@@ -121,7 +121,7 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props
121121
}
122122

123123
if (newComponentProps.isFocused != oldComponentProps.isFocused) {
124-
_isFocused = newComponentProps.isFocused;
124+
_isSelectedScreen = newComponentProps.isFocused;
125125
tabItemNeedsAppearanceUpdate = true;
126126
}
127127

ios/bottom-tabs/RNSTabBarController.mm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ - (void)reactMountingTransactionDidMount
5858
[self updateTabBarAppearanceIfNeeded];
5959
}
6060

61+
#pragma mark-- Signals related
62+
6163
- (void)updateReactChildrenControllersIfNeeded
6264
{
6365
if (_needsUpdateOfReactChildrenControllers) {
@@ -97,8 +99,8 @@ - (void)updateSelectedViewController
9799
NSLog(
98100
@"Update Selected View Controller [%ld] isFocused %d",
99101
tabViewController.tabScreenComponentView.tag,
100-
tabViewController.tabScreenComponentView.isFocused);
101-
if (tabViewController.tabScreenComponentView.isFocused == true) {
102+
tabViewController.tabScreenComponentView.isSelectedScreen);
103+
if (tabViewController.tabScreenComponentView.isSelectedScreen == true) {
102104
selectedViewController = tabViewController;
103105
break;
104106
}
@@ -141,7 +143,7 @@ - (void)assertExactlyOneFocusedTab
141143
{
142144
int selectedCount = 0;
143145
for (RNSTabsScreenViewController *tabViewController in _tabScreenControllers) {
144-
if (tabViewController.tabScreenComponentView.isFocused) {
146+
if (tabViewController.tabScreenComponentView.isSelectedScreen) {
145147
++selectedCount;
146148
}
147149
}

ios/bottom-tabs/RNSTabsScreenViewController.mm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ - (nullable RNSBottomTabsScreenComponentView *)tabScreenComponentView
1515

1616
- (void)tabScreenFocusHasChanged
1717
{
18-
NSLog(@"TabScreen [%ld] changed focus: %d", self.tabScreenComponentView.tag, self.tabScreenComponentView.isFocused);
18+
NSLog(
19+
@"TabScreen [%ld] changed focus: %d",
20+
self.tabScreenComponentView.tag,
21+
self.tabScreenComponentView.isSelectedScreen);
1922

2023
// The focus of owned tab has been updated from react. We tell the parent controller that it should update the
2124
// container.

src/fabric/BottomTabsNativeComponent.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@ import { Float, WithDefault } from 'react-native/Libraries/Types/CodegenTypes';
77
// TODO: Report issue on RN repo, that nesting color value inside a struct does not work.
88
// Generated code is ok, but the value is not passed down correctly - whatever color is set
99
// host component receives RGBA(0, 0, 0, 0) anyway.
10-
type TabBarAppearance = {
11-
backgroundColor?: ColorValue;
12-
};
13-
14-
type TabBarItemAppearance = {
15-
titleFontSize?: Float;
16-
};
10+
// type TabBarAppearance = {
11+
// backgroundColor?: ColorValue;
12+
// };
1713

1814
type BlurEffect =
1915
| 'none'
@@ -40,12 +36,11 @@ type BlurEffect =
4036

4137
export interface NativeProps extends ViewProps {
4238
// Appearance
43-
tabBarAppearance?: TabBarAppearance; // Does not work due to codegen issue.
39+
// tabBarAppearance?: TabBarAppearance; // Does not work due to codegen issue.
40+
4441
tabBarBackgroundColor?: ColorValue;
4542
tabBarBlurEffect?: WithDefault<BlurEffect, 'none'>;
46-
47-
tabBarItemAppearance?: TabBarItemAppearance;
48-
tabBarItemSelectedAppearance?: TabBarItemAppearance;
43+
tabBarItemTitleFontSize?: Float;
4944
}
5045

5146
export default codegenNativeComponent<NativeProps>('RNSBottomTabs', {});

0 commit comments

Comments
 (0)