Skip to content

Commit 91f172e

Browse files
committed
Add prefernce key for propagating navigation_title
1 parent 429d114 commit 91f172e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Sources/LiveViewNative/Modifiers/NavigationTitleModifier.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,18 @@ struct NavigationTitleModifier: ViewModifier, Decodable, Equatable {
2222
func body(content: Content) -> some View {
2323
content
2424
.navigationTitle(title)
25+
.preference(key: NavigationTitleModifierKey.self, value: self)
2526
}
2627

2728
enum CodingKeys: String, CodingKey {
2829
case title
2930
}
3031
}
32+
33+
enum NavigationTitleModifierKey: PreferenceKey {
34+
static var defaultValue: NavigationTitleModifier?
35+
36+
static func reduce(value: inout NavigationTitleModifier?, nextValue: () -> NavigationTitleModifier?) {
37+
value = nextValue() ?? value
38+
}
39+
}

0 commit comments

Comments
 (0)