Before I updated to iOS 18 everything worked fine. I pushed out an update to my application on the App Store and I had no issues. After updating to the latest OS many of my touch events are no longer working and I have no idea why.
Sometimes when the app runs the touch events work fine and other times I can't click on half of my views & buttons. I am completely lost as to what might be happening.
I am having issues all over the application but let's focus on the navigation stack and the toolbar item buttons. I will post some code snippets, I have been unable to replicate this in a small playground project. This is my setup, I have two buttons but lets focus on the home & notifications view.
The custom Router
import SwiftUI
import Foundation
@Observable
class HomeRouter {
var navPath = NavigationPath()
@MainActor
func navigate(to destination: HOME_ROUTES) {
navPath.append(destination)
}
@MainActor
func navigateBack() {
navPath.removeLast()
}
@MainActor
func navigateToRoot() {
navPath.removeLast(navPath.count)
}
}
Home View
import os
import SwiftUI
import CoreLocation
import NotificationCenter
struct Home: View {
@State public var router: HomeRouter
@State private var showDetail = false
@State private var showMoreFields = false
@EnvironmentObject private var session: SessionStore
private var log = Logger(subsystem: "com.olympsis.client", category: "home_view")
init(router: HomeRouter = HomeRouter()) {
self._router = State(initialValue: router)
}
var body: some View {
NavigationStack(path: $router.navPath) {
ScrollView(.vertical) {
//MARK: - Welcome message
WelcomeCard()
.padding(.top, 25)
.environmentObject(session)
// MARK: - Announcements
AnnouncementsView()
.environmentObject(session)
// MARK: - Next Events
NextEvents()
.environmentObject(session)
// MARK: - Hot Events
HotEvents()
.environmentObject(session)
// MARK: - Nearby Venues
NearbyVenues()
.environmentObject(session)
Spacer(minLength: 100)
}
.toolbar {
ToolbarItem(placement: .topBarLeading) {
Text("Olympsis")
.italic()
.font(.largeTitle)
.fontWeight(.black)
}
ToolbarItemGroup(placement: .topBarTrailing) {
Button(action: { router.navigate(to: .messages) }) {
ZStack(alignment: .topTrailing) {
Image(systemName: "bubble.left.and.bubble.right")
.foregroundStyle(Color.foreground)
if session.invitations.count > 0 {
NotificationCountView(value: $session.invitations.count)
}
}
}
Button(action: { router.navigate(to: .notifications) }) {
ZStack(alignment: .topTrailing) {
Image(systemName: "bell")
.foregroundStyle(Color.foreground)
if session.invitations.count > 0 {
NotificationCountView(value: $session.invitations.count)
}
}
}
}
}
.background(Color("background-color/primary"))
.navigationDestination(for: HOME_ROUTES.self, destination: { route in
switch route {
case .notifications:
NotificationsView()
.id(HOME_ROUTES.notifications)
.environment(router)
.environmentObject(session)
.navigationBarBackButtonHidden()
case .messages:
HomeMessagesView()
.id(HOME_ROUTES.messages)
.environment(router)
.environmentObject(session)
.navigationBarBackButtonHidden()
case .full_post_view(let id):
AsyncPostView(postId: id)
.id(HOME_ROUTES.full_post_view(id))
.environmentObject(session)
.navigationBarBackButtonHidden()
}
})
}
}
}
#Preview {
Home()
.environmentObject(SessionStore())
}
The Notifications View
import SwiftUI
struct NotificationsView: View {
@State private var notifications: [NotificationModel] = []
@Environment(HomeRouter.self) private var router
@EnvironmentObject private var session: SessionStore
var body: some View {
ScrollView {
if notifications.count > 0 {
ForEach(notifications, id: \.id){ note in
NotificationModelView(notification: note)
}
} else {
VStack {
Text("No new notifications")
HStack {
Spacer()
}
}.padding(.top, 50)
}
}
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .topBarLeading) {
Button(action:{ router.navigateBack() }) {
Image(systemName: "chevron.left")
.foregroundStyle(Color.foreground)
}
}
ToolbarItem(placement: .principal) {
Text("Notifications")
}
}
.task {
notifications = session.invitations.map({ i in
NotificationModel(id: UUID().uuidString, type: "invitation", invite: i, body: "")
})
}
}
}
#Preview {
NavigationStack {
NotificationsView()
.environment(HomeRouter())
.environmentObject(SessionStore())
}
}