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

Implements the editor title in RN for Gutenberg. #10794

Merged
merged 14 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ target 'WordPress' do
## React Native
## =====================
##
pod 'Gutenberg', :git => 'http://github.com/wordpress-mobile/gutenberg-mobile/', :commit => '704d003adc1f1b76ee0978aa54e05a36fb16371d'
pod 'Gutenberg', :git => 'http://github.com/wordpress-mobile/gutenberg-mobile/', :commit => 'e98f6fcf21cac614192ef189e9514ec7f4a03af4'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgive me if you already know about this, there's a recent agreement about not depending on commit numbers anymore even on develop branch. So I think we'll need to update the commit dependencies to a beta tag before merging our PRs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, but I'd suggest to publish a tag once the review process is complete to avoid multiple tags per PR.

Copy link
Contributor

@pinarol pinarol Jan 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was already agreeing on that sorry if I wasn't clear

So I think we'll need to update the commit dependencies to a beta tag before merging our PRs

Anyway after chatting on this, this conversation might even be outdated

gutenberg_pod 'React'
gutenberg_pod 'yoga'
gutenberg_pod 'Folly'
Expand Down
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ DEPENDENCIES:
- Gifu (= 3.2.0)
- GiphyCoreSDK (~> 1.4.0)
- Gridicons (= 0.16)
- Gutenberg (from `http://github.com/wordpress-mobile/gutenberg-mobile/`, commit `704d003adc1f1b76ee0978aa54e05a36fb16371d`)
- Gutenberg (from `http://github.com/wordpress-mobile/gutenberg-mobile/`, commit `e98f6fcf21cac614192ef189e9514ec7f4a03af4`)
- HockeySDK (= 5.1.4)
- lottie-ios (= 2.5.0)
- MGSwipeTableCell (= 1.6.7)
Expand Down Expand Up @@ -308,7 +308,7 @@ EXTERNAL SOURCES:
Folly:
:podspec: https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/develop/react-native-gutenberg-bridge/third-party-podspecs/Folly.podspec.json
Gutenberg:
:commit: 704d003adc1f1b76ee0978aa54e05a36fb16371d
:commit: e98f6fcf21cac614192ef189e9514ec7f4a03af4
:git: http://github.com/wordpress-mobile/gutenberg-mobile/
React:
:podspec: https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/develop/react-native-gutenberg-bridge/third-party-podspecs/React.podspec.json
Expand All @@ -331,7 +331,7 @@ CHECKOUT OPTIONS:
:git: https://github.com/Automattic/Automattic-Tracks-iOS.git
:tag: 0.2.3
Gutenberg:
:commit: 704d003adc1f1b76ee0978aa54e05a36fb16371d
:commit: e98f6fcf21cac614192ef189e9514ec7f4a03af4
:git: http://github.com/wordpress-mobile/gutenberg-mobile/
react-native-keyboard-aware-scroll-view:
:git: https://github.com/wordpress-mobile/react-native-keyboard-aware-scroll-view.git
Expand Down Expand Up @@ -396,6 +396,6 @@ SPEC CHECKSUMS:
yoga: f37b1edbd68be803f1dc4d57d40d8a5b277d8e2c
ZendeskSDK: 44ee00338dd718495f0364369420ae11b389c878

PODFILE CHECKSUM: 576e158ce5fa37639973c08879e37a64516e5c2b
PODFILE CHECKSUM: 1f21337a89cf447f4935e30046397b146de54be3

COCOAPODS: 1.5.3
Original file line number Diff line number Diff line change
@@ -1,40 +1,5 @@
import UIKit

class GutenbergContainerView: UIView, NibLoadable {

@IBOutlet weak var titleTextField: UITextField!
@IBOutlet weak var separatorView: UIView!
@IBOutlet weak var editorContainerView: UIView!

override func awakeFromNib() {
super.awakeFromNib()
configureTitleTextField()
configureSeparatorView()
}

func configureTitleTextField() {
titleTextField.borderStyle = .none
titleTextField.font = Fonts.title
titleTextField.textColor = Colors.title
titleTextField.backgroundColor = Colors.background
titleTextField.placeholder = NSLocalizedString("Title", comment: "Placeholder for the post title.")
titleTextField.autocapitalizationType = .sentences
}

func configureSeparatorView() {
separatorView.backgroundColor = Colors.separator
}
}

