Skip to content

Commit d582245

Browse files
authored
fix(iOS, Tabs): tab screen height when tabs are rendered dynamically (#3425)
## Description Fixes incorrect tab screen frame, assigned by UIKit when tabs are rendered dynamically & available space is less that window size. We enable auto-layout and add constraints so that `tabBarController.view`'s dimensions match `RNSBottomTabsHostComponentView`. Closes software-mansion/react-native-screens-labs#588. | before | after | | --- | --- | | <video src="https://github.com/user-attachments/assets/8cd02a27-aa52-46aa-90af-469d2f877887" /> | <video src="https://github.com/user-attachments/assets/ccb37d69-a9a4-4dc9-801d-ce8415b2e610" /> | | --- | --- | | <img width="409" height="814" alt="before3425_vh" src="https://github.com/user-attachments/assets/0e173b56-420c-4bb0-a36a-264e48464921" /> | <img width="511" height="829" alt="after3425_vh" src="https://github.com/user-attachments/assets/c042ef0f-7bf3-4f98-88b5-ee1cdf01b9ed" /> | We might want to investigate in more detail why we receive the incorrect frame. I created an issue for this: software-mansion/react-native-screens-labs#596. ## Changes - add layout constraints for `tabBarController.view`. ## Test code and steps to reproduce Run `Test3425`. ## Checklist - [x] Included code example that can be used to test this change - [x] Ensured that CI passes
1 parent 2381457 commit d582245

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

apps/src/tests/Test3425.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React, { useState } from 'react';
2+
import { Button, View } from 'react-native';
3+
import Colors from '../shared/styling/Colors';
4+
import { TestBottomTabs } from '.';
5+
6+
export default function App() {
7+
const [index, setIndex] = useState(0);
8+
return (
9+
<View
10+
style={{
11+
flex: 1,
12+
paddingHorizontal: 20,
13+
paddingVertical: 100,
14+
backgroundColor: Colors.BlueLight40,
15+
}}>
16+
{index === 0 ? (
17+
<View
18+
style={{
19+
flex: 1,
20+
justifyContent: 'center',
21+
alignItems: 'center',
22+
}}>
23+
<Button title="Go to Bottom Tabs" onPress={() => setIndex(1)} />
24+
</View>
25+
) : (
26+
<TestBottomTabs />
27+
)}
28+
</View>
29+
);
30+
}

apps/src/tests/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export { default as Test3342 } from './Test3342';
163163
export { default as Test3346 } from './Test3346';
164164
export { default as Test3369 } from './Test3369';
165165
export { default as Test3379 } from './Test3379';
166+
export { default as Test3425 } from './Test3425';
166167
export { default as TestScreenAnimation } from './TestScreenAnimation';
167168
export { default as TestScreenAnimationV5 } from './TestScreenAnimationV5';
168169
export { default as TestHeader } from './TestHeader';

ios/bottom-tabs/host/RNSBottomTabsHostComponentView.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ - (void)reactAddControllerToClosestParent:(UIViewController *)controller
146146
if (parentView.reactViewController) {
147147
[parentView.reactViewController addChildViewController:controller];
148148
[self addSubview:controller.view];
149+
150+
// Enable auto-layout to ensure valid size of tabBarController.view.
151+
// In host tree, tabBarController.view is the only child of HostComponentView.
152+
controller.view.translatesAutoresizingMaskIntoConstraints = NO;
153+
[NSLayoutConstraint activateConstraints:@[
154+
[controller.view.topAnchor constraintEqualToAnchor:self.topAnchor],
155+
[controller.view.bottomAnchor constraintEqualToAnchor:self.bottomAnchor],
156+
[controller.view.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
157+
[controller.view.trailingAnchor constraintEqualToAnchor:self.trailingAnchor]
158+
]];
159+
149160
[controller didMoveToParentViewController:parentView.reactViewController];
150161
break;
151162
}

0 commit comments

Comments
 (0)