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

Activate preformat block on android platform #1615

Merged
merged 32 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ff2805c
Added missing preformat block implementation
marecar3 Nov 19, 2019
25bcd4d
update gb reference
marecar3 Nov 19, 2019
f4097fd
Make sure to call EndOfBufferMarkerAdder watcher when tag is PRE
marecar3 Nov 25, 2019
a03ee8b
Update release notes
marecar3 Nov 25, 2019
1d273e1
Add preformatted block to react aztec text enum
marecar3 Nov 25, 2019
e9885a6
update aztec version
marecar3 Nov 25, 2019
35ae490
Fixed bug - Adding newline when last character on a line is a space c…
marecar3 Nov 27, 2019
68b31c8
use shouldRedirectTextChangeCalls for each call
marecar3 Nov 28, 2019
ea9765c
Update release notes
marecar3 Nov 28, 2019
bb6b161
Update gb refernece
marecar3 Nov 28, 2019
c523cc9
Update gb reference
marecar3 Dec 2, 2019
b827ce1
Merge branch 'develop' into issue/1264_activate_pre_format_block_android
marecar3 Dec 2, 2019
16fb958
Merge branch 'develop' into issue/1264_activate_pre_format_block_android
marecar3 Dec 3, 2019
15015dd
Merge branch 'develop' into issue/1264_activate_pre_format_block_android
marecar3 Dec 4, 2019
9dfbd6c
Update gb ref
marecar3 Dec 4, 2019
1b9301b
Update gutenberg ref
marecar3 Dec 5, 2019
c3ff614
Update gb reference
marecar3 Dec 5, 2019
1796926
Removed unused import
marecar3 Dec 5, 2019
a665093
Split condition in a smaller parts to make it easier for reading
marecar3 Dec 5, 2019
a3ac7d1
Update gb reference
marecar3 Dec 5, 2019
52bb6f0
Merge branch 'develop' into issue/1264_activate_pre_format_block_android
marecar3 Dec 5, 2019
dd76dc6
Merge branch 'develop' into issue/1264_activate_pre_format_block_android
marecar3 Dec 6, 2019
f4e610a
Update gb reference
marecar3 Dec 6, 2019
d23a3cb
Merge branch 'develop' into issue/1264_activate_pre_format_block_android
marecar3 Dec 6, 2019
a3e6700
Add AndroidX NonNull annotation
marecar3 Dec 6, 2019
7e1db03
Update gb ref
marecar3 Dec 6, 2019
c964d00
Optimize isPreTag condition
marecar3 Dec 7, 2019
4b5fed3
Update aztec version to v1.3.36
marecar3 Dec 7, 2019
7ac2038
Update gb ref to master
marecar3 Dec 9, 2019
69468f2
Merge branch 'develop' into issue/1264_activate_pre_format_block_android
marecar3 Dec 9, 2019
ed582a6
Update gb ref
marecar3 Dec 9, 2019
ba942f7
Update gb ref
marecar3 Dec 9, 2019
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
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1.19.0
------
* [iOS] Fix crash dismissing bottom-sheet after device rotation.
* [Android] Add support for Preformatted block.

1.18.0
------
Expand Down
2 changes: 1 addition & 1 deletion gutenberg
Submodule gutenberg updated 39 files
+1 −0 lib/blocks.php
+3 −1 packages/block-editor/src/components/block-list/block.js
+14 −3 packages/block-editor/src/components/block-list/index.js
+41 −14 packages/block-editor/src/components/block-list/style.scss
+1 −1 packages/block-editor/src/components/link-control/test/__snapshots__/index.js.snap
+1 −1 packages/block-editor/src/components/media-placeholder/README.md
+2 −0 packages/block-editor/src/components/rich-text/index.js
+4 −3 packages/block-library/src/index.js
+1 −6 packages/block-library/src/index.native.js
+0 −3 packages/block-library/src/list/ordered-list-settings.native.js
+15 −0 packages/block-library/src/template-part/block.json
+3 −0 packages/block-library/src/template-part/edit.js
+18 −0 packages/block-library/src/template-part/index.js
+60 −0 packages/block-library/src/template-part/index.php
+18 −29 packages/components/src/isolated-event-container/index.js
+15 −0 packages/components/src/mobile/bottom-sheet/cell.native.js
+111 −232 packages/components/src/popover/index.js
+24 −13 packages/components/src/popover/style.scss
+8 −4 packages/components/src/popover/test/__snapshots__/index.js.snap
+0 −23 packages/components/src/popover/test/utils.js
+1 −4 packages/components/src/popover/utils.js
+2 −2 packages/components/src/tooltip/style.scss
+1 −0 packages/e2e-tests/fixtures/blocks/core__template-part.html
+13 −0 packages/e2e-tests/fixtures/blocks/core__template-part.json
+12 −0 packages/e2e-tests/fixtures/blocks/core__template-part.parsed.json
+1 −0 packages/e2e-tests/fixtures/blocks/core__template-part.serialized.html
+18 −0 packages/e2e-tests/mu-plugins/normalize-theme.php
+2 −2 packages/e2e-tests/specs/editor/blocks/__snapshots__/heading.test.js.snap
+4 −4 packages/e2e-tests/specs/editor/blocks/heading.test.js
+1 −1 packages/e2e-tests/specs/editor/various/editor-modes.test.js
+3 −3 packages/e2e-tests/specs/editor/various/font-size-picker.test.js
+35 −0 packages/e2e-tests/specs/editor/various/multi-block-selection.test.js
+55 −19 packages/editor/src/components/post-featured-image/index.js
+11 −1 packages/editor/src/components/post-featured-image/style.scss
+15 −15 packages/nux/src/components/dot-tip/style.scss
+23 −3 packages/rich-text/src/component/index.native.js
+6 −0 packages/rich-text/src/component/test/index.native.js
+2 −28 storybook/test/__snapshots__/index.js.snap
+1 −1 test/integration/full-content/server-registered.json
2 changes: 1 addition & 1 deletion react-native-aztec/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
wordpressUtilsVersion = '1.22'
espressoVersion = '3.0.1'

