diff --git a/CHANGELOG.md b/CHANGELOG.md index 05b603abc..acceb20f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### 🔄 Changed - Uploading a HEIC photo from the library is now converted to JPEG for better compatibility [#767](https://github.com/GetStream/stream-chat-swiftui/pull/767) - Customizing the message avatar view is reflected in all views that use it [#772](https://github.com/GetStream/stream-chat-swiftui/pull/772) +- Move `ChangeBarsVisibilityModifier` into `ViewFactory` for better customization [#774](https://github.com/GetStream/stream-chat-swiftui/pull/774) # [4.73.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.73.0) _February 28, 2025_ diff --git a/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelView.swift b/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelView.swift index 4a5de0ac0..4013d866c 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelView.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelView.swift @@ -94,10 +94,10 @@ public struct ChatChannelView: View, KeyboardReadable { Divider() .navigationBarBackButtonHidden(viewModel.reactionsShown) .if(viewModel.reactionsShown, transform: { view in - view.changeBarsVisibility(shouldShow: false) + view.modifier(factory.makeChannelBarsVisibilityViewModifier(shouldShow: false)) }) .if(!viewModel.reactionsShown, transform: { view in - view.changeBarsVisibility(shouldShow: true) + view.modifier(factory.makeChannelBarsVisibilityViewModifier(shouldShow: true)) }) .if(viewModel.channelHeaderType == .regular) { view in view.modifier(factory.makeChannelHeaderViewModifier(for: channel)) diff --git a/Sources/StreamChatSwiftUI/DefaultViewFactory.swift b/Sources/StreamChatSwiftUI/DefaultViewFactory.swift index 466ed125f..4f350e9e3 100644 --- a/Sources/StreamChatSwiftUI/DefaultViewFactory.swift +++ b/Sources/StreamChatSwiftUI/DefaultViewFactory.swift @@ -301,6 +301,10 @@ extension ViewFactory { DefaultChannelHeaderModifier(factory: self, channel: channel) } + public func makeChannelBarsVisibilityViewModifier(shouldShow: Bool) -> some ViewModifier { + ChangeChannelBarsVisibilityModifier(shouldShow: shouldShow) + } + public func makeChannelLoadingView() -> some View { LoadingView() } diff --git a/Sources/StreamChatSwiftUI/Utils/Modifiers.swift b/Sources/StreamChatSwiftUI/Utils/Modifiers.swift index 5765d7674..706e109d5 100644 --- a/Sources/StreamChatSwiftUI/Utils/Modifiers.swift +++ b/Sources/StreamChatSwiftUI/Utils/Modifiers.swift @@ -79,7 +79,7 @@ struct IconOverImageModifier: ViewModifier { } } -struct ChangeBarsVisibilityModifier: ViewModifier { +struct ChangeChannelBarsVisibilityModifier: ViewModifier { @Injected(\.utils) private var utils @@ -110,10 +110,6 @@ extension View { public func applyDefaultIconOverlayStyle() -> some View { modifier(IconOverImageModifier()) } - - public func changeBarsVisibility(shouldShow: Bool) -> some View { - modifier(ChangeBarsVisibilityModifier(shouldShow: shouldShow)) - } } extension Image { diff --git a/Sources/StreamChatSwiftUI/ViewFactory.swift b/Sources/StreamChatSwiftUI/ViewFactory.swift index d09530d61..7f4db11d9 100644 --- a/Sources/StreamChatSwiftUI/ViewFactory.swift +++ b/Sources/StreamChatSwiftUI/ViewFactory.swift @@ -282,6 +282,12 @@ public protocol ViewFactory: AnyObject { /// - Parameter channel: the displayed channel. func makeChannelHeaderViewModifier(for channel: ChatChannel) -> ChatHeaderViewModifier + associatedtype ChangeBarsVisibilityModifier: ViewModifier + /// Creates a view modifier that changes the visibility of bars. + /// - Parameter shouldShow: A Boolean value indicating whether the bars should be shown. + /// - Returns: A view modifier that changes the visibility of bars. + func makeChannelBarsVisibilityViewModifier(shouldShow: Bool) -> ChangeBarsVisibilityModifier + associatedtype ChannelLoadingViewType: View /// Creates a loading view for the channel. func makeChannelLoadingView() -> ChannelLoadingViewType