Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on iOS 14 devices #6

Closed
GioPalusa opened this issue Jul 6, 2022 · 4 comments
Closed

Crash on iOS 14 devices #6

GioPalusa opened this issue Jul 6, 2022 · 4 comments

Comments

@GioPalusa
Copy link

I have an issue where the navigation works flawlessly on iOS 15 devices, but immediately crashes the app upon pressing a link on an iOS 14 device. I had a look at DestinationBuilderModifier and the content there is printed out differently.

on iOS 15 devices (Including simulator)
SwiftUI._ViewModifier_Content<NavigationBackport.DestinationBuilderModifier<MyProject.Event>>()

on iOS 14 devices (Including simulator)
(SwiftUI._ViewModifier_Content<NavigationBackport.DestinationBuilderModifier<MyProjectt.Event>>) content = {}

This is one of the places implemented that crashes the app. The navigation is done by NBNavigationDestination attached to a scroll view

NBNavigationStack {
	ScrollView {
		NBNavigationLink(value: account) {
			Text("CLICK ME")
				.Shadow()
		}
		.buttonStyle(.plain)
	}
	.setBackground()
	.nbNavigationDestination(for: Account.self) { account in
		DestinationView(for: account)
	}
}

Tested cases:

  • Navigation Stack with no path, does not navigate at all
  • Navigation Stack with path, crashes the app on second level
  • Navigation Stack that is added through a ViewModifier crashes the app, if generics is used

The error printed out is
2022-07-06 14:34:52.810190+0200 MyProject[99017:5417116] Fatal error: No view builder found for key MyProject.Account: file NavigationBackport/DestinationBuilderHolder.swift, line 34

Here is also another example where it works on iOS 15 and not on iOS 14

struct DestinationView: View {
    let account: Account

    @Binding var path: NBNavigationPath

    var body: some View {
      VStack {
        Text(account.name)

        Button {
          $path.withDelaysIfUnsupported { $0.append(Account()) }
        } label: {
          Text("Try me?")
        }

        NBNavigationLink(value: Account()) {
          Text("Or... try me?")
        }
      }
      .nbNavigationDestination(for: Account.self, destination: { person in
        Text("CRASHES")
      })
    }
  }
@johnpatrickmorgan
Copy link
Owner

Thanks for raising this issue @GioPalusa! I tried to replicate the issue by running your code on the iOS 14.4 (iPhone 12 Pro) simulator, but wasn't able to reproduce any strange behaviour or crashes. Do you only see the issue on device or can it be reproduced on simulator? I wasn't able to include everything in your sample code (e.g. .Shadow() and .setBackground()), and I had to guess at the missing details. Are you able to provide the entire code to reproduce the issue please? Thanks!

@GioPalusa
Copy link
Author

I have tried to replicate the issue in a separate project, but haven't been able to make it crash yet. Adding things one by one and testing what it might be that crashes the app. I'll let you know!

@GioPalusa
Copy link
Author

After about two days of debugging I finally made it work again.
One of my targets had some weird reference to the project, so it partially worked. When I added it as a local SPM it finally worked for iOS 14. If I then removed it and added it back in SPM through GIT it also worked. No idea how the project would build without the correct references, or why in the world it would work on iOS 15 devices with that setup.

@johnpatrickmorgan
Copy link
Owner

Glad to hear it's resolved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants