Skip to content

Commit

Permalink
Timeline composer layout loop fix (#6743)
Browse files Browse the repository at this point in the history
* Publish suitable view height for user suggestions

* Update container view height

* Add changelog

* Fix user suggestions layout for pre iOS 16
  • Loading branch information
ismailgulek authored Sep 20, 2022
1 parent 28dc2d0 commit f201ea5
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions Riot/Modules/Room/RoomViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ extern NSNotificationName const RoomGroupCallTileTappedNotification;
// The preview header
@property (weak, nonatomic, nullable) IBOutlet UIView *previewHeaderContainer;
@property (weak, nonatomic, nullable) IBOutlet NSLayoutConstraint *previewHeaderContainerHeightConstraint;
@property (weak, nonatomic, nullable) IBOutlet NSLayoutConstraint *userSuggestionContainerHeightConstraint;

// The jump to last unread banner
@property (weak, nonatomic, nullable) IBOutlet UIView *jumpToLastUnreadBannerContainer;
Expand Down
10 changes: 10 additions & 0 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7757,6 +7757,16 @@ - (void)userSuggestionCoordinatorBridge:(UserSuggestionCoordinatorBridge *)coord
[self mention:member];
}

- (void)userSuggestionCoordinatorBridge:(UserSuggestionCoordinatorBridge *)coordinator didUpdateViewHeight:(CGFloat)height
{
if (self.userSuggestionContainerHeightConstraint.constant != height)
{
self.userSuggestionContainerHeightConstraint.constant = height;

[self.view layoutIfNeeded];
}
}

#pragma mark - ThreadsCoordinatorBridgePresenterDelegate

- (void)threadsCoordinatorBridgePresenterDelegateDidComplete:(ThreadsCoordinatorBridgePresenter *)coordinatorBridgePresenter
Expand Down
3 changes: 2 additions & 1 deletion Riot/Modules/Room/RoomViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<outlet property="scrollToBottomBadgeLabel" destination="QHs-rM-UU8" id="wk7-PQ-9Jm"/>
<outlet property="scrollToBottomButton" destination="Ih9-EU-BOU" id="Wwg-gS-Sfp"/>
<outlet property="topBannersStackView" destination="3z2-8P-wlg" id="uf5-gw-zWi"/>
<outlet property="userSuggestionContainerHeightConstraint" destination="1Cd-cT-gOr" id="au5-3q-r54"/>
<outlet property="userSuggestionContainerView" destination="oni-F4-X1U" id="0js-Ji-8Mm"/>
<outlet property="view" destination="iN0-l3-epB" id="ieV-u7-rXU"/>
</connections>
Expand Down Expand Up @@ -171,7 +172,7 @@
<rect key="frame" x="0.0" y="626" width="375" height="0.0"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" placeholder="YES" id="1Cd-cT-gOr"/>
<constraint firstAttribute="height" id="1Cd-cT-gOr"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="nLd-BP-JAE" userLabel="Room Input Toolbar Container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import Foundation
import UIKit
import SwiftUI
import Combine

protocol UserSuggestionCoordinatorDelegate: AnyObject {
func userSuggestionCoordinator(_ coordinator: UserSuggestionCoordinator, didRequestMentionForMember member: MXRoomMember, textTrigger: String?)
func userSuggestionCoordinator(_ coordinator: UserSuggestionCoordinator, didUpdateViewHeight height: CGFloat)
}

struct UserSuggestionCoordinatorParameters {
Expand All @@ -35,10 +37,12 @@ final class UserSuggestionCoordinator: Coordinator, Presentable {

private let parameters: UserSuggestionCoordinatorParameters

private var userSuggestionHostingController: UIViewController
private var userSuggestionHostingController: UIHostingController<AnyView>
private var userSuggestionService: UserSuggestionServiceProtocol
private var userSuggestionViewModel: UserSuggestionViewModelProtocol
private var roomMemberProvider: UserSuggestionCoordinatorRoomMemberProvider

private var cancellables = Set<AnyCancellable>()

// MARK: Public

Expand Down Expand Up @@ -77,12 +81,18 @@ final class UserSuggestionCoordinator: Coordinator, Presentable {
self.delegate?.userSuggestionCoordinator(self, didRequestMentionForMember: member, textTrigger: self.userSuggestionService.currentTextTrigger)
}
}

userSuggestionService.items.sink { [weak self] _ in
guard let self = self else { return }
self.delegate?.userSuggestionCoordinator(self,
didUpdateViewHeight: self.calculateViewHeight())
}.store(in: &cancellables)
}

func processTextMessage(_ textMessage: String) {
userSuggestionService.processTextMessage(textMessage)
}

// MARK: - Public
func start() {

Expand All @@ -91,6 +101,33 @@ final class UserSuggestionCoordinator: Coordinator, Presentable {
func toPresentable() -> UIViewController {
return self.userSuggestionHostingController
}

// MARK: - Private

private func calculateViewHeight() -> CGFloat {
let viewModel = UserSuggestionViewModel(userSuggestionService: userSuggestionService)
let view = UserSuggestionList(viewModel: viewModel.context)
.addDependency(AvatarService.instantiate(mediaManager: parameters.mediaManager))

let controller = VectorHostingController(rootView: view)
guard let view = controller.view else {
return 0
}
view.isHidden = true

toPresentable().view.addSubview(view)
controller.didMove(toParent: toPresentable())

view.setNeedsLayout()
view.layoutIfNeeded()

let result = view.intrinsicContentSize.height

controller.didMove(toParent: nil)
view.removeFromSuperview()

return result
}
}

private class UserSuggestionCoordinatorRoomMemberProvider: RoomMembersProviderProtocol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Foundation
@objc
protocol UserSuggestionCoordinatorBridgeDelegate: AnyObject {
func userSuggestionCoordinatorBridge(_ coordinator: UserSuggestionCoordinatorBridge, didRequestMentionForMember member: MXRoomMember, textTrigger: String?)
func userSuggestionCoordinatorBridge(_ coordinator: UserSuggestionCoordinatorBridge, didUpdateViewHeight height: CGFloat)
}

@objcMembers
Expand Down Expand Up @@ -54,4 +55,8 @@ extension UserSuggestionCoordinatorBridge: UserSuggestionCoordinatorDelegate {
func userSuggestionCoordinator(_ coordinator: UserSuggestionCoordinator, didRequestMentionForMember member: MXRoomMember, textTrigger: String?) {
delegate?.userSuggestionCoordinatorBridge(self, didRequestMentionForMember: member, textTrigger: textTrigger)
}

func userSuggestionCoordinator(_ coordinator: UserSuggestionCoordinator, didUpdateViewHeight height: CGFloat) {
delegate?.userSuggestionCoordinatorBridge(self, didUpdateViewHeight: height)
}
}
1 change: 1 addition & 0 deletions changelog.d/6734.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Room: Fix a composer crash after long unsent messages.

0 comments on commit f201ea5

Please sign in to comment.