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 10 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/', :tag => 'v0.3.3'
pod 'Gutenberg', :git => 'http://github.com/wordpress-mobile/gutenberg-mobile/', :commit => '106234049b9c0b01c8d21e139f15f34cdcd1abaf'
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/`, tag `v0.3.3`)
- Gutenberg (from `http://github.com/wordpress-mobile/gutenberg-mobile/`, commit `106234049b9c0b01c8d21e139f15f34cdcd1abaf`)
- HockeySDK (= 5.1.4)
- lottie-ios (= 2.5.0)
- MGSwipeTableCell (= 1.6.7)
Expand Down Expand Up @@ -307,8 +307,8 @@ EXTERNAL SOURCES:
Folly:
:podspec: https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/master/react-native-gutenberg-bridge/third-party-podspecs/Folly.podspec.json
Gutenberg:
:commit: 106234049b9c0b01c8d21e139f15f34cdcd1abaf
:git: http://github.com/wordpress-mobile/gutenberg-mobile/
:tag: v0.3.3
React:
:podspec: https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/master/react-native-gutenberg-bridge/third-party-podspecs/React.podspec.json
react-native-keyboard-aware-scroll-view:
Expand All @@ -333,8 +333,8 @@ CHECKOUT OPTIONS:
:git: https://github.com/Automattic/Automattic-Tracks-iOS.git
:tag: 0.2.3
Gutenberg:
:commit: 106234049b9c0b01c8d21e139f15f34cdcd1abaf
:git: http://github.com/wordpress-mobile/gutenberg-mobile/
:tag: v0.3.3
react-native-keyboard-aware-scroll-view:
:git: https://github.com/wordpress-mobile/react-native-keyboard-aware-scroll-view.git
:tag: gb-v0.8.2
Expand Down Expand Up @@ -401,6 +401,6 @@ SPEC CHECKSUMS:
yoga: f37b1edbd68be803f1dc4d57d40d8a5b277d8e2c
ZendeskSDK: 44ee00338dd718495f0364369420ae11b389c878

PODFILE CHECKSUM: f6648a4bbed872847d3fd2dffdb1882581b33df6
PODFILE CHECKSUM: 36c2fb851c1246c4b4d57571b8ff892c812ca1ec

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 @@ -39,11 +35,12 @@ class GutenbergViewController: UIViewController, PostEditor {
}

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

get {
return post.postTitle ?? ""
}
}

Expand Down Expand Up @@ -77,6 +74,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 +142,13 @@ class GutenbergViewController: UIViewController, PostEditor {
switchToAztec: @escaping (EditorViewController) -> ()) {

self.post = post

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 +168,6 @@ class GutenbergViewController: UIViewController, PostEditor {
super.viewDidLoad()
setupContainerView()
setupGutenbergView()
registerEventListeners()
createRevisionOfPost()
configureNavigationBar()
refreshInterface()
Expand All @@ -177,10 +182,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 +201,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 +231,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 +276,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 +302,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 +312,10 @@ extension GutenbergViewController: GutenbergBridgeDataSource {
return post.content ?? ""
}

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

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