-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quick Start for Existing Users: Add media upload tour #18471
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
394bd5b
Add: Media upload tour basic info
hassaanelgarem f1b5efc
Add: first upload media step
hassaanelgarem 056f06a
Add: point to media button on the dashboard
hassaanelgarem 1182fdc
Add: point to menu button on site menu
hassaanelgarem 9bd6a12
Add: mark first step as visited
hassaanelgarem 02dc7bf
Refactor: always reevaluate if quick action spotlight should be shown
hassaanelgarem 6f18cfc
Add: add media step
hassaanelgarem 31d47b6
Add: mark the second step as visited
hassaanelgarem abf84b9
Add: spotlight view to add button
hassaanelgarem fdd5c02
Fix: spotlight view being clipped
hassaanelgarem 27b9a69
Change: always show add button, even if there's no media
hassaanelgarem 0b812f0
Change: use in-progress MediaPicker beta
hassaanelgarem f090094
Add: documentation for kvo usage
hassaanelgarem 7c979fc
Revert "Change: use in-progress MediaPicker beta"
hassaanelgarem 17d43db
Merge branch 'trunk' into task/18388-qs-media
hassaanelgarem a91b3b5
Change: use WPMediaPicker 1.8.3-beta.1
hassaanelgarem 913e67b
Fix: failing unit tests
hassaanelgarem 724a60d
Refactor: rename QuickStartTourElement media enum case
hassaanelgarem 3ee251c
Add: release note
hassaanelgarem aa5d805
Change: use WPMediaPicker 1.8.4-beta.1
hassaanelgarem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,9 @@ class MediaLibraryViewController: WPMediaPickerViewController { | |
|
||
fileprivate var isLoading: Bool = false | ||
fileprivate let noResultsView = NoResultsViewController.controller() | ||
fileprivate let addButton: SpotlightableButton = SpotlightableButton(type: .custom) | ||
|
||
fileprivate var kvoTokens: [NSKeyValueObservation]? | ||
|
||
fileprivate var selectedAsset: Media? = nil | ||
|
||
|
@@ -62,12 +65,13 @@ class MediaLibraryViewController: WPMediaPickerViewController { | |
controller.navigationItem.largeTitleDisplayMode = .never | ||
sourceController.navigationController?.pushViewController(controller, animated: true) | ||
|
||
QuickStartTourGuide.shared.visited(.blogDetailNavigation) | ||
QuickStartTourGuide.shared.visited(.mediaScreen) | ||
} | ||
|
||
deinit { | ||
unregisterChangeObserver() | ||
unregisterUploadCoordinatorObserver() | ||
stopObservingNavigationBarClipsToBounds() | ||
} | ||
|
||
private class func pickerOptions() -> WPMediaPickerOptions { | ||
|
@@ -104,6 +108,9 @@ class MediaLibraryViewController: WPMediaPickerViewController { | |
if let collectionView = collectionView { | ||
WPStyleGuide.configureColors(view: view, collectionView: collectionView) | ||
} | ||
|
||
navigationController?.navigationBar.subviews.forEach ({ $0.clipsToBounds = false }) | ||
startObservingNavigationBarClipsToBounds() | ||
} | ||
|
||
override func viewDidAppear(_ animated: Bool) { | ||
|
@@ -120,6 +127,11 @@ class MediaLibraryViewController: WPMediaPickerViewController { | |
} | ||
} | ||
|
||
override func viewWillAppear(_ animated: Bool) { | ||
super.viewWillAppear(animated) | ||
addButton.shouldShowSpotlight = QuickStartTourGuide.shared.isCurrentElement(.mediaUpload) | ||
} | ||
|
||
// MARK: - Update view state | ||
|
||
fileprivate func updateViewState(for assetCount: Int) { | ||
|
@@ -142,12 +154,18 @@ class MediaLibraryViewController: WPMediaPickerViewController { | |
|
||
var barButtonItems = [UIBarButtonItem]() | ||
|
||
if blog.userCanUploadMedia && assetCount > 0 { | ||
let addButton = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addTapped)) | ||
if blog.userCanUploadMedia { | ||
addButton.spotlightOffset = Constants.addButtonSpotlightOffset | ||
let config = UIImage.SymbolConfiguration(textStyle: .body, scale: .large) | ||
let image = UIImage(systemName: "plus", withConfiguration: config) ?? .gridicon(.plus) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Q] Any particular reason we're using the system image over the gridicon? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
addButton.setImage(image, for: .normal) | ||
addButton.contentEdgeInsets = Constants.addButtonContentInset | ||
addButton.addTarget(self, action: #selector(addTapped), for: .touchUpInside) | ||
addButton.accessibilityLabel = NSLocalizedString("Add", comment: "Accessibility label for add button to add items to the user's media library") | ||
addButton.accessibilityHint = NSLocalizedString("Add new media", comment: "Accessibility hint for add button to add items to the user's media library") | ||
|
||
barButtonItems.append(addButton) | ||
let addBarButton = UIBarButtonItem(customView: addButton) | ||
barButtonItems.append(addBarButton) | ||
} | ||
|
||
if blog.supports(.mediaDeletion) && assetCount > 0 { | ||
|
@@ -157,10 +175,8 @@ class MediaLibraryViewController: WPMediaPickerViewController { | |
|
||
barButtonItems.append(editButton) | ||
|
||
navigationItem.setRightBarButtonItems(barButtonItems, animated: false) | ||
} else { | ||
navigationItem.setRightBarButtonItems(barButtonItems, animated: false) | ||
} | ||
navigationItem.setRightBarButtonItems(barButtonItems, animated: false) | ||
} | ||
} | ||
|
||
|
@@ -255,6 +271,8 @@ class MediaLibraryViewController: WPMediaPickerViewController { | |
// MARK: - Actions | ||
|
||
@objc fileprivate func addTapped() { | ||
QuickStartTourGuide.shared.visited(.mediaUpload) | ||
addButton.shouldShowSpotlight = QuickStartTourGuide.shared.isCurrentElement(.mediaUpload) | ||
showOptionsMenu() | ||
} | ||
|
||
|
@@ -427,6 +445,25 @@ class MediaLibraryViewController: WPMediaPickerViewController { | |
MediaCoordinator.shared.removeObserver(withUUID: uuid) | ||
} | ||
} | ||
|
||
// MARK: ClipsToBounds KVO Observer | ||
|
||
/// The content view of the navigation bar causes the spotlight view on the add button to be clipped. | ||
/// This ensures that `clipsToBounds` of the content view is always `false`. | ||
/// Without this, `clipsToBounds` reverts to `true` at some point during the view lifecycle. This happens asynchronously, | ||
/// so we can't confidently reset it. Hence the need for KVO. | ||
private func startObservingNavigationBarClipsToBounds() { | ||
kvoTokens = navigationController?.navigationBar.subviews.map({ subview in | ||
return subview.observe(\.clipsToBounds, options: .new, changeHandler: { view, change in | ||
guard let newValue = change.newValue, newValue else { return } | ||
view.clipsToBounds = false | ||
}) | ||
}) | ||
} | ||
|
||
private func stopObservingNavigationBarClipsToBounds() { | ||
kvoTokens?.forEach({ $0.invalidate() }) | ||
} | ||
} | ||
|
||
// MARK: - UIDocumentPickerDelegate | ||
|
@@ -742,3 +779,12 @@ extension MediaLibraryViewController: TenorPickerDelegate { | |
} | ||
} | ||
} | ||
|
||
// MARK: Constants | ||
|
||
extension MediaLibraryViewController { | ||
private enum Constants { | ||
static let addButtonSpotlightOffset = UIOffset(horizontal: 20, vertical: -10) | ||
static let addButtonContentInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Q] Is it intentional that there no space between the "%@" and the "to"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is yes.
String.highlighting
adds a space between the title and the icon passed. Given that the title is empty in this case, this meansString.highlighting
will add an extra space either way.Removing the space from the base sting was to mitigate this issue. This was simpler than modifying
String.highlighting
to handle this specific case.