Skip to content

Commit

Permalink
Merge pull request #10794 from wordpress-mobile/gutenberg/post-title-…
Browse files Browse the repository at this point in the history
…in-rn

Implements the editor title in RN for Gutenberg.
  • Loading branch information
diegoreymendez authored Jan 28, 2019
2 parents 318f9b9 + bb38fbe commit a6518d6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 115 deletions.
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ target 'WordPress' do
## React Native
## =====================
##
pod 'Gutenberg', :git => 'http://github.com/wordpress-mobile/gutenberg-mobile/', :tag => 'v0.3.4'
pod 'Gutenberg', :git => 'http://github.com/wordpress-mobile/gutenberg-mobile/', :commit => '1559268a0d38df09266851f1dda10900b1e14fb4'
pod 'RNTAztecView', :git => 'http://github.com/wordpress-mobile/gutenberg-mobile/', :tag => 'v0.3.4'

gutenberg_pod 'React'
Expand Down
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,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.4`)
- Gutenberg (from `http://github.com/wordpress-mobile/gutenberg-mobile/`, commit `1559268a0d38df09266851f1dda10900b1e14fb4`)
- HockeySDK (= 5.1.4)
- MGSwipeTableCell (= 1.6.8)
- MRProgress (= 0.8.3)
Expand Down Expand Up @@ -302,8 +302,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: 1559268a0d38df09266851f1dda10900b1e14fb4
:git: http://github.com/wordpress-mobile/gutenberg-mobile/
:tag: v0.3.4
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 @@ -327,8 +327,8 @@ CHECKOUT OPTIONS:
:git: https://github.com/Automattic/Automattic-Tracks-iOS.git
:tag: '0.3'
Gutenberg:
:commit: 1559268a0d38df09266851f1dda10900b1e14fb4
:git: http://github.com/wordpress-mobile/gutenberg-mobile/
:tag: v0.3.4
RNSVG:
:git: https://github.com/wordpress-mobile/react-native-svg.git
:tag: 8.0.9-gb.0
Expand Down Expand Up @@ -389,6 +389,6 @@ SPEC CHECKSUMS:
yoga: f37b1edbd68be803f1dc4d57d40d8a5b277d8e2c
ZendeskSDK: 44ee00338dd718495f0364369420ae11b389c878

PODFILE CHECKSUM: 2a1d64bc084e239209898a7983a56579bcbc52e4
PODFILE CHECKSUM: 85dec766bd43d55144a49b87203bbcfe4d0a1440

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
}

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

0 comments on commit a6518d6

Please sign in to comment.