summaryrefslogtreecommitdiff
path: root/JuickNext/Helpers/View+ScreenTitle.swift
blob: 192b3bc6957aa4f72f79305656a4b304bc286f08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
//  View+ScreenTitle.swift
//  JuickNext
//
//  Created by Vitaly Takmazov on 15.05.2024.
//  Copyright © 2024 com.juick. All rights reserved.
//

import Foundation
import SwiftUI

public struct ScreenTitleModifier: ViewModifier {
    
    let screenTitle: String
    
    init(title: String) {
        self.screenTitle = title
    }
    
    
    public func body(content: Content) -> some View {
        if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) {
            content.navigationTitle(self.screenTitle)
        } else {
#if os(iOS)
            content.navigationBarTitle(self.screenTitle)
#else
            content
#endif
        }
    }
}

extension View {
    @ViewBuilder
    func screenTitle(title: String) -> some View {
        modifier(ScreenTitleModifier(title: title))
    }
}