diff --git a/Sources/Brave/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift b/Sources/Brave/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift index 37a9d18ecd1..9e6675498ed 100644 --- a/Sources/Brave/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift +++ b/Sources/Brave/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift @@ -273,12 +273,6 @@ class TabLocationView: UIView { contentView.snp.makeConstraints { make in make.leading.trailing.top.bottom.equalTo(self) } - - // Setup UIDragInteraction to handle dragging the location - // bar for dropping its URL into other apps. - let dragInteraction = UIDragInteraction(delegate: self) - dragInteraction.allowsSimultaneousRecognitionDuringLift = true - self.addInteraction(dragInteraction) privateModeCancellable = privateBrowsingManager.$isPrivateBrowsing .removeDuplicates() @@ -414,26 +408,6 @@ class TabLocationView: UIView { } } -// MARK: - UIDragInteractionDelegate - -extension TabLocationView: UIDragInteractionDelegate { - func dragInteraction(_ interaction: UIDragInteraction, itemsForBeginning session: UIDragSession) -> [UIDragItem] { - // Ensure we actually have a URL in the location bar and that the URL is not local. - guard let url = self.url, !InternalURL.isValid(url: url), let itemProvider = NSItemProvider(contentsOf: url), - !reloadButton.isHighlighted - else { - return [] - } - - let dragItem = UIDragItem(itemProvider: itemProvider) - return [dragItem] - } - - func dragInteraction(_ interaction: UIDragInteraction, sessionWillBegin session: UIDragSession) { - delegate?.tabLocationViewDidBeginDragInteraction(self) - } -} - // MARK: - TabEventHandler extension TabLocationView: TabEventHandler { diff --git a/Sources/Brave/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift b/Sources/Brave/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift index b6c2fbf8258..08fb51bdfc4 100644 --- a/Sources/Brave/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift +++ b/Sources/Brave/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift @@ -307,6 +307,10 @@ class TopToolbarView: UIView, ToolbarProtocol { swipeGestureRecognizer.isEnabled = false locationView.addGestureRecognizer(swipeGestureRecognizer) + let dragInteraction = UIDragInteraction(delegate: self) + dragInteraction.allowsSimultaneousRecognitionDuringLift = true + locationView.addInteraction(dragInteraction) + self.displayTabTraySwipeGestureRecognizer = swipeGestureRecognizer qrCodeButton.addTarget(self, action: #selector(topToolbarDidPressQrCodeButton), for: .touchUpInside) @@ -412,11 +416,11 @@ class TopToolbarView: UIView, ToolbarProtocol { $0.attributedPlaceholder = self.locationView.makePlaceholder(colors: .standard) $0.clearButtonMode = .whileEditing $0.rightViewMode = .never + if let dropInteraction = $0.textDropInteraction { + $0.removeInteraction(dropInteraction) + } } - let dragInteraction = UIDragInteraction(delegate: self) - locationTextField.addInteraction(dragInteraction) - if RecentSearchQRCodeScannerController.hasCameraSupport { locationBarOptionsStackView.addArrangedSubview(qrCodeButton) } @@ -807,12 +811,19 @@ extension TopToolbarView: AutocompleteTextFieldDelegate { extension TopToolbarView: UIDragInteractionDelegate { func dragInteraction(_ interaction: UIDragInteraction, itemsForBeginning session: UIDragSession) -> [UIDragItem] { - guard let text = locationTextField?.text else { + // Ensure we actually have a URL in the location bar and that the URL is not local. + guard let url = self.locationView.url, !InternalURL.isValid(url: url), let itemProvider = NSItemProvider(contentsOf: url), + !locationView.reloadButton.isHighlighted, !inOverlayMode + else { return [] } - - let dragItem = UIDragItem(itemProvider: NSItemProvider(object: text as NSString)) + + let dragItem = UIDragItem(itemProvider: itemProvider) dragItem.localObject = locationTextField return [dragItem] } + + func dragInteraction(_ interaction: UIDragInteraction, sessionWillBegin session: UIDragSession) { + delegate?.topToolbarDidBeginDragInteraction(self) + } }