Comments (7)
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.
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.
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.
@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.
@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.
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.
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)
- scrollPositionSetter is not working HOT 2
- Crash on iOS 15 occurs when sections do not have a .sectionHeader HOT 10
- Pod version appears not updated since 1.7.1 HOT 2
- iOS 15, ASCollectionView causes .sheet() to pop unexpectedly HOT 3
- Pull to refresh in iOS 15 with large title issue HOT 1
- No such module 'DifferenceKit' Xcode 13 HOT 1
- A bit sticky Drag & sort
- Terminating app due to uncaught exception 'NSInvalidArgumentException'
- ASCollectionView with horizontal scroll direction showing section header on side instead of top.
- macOS Support HOT 1
- ASCollectionView doesn't support ASSection with swipeToDelete?
- ASCollectionViewDelegate: support fast index scrolling?
- The operation couldn’t be completed. (SwiftPM.SPMRepositoryError error 3.)
- onScroll CPU issues HOT 1
- Unable to set scroll position of a cell
- Keep Showing Hidden Navbar
- Paging style ASTableView
- ASTableView warning (view does not load)
- Crash on IOS 16 HOT 1
- IOS16: NSInternalInconsistencyException: UICollectionViewLayoutAttributes: -setSize: requires finite dimensions HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ascollectionview.