Skip to content

Commit

Permalink
[fix/overlapping-sharing-buttons] Overlapping Sharing Buttons (#1248)
Browse files Browse the repository at this point in the history
  • Loading branch information
hosy authored Aug 4, 2023
1 parent 7986210 commit 9a3f828
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ extension OCShare: DataItemSelectionInteraction {
// Single share
editViewController = ShareViewController(mode: .edit, share: self, clientContext: context, completion: { _ in })
}

if let editViewController {
let navigationController = ThemeNavigationController(rootViewController: editViewController)
context.present(navigationController, animated: true)
Expand Down
60 changes: 25 additions & 35 deletions ownCloudAppShared/Client/Sharing/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ open class ShareViewController: CollectionViewController, SearchViewControllerDe
self.item = (item != nil) ? item! : ((location != nil) ? try? clientContext.core?.cachedItem(at: location!) : nil)
self.mode = mode
self.completionHandler = completion

// Item section
if let item = item {
let itemSectionContext = ClientContext(with: clientContext, modifier: { context in
context.permissions = []
})
var itemSectionDatasource = OCDataSourceArray(items: [item])
var itemSection = CollectionViewSection(identifier: "item", dataSource: itemSectionDatasource, cellStyle: .init(with: .header), cellLayout: .list(appearance: .plain, contentInsets: NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)), clientContext: itemSectionContext)
sections.append(itemSection)
}

// Managament section cell style
let managementCellStyle: CollectionViewCellStyle = .init(with: .tableCell)
Expand Down Expand Up @@ -220,25 +230,20 @@ open class ShareViewController: CollectionViewController, SearchViewControllerDe
collectionView.contentInset = extraContentInset

// Set navigation bar title
let itemDisplayName = location?.displayName(in: clientContext)
var navigationTitle: String?

if let itemDisplayName {
navigationTitle = "Share {{itemName}}".localized([ "itemName" : itemDisplayName ])
} else {
switch mode {
case .create:
navigationTitle = "Share".localized

case .edit:
navigationTitle = "Edit".localized
}

switch mode {
case .create:
navigationTitle = (type == .link) ? "Create link".localized : "Invite".localized

case .edit:
navigationTitle = "Edit".localized
}
navigationItem.titleLabelText = navigationTitle

// Add bottom button bar
let title = (mode == .create) ? ((type == .link) ? "Create link".localized : "Invite".localized) : "Save changes".localized

bottomButtonBar = BottomButtonBar(selectButtonTitle: title, cancelButtonTitle: "Cancel".localized, hasCancelButton: true, selectAction: UIAction(handler: { [weak self] _ in
self?.save()
}), cancelAction: UIAction(handler: { [weak self] _ in
Expand All @@ -250,26 +255,11 @@ open class ShareViewController: CollectionViewController, SearchViewControllerDe
bottomButtonBarViewController.view = bottomButtonBar

// - Add delete button for existing shares
if mode == .edit, let bottomButtonBar {
var deleteButtonConfig = UIButton.Configuration.borderedProminent()
deleteButtonConfig.title = "Unshare".localized
deleteButtonConfig.cornerStyle = .large
deleteButtonConfig.baseBackgroundColor = .systemRed
deleteButtonConfig.baseForegroundColor = .white

let deleteButton = UIButton()
deleteButton.translatesAutoresizingMaskIntoConstraints = false
deleteButton.configuration = deleteButtonConfig
deleteButton.addAction(UIAction(handler: { [weak self] action in
self?.deleteShare()
}), for: .primaryActionTriggered)

bottomButtonBar.addSubview(deleteButton)

NSLayoutConstraint.activate([
deleteButton.leadingAnchor.constraint(equalTo: bottomButtonBar.leadingAnchor, constant: 20),
deleteButton.centerYAnchor.constraint(equalTo: bottomButtonBar.selectButton.centerYAnchor)
])
if mode == .edit {
let unshare = UIBarButtonItem(title: "Unshare".localized, style: .plain, target: self, action: #selector(deleteShare))
unshare.tintColor = .red

self.navigationItem.rightBarButtonItem = unshare
}

self.addStacked(child: bottomButtonBarViewController, position: .bottom)
Expand Down Expand Up @@ -748,7 +738,7 @@ open class ShareViewController: CollectionViewController, SearchViewControllerDe
}
}

func deleteShare() {
@objc func deleteShare() {
guard let core = clientContext?.core, let share else {
self.showError(NSError(ocError: .internal))
return
Expand Down

0 comments on commit 9a3f828

Please sign in to comment.