-
Notifications
You must be signed in to change notification settings - Fork 58
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
Fix for Placeholder that is missing on heading block #739
Changes from all commits
f532315
0346d5b
bfe04df
d320301
e31652b
26a773b
46606b1
e9b0e38
4954937
55e4dba
5e1905f
d57b37f
2eb9671
8cda4bc
5ce3e12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,7 @@ module.exports = { | |
blockHolderFocused: { | ||
borderColor: 'gray', | ||
}, | ||
'wp-block-heading': { | ||
minHeight: 60, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import android.graphics.Typeface; | ||
import android.support.annotation.Nullable; | ||
import android.text.Editable; | ||
import android.text.TextUtils; | ||
import android.text.TextWatcher; | ||
import android.util.Log; | ||
import android.util.TypedValue; | ||
|
@@ -63,6 +64,8 @@ public class ReactAztecManager extends SimpleViewManager<ReactAztecText> { | |
|
||
private static final String TAG = "ReactAztecText"; | ||
|
||
private static final String BLOCK_TYPE_TAG_KEY = "tag"; | ||
|
||
public ReactAztecManager() { | ||
initializeFocusAndBlurCommandCodes(); | ||
} | ||
|
@@ -302,6 +305,13 @@ public void setColor(ReactAztecText view, @Nullable Integer color) { | |
view.setTextColor(newColor); | ||
} | ||
|
||
@ReactProp(name = "blockType") | ||
public void setBlockType(ReactAztecText view, ReadableMap inputMap) { | ||
if (inputMap.hasKey(BLOCK_TYPE_TAG_KEY)) { | ||
view.setTagName(inputMap.getString(BLOCK_TYPE_TAG_KEY)); | ||
} | ||
} | ||
|
||
@ReactProp(name = "placeholder") | ||
public void setPlaceholder(ReactAztecText view, @Nullable String placeholder) { | ||
view.setHint(placeholder); | ||
|
@@ -489,13 +499,14 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { | |
return; | ||
} | ||
|
||
int currentEventCount = mEditText.incrementAndGetEventCounter(); | ||
// The event that contains the event counter and updates it must be sent first. | ||
// TODO: t7936714 merge these events | ||
mEventDispatcher.dispatchEvent( | ||
new ReactTextChangedEvent( | ||
mEditText.getId(), | ||
mEditText.toHtml(false), | ||
mEditText.incrementAndGetEventCounter())); | ||
currentEventCount)); | ||
|
||
mEventDispatcher.dispatchEvent( | ||
new ReactTextInputEvent( | ||
|
@@ -504,6 +515,11 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { | |
oldText, | ||
start, | ||
start + before)); | ||
|
||
// Add the outer tags when the field was started empty, and only the first time the user types in it. | ||
if (mPreviousText.length() == 0 && currentEventCount == 1 && !TextUtils.isEmpty(mEditText.getTagName())) { | ||
mEditText.fromHtml('<' + mEditText.getTagName() + '>' + newText + "</" + mEditText.getTagName() + '>', false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there maybe some Util that we can use to generate the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not that i'm aware of, but in this case it's pretty simple the input string, that doesn't worth introduce a new function for it. We can use StringBuilder, but it's a very simple string. |
||
} | ||
} | ||
|
||
@Override | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you agree we can probably put
mPreviousText.isEmpty()
instad ofmPreviousText.length() == 0
also it would be good to put
currentEventCount == 1
in some constant with self-explaining name.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately there are cases where Aztec does only contain "non-breaking-space" char and
isEmpty
does return true, but the length is not0
. This is happening when you write and then remove all the content from the block.Will address the other comments instead.