Skip to content

Commit

Permalink
RUMM-1615 Workaround FB8907671 in 14.2 <= iOS < 14.5
Browse files Browse the repository at this point in the history
  • Loading branch information
maxep committed Nov 2, 2021
1 parent c4a7956 commit 566a95b
Showing 1 changed file with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,59 @@ class SwiftUIRootViewController: UIHostingController<RootView> {
struct RootView: View {
var body: some View {
TabView {
tabNavigationView
.tabItem {
Text("Navigation View")
}

tabScreenView
.tabItem {
Text("Screen 100")
}
}
}

@ViewBuilder
var tabNavigationView: some View {
// An issue was introduced in iOS 14.2 (FB8907671) which makes
// `TabView` items to be loaded twice, once when the `TabView`
// appears` and once when the Tab item itself appears. This
// lead to RUM views being reported twice. This issue was fixed
// in iOS 14.5, see https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-14_5-release-notes
// As a workaround, the tab view items can be embedded in a
// `LazyVStack` or `LazyHStack` to lazily load its content when
// it needs to render them onscreen.
if #available(iOS 14.5, *) {
NavigationView {
ScreenView(index: 1)
}.tabItem {
Text("Navigation View")
}
} else if #available(iOS 14.2, *) {
NavigationView {
LazyVStack {
ScreenView(index: 1)
}
}
} else {
NavigationView {
ScreenView(index: 1)
}
}
}

@ViewBuilder
var tabScreenView: some View {
if #available(iOS 14.5, *) {
ScreenView(index: 100)
.tabItem {
Text("Screen 100")
} else if #available(iOS 14.2, *) {
LazyVStack {
ScreenView(index: 100)
}
} else {
ScreenView(index: 100)
}
}
}


@available(iOS 13, *)
/// A basic Screen View at a given index in the stack.
///
Expand Down

0 comments on commit 566a95b

Please sign in to comment.