@@ -340,19 +340,20 @@ extension View {
340340
341341 public func _toolbarVisibility( _ visibility: Visibility , for placements: [ ToolbarPlacement ] ) -> any View {
342342 #if SKIP
343- // SKIP REPLACE: var view = this
344- var view = self
345343 var bars = placements
346344 if bars. isEmpty {
347345 bars = [ . automatic]
348346 }
349- if bars. contains ( ToolbarPlacement . tabBar) {
350- view = view. preference ( key: TabBarPreferenceKey . self, value: ToolbarBarPreferences ( visibility: visibility) )
351- }
352- if bars. contains ( where: { $0 != ToolbarPlacement . tabBar } ) {
353- view = view. preference ( key: ToolbarPreferenceKey . self, value: ToolbarPreferences ( visibility: visibility, for: bars) )
354- }
355- return view
347+ return ModifiedContent ( content: self , modifier: RenderModifier { renderable, context in
348+ let visibilityAnimation = EnvironmentValues . shared. _animation
349+ if bars. contains ( ToolbarPlacement . tabBar) {
350+ PreferenceValues . shared. contribute ( context: context, key: TabBarPreferenceKey . self, value: ToolbarBarPreferences ( visibility: visibility, visibilityAnimation: visibilityAnimation) )
351+ }
352+ if bars. contains ( where: { $0 != ToolbarPlacement . tabBar } ) {
353+ PreferenceValues . shared. contribute ( context: context, key: ToolbarPreferenceKey . self, value: ToolbarPreferences ( visibility: visibility, visibilityAnimation: visibilityAnimation, for: bars) )
354+ }
355+ renderable. Render ( context: context)
356+ } )
356357 #else
357358 return self
358359 #endif
@@ -524,8 +525,8 @@ struct ToolbarPreferences: Equatable {
524525 self . bottomBar = bottomBar
525526 }
526527
527- init ( visibility: Visibility ? = nil , background: ShapeStyle ? = nil , backgroundVisibility: Visibility ? = nil , colorScheme: ColorScheme ? = nil , isSystemBackground: Bool ? = nil , scrollableState: ScrollableState ? = nil , for bars: [ ToolbarPlacement ] ) {
528- let barPreferences = ToolbarBarPreferences ( visibility: visibility, background: background, backgroundVisibility: backgroundVisibility, colorScheme: colorScheme, isSystemBackground: isSystemBackground, scrollableState: scrollableState)
528+ init ( visibility: Visibility ? = nil , background: ShapeStyle ? = nil , backgroundVisibility: Visibility ? = nil , colorScheme: ColorScheme ? = nil , isSystemBackground: Bool ? = nil , scrollableState: ScrollableState ? = nil , visibilityAnimation : Animation ? = nil , for bars: [ ToolbarPlacement ] ) {
529+ let barPreferences = ToolbarBarPreferences ( visibility: visibility, background: background, backgroundVisibility: backgroundVisibility, colorScheme: colorScheme, isSystemBackground: isSystemBackground, scrollableState: scrollableState, visibilityAnimation : visibilityAnimation )
529530 var navigationBar : ToolbarBarPreferences ? = nil
530531 var bottomBar : ToolbarBarPreferences ? = nil
531532 for bar in bars {
@@ -568,14 +569,25 @@ struct ToolbarBarPreferences: Equatable {
568569 let colorScheme : ColorScheme ?
569570 let isSystemBackground : Bool ?
570571 let scrollableState : ScrollableState ?
572+ let visibilityAnimation : Animation ?
573+
574+ init ( visibility: Visibility ? = nil , background: ShapeStyle ? = nil , backgroundVisibility: Visibility ? = nil , colorScheme: ColorScheme ? = nil , isSystemBackground: Bool ? = nil , scrollableState: ScrollableState ? = nil , visibilityAnimation: Animation ? = nil ) {
575+ self . visibility = visibility
576+ self . background = background
577+ self . backgroundVisibility = backgroundVisibility
578+ self . colorScheme = colorScheme
579+ self . isSystemBackground = isSystemBackground
580+ self . scrollableState = scrollableState
581+ self . visibilityAnimation = visibilityAnimation
582+ }
571583
572584 func reduce( _ next: ToolbarBarPreferences ) -> ToolbarBarPreferences {
573- return ToolbarBarPreferences ( visibility: next. visibility ?? visibility, background: next. background ?? background, backgroundVisibility: next. backgroundVisibility ?? backgroundVisibility, colorScheme: next. colorScheme ?? colorScheme, isSystemBackground: next. isSystemBackground ?? isSystemBackground, scrollableState: next. scrollableState ?? scrollableState)
585+ return ToolbarBarPreferences ( visibility: next. visibility ?? visibility, background: next. background ?? background, backgroundVisibility: next. backgroundVisibility ?? backgroundVisibility, colorScheme: next. colorScheme ?? colorScheme, isSystemBackground: next. isSystemBackground ?? isSystemBackground, scrollableState: next. scrollableState ?? scrollableState, visibilityAnimation : next . visibilityAnimation ?? visibilityAnimation )
574586 }
575587
576588 public static func == ( lhs: ToolbarBarPreferences , rhs: ToolbarBarPreferences ) -> Bool {
577589 // Don't compare on background because it will never compare equal
578- return lhs. visibility == rhs. visibility && lhs. backgroundVisibility == rhs. backgroundVisibility && ( lhs. background != nil ) == ( rhs. background != nil ) && lhs. colorScheme == rhs. colorScheme && lhs. isSystemBackground == rhs. isSystemBackground && lhs. scrollableState == rhs. scrollableState
590+ return lhs. visibility == rhs. visibility && lhs. backgroundVisibility == rhs. backgroundVisibility && ( lhs. background != nil ) == ( rhs. background != nil ) && lhs. colorScheme == rhs. colorScheme && lhs. isSystemBackground == rhs. isSystemBackground && lhs. scrollableState == rhs. scrollableState && lhs . visibilityAnimation == rhs . visibilityAnimation
579591 }
580592}
581593
0 commit comments