Skip to content

Commit c6fe554

Browse files
authored
Put "share server" in navbar instead of list (#3663)
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. -->
1 parent 1b0bfa1 commit c6fe554

File tree

1 file changed

+33
-24
lines changed

1 file changed

+33
-24
lines changed

Sources/App/Settings/Connection/ConnectionSettingsViewController.swift

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ class ConnectionSettingsViewController: HAFormViewController, RowControllerType
1212

1313
let server: Server
1414

15+
private lazy var shareButton = UIBarButtonItem(
16+
image: UIImage(systemName: "square.and.arrow.up"),
17+
style: .plain,
18+
target: self,
19+
action: #selector(shareServer)
20+
)
21+
1522
init(server: Server) {
1623
self.server = server
1724

@@ -36,8 +43,8 @@ class ConnectionSettingsViewController: HAFormViewController, RowControllerType
3643

3744
let connection = Current.api(for: server)?.connection
3845

39-
addActivateButtonToNavBar()
40-
appendInvitationButton()
46+
addActivateButton()
47+
addInvitationButtonToNavBar()
4148

4249
form
4350
+++ Section(header: L10n.Settings.StatusSection.header, footer: "") {
@@ -287,7 +294,11 @@ class ConnectionSettingsViewController: HAFormViewController, RowControllerType
287294
}
288295
}
289296

290-
private func appendInvitationButton() {
297+
private func addInvitationButtonToNavBar() {
298+
navigationItem.rightBarButtonItem = shareButton
299+
}
300+
301+
@objc private func shareServer() {
291302
guard let activeURL = server.info.connection.activeURL() else {
292303
Current.Log.error("Invitation button failed, no active URL found for server \(server.identifier)")
293304
return
@@ -299,31 +310,29 @@ class ConnectionSettingsViewController: HAFormViewController, RowControllerType
299310
return
300311
}
301312

302-
form +++ Section {
303-
_ in
304-
} <<< ButtonRow {
305-
$0.title = L10n.Settings.ConnectionSection.inviteToServer
306-
$0.onCellSelection { [weak self] cell, _ in
307-
guard let self else { return }
308-
let activityVC = UIActivityViewController(activityItems: [invitationURL], applicationActivities: nil)
309-
if let popover = activityVC.popoverPresentationController {
310-
popover.sourceView = cell
311-
popover.sourceRect = cell.bounds
312-
}
313-
present(activityVC, animated: true, completion: nil)
314-
}
313+
let activityVC = UIActivityViewController(activityItems: [invitationURL], applicationActivities: nil)
314+
if let popover = activityVC.popoverPresentationController {
315+
popover.sourceView = shareButton.customView
316+
popover.sourceRect = shareButton.customView?.bounds ?? CGRect(
317+
x: view.bounds.width - 1,
318+
y: 0,
319+
width: 1,
320+
height: 1
321+
)
315322
}
323+
present(activityVC, animated: true, completion: nil)
316324
}
317325

318-
private func addActivateButtonToNavBar() {
326+
private func addActivateButton() {
319327
if Current.servers.all.count > 1 {
320-
let activateButton = UIBarButtonItem(
321-
title: L10n.Settings.ConnectionSection.activateServer,
322-
style: .plain,
323-
target: self,
324-
action: #selector(activateServerTapped)
325-
)
326-
navigationItem.rightBarButtonItem = activateButton
328+
form +++ Section {
329+
_ in
330+
} <<< ButtonRow {
331+
$0.title = L10n.Settings.ConnectionSection.activateServer
332+
$0.onCellSelection { [weak self] _, _ in
333+
self?.activateServerTapped()
334+
}
335+
}
327336
}
328337
}
329338

0 commit comments

Comments
 (0)