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

[RNMobile] Hide help button from UBE #37221

Merged
merged 12 commits into from
Jan 14, 2022
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();
twstokes marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -68,11 +68,13 @@ public extension SourceFile {
}
}

internal extension String {
public extension String {
twstokes marked this conversation as resolved.
Show resolved Hide resolved
func toJsScript() -> WKUserScript {
WKUserScript(source: self, injectionTime: .atDocumentEnd, forMainFrameOnly: false)
}
}

internal extension String {
func removingSpacesAndNewLines() -> String {
return replacingOccurrences(of: "\n", with: "").replacingOccurrences(of: " ", with: "")
}
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 page has started loading.
/// - Returns: Array of all the styles to be added
open func onGutenbergReadyStyles() -> [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)
onGutenbergReadyStyles().forEach(evaluateJavascript)
SiobhyB marked this conversation as resolved.
Show resolved Hide resolved
}

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)
onGutenbergReadyStyles().forEach(evaluateJavascript)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-bridge/ios/SourceFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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)")
}
Expand Down