private extension GutenbergContainerView {

enum Colors {
static let title = UIColor.darkText
static let separator = WPStyleGuide.greyLighten30()
static let background = UIColor.white
}

enum Fonts {
static let title = WPFontManager.notoBoldFont(ofSize: 24.0)
}
}
42 changes: 2 additions & 40 deletions WordPress/Classes/ViewRelated/Gutenberg/GutenbergContainerView.xib
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,21 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="1Wr-qV-SCb">
<rect key="frame" x="0.0" y="44" width="375" height="51"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="olW-iv-ZID">
<rect key="frame" x="0.0" y="0.0" width="375" height="50"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="HGg-Sw-1g3" userLabel="Padding view">
<rect key="frame" x="0.0" y="0.0" width="12" height="50"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="width" constant="12" id="3j6-aF-isN"/>
</constraints>
</view>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="WOn-ha-b6w">
<rect key="frame" x="12" y="0.0" width="363" height="50"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="sdB-Jj-uHz"/>
</constraints>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
</subviews>
</stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="lia-oS-aK0">
<rect key="frame" x="0.0" y="50" width="375" height="1"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="mGx-Rj-2z6"/>
</constraints>
</view>
</subviews>
</stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Gml-eF-Nq3">
<rect key="frame" x="0.0" y="95" width="375" height="717"/>
<rect key="frame" x="0.0" y="44" width="375" height="768"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="1Wr-qV-SCb" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" id="4P9-4e-VN9"/>
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="1Wr-qV-SCb" secondAttribute="trailing" id="QeZ-mG-iJL"/>
<constraint firstAttribute="bottom" secondItem="Gml-eF-Nq3" secondAttribute="bottom" id="Qyr-Ok-fpI"/>
<constraint firstItem="Gml-eF-Nq3" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="Xim-o2-B2m"/>
<constraint firstItem="Gml-eF-Nq3" firstAttribute="top" secondItem="1Wr-qV-SCb" secondAttribute="bottom" id="aHN-4N-S1h"/>
<constraint firstItem="1Wr-qV-SCb" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" id="j8g-Ia-1qw"/>
<constraint firstItem="Gml-eF-Nq3" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" id="fax-7h-5aZ"/>
<constraint firstAttribute="trailing" secondItem="Gml-eF-Nq3" secondAttribute="trailing" id="mfX-um-DiL"/>
</constraints>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
<connections>
<outlet property="editorContainerView" destination="Gml-eF-Nq3" id="h1X-eY-NjA"/>
<outlet property="separatorView" destination="lia-oS-aK0" id="ZXv-GI-yft"/>
<outlet property="titleTextField" destination="WOn-ha-b6w" id="Bcn-pZ-hGz"/>
</connections>
<point key="canvasLocation" x="138.40000000000001" y="152.21674876847291"/>
</view>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ class GutenbergViewController: UIViewController, PostEditor {

// MARK: - UI

private var titleTextField: UITextField {
return containerView.titleTextField
}

private var containerView = GutenbergContainerView.loadFromNib()

// MARK: - Aztec
Expand All @@ -38,14 +34,7 @@ class GutenbergViewController: UIViewController, PostEditor {
}
}

var postTitle: String {
get {
return titleTextField.text ?? ""
}
set {
titleTextField.text = newValue
}
}
var postTitle: String

/// Maintainer of state for editor - like for post button
///
Expand Down Expand Up @@ -77,6 +66,14 @@ class GutenbergViewController: UIViewController, PostEditor {
//TODO
}

func setTitle(_ title: String) {
guard gutenberg.isLoaded else {
return
}

gutenberg.setTitle(title)
}

func setHTML(_ html: String) {
guard gutenberg.isLoaded else {
return
Expand Down Expand Up @@ -137,12 +134,14 @@ class GutenbergViewController: UIViewController, PostEditor {
switchToAztec: @escaping (EditorViewController) -> ()) {

self.post = post
self.postTitle = post.postTitle ?? ""

self.switchToAztec = switchToAztec
verificationPromptHelper = AztecVerificationPromptHelper(account: self.post.blog.account)
shouldRemovePostOnDismiss = post.hasNeverAttemptedToUpload()

super.init(nibName: nil, bundle: nil)
postTitle = post.postTitle ?? ""

PostCoordinator.shared.cancelAnyPendingSaveOf(post: post)
navigationBarManager.delegate = self
}
Expand All @@ -162,7 +161,6 @@ class GutenbergViewController: UIViewController, PostEditor {
super.viewDidLoad()
setupContainerView()
setupGutenbergView()
registerEventListeners()
createRevisionOfPost()
configureNavigationBar()
refreshInterface()
Expand All @@ -177,10 +175,6 @@ class GutenbergViewController: UIViewController, PostEditor {

// MARK: - Functions

private func registerEventListeners() {
titleTextField.addTarget(self, action: #selector(titleTextFieldDidChange(_:)), for: .editingChanged)
}

private func configureNavigationBar() {
navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.accessibilityIdentifier = "Gutenberg Editor Navigation Bar"
Expand All @@ -200,7 +194,7 @@ class GutenbergViewController: UIViewController, PostEditor {
private func reloadEditorContents() {
let content = post.content ?? String()

titleTextField.text = post.postTitle
setTitle(post.postTitle ?? "")
setHTML(content)
}

Expand Down Expand Up @@ -230,11 +224,6 @@ class GutenbergViewController: UIViewController, PostEditor {
return presentationController(forPresented: presented, presenting: presenting)
}

@objc func titleTextFieldDidChange(_ textField: UITextField) {
mapUIContentToPostAndSave()
editorContentWasUpdated()
}

// MARK: - Switch to Aztec

func savePostEditsAndSwitchToAztec() {
Expand Down Expand Up @@ -280,9 +269,10 @@ extension GutenbergViewController: GutenbergBridgeDelegate {
callback: callback)
}

func gutenbergDidProvideHTML(_ html: String, changed: Bool) {
func gutenbergDidProvideHTML(title: String, html: String, changed: Bool) {
if changed {
self.html = html
self.postTitle = title
diegoreymendez marked this conversation as resolved.
Show resolved Hide resolved
}

editorContentWasUpdated()
Expand All @@ -305,20 +295,6 @@ extension GutenbergViewController: GutenbergBridgeDelegate {
}

func gutenbergDidLayout() {
defer {
isFirstGutenbergLayout = false
}
focusTitleIfNeeded()
}

private func focusTitleIfNeeded() {
if shouldFocusTitleAutomatically {
titleTextField.becomeFirstResponder()
}
}

private var shouldFocusTitleAutomatically: Bool {
return !post.hasContent() && !titleTextField.isFirstResponder && isFirstGutenbergLayout
}
}

Expand All @@ -329,6 +305,10 @@ extension GutenbergViewController: GutenbergBridgeDataSource {
return post.content ?? ""
}

func gutenbergInitialTitle() -> String? {
return post.postTitle ?? ""
}

func aztecAttachmentDelegate() -> TextViewAttachmentDelegate {
return attachmentDelegate
}
Expand Down