Skip to content

Commit

Permalink
[RNMobile] Hide help button from UBE (#37221)
Browse files Browse the repository at this point in the history
As described in wordpress-mobile/gutenberg-mobile#4339, a help button is currently displaying in the bottom right-hand corner of the unsupported block editor (UBE) in both the Android and iOS apps. The button can be seen while logged into WordPress.com. When tapped on, the button isn't working as expected on iOS and prompts users to navigate away from the editor on Android, creating the potential for edits to be lost.

With this PR, the button is hidden from view in order to avoid confusion and potential loss of edits. A high-level overview of the code changes can be found in the `Types of changes` section below.
  • Loading branch information
Siobhan Bamber authored Jan 14, 2022
1 parent bbaaae8 commit 0d5843d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,18 @@ private void injectCssScript() {
String injectWPBarsCssScript = getFileContentFromAssets("gutenberg-web-single-block/wp-bar-override.css");
injectWPBarsCssScript = removeWhiteSpace(removeNewLines(injectWPBarsCssScript));
evaluateJavaScript(String.format(INJECT_CSS_SCRIPT_TEMPLATE, injectWPBarsCssScript));

String injectExternalCssScript = getOnGutenbergReadyExternalStyles();
injectExternalCssScript = removeWhiteSpace(removeNewLines(injectExternalCssScript));
evaluateJavaScript(String.format(INJECT_CSS_SCRIPT_TEMPLATE, injectExternalCssScript));
}
});
}

protected String getOnGutenbergReadyExternalStyles() {
return new String();
}

private void injectOnGutenbergReadyExternalSources() {
List<String> list = getOnGutenbergReadyExternalSources();
for (String file : list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ public struct FallbackJavascriptInjection {
}
}

public extension SourceFile {
func jsScript(with argument: String? = nil) throws -> WKUserScript {
let content = try getContent()
let formatted = String(format: content, argument ?? [])
return formatted.toJsScript()
}
}

internal extension String {
func toJsScript() -> WKUserScript {
WKUserScript(source: self, injectionTime: .atDocumentEnd, forMainFrameOnly: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ open class GutenbergWebSingleBlockViewController: UIViewController {
return []
}

/// Requests a set of CSS styles to be added to the web view when the editor has started loading.
/// - Returns: Array of all the styles to be added
open func onGutenbergLoadStyles() -> [WKUserScript] {
return []
}

/// Requests a set of JS Scripts to be added to the web view when Gutenberg has been initialized.
/// - Returns: Array of all the scripts to be added
open func onGutenbergReadyScripts() -> [WKUserScript] {
Expand Down Expand Up @@ -152,6 +158,7 @@ extension GutenbergWebSingleBlockViewController: WKNavigationDelegate {
evaluateJavascript(jsInjection.injectWPBarsCssScript)
evaluateJavascript(jsInjection.injectLocalStorageScript)
onPageLoadScripts().forEach(evaluateJavascript)
onGutenbergLoadStyles().forEach(evaluateJavascript)
}

public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
Expand All @@ -160,6 +167,7 @@ extension GutenbergWebSingleBlockViewController: WKNavigationDelegate {
evaluateJavascript(jsInjection.preventAutosavesScript)
evaluateJavascript(jsInjection.injectEditorCssScript)
evaluateJavascript(jsInjection.gutenbergObserverScript)
onGutenbergLoadStyles().forEach(evaluateJavascript)
}
}

Expand Down
17 changes: 16 additions & 1 deletion packages/react-native-bridge/ios/SourceFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,29 @@ public struct SourceFile {
self.bundle = bundle
}

func getContent() throws -> String {
public func getContent() throws -> String {
guard let path = bundle.path(forResource: name, ofType: type.rawValue) else {
throw SourceFileError.sourceFileNotFound("\(name).\(type)")
}
return try String(contentsOfFile: path, encoding: .utf8)
}
}

extension SourceFile {
public func jsScript(with argument: String? = nil) throws -> WKUserScript {
let content = try getContent()
let formatted = String(format: content, argument ?? [])

switch self.type {
case .css:
let injectCssScriptTemplate = "window.injectCss(`%@`)"
return String(format: injectCssScriptTemplate, formatted).toJsScript()
case .js, .json:
return formatted.toJsScript()
}
}
}

extension SourceFile {
static let editorStyle = SourceFile(name: "editor-style-overrides", type: .css)
static let wpBarsStyle = SourceFile(name: "wp-bar-override", type: .css)
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ For each user feature we should also add a importance categorization label to i

## Unreleased

- [*] Hide help button from Unsupported Block Editor. [#37221]
- [*] Add contrast checker to text-based blocks [#34902]

## 1.69.0
- [*] Give multi-line block names central alignment in inserter [#37185]
- [**] Fix empty line apperaing when splitting heading blocks on Android 12 [#37279]
Expand Down

0 comments on commit 0d5843d

Please sign in to comment.