setNeedsUpdateOfSupportedInterfaceOrientations changed behavior iOS 18

I'm using setNeedsUpdateOfSupportedInterfaceOrientations to force the rotation in a specific view in my app, only this view should be in landscape and the rest of the app should always be in portrait.

After updating to iOS 18 and Xcode 16 RC, the behavior changed. Now after rotating occurs, my whole view seems to be rendered again, and this is resetting some states that were changed prior to rotating. This is working as expected in iOS 17 and under, and there was no change in the code in our side.

The (pseudo)code below shows how I'm doing it:

class NewAppDelegate: UIResponder, UIApplicationDelegate {
    private(set) static var instance: NewAppDelegate?
    var orientationLock = UIInterfaceOrientationMask.portrait
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        NewAppDelegate.instance = self
        return true
    }
    
    func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
        self.orientationLock
    }
}
static func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
    NewAppDelegate.instance?.orientationLock = orientation
}

static func rotate(to orientation: UIInterfaceOrientationMask) {
    DispatchQueue.main.async {
        lockOrientation(orientation)
        
        if #available(iOS 16.0, *) {
            guard let viewController = UIApplication.visibleViewController else {
                return
            }
            
            viewController.setNeedsUpdateOfSupportedInterfaceOrientations()
        } else {
            var rotateOrientation: UIInterfaceOrientation
            switch orientation {
            case .landscapeLeft:
                rotateOrientation = .landscapeLeft
            case .landscapeRight, .landscape:
                rotateOrientation = .landscapeRight
            default:
                rotateOrientation = .portrait
            }
            
            UIDevice.current.setValue(rotateOrientation.rawValue, forKey: "orientation")
            UINavigationController.attemptRotationToDeviceOrientation()
        }
    }
}
class MyViewModel: ObservableObject {
    @Published
    var state: EnumViewState
    
    init() {
        self.state = "First State"
    }
    
    func changeRotation() {
        self.state = "Second state"
        AppRotationHelper.rotate(to: .landscapeRight)
        
        // After rotating `init` gets called again and `state` goes back to `"First State"`
    }
    
}
struct MyView: View {
    @StateObject var viewModel: MyViewModel
    
    ...
}
setNeedsUpdateOfSupportedInterfaceOrientations changed behavior iOS 18
 
 
Q