Skip to content
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

Stories: iPad Support #16031

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def wordpress_kit
end

def kanvas
pod 'Kanvas', '~> 1.2.6'
#pod 'Kanvas', '~> 1.2.5'
#pod 'Kanvas', :git => 'https://github.com/tumblr/Kanvas-iOS.git', :tag => ''
#pod 'Kanvas', :git => 'https://github.com/tumblr/Kanvas-iOS.git', :commit => ''
pod 'Kanvas', :git => 'https://github.com/tumblr/Kanvas-iOS.git', :commit => 'b2d90a'
#pod 'Kanvas', :path => '../Kanvas-iOS'
end

Expand Down
11 changes: 8 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ DEPENDENCIES:
- Gridicons (~> 1.1.0)
- Gutenberg (from `https://github.com/wordpress-mobile/gutenberg-mobile.git`, tag `v1.51.0`)
- JTAppleCalendar (~> 8.0.2)
- Kanvas (~> 1.2.6)
- Kanvas (from `https://github.com/tumblr/Kanvas-iOS.git`, commit `b2d90a`)
- MediaEditor (~> 1.2.1)
- MRProgress (= 0.8.3)
- Nimble (~> 9.0.0)
Expand Down Expand Up @@ -534,7 +534,6 @@ SPEC REPOS:
- GTMAppAuth
- GTMSessionFetcher
- JTAppleCalendar
- Kanvas
- lottie-ios
- MediaEditor
- MRProgress
Expand Down Expand Up @@ -581,6 +580,9 @@ EXTERNAL SOURCES:
:git: https://github.com/wordpress-mobile/gutenberg-mobile.git
:submodules: true
:tag: v1.51.0
Kanvas:
:commit: b2d90a
:git: https://github.com/tumblr/Kanvas-iOS.git
RCTRequired:
:podspec: https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/v1.51.0/third-party-podspecs/RCTRequired.podspec.json
RCTTypeSafety:
Expand Down Expand Up @@ -662,6 +664,9 @@ CHECKOUT OPTIONS:
:git: https://github.com/wordpress-mobile/gutenberg-mobile.git
:submodules: true
:tag: v1.51.0
Kanvas:
:commit: b2d90a
:git: https://github.com/tumblr/Kanvas-iOS.git
RNTAztecView:
:git: https://github.com/wordpress-mobile/gutenberg-mobile.git
:submodules: true
Expand Down Expand Up @@ -763,6 +768,6 @@ SPEC CHECKSUMS:
ZendeskSupportSDK: e100a7a0a1bb5d7d43abbde3338727d985a4986d
ZIPFoundation: e27423c004a5a1410c15933407747374e7c6cb6e

PODFILE CHECKSUM: 6e7401c232011c94914623b98fea3c3277537c3a
PODFILE CHECKSUM: 32e84a0231a6a28591a523cca374104bf592a9d0

