Same behaviour on iOS 14 beta 8. OnAppear gets called after navigating via NavigationLink to a different view, which of course messes up the apps behavior
Post
Replies
Boosts
Views
Activity
Update:
I think I found a solution! (At least until the bug itself gets fixed) ->
Try to add a second "OnAppear" modifier somewhere below the one you actually want.
VStack{
...
}
.onAppear(){
print("Works as usual - only fired on appear, even when navigation back to this view as expected")
}
.onAppear(){
print("Fired directly after onDisappear")
}
.onDisappear(){
print("Fired on Disappear as expected")
}
It seems like the second onAppear modifier always gets fired shortly after onDisappear, as reported here. If your add another onAppear modifier somewhere above, it will behaves initially expected!
So this may be a workaround until the bug is fixed, maybe it even helps in finding the cause of the problem.
If it doesn't work for you, try putting the second onAppear above the one you want, instead of below. In my tests one or the other seemed to work.
If this also doesnt work, try placing the second on Appear somewhere else in your view and debug/experient with which gets fired. For me usually one behaves correctly while the other one show the strange behaviour.
I guess it may be some parsing error of the swift document or its timing based problems which may be cause by how many States/Bindings you are referencing in the specific block.
Update 2: -> above solution doesnt seem to work as I initially thought
Further testing seems to point me towards the conclusion, that it's the code inside the onAppear, that leads to the behavior. Adding a second onAppear somewhere with a simple print works as expected, while my onAppear always shows the incorrect behavior regardless of where I place it. So something inside the onAppear, maybe the amount of code, or some specific references cause the problem
using:
.listStyle(SidebarListStyle())
should be all you need. But you meed to use negative padding or other tricks as this style has bit more spacing from all sides then the old version
Error still persists in iOS14 GM. :(
Same behaviour in iOS 14 GM Version. CPU Usage goes up to 100% the moment you tap the Textfield and the Keyboard opens. It stays at 100% even after you closed the keyboard and navigated to different views.
I think I found the cause of the problem:
@Environment(\.scenePhase) private var scenePhase
If you want to detect app scenePhase changes as are available in iOS14, you probably added this line to your main swift file. The moment this line exists NFC stops detecting tags even if the prompt appears and the delegate method gets triggered.
My solution was to remove it and instead use for my purpose
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
I think I found the cause of the problem:
@Environment(\.scenePhase) private var scenePhase
If you want to detect app scenePhase changes as are available in iOS14, you probably added this line to your main swift file. The moment this line exists NFC stops detecting tags even if the prompt appears and the delegate method gets triggered.
My solution was to remove it and instead use for my purpose
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
Just an update: Same behavior/bug in release version of iOS 14.2
So far we could not find any working fix for this. I think this really is a major/ciritical bug as users are wondering why their phones are getting really hot and the battery is draining like crazy :/
Same problem here. iOS 14.5 messed up the whole app navigation und now views are immediately popped upon being pushed so the App jumps around and is unusable. I fear this behavior will find its way into the release version as it is also present in the latest release candidate.
Update: Found a fix which is really weird but seems to work until the real cause is found:
In the pushing view that contains the NavigationLinks, add the following meaningless Navigationlink next to your existing ones. So far it seems the problem only occurs if you have more than one NavigationLink in a view and I am sure its related to the mentioned new behavior of 14.5
Add this to your view containing your existing NavigationLinks:
swift
NavigationLink(destination: EmptyView()) {
EmptyView()
}
We updated our whole app and placed the empty NavigationLink in every view which already had a NavigationLink and it solved the problem for us :) Sad thing is that with the 14.5 being released, we will have to keep that thing in place for ages now even if 14.6 may solve it :/
@coopersita
For us it worked placing them at the same level as the other NavigationLinks already present in the same view.