aztecVersion = 'v1.3.34'
aztecVersion = '03dd2332c1deb7c26dac82a7638121ca7b4ca0fd'
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Looper;
Expand All @@ -23,11 +24,13 @@
import com.facebook.react.views.textinput.ReactTextInputLocalData;
import com.facebook.react.views.textinput.ScrollWatcher;

import org.jetbrains.annotations.NotNull;
hypest marked this conversation as resolved.
Show resolved Hide resolved
import org.wordpress.aztec.AztecText;
import org.wordpress.aztec.AztecTextFormat;
import org.wordpress.aztec.ITextFormat;
import org.wordpress.aztec.plugins.IAztecPlugin;
import org.wordpress.aztec.plugins.IToolbarButton;
import org.wordpress.aztec.watchers.EndOfBufferMarkerAdder;
hypest marked this conversation as resolved.
Show resolved Hide resolved

import java.util.ArrayList;
import java.util.LinkedList;
Expand All @@ -39,6 +42,8 @@

public class ReactAztecText extends AztecText {

private static final String PRE_TAG = "pre";

private final InputMethodManager mInputMethodManager;
// This flag is set to true when we set the text of the EditText explicitly. In that case, no
// *TextChanged events should be triggered. This is less expensive than removing the text
Expand Down Expand Up @@ -166,6 +171,16 @@ public boolean onTextContextMenuItem(int id) {
return super.onTextContextMenuItem(id);
}

@Override
public float getPreformatBackgroundAlpha(@NotNull TypedArray styles) {
return 0;
}

@Override
public boolean shouldSkipTidying() {
return isPreTag();
}

// VisibleForTesting from {@link TextInputEventsTestCase}.
public void requestFocusFromJS() {
mIsJSSettingFocus = true;
Expand Down Expand Up @@ -501,11 +516,18 @@ protected boolean isEnterPressedUnderway() {
/**
* This class will redirect *TextChanged calls to the listeners only in the case where the text
* is changed by the user, and not explicitly set by JS.
*
* Update:
* There is a special case when block is preformatted.
* In that case we want to propagate TextWatcher method calls even if text is set from JS.
* Otherwise, couple of bugs will be introduced
* bug 1# https://github.com/wordpress-mobile/AztecEditor-Android/pull/869#issuecomment-552864686
* bug 2# https://github.com/wordpress-mobile/gutenberg-mobile/pull/1615#pullrequestreview-323274540
*/
private class TextWatcherDelegator implements TextWatcher {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if (!mIsSettingTextFromJS && mListeners != null) {
if (shouldRedirectTextChangeCalls()) {
for (TextWatcher listener : mListeners) {
listener.beforeTextChanged(s, start, count, after);
}
Expand All @@ -514,7 +536,7 @@ public void beforeTextChanged(CharSequence s, int start, int count, int after) {

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (!mIsSettingTextFromJS && mListeners != null) {
if (shouldRedirectTextChangeCalls()) {
for (TextWatcher listener : mListeners) {
listener.onTextChanged(s, start, before, count);
}
Expand All @@ -525,11 +547,19 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {

@Override
public void afterTextChanged(Editable s) {
if (!mIsSettingTextFromJS && mListeners != null) {
if (shouldRedirectTextChangeCalls()) {
for (TextWatcher listener : mListeners) {
listener.afterTextChanged(s);
}
}
}
}

private boolean shouldRedirectTextChangeCalls() {
hypest marked this conversation as resolved.
Show resolved Hide resolved
return (!mIsSettingTextFromJS || isPreTag()) && mListeners != null;
hypest marked this conversation as resolved.
Show resolved Hide resolved
}

private boolean isPreTag() {
return !TextUtils.isEmpty(mTagName) && mTagName.equals(PRE_TAG);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just a nice-to-have, but I think this could be shortened to be a bit more clear by just reversing the equals check so you get a null and empty check for free since PRE_TAG is a constant:

return PRE_TAG.equals(mTagName);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Fixed.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public enum ReactAztecTextFormatEnum {
H3("h3", AztecTextFormat.FORMAT_HEADING_3),
H4("h4", AztecTextFormat.FORMAT_HEADING_4),
H5("h5", AztecTextFormat.FORMAT_HEADING_5),
H6("h6", AztecTextFormat.FORMAT_HEADING_6);
H6("h6", AztecTextFormat.FORMAT_HEADING_6),
PRE("pre", AztecTextFormat.FORMAT_PREFORMAT);

private final String mTag;
private final AztecTextFormat mAztecTextFormat;
Expand Down