Giter Site home page Giter Site logo

Comments (7)

apptekstudios avatar apptekstudios commented on May 19, 2024

Thanks for reporting the issue @ryangittings. This is unexpected behaviour, the environment objects should be getting carried across to the cells...

I haven't been able to reproduce the crash with EnvironmentObject or managedObjectContext. Do you have any simple demo that reproduces the crash?

A few questions to help narrow it down:

  • are you accessing the environment / environment object outside of the view body variable?
  • Is there an exception logged to the console when crashing?

As a workaround until we find the cause, consider doing the following (passing the environment object directly to your cells):

struct ContentView: View {
	@EnvironmentObject var yourObject: ObjectType
	
	var body: some View {
		ASCollectionView {
			ASCollectionViewSection(...) { item in
				Text("Your cell contents")
					.environmentObject(self.yourObject)
			}
		}
	}
}

from ascollectionview.

ryangittings avatar ryangittings commented on May 19, 2024

I found it was when using a tab view and switching between the tabs.

Nope it’s in the view body; I’ll see if I can reproduce the exception as soon as I can.

That was the workaround I’ve used, thanks for that!

from ascollectionview.

apptekstudios avatar apptekstudios commented on May 19, 2024

Closing this for now as it seems to be resolved in recent versions of SwiftUI. Please feel free to reopen if it recurs :)

from ascollectionview.

kerrmarin avatar kerrmarin commented on May 19, 2024

@apptekstudios I can reproduce the crash always by making these changes kerrmarin@cfb538d and then navigating the demo app to the "App Store Layout" demo then scrolling the top carousel

from ascollectionview.

apptekstudios avatar apptekstudios commented on May 19, 2024

@kerrmarin Thank you for the easy instructions to reproduce the error!

Unfortunately it seems that this is a SwiftUI bug, and I am unable to work around it within the library :(

I would recommend using the workaround I suggested above if utilising EnvironmentObject 👍

Further info from my debugging:

  • Primary issue: SwiftUI is calling the view's body immediately on initialising a UIHostingController.
  • This means there is no opportunity to add the UIHostingController to the view/VC hierarchy before there is attempted access to the environment object.

from ascollectionview.

kerrmarin avatar kerrmarin commented on May 19, 2024

Thanks for the feedback @apptekstudios. Do you think it's worth re-opening this issue until it's fixed? More for visibility than for anything else in case someone else comes looking for an answer :)

I'll also open a bug in the Swift bug tracker. If the issue is as you describe it should be pretty straightforward to create a demo project that shows the issue.

from ascollectionview.

apptekstudios avatar apptekstudios commented on May 19, 2024

Thanks for the feedback @apptekstudios. Do you think it's worth re-opening this issue until it's fixed? More for visibility than for anything else in case someone else comes looking for an answer :)

I've created a new issue #131 that outlines the bug and its workaround to make it easy for anyone having the problem :)

from ascollectionview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.