Skip to content

Custom Textfield v1 #1

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

Open
wants to merge 3 commits into
base: 0.64-stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 7 additions & 4 deletions Libraries/Text/RCTTextAttributes.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ - (NSParagraphStyle *)effectiveParagraphStyle
attributes[NSForegroundColorAttributeName] = effectiveForegroundColor;
}

if (_backgroundColor || !isnan(_opacity)) {
attributes[NSBackgroundColorAttributeName] = self.effectiveBackgroundColor;
}

// Kerning
if (!isnan(_letterSpacing)) {
attributes[NSKernAttributeName] = @(_letterSpacing);
Expand Down Expand Up @@ -169,6 +165,13 @@ - (NSParagraphStyle *)effectiveParagraphStyle
attributes[NSUnderlineColorAttributeName] = _textDecorationColor ?: effectiveForegroundColor;
}

// @Taskadev1 Turn background color into underline highlight
if (_backgroundColor || !isnan(_opacity)) {
isTextDecorationEnabled = YES;
attributes[NSUnderlineColorAttributeName] = self.effectiveBackgroundColor;
attributes[NSUnderlineStyleAttributeName] = @(NSUnderlineStyleThick + NSUnderlineStyleThick);
}

// Shadow
if (!isnan(_textShadowRadius)) {
NSShadow *shadow = [NSShadow new];
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Text/TextInput/Multiline/RCTUITextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ NS_ASSUME_NONNULL_BEGIN
// The `caretHidden` property actually is not supported yet;
// it's declared here only to conform to the interface.
@property (nonatomic, assign) BOOL caretHidden;
//@Taskadev1 Editor input prop declaration
@property (nonatomic, assign) BOOL editorInput;

@property (nonatomic, strong, nullable) NSString *inputAccessoryViewID;

Expand Down
5 changes: 5 additions & 0 deletions Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ - (BOOL)textView:(__unused UITextView *)textView shouldChangeTextInRange:(NSRang
if (newText == nil) {
return NO;
}

//@Taskadev1 Prevent enter for editor input
if (_backedTextInputView.editorInput && [text isEqualToString:@"\n"]) {
return NO;
}

if ([newText isEqualToString:text]) {
_textDidChangeIsComing = YES;
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign) BOOL contextMenuHidden;
@property (nonatomic, assign, getter=isEditable) BOOL editable;
@property (nonatomic, assign) BOOL caretHidden;
//@Taskadev1 Editor input declaration
@property (nonatomic, assign) BOOL editorInput;
@property (nonatomic, assign) BOOL enablesReturnKeyAutomatically;
@property (nonatomic, assign) UITextFieldViewMode clearButtonMode;
@property (nonatomic, getter=isScrollEnabled) BOOL scrollEnabled;
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Text/TextInput/RCTBaseTextInputView.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign) BOOL selectTextOnFocus;
@property (nonatomic, assign) BOOL clearTextOnFocus;
@property (nonatomic, assign) BOOL secureTextEntry;
//@Taskadev1 Editor input prop declaration
@property (nonatomic, assign) BOOL editorInput;
@property (nonatomic, copy) RCTTextSelection *selection;
@property (nonatomic, strong, nullable) NSNumber *maxLength;
@property (nonatomic, copy, nullable) NSAttributedString *attributedText;
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Text/TextInput/RCTBaseTextInputViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ @implementation RCTBaseTextInputViewManager
RCT_REMAP_VIEW_PROPERTY(clearButtonMode, backedTextInputView.clearButtonMode, UITextFieldViewMode)
RCT_REMAP_VIEW_PROPERTY(scrollEnabled, backedTextInputView.scrollEnabled, BOOL)
RCT_REMAP_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BOOL)
//@Taskadev1 Editor input map property
RCT_REMAP_VIEW_PROPERTY(editorInput, backedTextInputView.editorInput, BOOL)
RCT_EXPORT_VIEW_PROPERTY(autoFocus, BOOL)
RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL)
RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ private static void buildSpannedFromShadowNode(
new SetSpanOperation(start, end, new ReactForegroundColorSpan(textShadowNode.mColor)));
}
if (textShadowNode.mIsBackgroundColorSet) {
ops.add(
new SetSpanOperation(
start, end, new ReactBackgroundColorSpan(textShadowNode.mBackgroundColor)));
// @Taskadev1 Draw underline highlight
ops.add(new SetSpanOperation(
start,
end,
new UnderlineStyleSpan(textShadowNode.mBackgroundColor)));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
float effectiveLetterSpacing = textAttributes.getEffectiveLetterSpacing();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ private static void buildSpannableFromFragment(
start, end, new ReactForegroundColorSpan(textAttributes.mColor)));
}
if (textAttributes.mIsBackgroundColorSet) {
ops.add(
new SetSpanOperation(
start, end, new ReactBackgroundColorSpan(textAttributes.mBackgroundColor)));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (!Float.isNaN(textAttributes.getLetterSpacing())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.facebook.react.views.text;

import android.text.TextPaint;
import android.text.style.CharacterStyle;
import java.lang.reflect.Method;

// @Taskadev1 Color underline highlight span
public class UnderlineStyleSpan extends CharacterStyle implements ReactSpan {
private final int mColor;

public UnderlineStyleSpan(final int color) {
mColor = color;
}

@Override
public void updateDrawState(TextPaint textPaint) {
try {
final Method method = TextPaint.class.getMethod("setUnderlineText", Integer.TYPE, Float.TYPE);
method.invoke(textPaint, mColor, 8.0f);
} catch (final Exception e) {
textPaint.setUnderlineText(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ public class ReactEditText extends AppCompatEditText

private final FabricViewStateManager mFabricViewStateManager = new FabricViewStateManager();
protected boolean mDisableTextDiffing = false;


// @Taskadev1 Editor input prop declaration
protected boolean mIsEditorInput = false;
protected boolean mIsSettingTextFromState = false;

private static final KeyListener sKeyListener = QwertyKeyListener.getInstanceForFullKeyboard();
Expand Down Expand Up @@ -371,6 +373,11 @@ public void setBlurOnSubmit(@Nullable Boolean blurOnSubmit) {
public void setOnKeyPress(boolean onKeyPress) {
mOnKeyPress = onKeyPress;
}

// @Taskadev1 Set editor input prop
public void setIsEditorInput(boolean isEditorInput) {
mIsEditorInput = isEditorInput;
}

public boolean getBlurOnSubmit() {
if (mBlurOnSubmit == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ public void setOnKeyPress(final ReactEditText view, boolean onKeyPress) {
view.setOnKeyPress(onKeyPress);
}

@ReactProp(name = "editorInput", defaultBoolean = false)
public void setEditorInput(final ReactEditText view, boolean isEditorInput) {
view.setIsEditorInput(isEditorInput);
}

// Sets the letter spacing as an absolute point size.
// This extra handling, on top of what ReactBaseTextShadowNode already does, is required for the
// correct display of spacing in placeholder (hint) text.
Expand Down Expand Up @@ -931,6 +936,19 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
return;
}

// @Taskadev1 Prevent newline from being created
if (mEditText.mIsEditorInput) {
int mIndex = mEditText.getText().toString().lastIndexOf("\n");
if(mIndex != -1) {
if (mEditText.getText().length() > 0) {
mEditText.setText(mEditText.getText().delete(mIndex , mIndex + 1));
}
mEditText.setSelection(mEditText.getText().length());
mEventDispatcher.dispatchEvent(new ReactTextInputKeyPressEvent(mEditText.getId(), "Enter"));
return;
}
}

if (mEditText.getFabricViewStateManager().hasStateWrapper()) {
// Fabric: communicate to C++ layer that text has changed
// We need to call `incrementAndGetEventCounter` here explicitly because this
Expand Down Expand Up @@ -962,7 +980,8 @@ public WritableMap getStateUpdate() {
}

@Override
public void afterTextChanged(Editable s) {}
public void afterTextChanged(Editable s) {
}
}

@Override
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7d972dd78e71cb708035d0b0e6c78591
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7a3e42c0716bea28b9274c27805f1608052f1b3a
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d10960aa9edbad21c17b14d838dc8811
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0f97708048f5d22df4bd1608b285f6bff45a38b7
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
408f0278a28a568ee1836afbe08df09c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
25fa0e5bee7c971bf6cbcd3fe2f3e5113d00e7df
110 changes: 110 additions & 0 deletions android/com/facebook/react/react-native/0.64.2/react-native-0.64.2.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.facebook.react</groupId>
<artifactId>react-native</artifactId>
<version>0.64.2</version>
<packaging>aar</packaging>
<name>ReactNative</name>
<description>A framework for building native apps with React</description>
<url>https://github.com/facebook/react-native</url>
<licenses>
<license>
<name>MIT License</name>
<url>https://github.com/facebook/react-native/blob/master/LICENSE</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>facebook</id>
<name>Facebook</name>
</developer>
</developers>
<scm>
<connection>scm:git:https://github.com/facebook/react-native.git</connection>
<developerConnection>scm:git:[email protected]:facebook/react-native.git</developerConnection>
<url>https://github.com/facebook/react-native.git</url>
</scm>
<dependencies>
<dependency>
<groupId>com.facebook.infer.annotation</groupId>
<artifactId>infer-annotation</artifactId>
<version>0.11.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.facebook.yoga</groupId>
<artifactId>proguard-annotations</artifactId>
<version>1.14.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>androidx.appcompat</groupId>
<artifactId>appcompat</artifactId>
<version>1.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>androidx.swiperefreshlayout</groupId>
<artifactId>swiperefreshlayout</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.facebook.fresco</groupId>
<artifactId>fresco</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.facebook.fresco</groupId>
<artifactId>imagepipeline-okhttp3</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.facebook.soloader</groupId>
<artifactId>soloader</artifactId>
<version>0.9.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.12.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-urlconnection</artifactId>
<version>3.12.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>1.17.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.facebook.fbjni</groupId>
<artifactId>fbjni-java-only</artifactId>
<version>0.0.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
389f95f84193a6364d9a78816107b307
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
48fcceb199d9f1fa6010c5e9e54d824cb21ce869
12 changes: 12 additions & 0 deletions android/com/facebook/react/react-native/maven-metadata.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.facebook.react</groupId>
<artifactId>react-native</artifactId>
<versioning>
<release>0.64.2</release>
<versions>
<version>0.64.2</version>
</versions>
<lastUpdated>20210623071329</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
72c2334c691fc833eeeb3cefc91ef0e3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7a378f12d05028a350eb47508b4a99d9216209f7