Skip to content

Commit 036ab4a

Browse files
authored
Merge pull request #430 from nativescript-community/fix/tabstrip-ios-collapse
fix(tabs): handle removing, re-adding, and changing visibility of tabstrip
2 parents 00a517b + 7297d7e commit 036ab4a

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

src/tabs/index.ios.ts

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -162,34 +162,43 @@ class UIPageViewControllerImpl extends UIPageViewController {
162162
let scrollViewHeight = this.view.bounds.size.height + conditionalSafeAreaBottom;
163163

164164
if (owner.tabStrip && this.tabBar) {
165-
const viewWidth = this.view.bounds.size.width;
166-
const viewHeight = this.view.bounds.size.height;
167-
const tabBarHeight = this.tabBar.frame.size.height;
168-
let tabBarTop = safeAreaInsetsTop;
169-
170-
scrollViewTop = tabBarHeight;
171-
scrollViewHeight = this.view.bounds.size.height - tabBarHeight + conditionalSafeAreaBottom;
172-
173-
const tabsPosition = owner.tabsPosition;
174-
if (tabsPosition === TabsPosition.Bottom) {
175-
tabBarTop = viewHeight - tabBarHeight - safeAreaInsetsBottom;
176-
scrollViewTop = this.view.frame.origin.y;
177-
scrollViewHeight = viewHeight - tabBarHeight;
178-
}
179-
180-
let parent = owner.parent;
181-
182-
// Handle Angular scenario where Tabs is in a ProxyViewContainer
183-
// It is possible to wrap components in ProxyViewContainers indefinitely
184-
while (parent && !parent.nativeViewProtected) {
185-
parent = parent.parent;
165+
if (owner.tabStrip.visibility === 'visible') {
166+
this.tabBar.hidden = false;
167+
} else {
168+
this.tabBar.hidden = true;
186169
}
187-
188-
if (parent && majorVersion > 10) {
189-
// TODO: Figure out a better way to handle ViewController nesting/Safe Area nesting
190-
tabBarTop = Math.max(tabBarTop, parent.nativeView.safeAreaInsets.top);
170+
// failsafe with !this.tabBar.hidden just in some really odd case where hidden is false and collapse is true
171+
// which should never happen
172+
if (!owner.tabStrip.isCollapsed || !this.tabBar.hidden) {
173+
const viewWidth = this.view.bounds.size.width;
174+
const viewHeight = this.view.bounds.size.height;
175+
const tabBarHeight = this.tabBar.frame.size.height;
176+
let tabBarTop = safeAreaInsetsTop;
177+
178+
scrollViewTop = tabBarHeight;
179+
scrollViewHeight = this.view.bounds.size.height - tabBarHeight + conditionalSafeAreaBottom;
180+
181+
const tabsPosition = owner.tabsPosition;
182+
if (tabsPosition === TabsPosition.Bottom) {
183+
tabBarTop = viewHeight - tabBarHeight - safeAreaInsetsBottom;
184+
scrollViewTop = this.view.frame.origin.y;
185+
scrollViewHeight = viewHeight - tabBarHeight;
186+
}
187+
188+
let parent = owner.parent;
189+
190+
// Handle Angular scenario where Tabs is in a ProxyViewContainer
191+
// It is possible to wrap components in ProxyViewContainers indefinitely
192+
while (parent && !parent.nativeViewProtected) {
193+
parent = parent.parent;
194+
}
195+
196+
if (parent && majorVersion > 10) {
197+
// TODO: Figure out a better way to handle ViewController nesting/Safe Area nesting
198+
tabBarTop = Math.max(tabBarTop, parent.nativeView.safeAreaInsets.top);
199+
}
200+
this.tabBar.frame = CGRectMake(0, tabBarTop, viewWidth, tabBarHeight);
191201
}
192-
this.tabBar.frame = CGRectMake(0, tabBarTop, viewWidth, tabBarHeight);
193202
} else {
194203
this.tabBar.hidden = true;
195204
}

0 commit comments

Comments
 (0)