add dismiss button on start new conversation screen

pull/891/head
Ryan ZHAO 1 year ago
parent c5eb55d1e8
commit ace7f3e5a5

@ -868,10 +868,14 @@ final class HomeVC: BaseVC, SessionUtilRespondingViewController, UITableViewData
}
@objc func createNewConversation() {
let viewController = SessionHostingViewController(rootView: StartConversationScreen())
let viewController = SessionHostingViewController(
rootView: StartConversationScreen(),
customizedNavigationBackground: .backgroundSecondary
)
viewController.setNavBarTitle("start_conversation_screen_title".localized())
viewController.setUpDismissingButton(on: .right)
let navigationController = StyledNavigationController(rootViewController: viewController)
navigationController.view.backgroundColor = .blue
if UIDevice.current.isIPad {
navigationController.modalPresentationStyle = .fullScreen
}

@ -76,7 +76,7 @@ struct StartConversationScreen: View {
.aspectRatio(1, contentMode: .fit)
.padding(.vertical, Values.smallSpacing)
}
.padding(.all, Values.largeSpacing)
.padding(.horizontal, Values.largeSpacing)
}
}
.backgroundColor(themeColor: .backgroundSecondary)

@ -7,10 +7,18 @@ public class HostWrapper: ObservableObject {
public weak var controller: UIViewController?
}
public class SessionHostingViewController<Content>: UIHostingController<ModifiedContent<Content,SwiftUI._EnvironmentKeyWritingModifier<HostWrapper?>>> where Content : View {
public enum NavigationItemPosition {
case left
case right
}
public class SessionHostingViewController<Content>: UIHostingController<ModifiedContent<Content, _EnvironmentKeyWritingModifier<HostWrapper?>>>, ThemedNavigation where Content : View {
public override var preferredStatusBarStyle: UIStatusBarStyle {
return ThemeManager.currentTheme.statusBarStyle
}
public var navigationBackground: ThemeValue { customizedNavigationBackground ?? .backgroundPrimary }
private let customizedNavigationBackground: ThemeValue?
lazy var navBarTitleLabel: UILabel = {
let result = UILabel()
@ -32,7 +40,8 @@ public class SessionHostingViewController<Content>: UIHostingController<Modified
return result
}()
public init(rootView:Content) {
public init(rootView:Content, customizedNavigationBackground: ThemeValue? = nil) {
self.customizedNavigationBackground = customizedNavigationBackground
let container = HostWrapper()
let modified = rootView.environmentObject(container) as! ModifiedContent<Content, _EnvironmentKeyWritingModifier<HostWrapper?>>
super.init(rootView: modified)
@ -94,4 +103,19 @@ public class SessionHostingViewController<Content>: UIHostingController<Modified
navigationItem.titleView = logoImageView
}
internal func setUpDismissingButton(on postion: NavigationItemPosition) {
let closeButton = UIBarButtonItem(image: #imageLiteral(resourceName: "X"), style: .plain, target: self, action: #selector(close))
closeButton.themeTintColor = .textPrimary
switch postion {
case .left:
navigationItem.leftBarButtonItem = closeButton
case .right:
navigationItem.rightBarButtonItem = closeButton
}
}
@objc private func close() {
dismiss(animated: true, completion: nil)
}
}

Loading…
Cancel
Save