Skip to content

Commit d5e17be

Browse files
committed
feat(bottom-tabs,iOS): add support for title (#10)
## Description PR title says it all. ## Changes - **Native support for title** - **Expose title on JS side** - **Update example** ## Test code and steps to reproduce `TestBottomTabs` ## Checklist - [x] Included code example that can be used to test this change - [ ] Ensured that CI passes
1 parent 3c4ef70 commit d5e17be

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

apps/src/tests/TestBottomTabs.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ function App() {
3333
return (
3434
<View style={{ flex: 1 }}>
3535
<BottomTabs tabBarBackgroundColor={Colors.NavyLight100}>
36-
<BottomTabsScreen isFocused={focusedTab % 3 === 0} badgeValue="Tab 1" badgeColor={Colors.NavyDark80}>
36+
<BottomTabsScreen isFocused={focusedTab % 3 === 0} badgeValue="1" badgeColor={Colors.NavyDark80} title="Tab1">
3737
<LayoutView style={{ backgroundColor: Colors.OffWhite }} tabID={0}>
3838
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
3939
<Text>Hello world from native bottom tab</Text>
4040
<Button title="Next tab" onPress={selectNextTab} />
4141
</View>
4242
</LayoutView>
4343
</BottomTabsScreen>
44-
<BottomTabsScreen isFocused={focusedTab % 3 === 1} badgeValue="Tab 2" badgeColor={Colors.PurpleLight100}>
44+
<BottomTabsScreen isFocused={focusedTab % 3 === 1} badgeValue="2" badgeColor={Colors.PurpleLight100} title="Tab2">
4545
<LayoutView style={{ backgroundColor: Colors.PurpleLight80 }} tabID={1}>
4646
<Text>Tab2 world from native bottom tab</Text>
4747
<Button title="Next tab" onPress={selectNextTab} />
4848
</LayoutView>
4949
</BottomTabsScreen>
50-
<BottomTabsScreen isFocused={focusedTab % 3 === 2} badgeValue="Tab 3" badgeColor={Colors.YellowDark120}>
50+
<BottomTabsScreen isFocused={focusedTab % 3 === 2} badgeValue="3" badgeColor={Colors.YellowDark120} title="Tab3">
5151
<LayoutView style={{ backgroundColor: Colors.YellowDark80 }} tabID={2}>
5252
<Text>Tab3 world from native bottom tab</Text>
5353
<Button title="Next tab" onPress={selectNextTab} />

ios/bottom-tabs/RNSBottomTabsScreenComponentView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ NS_ASSUME_NONNULL_BEGIN
3434
@property (nonatomic, readonly) BOOL isFocused;
3535
@property (nonatomic, readonly, nullable) NSString *badgeValue;
3636
@property (nonatomic, readonly, nullable) UIColor *badgeColor;
37+
@property (nonatomic, readonly, nullable) NSString *title;
3738

3839
@end
3940

ios/bottom-tabs/RNSBottomTabsScreenComponentView.mm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import "RNSBottomTabsScreenComponentView.h"
2+
#import "RNSDefines.h"
23
#import "RNSTabBarController.h"
34

45
#import <React/RCTConversions.h>
@@ -28,8 +29,10 @@ - (void)initState
2829
{
2930
static const auto defaultProps = std::make_shared<const react::RNSBottomTabsScreenProps>();
3031
_props = defaultProps;
32+
3133
_controller = [RNSTabsScreenViewController new];
3234
_controller.view = self;
35+
3336
_reactSuperview = nil;
3437
[self resetProps];
3538
}
@@ -38,12 +41,16 @@ - (void)resetProps
3841
{
3942
_isFocused = NO;
4043
_badgeValue = nil;
44+
_title = nil;
45+
_badgeColor = nil;
4146
}
4247

48+
RNS_IGNORE_SUPER_CALL_BEGIN
4349
- (nullable RNSBottomTabsHostComponentView *)reactSuperview
4450
{
4551
return _reactSuperview;
4652
}
53+
RNS_IGNORE_SUPER_CALL_END
4754

4855
#pragma mark - Events
4956

@@ -101,6 +108,11 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props
101108
const auto &oldComponentProps = *std::static_pointer_cast<const react::RNSBottomTabsScreenProps>(_props);
102109
const auto &newComponentProps = *std::static_pointer_cast<const react::RNSBottomTabsScreenProps>(props);
103110

111+
if (newComponentProps.title != oldComponentProps.title) {
112+
_title = RCTNSStringFromStringNilIfEmpty(newComponentProps.title);
113+
_controller.title = _title;
114+
}
115+
104116
if (newComponentProps.isFocused != oldComponentProps.isFocused) {
105117
_isFocused = newComponentProps.isFocused;
106118
[_controller tabScreenFocusHasChanged];

src/components/BottomTabsScreen.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface BottomTabsScreenProps {
1717
isFocused?: boolean;
1818
badgeValue?: string;
1919
badgeColor?: ColorValue;
20+
title?: string;
2021
}
2122

2223
// const LIFECYCLE_STATE_INITIAL = 0;

src/fabric/BottomTabScreenNativeComponent.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export interface NativeProps extends ViewProps {
2929
// Appearance
3030
badgeValue?: string;
3131
badgeColor?: ColorValue;
32+
33+
// General
34+
title?: string | undefined | null;
3235
}
3336

3437
export default codegenNativeComponent<NativeProps>('RNSBottomTabsScreen', {});

0 commit comments

Comments
 (0)