Closed dinzzz closed 1 week ago
Hi @dinzzz,
The sample code you shared works for me. Can you try cleaning derived data and your project?
Best, Martin
Unfortunately didn't do it.
Here's also CustomViewFactory Implementation as well as the usage, if you can spot something
import SwiftUI
import StreamChat
import StreamChatSwiftUI
class CustomViewFactory: ViewFactory {
@Injected(\.chatClient) public var chatClient
private init() {}
public static let shared = CustomViewFactory()
// Customise the channel list header
func makeChannelListHeaderViewModifier(title: String) -> some ChannelListHeaderViewModifier {
CustomChannelModifier(title: title)
}
// Customise the channel list top view
func makeChannelListTopView(searchText: Binding<String>) -> some View {
CustomTopView(searchText: searchText)
}
// Customise the channel list background
func makeChannelListBackground(colors: ColorPalette) -> some View {
CustomChannelHeaderBackgroundView()
}
// swiftlint:disable function_parameter_count
public func makeChannelListItem(
channel: ChatChannel,
channelName: String,
avatar: UIImage,
onlineIndicatorShown: Bool,
disabled: Bool,
selectedChannel: Binding<ChannelSelectionInfo?>,
swipedChannelId: Binding<String?>,
channelDestination: @escaping (ChannelSelectionInfo) -> ChatChannelView<CustomViewFactory>,
onItemTap: @escaping (ChatChannel) -> Void,
trailingSwipeRightButtonTapped: @escaping (ChatChannel) -> Void,
trailingSwipeLeftButtonTapped: @escaping (ChatChannel) -> Void,
leadingSwipeButtonTapped: @escaping (ChatChannel) -> Void
) -> some View {
let listItem = CustomChatChannelNavigatableListItem(
channel: channel,
channelName: channelName,
avatar: avatar,
onlineIndicatorShown: onlineIndicatorShown,
disabled: disabled,
selectedChannel: selectedChannel,
channelDestination: channelDestination,
onItemTap: onItemTap
)
return ChatChannelSwipeableListItem(
factory: self,
channelListItem: listItem,
swipedChannelId: swipedChannelId,
channel: channel,
numberOfTrailingItems: channel.ownCapabilities.contains(.deleteChannel) ? 2 : 1,
trailingRightButtonTapped: trailingSwipeRightButtonTapped,
trailingLeftButtonTapped: trailingSwipeLeftButtonTapped,
leadingSwipeButtonTapped: leadingSwipeButtonTapped
)
}
}
struct ChatView: View {
@EnvironmentObject var tabSettings: TabSettings
@EnvironmentObject private var router: Router
@CustomInjected private var channelsDescriptor: ChannelsDescriptor
@StateObject private var viewModel: ChatViewModel
@State private var isAscending: Bool = true
init() {
// initialising the chat manager
_viewModel = StateObject(wrappedValue: ChatViewModel())
}
var body: some View {
ChatChannelListView(
viewFactory: CustomViewFactory.shared,
// channelListController: viewModel.channelListController,
onItemTap: { channel in
router.pushToRooms(RoomsRoute.room(cid: channel.cid.rawValue))
},
handleTabBarVisibility: true,
embedInNavigationView: false)
.id(isAscending)
.onAppear {
tabSettings.isHidden = false
}
.onReceive(channelsDescriptor.$isAscending) { newValue in
if newValue != isAscending {
isAscending = newValue
viewModel.updateChannelListController(isAscending: newValue)
}
}
}
}
The only thing that comes to mind is this line:
onItemTap: { channel in
router.pushToRooms(RoomsRoute.room(cid: channel.cid.rawValue))
}
Can you try without it to see if the issues still appears?
@martinmitrevski no luck, still the same behavior
Accidentaly overriden ChannelSelectionInfo in one of the customized classes. Code works.
Thanks @martinmitrevski
What did you do?
Implementing a 'makeChannelListItem' method to have custom list item view
What did you expect to happen?
Method to be invoked from my CustomViewFactory
What happened instead?
Method was invoked from DefaultViewFactory. Other methods from CustomViewFactory behaving normally.
GetStream Environment
GetStream Chat version:4.62.0 GetStream Chat frameworks: StreamChat, StreamChatSwiftUI iOS version:17..5 Swift version:5.7 Xcode version:15.4 *Device:iPhone 15 Pro Max // Simulator*
Additional context
Things that didn't work:
Implementing this manually (with my own channel controller)
channelDestination: @escaping (ChannelSelectionInfo) -> ChatChannelView<CustomViewFactory>,
other ways of return value in makeChannelDestination (some View, ChatChannelSwipeableListItem, ChannelListItemType)...