Skip to content

Commit 1b630b9

Browse files
elliscwcalphatrl
authored andcommitted
feat: Android changes
1 parent 0d543bd commit 1b630b9

File tree

5 files changed

+57
-8
lines changed

5 files changed

+57
-8
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,11 @@ private static void buildSpannedFromShadowNode(
174174
new SetSpanOperation(start, end, new ReactForegroundColorSpan(textShadowNode.mColor)));
175175
}
176176
if (textShadowNode.mIsBackgroundColorSet) {
177-
ops.add(
178-
new SetSpanOperation(
179-
start, end, new ReactBackgroundColorSpan(textShadowNode.mBackgroundColor)));
177+
// @Taskadev1 Draw underline highlight
178+
ops.add(new SetSpanOperation(
179+
start,
180+
end,
181+
new UnderlineStyleSpan(textShadowNode.mBackgroundColor)));
180182
}
181183
float effectiveLetterSpacing = textAttributes.getEffectiveLetterSpacing();
182184
if (!Float.isNaN(effectiveLetterSpacing)

ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ private static void buildSpannableFromFragment(
136136
start, end, new ReactForegroundColorSpan(textAttributes.mColor)));
137137
}
138138
if (textAttributes.mIsBackgroundColorSet) {
139-
ops.add(
140-
new SetSpanOperation(
141-
start, end, new ReactBackgroundColorSpan(textAttributes.mBackgroundColor)));
142139
}
143140
if (!Float.isNaN(textAttributes.getLetterSpacing())) {
144141
ops.add(
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.facebook.react.views.text;
2+
3+
import android.text.TextPaint;
4+
import android.text.style.CharacterStyle;
5+
import java.lang.reflect.Method;
6+
7+
// @Taskadev1 Color underline highlight span
8+
public class UnderlineStyleSpan extends CharacterStyle implements ReactSpan {
9+
private final int mColor;
10+
11+
public UnderlineStyleSpan(final int color) {
12+
mColor = color;
13+
}
14+
15+
@Override
16+
public void updateDrawState(TextPaint textPaint) {
17+
try {
18+
final Method method = TextPaint.class.getMethod("setUnderlineText", Integer.TYPE, Float.TYPE);
19+
method.invoke(textPaint, mColor, 8.0f);
20+
} catch (final Exception e) {
21+
textPaint.setUnderlineText(true);
22+
}
23+
}
24+
}

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ public class ReactEditText extends AppCompatEditText
116116

117117
private final FabricViewStateManager mFabricViewStateManager = new FabricViewStateManager();
118118
protected boolean mDisableTextDiffing = false;
119-
119+
120+
// @Taskadev1 Editor input prop declaration
121+
protected boolean mIsEditorInput = false;
120122
protected boolean mIsSettingTextFromState = false;
121123

122124
private static final KeyListener sKeyListener = QwertyKeyListener.getInstanceForFullKeyboard();
@@ -384,6 +386,11 @@ public void setBlurOnSubmit(@Nullable Boolean blurOnSubmit) {
384386
public void setOnKeyPress(boolean onKeyPress) {
385387
mOnKeyPress = onKeyPress;
386388
}
389+
390+
// @Taskadev1 Set editor input prop
391+
public void setIsEditorInput(boolean isEditorInput) {
392+
mIsEditorInput = isEditorInput;
393+
}
387394

388395
public boolean getBlurOnSubmit() {
389396
if (mBlurOnSubmit == null) {

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,11 @@ public void setOnKeyPress(final ReactEditText view, boolean onKeyPress) {
454454
view.setOnKeyPress(onKeyPress);
455455
}
456456

457+
@ReactProp(name = "editorInput", defaultBoolean = false)
458+
public void setEditorInput(final ReactEditText view, boolean isEditorInput) {
459+
view.setIsEditorInput(isEditorInput);
460+
}
461+
457462
// Sets the letter spacing as an absolute point size.
458463
// This extra handling, on top of what ReactBaseTextShadowNode already does, is required for the
459464
// correct display of spacing in placeholder (hint) text.
@@ -988,6 +993,19 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
988993
return;
989994
}
990995

996+
// @Taskadev1 Prevent newline from being created
997+
if (mEditText.mIsEditorInput) {
998+
int mIndex = mEditText.getText().toString().lastIndexOf("\n");
999+
if(mIndex != -1) {
1000+
if (mEditText.getText().length() > 0) {
1001+
mEditText.setText(mEditText.getText().delete(mIndex , mIndex + 1));
1002+
}
1003+
mEditText.setSelection(mEditText.getText().length());
1004+
mEventDispatcher.dispatchEvent(new ReactTextInputKeyPressEvent(mEditText.getId(), "Enter"));
1005+
return;
1006+
}
1007+
}
1008+
9911009
if (mEditText.getFabricViewStateManager().hasStateWrapper()) {
9921010
// Fabric: communicate to C++ layer that text has changed
9931011
// We need to call `incrementAndGetEventCounter` here explicitly because this
@@ -1023,7 +1041,8 @@ public WritableMap getStateUpdate() {
10231041
}
10241042

10251043
@Override
1026-
public void afterTextChanged(Editable s) {}
1044+
public void afterTextChanged(Editable s) {
1045+
}
10271046
}
10281047

10291048
@Override

0 commit comments

Comments
 (0)