COCOAPODS: 1.10.0
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/Stories/CameraHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CameraHandler: CameraControllerDelegate {
let cancelTitle = NSLocalizedString("Keep Editing", comment: "Button shown if there are unsaved changes and the author is trying to move away from the post.")
let discardTitle = NSLocalizedString("Discard", comment: "Button shown if there are unsaved changes and the author is trying to move away from the post.")

let alertController = UIAlertController(title: title, message: nil, preferredStyle: .actionSheet)
let alertController = UIAlertController(title: title, message: nil, preferredStyle: UIDevice.isPad() ? .alert : .actionSheet)
alertController.view.accessibilityIdentifier = "post-has-changes-alert"

// Button: Keep editing
Expand Down
17 changes: 5 additions & 12 deletions WordPress/Classes/Services/Stories/StoryEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,18 @@ class StoryEditor: CameraController {
settings.exportStopMotionPhotoAsVideo = false
settings.fontSelectorUsesFont = true
settings.aspectRatio = 9/16
settings.showShadowOverMediaClips = false

return settings
}

enum EditorCreationError: Error {
case unsupportedDevice
}

typealias UpdateResult = Result<String, PostCoordinator.SavingError>
typealias UploadResult = Result<Void, PostCoordinator.SavingError>

static func editor(blog: Blog,
context: NSManagedObjectContext,
updated: @escaping (UpdateResult) -> Void,
uploaded: @escaping (UploadResult) -> Void) throws -> StoryEditor {
uploaded: @escaping (UploadResult) -> Void) -> StoryEditor {
let post = PostService(managedObjectContext: context).createDraftPost(for: blog)
return try editor(post: post, mediaFiles: nil, publishOnCompletion: true, updated: updated, uploaded: uploaded)
}
Expand All @@ -109,12 +106,7 @@ class StoryEditor: CameraController {
mediaFiles: [MediaFile]?,
publishOnCompletion: Bool = false,
updated: @escaping (UpdateResult) -> Void,
uploaded: @escaping (UploadResult) -> Void) throws -> StoryEditor {

guard !UIDevice.isPad() else {
throw EditorCreationError.unsupportedDevice
}

uploaded: @escaping (UploadResult) -> Void) -> StoryEditor {
let controller = StoryEditor(post: post,
onClose: nil,
settings: cameraSettings,
Expand Down Expand Up @@ -150,6 +142,7 @@ class StoryEditor: CameraController {
Kanvas.KanvasColors.shared = KanvasCustomUI.shared.cameraColors()
Kanvas.KanvasFonts.shared = KanvasCustomUI.shared.cameraFonts()
Kanvas.KanvasImages.shared = KanvasCustomUI.shared.cameraImages()
Kanvas.KanvasEditorDesign.shared = Kanvas.KanvasEditorDesign.storiesDesign
Kanvas.KanvasStrings.shared = KanvasStrings(
cameraPermissionsTitleLabel: NSLocalizedString("Post to WordPress", comment: "Title of camera permissions screen"),
cameraPermissionsDescriptionLabel: NSLocalizedString("Allow access so you can start taking photos and videos.", comment: "Message on camera permissions screen to explain why the app needs camera and microphone permissions")
Expand Down Expand Up @@ -233,7 +226,7 @@ extension StoryEditor: PublishingEditor {
}

var prepublishingSourceView: UIView? {
return nil
return confirmButton
}

var alertBarButtonItem: UIBarButtonItem? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class WPMediaPickerForKanvas: WPNavigationMediaPickerViewController, MediaPicker
}

let tabBar = PortraitTabBarController()
tabBar.modalPresentationStyle = .overFullScreen

let mediaPickerDelegate = MediaPickerDelegate(kanvasDelegate: delegate, presenter: tabBar)
let options = WPMediaPickerOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ extension BlogDetailsViewController {

//TODO: Can be removed after stories launches
private var shouldShowNewStory: Bool {
return Feature.enabled(.stories) && blog.supports(.stories) && !UIDevice.isPad()
return Feature.enabled(.stories) && blog.supports(.stories)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -674,32 +674,20 @@ extension GutenbergViewController: GutenbergBridgeDelegate {

do {
try showEditor(files: files, blockID: blockId)
} catch let error {
switch error {
case StoryEditor.EditorCreationError.unsupportedDevice:
let title = NSLocalizedString("Unsupported Device", comment: "Title for stories unsupported device error.")
let message = NSLocalizedString("The Stories editor is not currently available for your iPad. Please try Stories on your iPhone.", comment: "Message for stories unsupported device error.")
let controller = UIAlertController(title: title, message: message, preferredStyle: .alert)
let dismiss = UIAlertAction(title: "Dismiss", style: .default) { _ in
controller.dismiss(animated: true, completion: nil)
}
controller.addAction(dismiss)
present(controller, animated: true, completion: nil)
default:
let title = NSLocalizedString("Unable to Create Stories Editor", comment: "Title for stories unknown error.")
let message = NSLocalizedString("There was a problem with the Stories editor. If the problem persists you can contact us via the Me > Help & Support screen.", comment: "Message for stories unknown error.")
let controller = UIAlertController(title: title, message: message, preferredStyle: .alert)
let dismiss = UIAlertAction(title: "Dismiss", style: .default) { _ in
controller.dismiss(animated: true, completion: nil)
}
controller.addAction(dismiss)
present(controller, animated: true, completion: nil)
} catch {
let title = NSLocalizedString("Unable to Create Stories Editor", comment: "Title for stories unknown error.")
let message = NSLocalizedString("There was a problem with the Stories editor. If the problem persists you can contact us via the Me > Help & Support screen.", comment: "Message for stories unknown error.")
let controller = UIAlertController(title: title, message: message, preferredStyle: .alert)
let dismiss = UIAlertAction(title: "Dismiss", style: .default) { _ in
controller.dismiss(animated: true, completion: nil)
}
controller.addAction(dismiss)
present(controller, animated: true, completion: nil)
}
}

func showEditor(files: [MediaFile], blockID: String) throws {
storyEditor = try StoryEditor.editor(post: post, mediaFiles: files, publishOnCompletion: false, updated: { [weak self] result in
storyEditor = StoryEditor.editor(post: post, mediaFiles: files, publishOnCompletion: false, updated: { [weak self] result in
switch result {
case .success(let content):
self?.gutenberg.replace(blockID: blockID, content: content)
Expand Down Expand Up @@ -1052,8 +1040,7 @@ extension GutenbergViewController: GutenbergBridgeDataSource {
.unsupportedBlockEditor: isUnsupportedBlockEditorEnabled,
.canEnableUnsupportedBlockEditor: post.blog.jetpack?.isConnected ?? false,
.audioBlock: !isFreeWPCom, // Disable audio block until it's usable on free sites via "Insert from URL" capability
.mediaFilesCollectionBlock: FeatureFlag.stories.enabled && post.blog.supports(.stories) && !UIDevice.isPad()
]
.mediaFilesCollectionBlock: FeatureFlag.stories.enabled && post.blog.supports(.stories) ]
}

private var isUnsupportedBlockEditorEnabled: Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ extension PublishingEditor where Self: UIViewController {
let prepublishingNavigationController = PrepublishingNavigationController(rootViewController: prepublishing)
let bottomSheet = BottomSheetViewController(childViewController: prepublishingNavigationController, customHeaderSpacing: 0)
if let sourceView = prepublishingSourceView {
bottomSheet.show(from: self, sourceView: sourceView)
bottomSheet.show(from: self.topmostPresentedViewController, sourceView: sourceView)
} else {
bottomSheet.show(from: self.topmostPresentedViewController)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,18 @@ protocol PrepublishingDismissible {
}

class PrepublishingNavigationController: LightNavigationController {
override func viewDidLoad() {
super.viewDidLoad()

// Set the height for iPad
if UIDevice.isPad() {
preferredContentSize = Constants.iPadPreferredContentSize
}
}

// We are using intrinsicHeight as the view's collapsedHeight which is calculated from the preferredContentSize.
override public var preferredContentSize: CGSize {
set {
viewControllers.last?.preferredContentSize = newValue
}
get {
if UIDevice.isPad() {
return Constants.iPadPreferredContentSize
}

guard let visibleViewController = viewControllers.last else {
return .zero
}

visibleViewController.view.layoutIfNeeded()

return visibleViewController.preferredContentSize
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@ class PrepublishingViewController: UITableViewController {
}
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if let footerView = tableView.tableFooterView {
let width = tableView.bounds.size.width
let size = footerView.systemLayoutSizeFitting(CGSize(width: width, height: UIView.layoutFittingCompressedSize.height))
if footerView.frame.size.height != size.height {
footerView.frame.size.height = size.height
tableView.tableFooterView = footerView
}
}
calculatePreferredContentSize()
}

override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
Expand Down Expand Up @@ -347,7 +360,7 @@ class PrepublishingViewController: UITableViewController {
// MARK: - Publish Button

private func setupPublishButton() {
let footer = UIView(frame: Constants.footerFrame)
let footer = UIView(frame: .zero)
footer.addSubview(publishButton)
footer.pinSubviewToSafeArea(publishButton, insets: Constants.nuxButtonInsets)
publishButton.translatesAutoresizingMaskIntoConstraints = false
Expand Down Expand Up @@ -432,7 +445,6 @@ class PrepublishingViewController: UITableViewController {
static let textFieldReuseIdentifier = "wpTextFieldCell"
static let nuxButtonInsets = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
static let cellMargins = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
static let footerFrame = CGRect(x: 0, y: 0, width: 100, height: 80)
static let publishNow = NSLocalizedString("Publish Now", comment: "Label for a button that publishes the post")
static let scheduleNow = NSLocalizedString("Schedule Now", comment: "Label for the button that schedules the post")
static let publishDateLabel = NSLocalizedString("Publish Date", comment: "Label for Publish date")
Expand Down